Skip to content

Commit

Permalink
Rename Output to PlatformOutput
Browse files Browse the repository at this point in the history
  • Loading branch information
emilk committed Feb 22, 2022
1 parent 01c702a commit efd7371
Show file tree
Hide file tree
Showing 15 changed files with 64 additions and 51 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ NOTE: [`epaint`](epaint/CHANGELOG.md), [`eframe`](eframe/CHANGELOG.md), [`egui_w
* Renamed `Ui::visible` to `Ui::is_visible`.
* Split `Event::Text` into `Event::Text` and `Event::Paste` ([#1058](https://github.com/emilk/egui/pull/1058)).
* For integrations:
* `FontImage` has been replaced by `TexturesDelta` (found in `Output`), describing what textures were loaded and freed each frame ([#1110](https://github.com/emilk/egui/pull/1110)).
* `Output` has now been renamed `PlatformOutput` and `Context::run` now returns the new `FullOutput` ([#1292](https://github.com/emilk/egui/pull/1292)).
* `FontImage` has been replaced by `TexturesDelta` (found in `FullOutput`), describing what textures were loaded and freed each frame ([#1110](https://github.com/emilk/egui/pull/1110)).
* The painter must support partial texture updates ([#1149](https://github.com/emilk/egui/pull/1149)).
* Added `RawInput::max_texture_side` which should be filled in with e.g. `GL_MAX_TEXTURE_SIZE` ([#1154](https://github.com/emilk/egui/pull/1154)).
* Replaced `Style::body_text_style` with more generic `Style::text_styles` ([#1154](https://github.com/emilk/egui/pull/1154)).
Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -208,12 +208,12 @@ loop {

my_integration.paint(&full_output.textures_delta, clipped_meshes);

let output = full_output.output;
my_integration.set_cursor_icon(output.cursor_icon);
if !output.copied_text.is_empty() {
my_integration.set_clipboard_text(output.copied_text);
let platform_output = full_output.platform_output;
my_integration.set_cursor_icon(platform_output.cursor_icon);
if !platform_output.copied_text.is_empty() {
my_integration.set_clipboard_text(platform_output.copied_text);
}
// See `egui::FullOutput` for more
// See `egui::FullOutput` and `egui::PlatformOutput` for more
}
```

Expand Down
6 changes: 3 additions & 3 deletions egui-winit/src/epi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -348,13 +348,13 @@ impl EpiIntegration {
full_output
}

pub fn handle_egui_output(
pub fn handle_platform_output(
&mut self,
window: &winit::window::Window,
egui_output: egui::Output,
platform_output: egui::PlatformOutput,
) {
self.egui_winit
.handle_egui_output(window, &self.egui_ctx, egui_output);
.handle_platform_output(window, &self.egui_ctx, platform_output);
}

pub fn maybe_autosave(&mut self, window: &winit::window::Window) {
Expand Down
11 changes: 6 additions & 5 deletions egui-winit/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -514,24 +514,25 @@ impl State {
/// * open any clicked urls
/// * update the IME
/// *
pub fn handle_egui_output(
pub fn handle_platform_output(
&mut self,
window: &winit::window::Window,
egui_ctx: &egui::Context,
output: egui::Output,
platform_output: egui::PlatformOutput,
) {
if egui_ctx.options().screen_reader {
self.screen_reader.speak(&output.events_description());
self.screen_reader
.speak(&platform_output.events_description());
}

let egui::Output {
let egui::PlatformOutput {
cursor_icon,
open_url,
copied_text,
events: _, // handled above
mutable_text_under_cursor: _, // only used in egui_web
text_cursor_pos,
} = output;
} = platform_output;

self.current_pixels_per_point = egui_ctx.pixels_per_point(); // someone can have changed it to scale the UI

Expand Down
21 changes: 13 additions & 8 deletions egui/src/context.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// #![warn(missing_docs)]

use crate::{
animation_manager::AnimationManager, data::output::Output, frame_state::FrameState,
animation_manager::AnimationManager, data::output::PlatformOutput, frame_state::FrameState,
input_state::*, layers::GraphicLayers, memory::Options, output::FullOutput, TextureHandle, *,
};
use epaint::{mutex::*, stats::*, text::Fonts, TessellationOptions, *};
Expand Down Expand Up @@ -42,7 +42,7 @@ struct ContextImpl {

// The output of a frame:
graphics: GraphicLayers,
output: Output,
output: PlatformOutput,

paint_stats: PaintStats,

Expand Down Expand Up @@ -108,7 +108,7 @@ impl ContextImpl {
/// Your handle to egui.
///
/// This is the first thing you need when working with egui.
/// Contains the [`InputState`], [`Memory`], [`Output`], and more.
/// Contains the [`InputState`], [`Memory`], [`PlatformOutput`], and more.
///
/// [`Context`] is cheap to clone, and any clones refers to the same mutable data
/// ([`Context`] uses refcounting internally).
Expand All @@ -121,7 +121,7 @@ impl ContextImpl {
/// # Example:
///
/// ``` no_run
/// # fn handle_output(_: egui::Output) {}
/// # fn handle_platform_output(_: egui::PlatformOutput) {}
/// # fn paint(textures_detla: egui::TexturesDelta, _: Vec<egui::ClippedMesh>) {}
/// let mut ctx = egui::Context::default();
///
Expand All @@ -136,7 +136,7 @@ impl ContextImpl {
/// }
/// });
/// });
/// handle_output(full_output.output);
/// handle_platform_output(full_output.platform_output);
/// let clipped_meshes = ctx.tessellate(full_output.shapes); // create triangles to paint
/// paint(full_output.textures_delta, clipped_meshes);
/// }
Expand Down Expand Up @@ -459,8 +459,13 @@ impl Context {
}

/// What egui outputs each frame.
///
/// ```
/// # let mut ctx = egui::Context::default();
/// ctx.output().cursor_icon = egui::CursorIcon::Progress;
/// ```
#[inline]
pub fn output(&self) -> RwLockWriteGuard<'_, Output> {
pub fn output(&self) -> RwLockWriteGuard<'_, PlatformOutput> {
RwLockWriteGuard::map(self.write(), |c| &mut c.output)
}

Expand Down Expand Up @@ -740,7 +745,7 @@ impl Context {
textures_delta = ctx_impl.tex_manager.0.write().take_delta();
};

let output: Output = std::mem::take(&mut self.output());
let platform_output: PlatformOutput = std::mem::take(&mut self.output());

let needs_repaint = if self.read().repaint_requests > 0 {
self.write().repaint_requests -= 1;
Expand All @@ -752,7 +757,7 @@ impl Context {
let shapes = self.drain_paint_lists();

FullOutput {
output,
platform_output,
needs_repaint,
textures_delta,
shapes,
Expand Down
16 changes: 9 additions & 7 deletions egui/src/data/output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

use crate::WidgetType;

/// What egui emits each frame.
/// What egui emits each frame from [`crate::Context::run`].
///
/// The backend should use this.
#[derive(Clone, Default, PartialEq)]
pub struct FullOutput {
/// Non-rendering related output.
pub output: Output,
pub platform_output: PlatformOutput,

/// If `true`, egui is requesting immediate repaint (i.e. on the next frame).
///
Expand All @@ -31,13 +31,13 @@ impl FullOutput {
/// Add on new output.
pub fn append(&mut self, newer: Self) {
let Self {
output,
platform_output,
needs_repaint,
textures_delta,
shapes,
} = newer;

self.output.append(output);
self.platform_output.append(platform_output);
self.needs_repaint = needs_repaint; // if the last frame doesn't need a repaint, then we don't need to repaint
self.textures_delta.append(textures_delta);
self.shapes = shapes; // Only paint the latest
Expand All @@ -46,10 +46,12 @@ impl FullOutput {

/// The non-rendering part of what egui emits each frame.
///
/// You can access (and modify) this with [`crate::Context::output`].
///
/// The backend should use this.
#[derive(Clone, Default, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
pub struct Output {
pub struct PlatformOutput {
/// Set the cursor to this icon.
pub cursor_icon: CursorIcon,

Expand All @@ -72,7 +74,7 @@ pub struct Output {
pub text_cursor_pos: Option<crate::Pos2>,
}

impl Output {
impl PlatformOutput {
/// Open the given url in a web browser.
/// If egui is running in a browser, the same tab will be reused.
pub fn open_url(&mut self, url: impl ToString) {
Expand Down Expand Up @@ -157,7 +159,7 @@ impl OpenUrl {

/// A mouse cursor icon.
///
/// egui emits a [`CursorIcon`] in [`Output`] each frame as a request to the integration.
/// egui emits a [`CursorIcon`] in [`PlatformOutput`] each frame as a request to the integration.
///
/// Loosely based on <https://developer.mozilla.org/en-US/docs/Web/CSS/cursor>.
#[derive(Clone, Copy, Debug, PartialEq)]
Expand Down
6 changes: 3 additions & 3 deletions egui/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@
//! To write your own integration for egui you need to do this:
//!
//! ``` no_run
//! # fn handle_output(_: egui::Output) {}
//! # fn handle_platform_output(_: egui::PlatformOutput) {}
//! # fn gather_input() -> egui::RawInput { egui::RawInput::default() }
//! # fn paint(textures_detla: egui::TexturesDelta, _: Vec<egui::ClippedMesh>) {}
//! let mut ctx = egui::Context::default();
Expand All @@ -127,7 +127,7 @@
//! }
//! });
//! });
//! handle_output(full_output.output);
//! handle_platform_output(full_output.platform_output);
//! let clipped_meshes = ctx.tessellate(full_output.shapes); // create triangles to paint
//! paint(full_output.textures_delta, clipped_meshes);
//! }
Expand Down Expand Up @@ -402,7 +402,7 @@ pub use {
context::Context,
data::{
input::*,
output::{self, CursorIcon, FullOutput, Output, WidgetInfo},
output::{self, CursorIcon, FullOutput, PlatformOutput, WidgetInfo},
},
grid::Grid,
id::{Id, IdMap},
Expand Down
2 changes: 1 addition & 1 deletion egui/src/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ pub struct Options {
pub tessellation_options: epaint::TessellationOptions,

/// This does not at all change the behavior of egui,
/// but is a signal to any backend that we want the [`crate::Output::events`] read out loud.
/// but is a signal to any backend that we want the [`crate::PlatformOutput::events`] read out loud.
/// Screen readers is an experimental feature of egui, and not supported on all platforms.
pub screen_reader: bool,

Expand Down
4 changes: 2 additions & 2 deletions egui/src/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -366,10 +366,10 @@ impl Ui {
self.ctx().data()
}

/// The [`Output`] of the [`Context`] associated with this ui.
/// The [`PlatformOutput`] of the [`Context`] associated with this ui.
/// Equivalent to `.ctx().output()`.
#[inline]
pub fn output(&self) -> RwLockWriteGuard<'_, Output> {
pub fn output(&self) -> RwLockWriteGuard<'_, PlatformOutput> {
self.ctx().output()
}

Expand Down
4 changes: 2 additions & 2 deletions egui_glium/src/epi_backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,13 @@ pub fn run(app: Box<dyn epi::App>, native_options: &epi::NativeOptions) -> ! {
}

let egui::FullOutput {
output,
platform_output,
needs_repaint,
textures_delta,
shapes,
} = integration.update(display.gl_window().window());

integration.handle_egui_output(display.gl_window().window(), output);
integration.handle_platform_output(display.gl_window().window(), platform_output);

let clipped_meshes = integration.egui_ctx.tessellate(shapes);

Expand Down
9 changes: 6 additions & 3 deletions egui_glium/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,14 +142,17 @@ impl EguiGlium {
.egui_winit
.take_egui_input(display.gl_window().window());
let egui::FullOutput {
output,
platform_output,
needs_repaint,
textures_delta,
shapes,
} = self.egui_ctx.run(raw_input, run_ui);

self.egui_winit
.handle_egui_output(display.gl_window().window(), &self.egui_ctx, output);
self.egui_winit.handle_platform_output(
display.gl_window().window(),
&self.egui_ctx,
platform_output,
);

self.shapes = shapes;
self.textures_delta.append(textures_delta);
Expand Down
4 changes: 2 additions & 2 deletions egui_glow/src/epi_backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,13 @@ pub fn run(app: Box<dyn epi::App>, native_options: &epi::NativeOptions) -> ! {
}

let egui::FullOutput {
output,
platform_output,
needs_repaint,
textures_delta,
shapes,
} = integration.update(gl_window.window());

integration.handle_egui_output(gl_window.window(), output);
integration.handle_platform_output(gl_window.window(), platform_output);

let clipped_meshes = integration.egui_ctx.tessellate(shapes);

Expand Down
4 changes: 2 additions & 2 deletions egui_glow/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,14 +157,14 @@ impl EguiGlow {
) -> bool {
let raw_input = self.egui_winit.take_egui_input(window);
let egui::FullOutput {
output,
platform_output,
needs_repaint,
textures_delta,
shapes,
} = self.egui_ctx.run(raw_input, run_ui);

self.egui_winit
.handle_egui_output(window, &self.egui_ctx, output);
.handle_platform_output(window, &self.egui_ctx, platform_output);

self.shapes = shapes;
self.textures_delta.append(textures_delta);
Expand Down
13 changes: 7 additions & 6 deletions egui_web/src/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -271,13 +271,13 @@ impl AppRunner {
self.app.update(egui_ctx, &self.frame);
});
let egui::FullOutput {
output,
platform_output,
needs_repaint,
textures_delta,
shapes,
} = full_output;

self.handle_egui_output(output);
self.handle_platform_output(platform_output);
self.textures_delta.append(textures_delta);
let clipped_meshes = self.egui_ctx.tessellate(shapes);

Expand Down Expand Up @@ -311,19 +311,20 @@ impl AppRunner {
Ok(())
}

fn handle_egui_output(&mut self, output: egui::Output) {
fn handle_platform_output(&mut self, platform_output: egui::PlatformOutput) {
if self.egui_ctx.options().screen_reader {
self.screen_reader.speak(&output.events_description());
self.screen_reader
.speak(&platform_output.events_description());
}

let egui::Output {
let egui::PlatformOutput {
cursor_icon,
open_url,
copied_text,
events: _, // already handled
mutable_text_under_cursor,
text_cursor_pos,
} = output;
} = platform_output;

set_cursor_icon(cursor_icon);
if let Some(open) = open_url {
Expand Down
2 changes: 1 addition & 1 deletion epaint/src/textures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ pub struct TexturesDelta {
/// New or changed textures. Apply before painting.
pub set: AHashMap<TextureId, ImageDelta>,

/// Texture to free after painting.
/// Textures to free after painting.
pub free: Vec<TextureId>,
}

Expand Down

0 comments on commit efd7371

Please sign in to comment.