diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md index 98a3b496a21..336b454f7bd 100644 --- a/.github/pull_request_template.md +++ b/.github/pull_request_template.md @@ -5,7 +5,7 @@ Please read the "Making a PR" section of [`CONTRIBUTING.md`](https://github.com/ * The PR title is what ends up in the changelog, so make it descriptive! * If applicable, add a screenshot or gif. * If it is a non-trivial addition, consider adding a demo for it to `egui_demo_lib`, or a new example. -* Do NOT open PR:s from your `master` branch, as that makes it hard for maintainers to add commits to your PR. +* Do NOT open PR:s from your `master` branch, as that makes it hard for maintainers to test and add commits to your PR. * Remember to run `cargo fmt` and `cargo clippy`. * Open the PR as a draft until you have self-reviewed it and run `./scripts/check.sh`. * When you have addressed a PR comment, mark it as resolved. diff --git a/crates/eframe/src/lib.rs b/crates/eframe/src/lib.rs index 9f9f3a4c807..4e3ebad1dfe 100644 --- a/crates/eframe/src/lib.rs +++ b/crates/eframe/src/lib.rs @@ -197,7 +197,7 @@ pub mod icon_data; /// ``` no_run /// use eframe::egui; /// -/// fn main() -> eframe::Result<()> { +/// fn main() -> eframe::Result { /// let native_options = eframe::NativeOptions::default(); /// eframe::run_native("MyApp", native_options, Box::new(|cc| Ok(Box::new(MyEguiApp::new(cc))))) /// } @@ -233,7 +233,7 @@ pub fn run_native( app_name: &str, mut native_options: NativeOptions, app_creator: AppCreator, -) -> Result<()> { +) -> Result { #[cfg(not(feature = "__screenshot"))] assert!( std::env::var("EFRAME_SCREENSHOT_TO").is_err(), @@ -278,7 +278,7 @@ pub fn run_native( /// /// # Example /// ``` no_run -/// fn main() -> eframe::Result<()> { +/// fn main() -> eframe::Result { /// // Our application state: /// let mut name = "Arthur".to_owned(); /// let mut age = 42; @@ -310,7 +310,7 @@ pub fn run_simple_native( app_name: &str, native_options: NativeOptions, update_fun: impl FnMut(&egui::Context, &mut Frame) + 'static, -) -> Result<()> { +) -> Result { struct SimpleApp { update_fun: U, } @@ -445,7 +445,7 @@ impl std::fmt::Display for Error { } /// Short for `Result`. -pub type Result = std::result::Result; +pub type Result = std::result::Result; // --------------------------------------------------------------------------- diff --git a/crates/eframe/src/native/glow_integration.rs b/crates/eframe/src/native/glow_integration.rs index 4395bd99b3c..6d270b2ccb6 100644 --- a/crates/eframe/src/native/glow_integration.rs +++ b/crates/eframe/src/native/glow_integration.rs @@ -1112,7 +1112,7 @@ impl GlutinWindowContext { &mut self, viewport_id: ViewportId, event_loop: &EventLoopWindowTarget, - ) -> Result<()> { + ) -> Result { crate::profile_function!(); let Some(viewport) = self.viewports.get_mut(&viewport_id) else { @@ -1218,7 +1218,7 @@ impl GlutinWindowContext { } /// only applies for android. but we basically drop surface + window and make context not current - fn on_suspend(&mut self) -> Result<()> { + fn on_suspend(&mut self) -> Result { log::debug!("received suspend event. dropping window and surface"); for viewport in self.viewports.values_mut() { viewport.gl_surface = None; diff --git a/crates/eframe/src/native/run.rs b/crates/eframe/src/native/run.rs index 2d6c1fc4bf4..0697b7df3f3 100644 --- a/crates/eframe/src/native/run.rs +++ b/crates/eframe/src/native/run.rs @@ -60,10 +60,7 @@ fn with_event_loop( } #[cfg(not(target_os = "ios"))] -fn run_and_return( - event_loop: &mut EventLoop, - mut winit_app: impl WinitApp, -) -> Result<()> { +fn run_and_return(event_loop: &mut EventLoop, mut winit_app: impl WinitApp) -> Result { use winit::{event_loop::ControlFlow, platform::run_on_demand::EventLoopExtRunOnDemand}; log::trace!("Entering the winit event loop (run_on_demand)…"); @@ -228,7 +225,7 @@ fn run_and_return( fn run_and_exit( event_loop: EventLoop, mut winit_app: impl WinitApp + 'static, -) -> Result<()> { +) -> Result { use winit::event_loop::ControlFlow; log::trace!("Entering the winit event loop (run)…"); @@ -391,7 +388,7 @@ pub fn run_glow( app_name: &str, mut native_options: epi::NativeOptions, app_creator: epi::AppCreator, -) -> Result<()> { +) -> Result { #![allow(clippy::needless_return_with_question_mark)] // False positive use super::glow_integration::GlowWinitApp; @@ -416,7 +413,7 @@ pub fn run_wgpu( app_name: &str, mut native_options: epi::NativeOptions, app_creator: epi::AppCreator, -) -> Result<()> { +) -> Result { #![allow(clippy::needless_return_with_question_mark)] // False positive use super::wgpu_integration::WgpuWinitApp; diff --git a/crates/egui/src/containers/popup.rs b/crates/egui/src/containers/popup.rs index 5f4a9d6203a..b0aad3636b2 100644 --- a/crates/egui/src/containers/popup.rs +++ b/crates/egui/src/containers/popup.rs @@ -302,10 +302,16 @@ pub fn popup_above_or_below_widget( add_contents: impl FnOnce(&mut Ui) -> R, ) -> Option { if parent_ui.memory(|mem| mem.is_popup_open(popup_id)) { - let (pos, pivot) = match above_or_below { + let (mut pos, pivot) = match above_or_below { AboveOrBelow::Above => (widget_response.rect.left_top(), Align2::LEFT_BOTTOM), AboveOrBelow::Below => (widget_response.rect.left_bottom(), Align2::LEFT_TOP), }; + if let Some(transform) = parent_ui + .ctx() + .memory(|m| m.layer_transforms.get(&parent_ui.layer_id()).copied()) + { + pos = transform * pos; + } let frame = Frame::popup(parent_ui.style()); let frame_margin = frame.total_margin(); diff --git a/crates/egui/src/menu.rs b/crates/egui/src/menu.rs index 01c3e2bf213..2b8ed3a4579 100644 --- a/crates/egui/src/menu.rs +++ b/crates/egui/src/menu.rs @@ -363,6 +363,13 @@ impl MenuRoot { } } + if let Some(transform) = button + .ctx + .memory(|m| m.layer_transforms.get(&button.layer_id).copied()) + { + pos = transform * pos; + } + return MenuResponse::Create(pos, id); } else if button .ctx diff --git a/crates/egui/src/response.rs b/crates/egui/src/response.rs index 192c573ff16..bb3d6456b88 100644 --- a/crates/egui/src/response.rs +++ b/crates/egui/src/response.rs @@ -562,7 +562,14 @@ impl Response { /// /// This can be used to give attention to a widget during a tutorial. pub fn show_tooltip_ui(&self, add_contents: impl FnOnce(&mut Ui)) { - crate::containers::show_tooltip_for(&self.ctx, self.id, &self.rect, add_contents); + let mut rect = self.rect; + if let Some(transform) = self + .ctx + .memory(|m| m.layer_transforms.get(&self.layer_id).copied()) + { + rect = transform * rect; + } + crate::containers::show_tooltip_for(&self.ctx, self.id, &rect, add_contents); } /// Always show this tooltip, even if disabled and the user isn't hovering it. diff --git a/crates/egui/src/widgets/label.rs b/crates/egui/src/widgets/label.rs index de6cc98dfe2..c6d44a3e14f 100644 --- a/crates/egui/src/widgets/label.rs +++ b/crates/egui/src/widgets/label.rs @@ -182,8 +182,21 @@ impl Label { } (pos, galley, response) } else { - layout_job.wrap = - text::TextWrapping::from_wrap_mode_and_width(wrap_mode, available_width); + // Apply wrap_mode, but don't overwrite anything important + // the user may have set manually on the layout_job: + match wrap_mode { + TextWrapMode::Extend => { + layout_job.wrap.max_width = f32::INFINITY; + } + TextWrapMode::Wrap => { + layout_job.wrap.max_width = available_width; + } + TextWrapMode::Truncate => { + layout_job.wrap.max_width = available_width; + layout_job.wrap.max_rows = 1; + layout_job.wrap.break_anywhere = true; + } + } if ui.is_grid() { // TODO(emilk): remove special Grid hacks like these diff --git a/crates/egui_demo_app/src/main.rs b/crates/egui_demo_app/src/main.rs index e30a73f22ea..61c0e94bb65 100644 --- a/crates/egui_demo_app/src/main.rs +++ b/crates/egui_demo_app/src/main.rs @@ -5,7 +5,7 @@ #![allow(clippy::never_loop)] // False positive // When compiling natively: -fn main() -> Result<(), eframe::Error> { +fn main() -> eframe::Result { for arg in std::env::args().skip(1) { match arg.as_str() { "--profile" => { diff --git a/crates/emath/src/rot2.rs b/crates/emath/src/rot2.rs index 45d1f0b553c..88c425a5095 100644 --- a/crates/emath/src/rot2.rs +++ b/crates/emath/src/rot2.rs @@ -8,9 +8,9 @@ use super::Vec2; // `vec2(c,s)` represents where the X axis will end up after rotation. // /// Represents a rotation in the 2D plane. -// +/// /// A rotation of 𝞃/4 = 90° rotates the X axis to the Y axis. -// +/// /// Normally a [`Rot2`] is normalized (unit-length). /// If not, it will also scale vectors. #[repr(C)] diff --git a/examples/confirm_exit/src/main.rs b/examples/confirm_exit/src/main.rs index 1ec4a7e0f15..e02c5c1d00f 100644 --- a/examples/confirm_exit/src/main.rs +++ b/examples/confirm_exit/src/main.rs @@ -3,7 +3,7 @@ use eframe::egui; -fn main() -> Result<(), eframe::Error> { +fn main() -> eframe::Result { env_logger::init(); // Log to stderr (if you run with `RUST_LOG=debug`). let options = eframe::NativeOptions { viewport: egui::ViewportBuilder::default().with_inner_size([320.0, 240.0]), diff --git a/examples/custom_3d_glow/src/main.rs b/examples/custom_3d_glow/src/main.rs index c4b89103d3f..2242958779f 100644 --- a/examples/custom_3d_glow/src/main.rs +++ b/examples/custom_3d_glow/src/main.rs @@ -8,7 +8,7 @@ use eframe::{egui, egui_glow, glow}; use egui::mutex::Mutex; use std::sync::Arc; -fn main() -> Result<(), eframe::Error> { +fn main() -> eframe::Result { env_logger::init(); // Log to stderr (if you run with `RUST_LOG=debug`). let options = eframe::NativeOptions { viewport: egui::ViewportBuilder::default().with_inner_size([350.0, 380.0]), diff --git a/examples/custom_font/src/main.rs b/examples/custom_font/src/main.rs index 9687cb0215b..8960a8fe82b 100644 --- a/examples/custom_font/src/main.rs +++ b/examples/custom_font/src/main.rs @@ -3,7 +3,7 @@ use eframe::egui; -fn main() -> Result<(), eframe::Error> { +fn main() -> eframe::Result { env_logger::init(); // Log to stderr (if you run with `RUST_LOG=debug`). let options = eframe::NativeOptions { viewport: egui::ViewportBuilder::default().with_inner_size([320.0, 240.0]), diff --git a/examples/custom_font_style/src/main.rs b/examples/custom_font_style/src/main.rs index 11608bfc012..fae1e8b079d 100644 --- a/examples/custom_font_style/src/main.rs +++ b/examples/custom_font_style/src/main.rs @@ -4,7 +4,7 @@ use eframe::egui; use egui::{FontFamily, FontId, RichText, TextStyle}; -fn main() -> Result<(), eframe::Error> { +fn main() -> eframe::Result { env_logger::init(); // Log to stderr (if you run with `RUST_LOG=debug`). let options = eframe::NativeOptions::default(); diff --git a/examples/custom_keypad/src/main.rs b/examples/custom_keypad/src/main.rs index d72d520a110..b4397be2f97 100644 --- a/examples/custom_keypad/src/main.rs +++ b/examples/custom_keypad/src/main.rs @@ -5,7 +5,7 @@ use eframe::egui; mod keypad; use keypad::Keypad; -fn main() -> Result<(), eframe::Error> { +fn main() -> eframe::Result { env_logger::init(); // Log to stderr (if you run with `RUST_LOG=debug`). let options = eframe::NativeOptions { viewport: egui::ViewportBuilder::default().with_inner_size([640.0, 480.0]), diff --git a/examples/custom_plot_manipulation/src/main.rs b/examples/custom_plot_manipulation/src/main.rs index 1d4abca3a6b..bb62645cbe2 100644 --- a/examples/custom_plot_manipulation/src/main.rs +++ b/examples/custom_plot_manipulation/src/main.rs @@ -5,7 +5,7 @@ use eframe::egui::{self, DragValue, Event, Vec2}; use egui_plot::{Legend, Line, PlotPoints}; -fn main() -> Result<(), eframe::Error> { +fn main() -> eframe::Result { env_logger::init(); // Log to stderr (if you run with `RUST_LOG=debug`). let options = eframe::NativeOptions::default(); eframe::run_native( diff --git a/examples/custom_window_frame/src/main.rs b/examples/custom_window_frame/src/main.rs index ef5cc2dbb55..2912e5bba17 100644 --- a/examples/custom_window_frame/src/main.rs +++ b/examples/custom_window_frame/src/main.rs @@ -5,7 +5,7 @@ use eframe::egui::{self, ViewportCommand}; -fn main() -> Result<(), eframe::Error> { +fn main() -> eframe::Result { env_logger::init(); // Log to stderr (if you run with `RUST_LOG=debug`). let options = eframe::NativeOptions { viewport: egui::ViewportBuilder::default() diff --git a/examples/file_dialog/src/main.rs b/examples/file_dialog/src/main.rs index 840a72fb5c7..63874649b66 100644 --- a/examples/file_dialog/src/main.rs +++ b/examples/file_dialog/src/main.rs @@ -3,7 +3,7 @@ use eframe::egui; -fn main() -> Result<(), eframe::Error> { +fn main() -> eframe::Result { env_logger::init(); // Log to stderr (if you run with `RUST_LOG=debug`). let options = eframe::NativeOptions { viewport: egui::ViewportBuilder::default() diff --git a/examples/hello_world/src/main.rs b/examples/hello_world/src/main.rs index 2780d0ce56e..6b85198a4d4 100644 --- a/examples/hello_world/src/main.rs +++ b/examples/hello_world/src/main.rs @@ -3,7 +3,7 @@ use eframe::egui; -fn main() -> Result<(), eframe::Error> { +fn main() -> eframe::Result { env_logger::init(); // Log to stderr (if you run with `RUST_LOG=debug`). let options = eframe::NativeOptions { viewport: egui::ViewportBuilder::default().with_inner_size([320.0, 240.0]), diff --git a/examples/hello_world_par/src/main.rs b/examples/hello_world_par/src/main.rs index ecf7034c2e1..7eeb7a2b6a3 100644 --- a/examples/hello_world_par/src/main.rs +++ b/examples/hello_world_par/src/main.rs @@ -8,7 +8,7 @@ use std::thread::JoinHandle; use eframe::egui; -fn main() -> Result<(), eframe::Error> { +fn main() -> eframe::Result { env_logger::init(); // Log to stderr (if you run with `RUST_LOG=debug`). let options = eframe::NativeOptions { viewport: egui::ViewportBuilder::default().with_inner_size([1024.0, 768.0]), diff --git a/examples/hello_world_simple/src/main.rs b/examples/hello_world_simple/src/main.rs index 4e48feeff90..4fe49a89d68 100644 --- a/examples/hello_world_simple/src/main.rs +++ b/examples/hello_world_simple/src/main.rs @@ -3,7 +3,7 @@ use eframe::egui; -fn main() -> Result<(), eframe::Error> { +fn main() -> eframe::Result { env_logger::init(); // Log to stderr (if you run with `RUST_LOG=debug`). let options = eframe::NativeOptions { diff --git a/examples/images/src/main.rs b/examples/images/src/main.rs index 1f53734e05c..cd657537278 100644 --- a/examples/images/src/main.rs +++ b/examples/images/src/main.rs @@ -3,7 +3,7 @@ use eframe::egui; -fn main() -> Result<(), eframe::Error> { +fn main() -> eframe::Result { env_logger::init(); // Log to stderr (if you run with `RUST_LOG=debug`). let options = eframe::NativeOptions { viewport: egui::ViewportBuilder::default().with_inner_size([600.0, 800.0]), diff --git a/examples/keyboard_events/src/main.rs b/examples/keyboard_events/src/main.rs index 3c1223d671d..b5dc9006ee1 100644 --- a/examples/keyboard_events/src/main.rs +++ b/examples/keyboard_events/src/main.rs @@ -4,7 +4,7 @@ use eframe::egui; use egui::*; -fn main() -> Result<(), eframe::Error> { +fn main() -> eframe::Result { env_logger::init(); // Log to stderr (if you run with `RUST_LOG=debug`). let options = eframe::NativeOptions::default(); eframe::run_native( diff --git a/examples/multiple_viewports/src/main.rs b/examples/multiple_viewports/src/main.rs index 0ed26e4e8a0..a8adab2c788 100644 --- a/examples/multiple_viewports/src/main.rs +++ b/examples/multiple_viewports/src/main.rs @@ -8,7 +8,7 @@ use std::sync::{ use eframe::egui; -fn main() -> Result<(), eframe::Error> { +fn main() -> eframe::Result { env_logger::init(); // Log to stderr (if you run with `RUST_LOG=debug`). let options = eframe::NativeOptions { viewport: egui::ViewportBuilder::default().with_inner_size([320.0, 240.0]), diff --git a/examples/puffin_profiler/src/main.rs b/examples/puffin_profiler/src/main.rs index 2987e93c5e8..5ae9bf03863 100644 --- a/examples/puffin_profiler/src/main.rs +++ b/examples/puffin_profiler/src/main.rs @@ -8,7 +8,7 @@ use std::sync::{ use eframe::egui; -fn main() -> Result<(), eframe::Error> { +fn main() -> eframe::Result { env_logger::init(); // Log to stderr (if you run with `RUST_LOG=debug`). start_puffin_server(); // NOTE: you may only want to call this if the users specifies some flag or clicks a button! diff --git a/examples/save_plot/src/main.rs b/examples/save_plot/src/main.rs index fa24ec84295..cb5526beb52 100644 --- a/examples/save_plot/src/main.rs +++ b/examples/save_plot/src/main.rs @@ -4,7 +4,7 @@ use eframe::egui; use egui_plot::{Legend, Line, Plot, PlotPoints}; -fn main() -> Result<(), eframe::Error> { +fn main() -> eframe::Result { env_logger::init(); // Log to stderr (if you run with `RUST_LOG=debug`). let options = eframe::NativeOptions { diff --git a/examples/screenshot/src/main.rs b/examples/screenshot/src/main.rs index 24eccd2d27c..155530042c4 100644 --- a/examples/screenshot/src/main.rs +++ b/examples/screenshot/src/main.rs @@ -5,7 +5,7 @@ use std::sync::Arc; use eframe::egui::{self, ColorImage}; -fn main() -> Result<(), eframe::Error> { +fn main() -> eframe::Result { env_logger::init(); // Log to stderr (if you run with `RUST_LOG=debug`). let options = eframe::NativeOptions { renderer: eframe::Renderer::Wgpu, diff --git a/examples/serial_windows/src/main.rs b/examples/serial_windows/src/main.rs index 9ea1f3ea8ef..133155bd131 100644 --- a/examples/serial_windows/src/main.rs +++ b/examples/serial_windows/src/main.rs @@ -3,7 +3,7 @@ use eframe::egui; -fn main() -> Result<(), eframe::Error> { +fn main() -> eframe::Result { env_logger::init(); // Log to stderr (if you run with `RUST_LOG=debug`). if cfg!(target_os = "macos") { diff --git a/examples/user_attention/src/main.rs b/examples/user_attention/src/main.rs index 53c170a1144..3d171c279e8 100644 --- a/examples/user_attention/src/main.rs +++ b/examples/user_attention/src/main.rs @@ -6,7 +6,7 @@ use egui::{Button, CentralPanel, Context, UserAttentionType}; use std::time::{Duration, SystemTime}; -fn main() -> eframe::Result<()> { +fn main() -> eframe::Result { env_logger::init(); // Log to stderr (if you run with `RUST_LOG=debug`). let native_options = NativeOptions { viewport: egui::ViewportBuilder::default().with_inner_size([400., 200.]), diff --git a/tests/test_size_pass/src/main.rs b/tests/test_size_pass/src/main.rs index ab9ad17e500..0376868b279 100644 --- a/tests/test_size_pass/src/main.rs +++ b/tests/test_size_pass/src/main.rs @@ -3,7 +3,7 @@ use eframe::egui; -fn main() -> eframe::Result<()> { +fn main() -> eframe::Result { env_logger::init(); // Use `RUST_LOG=debug` to see logs. let options = eframe::NativeOptions::default(); diff --git a/tests/test_ui_stack/src/main.rs b/tests/test_ui_stack/src/main.rs index 3afb659366d..7cd57135418 100644 --- a/tests/test_ui_stack/src/main.rs +++ b/tests/test_ui_stack/src/main.rs @@ -5,7 +5,7 @@ use eframe::egui; use eframe::egui::{Rangef, Shape, UiKind}; use egui_extras::Column; -fn main() -> Result<(), eframe::Error> { +fn main() -> eframe::Result { env_logger::init(); // Log to stderr (if you run with `RUST_LOG=debug`). let options = eframe::NativeOptions { viewport: egui::ViewportBuilder::default().with_inner_size([320.0, 240.0]),