diff --git a/crates/eframe/src/native/glow_integration.rs b/crates/eframe/src/native/glow_integration.rs index e448c6c19..d87bf264c 100644 --- a/crates/eframe/src/native/glow_integration.rs +++ b/crates/eframe/src/native/glow_integration.rs @@ -571,7 +571,7 @@ impl GlowWinitRunning<'_> { .options_mut(|opt| opt.begin_pass(&raw_input)); let clear_color = self .app - .clear_color(&self.integration.egui_ctx.style().visuals); + .clear_color(&self.integration.egui_ctx.global_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 c6c715c8c..040f16d28 100644 --- a/crates/eframe/src/native/wgpu_integration.rs +++ b/crates/eframe/src/native/wgpu_integration.rs @@ -690,7 +690,7 @@ impl WgpuWinitRunning<'_> { let vsync_secs = painter.paint_and_update_textures( viewport_id, pixels_per_point, - app.clear_color(&egui_ctx.style().visuals), + app.clear_color(&egui_ctx.global_style().visuals), &clipped_primitives, &textures_delta, screenshot_commands, diff --git a/crates/eframe/src/web/app_runner.rs b/crates/eframe/src/web/app_runner.rs index 8a10a90ef..06cfc7387 100644 --- a/crates/eframe/src/web/app_runner.rs +++ b/crates/eframe/src/web/app_runner.rs @@ -331,7 +331,7 @@ impl AppRunner { } if let Err(err) = self.painter.paint_and_update_textures( - self.app.clear_color(&self.egui_ctx.style().visuals), + self.app.clear_color(&self.egui_ctx.global_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 3ebac1d65..99b8e56a7 100644 --- a/crates/egui/src/containers/area.rs +++ b/crates/egui/src/containers/area.rs @@ -469,7 +469,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.style().spacing.default_area_size; + let default_area_size = ctx.global_style().spacing.default_area_size; if size.x.is_nan() { size.x = default_area_size.x; } @@ -634,7 +634,8 @@ impl Prepared { { 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.style().animation_time, 0.0..=1.0); + let opacity = + crate::remap_clamp(age, 0.0..=ctx.global_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 3c52f63a3..6b1fabfd7 100644 --- a/crates/egui/src/containers/panel.rs +++ b/crates/egui/src/containers/panel.rs @@ -934,8 +934,8 @@ impl Panel { }; let get_spacing_size = || match panel.side { - PanelSide::Vertical(_) => ctx.style().spacing.interact_size.x, - PanelSide::Horizontal(_) => ctx.style().spacing.interact_size.y, + PanelSide::Vertical(_) => ctx.global_style().spacing.interact_size.x, + PanelSide::Horizontal(_) => ctx.global_style().spacing.interact_size.y, }; PanelState::load(ctx, panel.id) diff --git a/crates/egui/src/containers/resize.rs b/crates/egui/src/containers/resize.rs index 50cc28774..a273db6a7 100644 --- a/crates/egui/src/containers/resize.rs +++ b/crates/egui/src/containers/resize.rs @@ -369,7 +369,7 @@ impl Resize { state.store(ui.ctx(), id); #[cfg(debug_assertions)] - if ui.ctx().style().debug.show_resize { + if ui.global_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/tooltip.rs b/crates/egui/src/containers/tooltip.rs index c46e21d57..78c5a726b 100644 --- a/crates/egui/src/containers/tooltip.rs +++ b/crates/egui/src/containers/tooltip.rs @@ -41,7 +41,7 @@ impl Tooltip<'_> { parent_widget: Id, anchor: impl Into, ) -> Self { - let width = ctx.style().spacing.tooltip_width; + let width = ctx.global_style().spacing.tooltip_width; Self { popup: Popup::new(parent_widget, ctx, anchor.into(), parent_layer) .kind(PopupKind::Tooltip) @@ -58,7 +58,7 @@ impl Tooltip<'_> { let popup = Popup::from_response(response) .kind(PopupKind::Tooltip) .gap(4.0) - .width(response.ctx.style().spacing.tooltip_width) + .width(response.ctx.global_style().spacing.tooltip_width) .sense(Sense::hover()); Self { popup, @@ -229,7 +229,7 @@ impl Tooltip<'_> { return false; } - let style = response.ctx.style(); + let style = response.ctx.global_style(); let tooltip_delay = style.interaction.tooltip_delay; let tooltip_grace_time = style.interaction.tooltip_grace_time; diff --git a/crates/egui/src/containers/window.rs b/crates/egui/src/containers/window.rs index 8d7a95be7..4cbc8bdef 100644 --- a/crates/egui/src/containers/window.rs +++ b/crates/egui/src/containers/window.rs @@ -440,9 +440,11 @@ impl Window<'_> { fade_out, } = self; - 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())); + let header_color = frame.map_or_else( + || ctx.global_style().visuals.widgets.open.weak_bg_fill, + |f| f.fill, + ); + let mut window_frame = frame.unwrap_or_else(|| Frame::window(&ctx.global_style())); let is_explicitly_closed = matches!(open, Some(false)); let is_open = !is_explicitly_closed || ctx.memory(|mem| mem.everything_is_visible()); @@ -474,7 +476,7 @@ impl Window<'_> { // Calculate roughly how much larger the full window inner size is compared to the content rect let (title_bar_height_with_margin, title_content_spacing) = if with_title_bar { - let style = ctx.style(); + let style = ctx.global_style(); let title_bar_inner_height = ctx .fonts_mut(|fonts| title.font_height(fonts, &style)) .at_least(style.spacing.interact_size.y); @@ -930,8 +932,8 @@ fn resize_interaction( let id = Id::new(layer_id).with("edge_drag"); - let side_grab_radius = ctx.style().interaction.resize_grab_radius_side; - let corner_grab_radius = ctx.style().interaction.resize_grab_radius_corner; + let side_grab_radius = ctx.global_style().interaction.resize_grab_radius_side; + let corner_grab_radius = ctx.global_style().interaction.resize_grab_radius_corner; let vetrtical_rect = |a: Pos2, b: Pos2| { Rect::from_min_max(a, b).expand2(vec2(side_grab_radius, -corner_grab_radius)) diff --git a/crates/egui/src/context.rs b/crates/egui/src/context.rs index ad329e7fb..0f23178e5 100644 --- a/crates/egui/src/context.rs +++ b/crates/egui/src/context.rs @@ -1148,7 +1148,7 @@ impl Context { let content_rect = self.content_rect(); let text = format!("🔥 {text}"); - let color = self.style().visuals.error_fg_color; + let color = self.global_style().visuals.error_fg_color; let painter = self.debug_painter(); painter.rect_stroke(widget_rect, 0.0, (1.0, color), StrokeKind::Outside); @@ -1603,7 +1603,7 @@ impl Context { .. } = ModifierNames::SYMBOLS; - let font_id = TextStyle::Body.resolve(&self.style()); + let font_id = TextStyle::Body.resolve(&self.global_style()); self.fonts_mut(|f| { let mut font = f.fonts.font(&font_id.family); font.has_glyphs(alt) @@ -2052,13 +2052,13 @@ impl Context { } /// The [`Theme`] used to select the appropriate [`Style`] (dark or light) - /// used by all subsequent windows, panels etc. + /// used by all subsequent popups, menus, etc. pub fn theme(&self) -> Theme { self.options(|opt| opt.theme()) } /// The [`Theme`] used to select between dark and light [`Self::style`] - /// as the active style used by all subsequent windows, panels etc. + /// as the active style used by all subsequent popups, menus, etc. /// /// Example: /// ``` @@ -2069,37 +2069,70 @@ impl Context { self.options_mut(|opt| opt.theme_preference = theme_preference.into()); } - /// The currently active [`Style`] used by all subsequent windows, panels etc. + /// The currently active [`Style`] used by all subsequent popups, menus, etc. + pub fn global_style(&self) -> Arc