From 04c0f22799c1f17ecdb1ca060828aaa878ccdd00 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tau=20G=C3=A4rtli?= Date: Fri, 6 Sep 2024 13:36:57 +0200 Subject: [PATCH] Add back style and style_mut for the active style --- crates/eframe/src/epi.rs | 2 +- crates/eframe/src/native/glow_integration.rs | 2 +- crates/eframe/src/native/wgpu_integration.rs | 2 +- crates/eframe/src/web/app_runner.rs | 2 +- crates/egui/src/containers/area.rs | 5 +- crates/egui/src/containers/panel.rs | 6 +-- crates/egui/src/containers/popup.rs | 6 +-- crates/egui/src/containers/resize.rs | 2 +- crates/egui/src/containers/window.rs | 14 +++-- crates/egui/src/context.rs | 52 ++++++++++++------- crates/egui/src/debug_text.rs | 2 +- crates/egui/src/frame_state.rs | 2 +- crates/egui/src/memory/mod.rs | 7 +++ crates/egui/src/menu.rs | 6 +-- crates/egui/src/painter.rs | 2 +- crates/egui/src/response.rs | 4 +- crates/egui/src/style.rs | 4 +- crates/egui/src/ui.rs | 10 ++-- crates/egui/src/widgets/color_picker.rs | 2 +- crates/egui_demo_app/src/apps/http_app.rs | 2 +- crates/egui_demo_app/src/backend_panel.rs | 7 +-- crates/egui_demo_app/src/wrap_app.rs | 6 +-- .../src/demo/demo_app_windows.rs | 2 +- crates/egui_demo_lib/src/demo/pan_zoom.rs | 2 +- crates/egui_demo_lib/src/demo/scrolling.rs | 2 +- crates/egui_extras/src/syntax_highlighting.rs | 4 +- examples/custom_keypad/src/keypad.rs | 2 +- examples/custom_style/src/main.rs | 4 +- examples/custom_window_frame/src/main.rs | 4 +- examples/file_dialog/src/main.rs | 2 +- 30 files changed, 90 insertions(+), 79 deletions(-) diff --git a/crates/eframe/src/epi.rs b/crates/eframe/src/epi.rs index d0ce7074395..f62a6bb5fb7 100644 --- a/crates/eframe/src/epi.rs +++ b/crates/eframe/src/epi.rs @@ -54,7 +54,7 @@ pub struct CreationContext<'s> { /// The egui Context. /// /// You can use this to customize the look of egui, e.g to call [`egui::Context::set_fonts`], - /// [`egui::Context::set_visuals`] etc. + /// [`egui::Context::set_visuals_of`] etc. pub egui_ctx: egui::Context, /// Information about the surrounding environment. diff --git a/crates/eframe/src/native/glow_integration.rs b/crates/eframe/src/native/glow_integration.rs index 3d1a606dfe0..c1a3f5eaf89 100644 --- a/crates/eframe/src/native/glow_integration.rs +++ b/crates/eframe/src/native/glow_integration.rs @@ -557,7 +557,7 @@ impl<'app> GlowWinitRunning<'app> { let clear_color = self .app - .clear_color(&self.integration.egui_ctx.active_style().visuals); + .clear_color(&self.integration.egui_ctx.style().visuals); let has_many_viewports = self.glutin.borrow().viewports.len() > 1; let clear_before_update = !has_many_viewports; // HACK: for some reason, an early clear doesn't "take" on Mac with multiple viewports. diff --git a/crates/eframe/src/native/wgpu_integration.rs b/crates/eframe/src/native/wgpu_integration.rs index 6e63c804169..b38b78c9b4e 100644 --- a/crates/eframe/src/native/wgpu_integration.rs +++ b/crates/eframe/src/native/wgpu_integration.rs @@ -652,7 +652,7 @@ impl<'app> WgpuWinitRunning<'app> { let (vsync_secs, screenshot) = painter.paint_and_update_textures( viewport_id, pixels_per_point, - app.clear_color(&egui_ctx.active_style().visuals), + app.clear_color(&egui_ctx.style().visuals), &clipped_primitives, &textures_delta, screenshot_requested, diff --git a/crates/eframe/src/web/app_runner.rs b/crates/eframe/src/web/app_runner.rs index 4ed3b1915af..b636f341989 100644 --- a/crates/eframe/src/web/app_runner.rs +++ b/crates/eframe/src/web/app_runner.rs @@ -240,7 +240,7 @@ impl AppRunner { if let Some(clipped_primitives) = clipped_primitives { if let Err(err) = self.painter.paint_and_update_textures( - self.app.clear_color(&self.egui_ctx.active_style().visuals), + self.app.clear_color(&self.egui_ctx.style().visuals), &clipped_primitives, self.egui_ctx.pixels_per_point(), &textures_delta, diff --git a/crates/egui/src/containers/area.rs b/crates/egui/src/containers/area.rs index 10c995537c1..378b0edc8d9 100644 --- a/crates/egui/src/containers/area.rs +++ b/crates/egui/src/containers/area.rs @@ -418,7 +418,7 @@ impl Area { // during the sizing pass we will use this as the max size let mut size = default_size; - let default_area_size = ctx.active_style().spacing.default_area_size; + let default_area_size = ctx.style().spacing.default_area_size; if size.x.is_nan() { size.x = default_area_size.x; } @@ -553,8 +553,7 @@ impl Prepared { if let Some(last_became_visible_at) = self.state.last_became_visible_at { let age = ctx.input(|i| (i.time - last_became_visible_at) as f32 + i.predicted_dt / 2.0); - let opacity = - crate::remap_clamp(age, 0.0..=ctx.active_style().animation_time, 0.0..=1.0); + let opacity = crate::remap_clamp(age, 0.0..=ctx.style().animation_time, 0.0..=1.0); let opacity = emath::easing::quadratic_out(opacity); // slow fade-out = quick fade-in ui.multiply_opacity(opacity); if opacity < 1.0 { diff --git a/crates/egui/src/containers/panel.rs b/crates/egui/src/containers/panel.rs index 8e599eabb07..652a6755686 100644 --- a/crates/egui/src/containers/panel.rs +++ b/crates/egui/src/containers/panel.rs @@ -918,7 +918,7 @@ impl TopBottomPanel { let expanded_height = PanelState::load(ctx, self.id) .map(|state| state.rect.height()) .or(self.default_height) - .unwrap_or_else(|| ctx.active_style().spacing.interact_size.y); + .unwrap_or_else(|| ctx.style().spacing.interact_size.y); let fake_height = how_expanded * expanded_height; Self { id: self.id.with("animating_panel"), @@ -986,12 +986,12 @@ impl TopBottomPanel { let collapsed_height = PanelState::load(ctx, collapsed_panel.id) .map(|state| state.rect.height()) .or(collapsed_panel.default_height) - .unwrap_or_else(|| ctx.active_style().spacing.interact_size.y); + .unwrap_or_else(|| ctx.style().spacing.interact_size.y); let expanded_height = PanelState::load(ctx, expanded_panel.id) .map(|state| state.rect.height()) .or(expanded_panel.default_height) - .unwrap_or_else(|| ctx.active_style().spacing.interact_size.y); + .unwrap_or_else(|| ctx.style().spacing.interact_size.y); let fake_height = lerp(collapsed_height..=expanded_height, how_expanded); Self { diff --git a/crates/egui/src/containers/popup.rs b/crates/egui/src/containers/popup.rs index ad6ba03527f..959d653fffb 100644 --- a/crates/egui/src/containers/popup.rs +++ b/crates/egui/src/containers/popup.rs @@ -198,7 +198,7 @@ fn show_tooltip_at_dyn<'c, R>( .order(Order::Tooltip) .pivot(pivot) .fixed_pos(anchor) - .default_width(ctx.active_style().spacing.tooltip_width) + .default_width(ctx.style().spacing.tooltip_width) .sense(Sense::hover()) // don't click to bring to front .show(ctx, |ui| { // By default the text in tooltips aren't selectable. @@ -208,9 +208,7 @@ fn show_tooltip_at_dyn<'c, R>( // will stick around when you try to click them. ui.style_mut().interaction.selectable_labels = false; - Frame::popup(&ctx.active_style()) - .show_dyn(ui, add_contents) - .inner + Frame::popup(&ctx.style()).show_dyn(ui, add_contents).inner }); state.tooltip_count += 1; diff --git a/crates/egui/src/containers/resize.rs b/crates/egui/src/containers/resize.rs index d2d6dd1ec71..458bf11229d 100644 --- a/crates/egui/src/containers/resize.rs +++ b/crates/egui/src/containers/resize.rs @@ -368,7 +368,7 @@ impl Resize { state.store(ui.ctx(), id); #[cfg(debug_assertions)] - if ui.ctx().active_style().debug.show_resize { + if ui.ctx().style().debug.show_resize { ui.ctx().debug_painter().debug_rect( Rect::from_min_size(content_ui.min_rect().left_top(), state.desired_size), Color32::GREEN, diff --git a/crates/egui/src/containers/window.rs b/crates/egui/src/containers/window.rs index aa472ea6a1d..c183a4dc731 100644 --- a/crates/egui/src/containers/window.rs +++ b/crates/egui/src/containers/window.rs @@ -434,11 +434,9 @@ impl<'open> Window<'open> { fade_out, } = self; - let header_color = frame.map_or_else( - || ctx.active_style().visuals.widgets.open.weak_bg_fill, - |f| f.fill, - ); - let mut window_frame = frame.unwrap_or_else(|| Frame::window(&ctx.active_style())); + let header_color = + frame.map_or_else(|| ctx.style().visuals.widgets.open.weak_bg_fill, |f| f.fill); + let mut window_frame = frame.unwrap_or_else(|| Frame::window(&ctx.style())); // Keep the original inner margin for later use let window_margin = window_frame.inner_margin; @@ -470,7 +468,7 @@ impl<'open> Window<'open> { // Calculate roughly how much larger the window size is compared to the inner rect let (title_bar_height, title_content_spacing) = if with_title_bar { - let style = ctx.active_style(); + let style = ctx.style(); let spacing = window_margin.top + window_margin.bottom; let height = ctx.fonts(|f| title.font_height(f, &style)) + spacing; window_frame.rounding.ne = window_frame.rounding.ne.clamp(0.0, height / 2.0); @@ -851,8 +849,8 @@ fn resize_interaction( let id = Id::new(layer_id).with("edge_drag"); - let side_grab_radius = ctx.active_style().interaction.resize_grab_radius_side; - let corner_grab_radius = ctx.active_style().interaction.resize_grab_radius_corner; + let side_grab_radius = ctx.style().interaction.resize_grab_radius_side; + let corner_grab_radius = ctx.style().interaction.resize_grab_radius_corner; let corner_rect = |center: Pos2| Rect::from_center_size(center, Vec2::splat(2.0 * corner_grab_radius)); diff --git a/crates/egui/src/context.rs b/crates/egui/src/context.rs index 17ee2c2d754..838a8543a29 100644 --- a/crates/egui/src/context.rs +++ b/crates/egui/src/context.rs @@ -988,7 +988,7 @@ impl Context { let screen_rect = self.screen_rect(); let text = format!("🔥 {text}"); - let color = self.active_style().visuals.error_fg_color; + let color = self.style().visuals.error_fg_color; let painter = self.debug_painter(); painter.rect_stroke(widget_rect, 0.0, (1.0, color)); @@ -1357,7 +1357,7 @@ impl Context { .. } = ModifierNames::SYMBOLS; - let font_id = TextStyle::Body.resolve(&self.active_style()); + let font_id = TextStyle::Body.resolve(&self.style()); self.fonts(|f| { let mut lock = f.lock(); let font = lock.fonts.font(&font_id); @@ -1636,11 +1636,25 @@ impl Context { self.options_mut(|opt| opt.theme_preference = theme_preference.into()); } - /// The [`Style`] used by all subsequent windows, panels etc. - pub fn active_style(&self) -> Arc