Skip to content

Commit

Permalink
Access style via method
Browse files Browse the repository at this point in the history
  • Loading branch information
bash committed Sep 3, 2024
1 parent b82e51e commit 7d8fe1e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
12 changes: 6 additions & 6 deletions crates/egui/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,7 @@ impl ContextImpl {
});

viewport.hits = if let Some(pos) = viewport.input.pointer.interact_pos() {
let interact_radius = self.memory.options.style.interaction.interact_radius;
let interact_radius = self.memory.options.style().interaction.interact_radius;

crate::hit_test::hit_test(
&viewport.prev_frame.widgets,
Expand Down Expand Up @@ -583,7 +583,7 @@ impl ContextImpl {
crate::profile_scope!("preload_font_glyphs");
// Preload the most common characters for the most common fonts.
// This is not very important to do, but may save a few GPU operations.
for font_id in self.memory.options.style.text_styles.values() {
for font_id in self.memory.options.style().text_styles.values() {
fonts.lock().fonts.font(font_id).preload_common_characters();
}
}
Expand Down Expand Up @@ -1245,7 +1245,7 @@ impl Context {
pub fn register_widget_info(&self, id: Id, make_info: impl Fn() -> crate::WidgetInfo) {
#[cfg(debug_assertions)]
self.write(|ctx| {
if ctx.memory.options.style.debug.show_interactive_widgets {
if ctx.memory.options.style().debug.show_interactive_widgets {
ctx.viewport().this_frame.widgets.set_info(id, make_info());
}
});
Expand Down Expand Up @@ -1624,7 +1624,7 @@ impl Context {
self.options(|opt| opt.theme())
}

/// The [`Theme`] used to select between [`Self::dark_style()`] and [`Self::light_style()`]
/// The [`crate::Theme`] used to select between [`Self::dark_style()`] and [`Self::light_style()`]
/// as the active style used by all subsequent windows, panels etc.
///
/// Example:
Expand All @@ -1638,7 +1638,7 @@ impl Context {

/// The [`Style`] used by all subsequent windows, panels etc.
pub fn style(&self) -> Arc<Style> {
self.options(|opt| opt.style.clone())
self.options(|opt| opt.style().clone())
}

/// Mutate the [`Style`] used by all subsequent windows, panels etc.
Expand Down Expand Up @@ -2505,7 +2505,7 @@ impl Context {
/// Whether or not to debug widget layout on hover.
#[cfg(debug_assertions)]
pub fn debug_on_hover(&self) -> bool {
self.options(|opt| opt.style.debug.debug_on_hover)
self.options(|opt| opt.style().debug.debug_on_hover)
}

/// Turn on/off whether or not to debug widget layout on hover.
Expand Down
4 changes: 4 additions & 0 deletions crates/egui/src/memory/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,10 @@ impl Options {
ThemePreference::System => self.system_theme.unwrap_or(self.fallback_theme),
}
}

pub(crate) fn style(&self) -> &std::sync::Arc<Style> {
&self.style
}
}

impl Options {
Expand Down

0 comments on commit 7d8fe1e

Please sign in to comment.