mirror of
https://github.com/emilk/egui.git
synced 2026-06-27 15:13:12 -04:00
Now App::update will be responsabile for what viewport will be drawned and its content
A big refactoring was needed
This commit is contained in:
@@ -9,6 +9,7 @@
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
mod icon_data;
|
||||
|
||||
use egui::ViewportRender;
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
pub use icon_data::IconData;
|
||||
|
||||
@@ -112,7 +113,12 @@ pub trait App {
|
||||
/// The [`egui::Context`] can be cloned and saved if you like.
|
||||
///
|
||||
/// To force a repaint, call [`egui::Context::request_repaint`] at any time (e.g. from another thread).
|
||||
fn update(&mut self, ctx: &egui::Context, frame: &mut Frame);
|
||||
fn update(
|
||||
&mut self,
|
||||
ctx: &egui::Context,
|
||||
frame: &mut Frame,
|
||||
render_function: Option<&ViewportRender>,
|
||||
);
|
||||
|
||||
/// Get a handle to the app.
|
||||
///
|
||||
@@ -774,6 +780,22 @@ impl Frame {
|
||||
self.info.clone()
|
||||
}
|
||||
|
||||
/// If this is the main window will return true!
|
||||
/// When is a single window mode will always return true!
|
||||
pub fn is_main_window(&self) -> bool {
|
||||
self.info.viewport_id == 0
|
||||
}
|
||||
|
||||
/// Returns the current viewport id
|
||||
pub fn viewport_id(&self) -> u64 {
|
||||
self.info.viewport_id
|
||||
}
|
||||
|
||||
/// Returns the current viewport parent id
|
||||
pub fn parent_viewport_id(&self) -> u64 {
|
||||
self.info.parent_viewport
|
||||
}
|
||||
|
||||
/// A place where you can store custom data in a way that persists when you restart the app.
|
||||
pub fn storage(&self) -> Option<&dyn Storage> {
|
||||
self.storage.as_deref()
|
||||
@@ -1125,6 +1147,9 @@ pub struct IntegrationInfo {
|
||||
/// The OS native pixels-per-point
|
||||
pub native_pixels_per_point: Option<f32>,
|
||||
|
||||
pub viewport_id: u64,
|
||||
pub parent_viewport: u64,
|
||||
|
||||
/// The position and size of the native window.
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
pub window_info: WindowInfo,
|
||||
|
||||
@@ -273,8 +273,17 @@ pub fn run_simple_native(
|
||||
update_fun: U,
|
||||
}
|
||||
impl<U: FnMut(&egui::Context, &mut Frame)> App for SimpleApp<U> {
|
||||
fn update(&mut self, ctx: &egui::Context, frame: &mut Frame) {
|
||||
(self.update_fun)(ctx, frame);
|
||||
fn update(
|
||||
&mut self,
|
||||
ctx: &egui::Context,
|
||||
frame: &mut Frame,
|
||||
render_function: Option<&(dyn Fn(&egui::Context, u64, u64) + Send + Sync)>,
|
||||
) {
|
||||
if frame.is_main_window() {
|
||||
(self.update_fun)(ctx, frame);
|
||||
} else if let Some(render_function) = render_function {
|
||||
render_function(ctx, frame.viewport_id(), frame.parent_viewport_id())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -369,6 +369,8 @@ impl EpiIntegration {
|
||||
cpu_usage: None,
|
||||
native_pixels_per_point: Some(native_pixels_per_point),
|
||||
window_info: read_window_info(window, egui_ctx.pixels_per_point(), &window_state),
|
||||
viewport_id: 0,
|
||||
parent_viewport: 0,
|
||||
},
|
||||
output: epi::backend::AppOutput {
|
||||
visible: Some(true),
|
||||
@@ -509,6 +511,8 @@ impl EpiIntegration {
|
||||
read_window_info(window, self.egui_ctx.pixels_per_point(), &self.window_state);
|
||||
let mut raw_input = egui_winit.take_egui_input(window);
|
||||
raw_input.time = Some(self.beagining.elapsed().as_secs_f64());
|
||||
self.frame.info.viewport_id = viewport_id;
|
||||
self.frame.info.parent_viewport = parent_id;
|
||||
|
||||
// Run user code:
|
||||
let full_output = self.egui_ctx.run(raw_input, |egui_ctx| {
|
||||
@@ -516,7 +520,7 @@ impl EpiIntegration {
|
||||
if let Some(render) = render {
|
||||
(render.as_ref())(egui_ctx, viewport_id, parent_id)
|
||||
} else {
|
||||
app.update(egui_ctx, &mut self.frame);
|
||||
app.update(egui_ctx, &mut self.frame, render.as_ref().map(|r| &***r));
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -546,6 +546,9 @@ pub enum WidgetType {
|
||||
Other,
|
||||
}
|
||||
|
||||
/// This is used to render a viewport
|
||||
pub type ViewportRender = dyn Fn(&Context, u64, u64) + Sync + Send;
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
/// For use in tests; especially doctests.
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use std::sync::Arc;
|
||||
|
||||
use eframe::egui_glow;
|
||||
use egui::mutex::Mutex;
|
||||
use egui::{mutex::Mutex, ViewportRender};
|
||||
use egui_glow::glow;
|
||||
|
||||
pub struct Custom3d {
|
||||
@@ -21,7 +21,16 @@ impl Custom3d {
|
||||
}
|
||||
|
||||
impl eframe::App for Custom3d {
|
||||
fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {
|
||||
fn update(
|
||||
&mut self,
|
||||
ctx: &egui::Context,
|
||||
frame: &mut eframe::Frame,
|
||||
render: Option<&ViewportRender>,
|
||||
) {
|
||||
if let Some(render) = render {
|
||||
render(ctx, frame.viewport_id(), frame.parent_viewport_id());
|
||||
return;
|
||||
}
|
||||
egui::CentralPanel::default().show(ctx, |ui| {
|
||||
egui::ScrollArea::both()
|
||||
.auto_shrink([false; 2])
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
use egui::ViewportRender;
|
||||
use egui_demo_lib::is_mobile;
|
||||
|
||||
#[cfg(feature = "glow")]
|
||||
@@ -14,7 +15,16 @@ struct EasyMarkApp {
|
||||
}
|
||||
|
||||
impl eframe::App for EasyMarkApp {
|
||||
fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {
|
||||
fn update(
|
||||
&mut self,
|
||||
ctx: &egui::Context,
|
||||
frame: &mut eframe::Frame,
|
||||
render: Option<&ViewportRender>,
|
||||
) {
|
||||
if let Some(render) = render {
|
||||
render(ctx, frame.viewport_id(), frame.parent_viewport_id());
|
||||
return;
|
||||
}
|
||||
self.editor.panels(ctx);
|
||||
}
|
||||
}
|
||||
@@ -28,7 +38,16 @@ pub struct DemoApp {
|
||||
}
|
||||
|
||||
impl eframe::App for DemoApp {
|
||||
fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {
|
||||
fn update(
|
||||
&mut self,
|
||||
ctx: &egui::Context,
|
||||
frame: &mut eframe::Frame,
|
||||
render: Option<&ViewportRender>,
|
||||
) {
|
||||
if let Some(render) = render {
|
||||
render(ctx, frame.viewport_id(), frame.parent_viewport_id());
|
||||
return;
|
||||
}
|
||||
self.demo_windows.ui(ctx);
|
||||
}
|
||||
}
|
||||
@@ -42,7 +61,16 @@ pub struct FractalClockApp {
|
||||
}
|
||||
|
||||
impl eframe::App for FractalClockApp {
|
||||
fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {
|
||||
fn update(
|
||||
&mut self,
|
||||
ctx: &egui::Context,
|
||||
frame: &mut eframe::Frame,
|
||||
render: Option<&ViewportRender>,
|
||||
) {
|
||||
if let Some(render) = render {
|
||||
render(ctx, frame.viewport_id(), frame.parent_viewport_id());
|
||||
return;
|
||||
}
|
||||
egui::CentralPanel::default()
|
||||
.frame(egui::Frame::dark_canvas(&ctx.style()))
|
||||
.show(ctx, |ui| {
|
||||
@@ -61,7 +89,16 @@ pub struct ColorTestApp {
|
||||
}
|
||||
|
||||
impl eframe::App for ColorTestApp {
|
||||
fn update(&mut self, ctx: &egui::Context, frame: &mut eframe::Frame) {
|
||||
fn update(
|
||||
&mut self,
|
||||
ctx: &egui::Context,
|
||||
frame: &mut eframe::Frame,
|
||||
render: Option<&ViewportRender>,
|
||||
) {
|
||||
if let Some(render) = render {
|
||||
render(ctx, frame.viewport_id(), frame.parent_viewport_id());
|
||||
return;
|
||||
}
|
||||
egui::CentralPanel::default().show(ctx, |ui| {
|
||||
if frame.is_web() {
|
||||
ui.label(
|
||||
@@ -227,7 +264,16 @@ impl eframe::App for WrapApp {
|
||||
visuals.panel_fill.to_normalized_gamma_f32()
|
||||
}
|
||||
|
||||
fn update(&mut self, ctx: &egui::Context, frame: &mut eframe::Frame) {
|
||||
fn update(
|
||||
&mut self,
|
||||
ctx: &egui::Context,
|
||||
frame: &mut eframe::Frame,
|
||||
render: Option<&ViewportRender>,
|
||||
) {
|
||||
if let Some(render) = render {
|
||||
render(ctx, frame.viewport_id(), frame.parent_viewport_id());
|
||||
return;
|
||||
}
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
if let Some(anchor) = frame.info().web_info.location.hash.strip_prefix('#') {
|
||||
let anchor = Anchor::all().into_iter().find(|x| x.to_string() == anchor);
|
||||
@@ -255,7 +301,7 @@ impl eframe::App for WrapApp {
|
||||
self.backend_panel(ctx, frame);
|
||||
}
|
||||
|
||||
self.show_selected_app(ctx, frame);
|
||||
self.show_selected_app(ctx, frame, render);
|
||||
|
||||
self.state.backend_panel.end_of_frame(ctx);
|
||||
|
||||
@@ -322,11 +368,16 @@ impl WrapApp {
|
||||
});
|
||||
}
|
||||
|
||||
fn show_selected_app(&mut self, ctx: &egui::Context, frame: &mut eframe::Frame) {
|
||||
fn show_selected_app(
|
||||
&mut self,
|
||||
ctx: &egui::Context,
|
||||
frame: &mut eframe::Frame,
|
||||
render: Option<&ViewportRender>,
|
||||
) {
|
||||
let selected_anchor = self.state.selected_anchor;
|
||||
for (_name, anchor, app) in self.apps_iter_mut() {
|
||||
if anchor == selected_anchor || ctx.memory(|mem| mem.everything_is_visible()) {
|
||||
app.update(ctx, frame);
|
||||
app.update(ctx, frame, render);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
use std::sync::{Arc, RwLock};
|
||||
|
||||
use eframe::egui;
|
||||
use eframe::egui::{self, ViewportRender};
|
||||
|
||||
fn main() -> Result<(), eframe::Error> {
|
||||
env_logger::init(); // Log to stderr (if you run with `RUST_LOG=debug`).
|
||||
@@ -34,7 +34,16 @@ impl eframe::App for MyApp {
|
||||
self.data.read().unwrap().allowed_to_close
|
||||
}
|
||||
|
||||
fn update(&mut self, ctx: &egui::Context, frame: &mut eframe::Frame) {
|
||||
fn update(
|
||||
&mut self,
|
||||
ctx: &egui::Context,
|
||||
frame: &mut eframe::Frame,
|
||||
render: Option<&ViewportRender>,
|
||||
) {
|
||||
if let Some(render) = render {
|
||||
render(ctx, frame.viewport_id(), frame.parent_viewport_id());
|
||||
return;
|
||||
}
|
||||
egui::CentralPanel::default().show(ctx, |ui| {
|
||||
ui.heading("Try to close the window");
|
||||
});
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")] // hide console window on Windows in release
|
||||
#![allow(unsafe_code)]
|
||||
|
||||
use eframe::egui;
|
||||
use eframe::egui::{self, ViewportRender};
|
||||
|
||||
use egui::mutex::Mutex;
|
||||
use std::sync::Arc;
|
||||
@@ -41,7 +41,16 @@ impl MyApp {
|
||||
}
|
||||
|
||||
impl eframe::App for MyApp {
|
||||
fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {
|
||||
fn update(
|
||||
&mut self,
|
||||
ctx: &egui::Context,
|
||||
frame: &mut eframe::Frame,
|
||||
render: Option<&ViewportRender>,
|
||||
) {
|
||||
if let Some(render) = render {
|
||||
render(ctx, frame.viewport_id(), frame.parent_viewport_id());
|
||||
return;
|
||||
}
|
||||
egui::CentralPanel::default().show(ctx, |ui| {
|
||||
ui.horizontal(|ui| {
|
||||
ui.spacing_mut().item_spacing.x = 0.0;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")] // hide console window on Windows in release
|
||||
|
||||
use eframe::egui;
|
||||
use eframe::egui::{self, ViewportRender};
|
||||
|
||||
fn main() -> Result<(), eframe::Error> {
|
||||
env_logger::init(); // Log to stderr (if you run with `RUST_LOG=debug`).
|
||||
@@ -60,7 +60,16 @@ impl MyApp {
|
||||
}
|
||||
|
||||
impl eframe::App for MyApp {
|
||||
fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {
|
||||
fn update(
|
||||
&mut self,
|
||||
ctx: &egui::Context,
|
||||
frame: &mut eframe::Frame,
|
||||
render: Option<&ViewportRender>,
|
||||
) {
|
||||
if let Some(render) = render {
|
||||
render(ctx, frame.viewport_id(), frame.parent_viewport_id());
|
||||
return;
|
||||
}
|
||||
egui::CentralPanel::default().show(ctx, |ui| {
|
||||
ui.heading("egui using custom fonts");
|
||||
ui.text_edit_multiline(&mut self.text);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")] // hide console window on Windows in release
|
||||
|
||||
use eframe::egui;
|
||||
use eframe::egui::{self, ViewportRender};
|
||||
use egui::{FontFamily, FontId, RichText, TextStyle};
|
||||
|
||||
fn main() -> Result<(), eframe::Error> {
|
||||
@@ -64,7 +64,16 @@ impl MyApp {
|
||||
}
|
||||
|
||||
impl eframe::App for MyApp {
|
||||
fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {
|
||||
fn update(
|
||||
&mut self,
|
||||
ctx: &egui::Context,
|
||||
frame: &mut eframe::Frame,
|
||||
render: Option<&ViewportRender>,
|
||||
) {
|
||||
if let Some(render) = render {
|
||||
render(ctx, frame.viewport_id(), frame.parent_viewport_id());
|
||||
return;
|
||||
}
|
||||
egui::CentralPanel::default().show(ctx, content);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")] // hide console window on Windows in release
|
||||
|
||||
use eframe::egui;
|
||||
use eframe::egui::{self, ViewportRender};
|
||||
|
||||
fn main() -> Result<(), eframe::Error> {
|
||||
env_logger::init(); // Log to stderr (if you run with `RUST_LOG=debug`).
|
||||
@@ -30,7 +30,16 @@ impl eframe::App for MyApp {
|
||||
egui::Rgba::TRANSPARENT.to_array() // Make sure we don't paint anything behind the rounded corners
|
||||
}
|
||||
|
||||
fn update(&mut self, ctx: &egui::Context, frame: &mut eframe::Frame) {
|
||||
fn update(
|
||||
&mut self,
|
||||
ctx: &egui::Context,
|
||||
frame: &mut eframe::Frame,
|
||||
render: Option<&ViewportRender>,
|
||||
) {
|
||||
if let Some(render) = render {
|
||||
render(ctx, frame.viewport_id(), frame.parent_viewport_id());
|
||||
return;
|
||||
}
|
||||
custom_window_frame(ctx, frame, "egui with custom frame", |ui| {
|
||||
ui.label("This is just the contents of the window.");
|
||||
ui.horizontal(|ui| {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")] // hide console window on Windows in release
|
||||
|
||||
use eframe::egui;
|
||||
use eframe::egui::{self, ViewportRender};
|
||||
use egui_extras::RetainedImage;
|
||||
use poll_promise::Promise;
|
||||
|
||||
@@ -21,7 +21,16 @@ struct MyApp {
|
||||
}
|
||||
|
||||
impl eframe::App for MyApp {
|
||||
fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {
|
||||
fn update(
|
||||
&mut self,
|
||||
ctx: &egui::Context,
|
||||
frame: &mut eframe::Frame,
|
||||
render: Option<&ViewportRender>,
|
||||
) {
|
||||
if let Some(render) = render {
|
||||
render(ctx, frame.viewport_id(), frame.parent_viewport_id());
|
||||
return;
|
||||
}
|
||||
let promise = self.promise.get_or_insert_with(|| {
|
||||
// Begin download.
|
||||
// We download the image using `ehttp`, a library that works both in WASM and on native.
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")] // hide console window on Windows in release
|
||||
|
||||
use eframe::egui;
|
||||
use eframe::egui::{self, ViewportRender};
|
||||
|
||||
fn main() -> Result<(), eframe::Error> {
|
||||
env_logger::init(); // Log to stderr (if you run with `RUST_LOG=debug`).
|
||||
@@ -23,7 +23,16 @@ struct MyApp {
|
||||
}
|
||||
|
||||
impl eframe::App for MyApp {
|
||||
fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {
|
||||
fn update(
|
||||
&mut self,
|
||||
ctx: &egui::Context,
|
||||
frame: &mut eframe::Frame,
|
||||
render: Option<&ViewportRender>,
|
||||
) {
|
||||
if let Some(render) = render {
|
||||
render(ctx, frame.viewport_id(), frame.parent_viewport_id());
|
||||
return;
|
||||
}
|
||||
egui::CentralPanel::default().show(ctx, |ui| {
|
||||
ui.label("Drag-and-drop files onto the window!");
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")] // hide console window on Windows in release
|
||||
|
||||
use eframe::egui;
|
||||
use eframe::egui::{self, ViewportRender};
|
||||
|
||||
fn main() -> Result<(), eframe::Error> {
|
||||
env_logger::init(); // Log to stderr (if you run with `RUST_LOG=debug`).
|
||||
@@ -30,7 +30,16 @@ impl Default for MyApp {
|
||||
}
|
||||
|
||||
impl eframe::App for MyApp {
|
||||
fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {
|
||||
fn update(
|
||||
&mut self,
|
||||
ctx: &egui::Context,
|
||||
frame: &mut eframe::Frame,
|
||||
render: Option<&ViewportRender>,
|
||||
) {
|
||||
if let Some(render) = render {
|
||||
render(ctx, frame.viewport_id(), frame.parent_viewport_id());
|
||||
return;
|
||||
}
|
||||
egui::CentralPanel::default().show(ctx, |ui| {
|
||||
ui.heading("My egui Application");
|
||||
ui.horizontal(|ui| {
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
use std::sync::{mpsc, Arc, RwLock};
|
||||
use std::thread::JoinHandle;
|
||||
|
||||
use eframe::egui;
|
||||
use eframe::egui::{self, ViewportRender};
|
||||
|
||||
fn main() -> Result<(), eframe::Error> {
|
||||
env_logger::init(); // Log to stderr (if you run with `RUST_LOG=debug`).
|
||||
@@ -136,7 +136,16 @@ impl std::ops::Drop for MyApp {
|
||||
}
|
||||
|
||||
impl eframe::App for MyApp {
|
||||
fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {
|
||||
fn update(
|
||||
&mut self,
|
||||
ctx: &egui::Context,
|
||||
frame: &mut eframe::Frame,
|
||||
render: Option<&ViewportRender>,
|
||||
) {
|
||||
if let Some(render) = render {
|
||||
render(ctx, frame.viewport_id(), frame.parent_viewport_id());
|
||||
return;
|
||||
}
|
||||
let data = self.data.clone();
|
||||
egui::Window::new("Main thread").show(ctx, move |ui, _, parent_id| {
|
||||
if ui.button("Spawn another thread").clicked() {
|
||||
|
||||
@@ -19,7 +19,16 @@ struct Content {
|
||||
}
|
||||
|
||||
impl eframe::App for Content {
|
||||
fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {
|
||||
fn update(
|
||||
&mut self,
|
||||
ctx: &egui::Context,
|
||||
frame: &mut eframe::Frame,
|
||||
render: Option<&ViewportRender>,
|
||||
) {
|
||||
if let Some(render) = render {
|
||||
render(ctx, frame.viewport_id(), frame.parent_viewport_id());
|
||||
return;
|
||||
}
|
||||
egui::CentralPanel::default().show(ctx, |ui| {
|
||||
ui.heading("Press/Hold/Release example. Press A to test.");
|
||||
if ui.button("Clear").clicked() {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")] // hide console window on Windows in release
|
||||
|
||||
use eframe::egui;
|
||||
use eframe::egui::{self, ViewportRender};
|
||||
|
||||
fn main() -> Result<(), eframe::Error> {
|
||||
env_logger::init(); // Log to stderr (if you run with `RUST_LOG=debug`).
|
||||
@@ -17,7 +17,16 @@ fn main() -> Result<(), eframe::Error> {
|
||||
struct MyApp {}
|
||||
|
||||
impl eframe::App for MyApp {
|
||||
fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {
|
||||
fn update(
|
||||
&mut self,
|
||||
ctx: &egui::Context,
|
||||
frame: &mut eframe::Frame,
|
||||
render: Option<&ViewportRender>,
|
||||
) {
|
||||
if let Some(render) = render {
|
||||
render(ctx, frame.viewport_id(), frame.parent_viewport_id());
|
||||
return;
|
||||
}
|
||||
egui::CentralPanel::default().show(ctx, |ui| {
|
||||
ui.heading("Example of how to use the puffin profiler with egui");
|
||||
ui.separator();
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")] // hide console window on Windows in release
|
||||
|
||||
use eframe::egui;
|
||||
use eframe::egui::{self, ViewportRender};
|
||||
use egui_extras::RetainedImage;
|
||||
|
||||
fn main() -> Result<(), eframe::Error> {
|
||||
@@ -35,7 +35,16 @@ impl Default for MyApp {
|
||||
}
|
||||
|
||||
impl eframe::App for MyApp {
|
||||
fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {
|
||||
fn update(
|
||||
&mut self,
|
||||
ctx: &egui::Context,
|
||||
frame: &mut eframe::Frame,
|
||||
render: Option<&ViewportRender>,
|
||||
) {
|
||||
if let Some(render) = render {
|
||||
render(ctx, frame.viewport_id(), frame.parent_viewport_id());
|
||||
return;
|
||||
}
|
||||
egui::CentralPanel::default().show(ctx, |ui| {
|
||||
ui.heading("This is an image:");
|
||||
self.image.show(ui);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")] // hide console window on Windows in release
|
||||
|
||||
use eframe::egui::{self, ColorImage};
|
||||
use eframe::egui::{self, ColorImage, ViewportRender};
|
||||
|
||||
fn main() -> Result<(), eframe::Error> {
|
||||
env_logger::init(); // Log to stderr (if you run with `RUST_LOG=debug`).
|
||||
@@ -24,7 +24,16 @@ struct MyApp {
|
||||
}
|
||||
|
||||
impl eframe::App for MyApp {
|
||||
fn update(&mut self, ctx: &egui::Context, frame: &mut eframe::Frame) {
|
||||
fn update(
|
||||
&mut self,
|
||||
ctx: &egui::Context,
|
||||
frame: &mut eframe::Frame,
|
||||
render: Option<&ViewportRender>,
|
||||
) {
|
||||
if let Some(render) = render {
|
||||
render(ctx, frame.viewport_id(), frame.parent_viewport_id());
|
||||
return;
|
||||
}
|
||||
egui::CentralPanel::default().show(ctx, |ui| {
|
||||
if let Some(screenshot) = self.screenshot.take() {
|
||||
self.texture = Some(ui.ctx().load_texture(
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")] // hide console window on Windows in release
|
||||
|
||||
use eframe::egui;
|
||||
use eframe::egui::{self, ViewportRender};
|
||||
|
||||
fn main() -> Result<(), eframe::Error> {
|
||||
env_logger::init(); // Log to stderr (if you run with `RUST_LOG=debug`).
|
||||
@@ -46,7 +46,16 @@ struct MyApp {
|
||||
}
|
||||
|
||||
impl eframe::App for MyApp {
|
||||
fn update(&mut self, ctx: &egui::Context, frame: &mut eframe::Frame) {
|
||||
fn update(
|
||||
&mut self,
|
||||
ctx: &egui::Context,
|
||||
frame: &mut eframe::Frame,
|
||||
render: Option<&ViewportRender>,
|
||||
) {
|
||||
if let Some(render) = render {
|
||||
render(ctx, frame.viewport_id(), frame.parent_viewport_id());
|
||||
return;
|
||||
}
|
||||
egui::CentralPanel::default().show(ctx, |ui| {
|
||||
let label_text = if self.has_next {
|
||||
"When this window is closed the next will be opened after a short delay"
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")] // hide console window on Windows in release
|
||||
|
||||
use eframe::egui;
|
||||
use eframe::egui::{self, ViewportRender};
|
||||
|
||||
fn main() -> Result<(), eframe::Error> {
|
||||
env_logger::init(); // Log to stderr (if you run with `RUST_LOG=debug`).
|
||||
@@ -37,7 +37,16 @@ impl Default for MyApp {
|
||||
}
|
||||
|
||||
impl eframe::App for MyApp {
|
||||
fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {
|
||||
fn update(
|
||||
&mut self,
|
||||
ctx: &egui::Context,
|
||||
frame: &mut eframe::Frame,
|
||||
render: Option<&ViewportRender>,
|
||||
) {
|
||||
if let Some(render) = render {
|
||||
render(ctx, frame.viewport_id(), frame.parent_viewport_id());
|
||||
return;
|
||||
}
|
||||
egui::CentralPanel::default().show(ctx, |ui| {
|
||||
ui.heading("SVG example");
|
||||
ui.label("The SVG is rasterized and displayed as a texture.");
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use eframe::{
|
||||
egui::{Button, CentralPanel, Context, UserAttentionType},
|
||||
egui::{Button, CentralPanel, Context, UserAttentionType, ViewportRender},
|
||||
CreationContext, NativeOptions,
|
||||
};
|
||||
|
||||
@@ -54,7 +54,16 @@ impl Application {
|
||||
}
|
||||
|
||||
impl eframe::App for Application {
|
||||
fn update(&mut self, ctx: &Context, frame: &mut eframe::Frame) {
|
||||
fn update(
|
||||
&mut self,
|
||||
ctx: &Context,
|
||||
frame: &mut eframe::Frame,
|
||||
render: Option<&ViewportRender>,
|
||||
) {
|
||||
if let Some(render) = render {
|
||||
render(ctx, frame.viewport_id(), frame.parent_viewport_id());
|
||||
return;
|
||||
}
|
||||
if let Some(request_at) = self.request_at {
|
||||
if request_at < SystemTime::now() {
|
||||
self.request_at = None;
|
||||
|
||||
Reference in New Issue
Block a user