1
0
mirror of https://github.com/emilk/egui.git synced 2026-08-29 12:50:04 -04:00

rename comment & variable, add const root class for root ui

This commit is contained in:
adrien
2026-03-17 17:39:57 +01:00
parent fea172f315
commit b7e11af52e
3 changed files with 15 additions and 36 deletions

View File

@@ -7,6 +7,7 @@ use emath::GuiRounding as _;
use epaint::mutex::RwLock;
use crate::containers::menu;
use crate::widget_style::{HasClasses as _, ROOT_CLASS};
use crate::{containers::*, ecolor::*, layout::*, placer::Placer, widgets::*, *};
// ----------------------------------------------------------------------------
@@ -113,7 +114,7 @@ impl Ui {
let UiBuilder {
id_salt,
global_scope: _,
mut ui_stack_info,
ui_stack_info,
layer_id,
max_rect,
layout,
@@ -123,7 +124,7 @@ impl Ui {
style,
sense,
accessibility_parent,
classes: modifiers,
classes,
} = ui_builder;
let layer_id = layer_id.unwrap_or_else(LayerId::background);
@@ -139,10 +140,7 @@ impl Ui {
let disabled = disabled || invisible;
let style = style.unwrap_or_else(|| ctx.global_style());
let sense = sense.unwrap_or_else(Sense::hover);
let modifiers = modifiers.unwrap_or_default();
// Temporary use of user tags as proof of concept
ui_stack_info = ui_stack_info.with_tag("root");
let classes = classes.unwrap_or_default().with_class(ROOT_CLASS);
let placer = Placer::new(max_rect, layout);
let ui_stack = UiStack {
@@ -152,7 +150,7 @@ impl Ui {
parent: None,
min_rect: placer.min_rect(),
max_rect: placer.max_rect(),
classes: modifiers,
classes,
};
let mut ui = Ui {
@@ -268,7 +266,7 @@ impl Ui {
style,
sense,
accessibility_parent,
classes: modifiers,
classes,
} = ui_builder;
let mut painter = self.painter.clone();
@@ -286,7 +284,7 @@ impl Ui {
let sizing_pass = self.sizing_pass || sizing_pass;
let style = style.unwrap_or_else(|| Arc::clone(&self.style));
let sense = sense.unwrap_or_else(Sense::hover);
let modifiers = modifiers.unwrap_or_default();
let classes = classes.unwrap_or_default();
if sizing_pass {
// During the sizing pass we want widgets to use up as little space as possible,
@@ -318,7 +316,7 @@ impl Ui {
parent: Some(Arc::clone(&self.stack)),
min_rect: placer.min_rect(),
max_rect: placer.max_rect(),
classes: modifiers,
classes,
};
let mut child_ui = Ui {

View File

@@ -202,6 +202,8 @@ impl Style {
}
}
pub const ROOT_CLASS: &str = "root";
pub type ClassName = Cow<'static, str>;
#[derive(Debug, Default, Clone)]
@@ -280,31 +282,8 @@ pub trait HasClasses {
self
}
/// Return true if the modifier is present in the list
/// Return true if the class is present in the list
fn has(&self, class: impl Into<ClassName>) -> bool {
self.classes().classes.contains(&class.into())
}
}
/// Add a shortcut to add modifiers. The syntax is `add_modifiers`!(Name: (modifier1, modifier2, modifier3,)) for any number of modifiers
#[macro_export]
macro_rules! define_modifiers {
($trait_name:ident: ($( $name:ident )+),?) => {
pub trait $trait_name {
$(
fn $name(self) -> Self;
)*
}
impl<T> $trait_name for T
where
T: HasModifiers,
{
#[inline]
$(fn $name(mut self) -> Self {
self.with_class(stringify!($name))
})?
}
};
}

View File

@@ -49,7 +49,9 @@ fn main() -> eframe::Result {
while let Some(p) = parent {
text.push(format!(
"{}{}class : '{}', kind : {:?}",
" ".repeat((2 * 0_i32.max(i - 1)) as usize),
" ".repeat(
(2 * 0_i32.max(i - 1) + 1.min(i)) as usize
),
if i > 0 { "\\- " } else { "" },
p.classes,
p.kind()
@@ -58,7 +60,7 @@ fn main() -> eframe::Result {
parent = p.parent.as_ref();
}
ui.label(format!(
"Current hierarchy :\n{}",
"Current hierarchy (child to root):\n{}",
text.join("\n")
));
},