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 Aug 7, 2024
1 parent 1f2b9ba commit f9cbf51
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
10 changes: 5 additions & 5 deletions crates/egui/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,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 @@ -567,7 +567,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 @@ -1229,7 +1229,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 @@ -1622,7 +1622,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 @@ -2473,7 +2473,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.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 f9cbf51

Please sign in to comment.