mirror of
https://github.com/emilk/egui.git
synced 2026-06-26 22:53:14 -04:00
Use IdSalt everywhere
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
use crate::{
|
||||
Context, Id, InnerResponse, NumExt as _, Rect, Response, Sense, Stroke, TextStyle,
|
||||
Context, Id, IdSalt, InnerResponse, NumExt as _, Rect, Response, Sense, Stroke, TextStyle,
|
||||
TextWrapMode, Ui, UiBuilder, UiKind, UiStackInfo, Vec2, WidgetInfo, WidgetText, WidgetType,
|
||||
emath, epaint, pos2, remap, remap_clamp, vec2,
|
||||
};
|
||||
@@ -391,7 +391,7 @@ pub struct CollapsingHeader {
|
||||
text: WidgetText,
|
||||
default_open: bool,
|
||||
open: Option<bool>,
|
||||
id_salt: Id,
|
||||
id_salt: IdSalt,
|
||||
enabled: bool,
|
||||
selectable: bool,
|
||||
selected: bool,
|
||||
@@ -408,7 +408,7 @@ impl CollapsingHeader {
|
||||
/// you need to provide a unique id source with [`Self::id_salt`].
|
||||
pub fn new(text: impl Into<WidgetText>) -> Self {
|
||||
let text = text.into();
|
||||
let id_salt = Id::new_salt(text.text());
|
||||
let id_salt = IdSalt::new(text.text());
|
||||
Self {
|
||||
text,
|
||||
default_open: false,
|
||||
@@ -445,7 +445,7 @@ impl CollapsingHeader {
|
||||
/// This is useful if the title label is dynamic or not unique.
|
||||
#[inline]
|
||||
pub fn id_salt(mut self, id_salt: impl Into<crate::IdSalt>) -> Self {
|
||||
self.id_salt = id_salt.into().id();
|
||||
self.id_salt = id_salt.into();
|
||||
self
|
||||
}
|
||||
|
||||
@@ -454,7 +454,7 @@ impl CollapsingHeader {
|
||||
#[deprecated = "Renamed id_salt"]
|
||||
#[inline]
|
||||
pub fn id_source(mut self, id_salt: impl Into<crate::IdSalt>) -> Self {
|
||||
self.id_salt = id_salt.into().id();
|
||||
self.id_salt = id_salt.into();
|
||||
self
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use epaint::Shape;
|
||||
|
||||
use crate::{
|
||||
Align2, Context, Id, InnerResponse, NumExt as _, Painter, Popup, PopupCloseBehavior, Rect,
|
||||
Align2, Context, Id, IdSalt, InnerResponse, NumExt as _, Painter, Popup, PopupCloseBehavior, Rect,
|
||||
Response, ScrollArea, Sense, Stroke, TextStyle, TextWrapMode, Ui, UiBuilder, Vec2, WidgetInfo,
|
||||
WidgetText, WidgetType, epaint, style::StyleModifier, style::WidgetVisuals, vec2,
|
||||
};
|
||||
@@ -36,7 +36,7 @@ pub type IconPainter = Box<dyn FnOnce(&Ui, Rect, &WidgetVisuals, bool)>;
|
||||
/// ```
|
||||
#[must_use = "You should call .show*"]
|
||||
pub struct ComboBox {
|
||||
id_salt: Id,
|
||||
id_salt: IdSalt,
|
||||
label: Option<WidgetText>,
|
||||
selected_text: WidgetText,
|
||||
width: Option<f32>,
|
||||
@@ -51,7 +51,7 @@ impl ComboBox {
|
||||
/// Create new [`ComboBox`] with id and label
|
||||
pub fn new(id_salt: impl Into<crate::IdSalt>, label: impl Into<WidgetText>) -> Self {
|
||||
Self {
|
||||
id_salt: id_salt.into().id(),
|
||||
id_salt: id_salt.into(),
|
||||
label: Some(label.into()),
|
||||
selected_text: Default::default(),
|
||||
width: None,
|
||||
@@ -67,7 +67,7 @@ impl ComboBox {
|
||||
pub fn from_label(label: impl Into<WidgetText>) -> Self {
|
||||
let label = label.into();
|
||||
Self {
|
||||
id_salt: Id::new_salt(label.text()),
|
||||
id_salt: IdSalt::new(label.text()),
|
||||
label: Some(label),
|
||||
selected_text: Default::default(),
|
||||
width: None,
|
||||
@@ -82,7 +82,7 @@ impl ComboBox {
|
||||
/// Without label.
|
||||
pub fn from_id_salt(id_salt: impl Into<crate::IdSalt>) -> Self {
|
||||
Self {
|
||||
id_salt: id_salt.into().id(),
|
||||
id_salt: id_salt.into(),
|
||||
label: Default::default(),
|
||||
selected_text: Default::default(),
|
||||
width: None,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use crate::{
|
||||
Align2, Color32, Context, CursorIcon, Id, NumExt as _, Rect, Response, Sense, Shape, Ui,
|
||||
UiBuilder, UiKind, UiStackInfo, Vec2, Vec2b, pos2, vec2,
|
||||
Align2, Color32, Context, CursorIcon, Id, IdSalt, NumExt as _, Rect, Response, Sense, Shape,
|
||||
Ui, UiBuilder, UiKind, UiStackInfo, Vec2, Vec2b, pos2, vec2,
|
||||
};
|
||||
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
@@ -34,7 +34,7 @@ impl State {
|
||||
#[must_use = "You should call .show()"]
|
||||
pub struct Resize {
|
||||
id: Option<Id>,
|
||||
id_salt: Option<Id>,
|
||||
id_salt: Option<IdSalt>,
|
||||
|
||||
/// If false, we are no enabled
|
||||
resizable: Vec2b,
|
||||
@@ -79,7 +79,7 @@ impl Resize {
|
||||
/// A source for the unique [`Id`], e.g. `.id_salt("second_resize_area")` or `.id_salt(loop_index)`.
|
||||
#[inline]
|
||||
pub fn id_salt(mut self, id_salt: impl Into<crate::IdSalt>) -> Self {
|
||||
self.id_salt = Some(id_salt.into().id());
|
||||
self.id_salt = Some(id_salt.into());
|
||||
self
|
||||
}
|
||||
|
||||
@@ -208,7 +208,7 @@ impl Resize {
|
||||
fn begin(&self, ui: &mut Ui) -> Prepared {
|
||||
let position = ui.available_rect_before_wrap().min;
|
||||
let id = self.id.unwrap_or_else(|| {
|
||||
let id_salt = self.id_salt.unwrap_or_else(|| Id::new("resize"));
|
||||
let id_salt = self.id_salt.unwrap_or_else(|| IdSalt::from("resize"));
|
||||
ui.make_persistent_id(id_salt)
|
||||
});
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ use emath::GuiRounding as _;
|
||||
use epaint::Margin;
|
||||
|
||||
use crate::{
|
||||
Context, CursorIcon, Id, NumExt as _, Pos2, Rangef, Rect, Response, Sense, Ui, UiBuilder,
|
||||
Context, CursorIcon, Id, IdSalt, NumExt as _, Pos2, Rangef, Rect, Response, Sense, Ui, UiBuilder,
|
||||
UiKind, UiStackInfo, Vec2, Vec2b, WidgetInfo, emath, epaint, lerp, pass_state, pos2, remap,
|
||||
remap_clamp,
|
||||
};
|
||||
@@ -290,7 +290,7 @@ pub struct ScrollArea {
|
||||
min_scrolled_size: Vec2,
|
||||
scroll_bar_visibility: ScrollBarVisibility,
|
||||
scroll_bar_rect: Option<Rect>,
|
||||
id_salt: Option<Id>,
|
||||
id_salt: Option<IdSalt>,
|
||||
offset_x: Option<f32>,
|
||||
offset_y: Option<f32>,
|
||||
on_hover_cursor: Option<CursorIcon>,
|
||||
@@ -433,7 +433,7 @@ impl ScrollArea {
|
||||
/// A source for the unique [`Id`], e.g. `.id_salt("second_scroll_area")` or `.id_salt(loop_index)`.
|
||||
#[inline]
|
||||
pub fn id_salt(mut self, id_salt: impl Into<crate::IdSalt>) -> Self {
|
||||
self.id_salt = Some(id_salt.into().id());
|
||||
self.id_salt = Some(id_salt.into());
|
||||
self
|
||||
}
|
||||
|
||||
@@ -709,7 +709,7 @@ impl ScrollArea {
|
||||
|
||||
let ctx = ui.ctx().clone();
|
||||
|
||||
let id_salt = id_salt.unwrap_or_else(|| Id::new("scroll_area"));
|
||||
let id_salt = id_salt.unwrap_or_else(|| IdSalt::from("scroll_area"));
|
||||
let id = ui.make_persistent_id(id_salt);
|
||||
ctx.check_for_id_clash(
|
||||
id,
|
||||
|
||||
@@ -3,7 +3,7 @@ use std::sync::Arc;
|
||||
use emath::GuiRounding as _;
|
||||
|
||||
use crate::{
|
||||
Align2, Color32, Context, Id, InnerResponse, NumExt as _, Painter, Rect, Region, Style, Ui,
|
||||
Align2, Color32, Context, Id, IdSalt, InnerResponse, NumExt as _, Painter, Rect, Region, Style, Ui,
|
||||
UiBuilder, Vec2, vec2,
|
||||
};
|
||||
|
||||
@@ -312,7 +312,7 @@ impl GridLayout {
|
||||
/// ```
|
||||
#[must_use = "You should call .show()"]
|
||||
pub struct Grid {
|
||||
id_salt: Id,
|
||||
id_salt: IdSalt,
|
||||
num_columns: Option<usize>,
|
||||
min_col_width: Option<f32>,
|
||||
min_row_height: Option<f32>,
|
||||
@@ -326,7 +326,7 @@ impl Grid {
|
||||
/// Create a new [`Grid`] with a locally unique identifier.
|
||||
pub fn new(id_salt: impl Into<crate::IdSalt>) -> Self {
|
||||
Self {
|
||||
id_salt: id_salt.into().id(),
|
||||
id_salt: id_salt.into(),
|
||||
num_columns: None,
|
||||
min_col_width: None,
|
||||
min_row_height: None,
|
||||
|
||||
@@ -171,7 +171,7 @@ fn test_id_new_rejects_id() {
|
||||
/// let id = Id::new("parent");
|
||||
/// let salt: IdSalt = id.into();
|
||||
/// ```
|
||||
#[derive(Clone, Copy)]
|
||||
#[derive(Clone, Copy, Debug, Hash)]
|
||||
pub struct IdSalt(Id);
|
||||
|
||||
impl IdSalt {
|
||||
|
||||
@@ -265,7 +265,7 @@ impl Ui {
|
||||
|
||||
let mut painter = self.painter.clone();
|
||||
|
||||
let id_salt = id_salt.unwrap_or_else(|| Id::from("child"));
|
||||
let id_salt = id_salt.unwrap_or_else(|| IdSalt::from("child"));
|
||||
let max_rect = max_rect.unwrap_or_else(|| self.available_rect_before_wrap());
|
||||
let mut layout = layout.unwrap_or_else(|| *self.layout());
|
||||
let enabled = self.enabled && !disabled && !invisible;
|
||||
@@ -290,7 +290,7 @@ impl Ui {
|
||||
|
||||
debug_assert!(!max_rect.any_nan(), "max_rect is NaN: {max_rect:?}");
|
||||
let (stable_id, unique_id) = if global_scope {
|
||||
(id_salt, id_salt)
|
||||
(id_salt.id(), id_salt.id())
|
||||
} else {
|
||||
let stable_id = self.id.with(id_salt);
|
||||
let unique_id = stable_id.with(self.next_auto_id_salt);
|
||||
|
||||
@@ -13,7 +13,7 @@ use crate::{Id, IdSalt, LayerId, Layout, Rect, Sense, Style, UiStackInfo};
|
||||
#[must_use]
|
||||
#[derive(Clone, Default)]
|
||||
pub struct UiBuilder {
|
||||
pub id_salt: Option<Id>,
|
||||
pub id_salt: Option<IdSalt>,
|
||||
pub global_scope: bool,
|
||||
pub ui_stack_info: UiStackInfo,
|
||||
pub layer_id: Option<LayerId>,
|
||||
@@ -40,7 +40,7 @@ impl UiBuilder {
|
||||
/// within the parent, or give it none at all.
|
||||
#[inline]
|
||||
pub fn id_salt(mut self, id_salt: impl Into<IdSalt>) -> Self {
|
||||
self.id_salt = Some(id_salt.into().id());
|
||||
self.id_salt = Some(id_salt.into());
|
||||
self
|
||||
}
|
||||
|
||||
@@ -55,7 +55,7 @@ impl UiBuilder {
|
||||
/// This is a shortcut for `.id_salt(my_id).global_scope(true)`.
|
||||
#[inline]
|
||||
pub fn id(mut self, id: Id) -> Self {
|
||||
self.id_salt = Some(id);
|
||||
self.id_salt = Some(id.into());
|
||||
self.global_scope = true;
|
||||
self
|
||||
}
|
||||
|
||||
@@ -7,7 +7,8 @@ use epaint::{
|
||||
};
|
||||
|
||||
use crate::{
|
||||
Align, Align2, Color32, Context, CursorIcon, Event, EventFilter, FontSelection, Id, ImeEvent,
|
||||
Align, Align2, Color32, Context, CursorIcon, Event, EventFilter, FontSelection, Id, IdSalt,
|
||||
ImeEvent,
|
||||
Key, KeyboardShortcut, Margin, Modifiers, NumExt as _, Response, Sense, Shape, TextBuffer,
|
||||
TextStyle, TextWrapMode, Ui, Vec2, Widget, WidgetInfo, WidgetText, WidgetWithState, epaint,
|
||||
os::OperatingSystem,
|
||||
@@ -70,7 +71,7 @@ pub struct TextEdit<'t> {
|
||||
hint_text: WidgetText,
|
||||
hint_text_font: Option<FontSelection>,
|
||||
id: Option<Id>,
|
||||
id_salt: Option<Id>,
|
||||
id_salt: Option<IdSalt>,
|
||||
font_selection: FontSelection,
|
||||
text_color: Option<Color32>,
|
||||
layouter: Option<LayouterFn<'t>>,
|
||||
@@ -175,7 +176,7 @@ impl<'t> TextEdit<'t> {
|
||||
/// A source for the unique [`Id`], e.g. `.id_salt("second_text_edit_field")` or `.id_salt(loop_index)`.
|
||||
#[inline]
|
||||
pub fn id_salt(mut self, id_salt: impl Into<crate::IdSalt>) -> Self {
|
||||
self.id_salt = Some(id_salt.into().id());
|
||||
self.id_salt = Some(id_salt.into());
|
||||
self
|
||||
}
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ use accesskit_consumer::{FilterResult, Node, NodeId, Tree, TreeChangeHandler};
|
||||
|
||||
use eframe::epaint::text::TextWrapMode;
|
||||
use egui::{
|
||||
Button, Color32, Event, Frame, FullOutput, Id, Key, KeyboardShortcut, Label, Modifiers, Panel,
|
||||
Button, Color32, Event, Frame, FullOutput, Id, IdSalt, Key, KeyboardShortcut, Label, Modifiers, Panel,
|
||||
RawInput, RichText, ScrollArea, Ui, collapsing_header::CollapsingState,
|
||||
};
|
||||
|
||||
@@ -213,7 +213,7 @@ impl AccessibilityInspectorPlugin {
|
||||
#[expect(unsafe_code)]
|
||||
let egui_node_id = unsafe { Id::from_high_entropy_bits(node.locate().0.0) };
|
||||
|
||||
ui.push_id(node.id(), |ui| {
|
||||
ui.push_id(IdSalt::new(node.id()), |ui| {
|
||||
let child_count = node.children().len();
|
||||
let has_children = child_count > 0;
|
||||
let default_open = child_count == 1 && node.role() != accesskit::Role::Label;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use egui::{Id, Pos2, Rect, Response, Sense, Ui, UiBuilder, emath::GuiRounding as _};
|
||||
use egui::{Pos2, Rect, Response, Sense, Ui, UiBuilder, emath::GuiRounding as _};
|
||||
|
||||
#[derive(Clone, Copy)]
|
||||
pub(crate) enum CellSize {
|
||||
@@ -117,7 +117,7 @@ impl<'l> StripLayout<'l> {
|
||||
flags: StripLayoutFlags,
|
||||
width: CellSize,
|
||||
height: CellSize,
|
||||
child_ui_id_salt: Id,
|
||||
child_ui_id_salt: egui::IdSalt,
|
||||
add_cell_contents: impl FnOnce(&mut Ui),
|
||||
) -> (Rect, Response) {
|
||||
let max_rect = self.cell_rect(&width, &height);
|
||||
@@ -201,7 +201,7 @@ impl<'l> StripLayout<'l> {
|
||||
&mut self,
|
||||
flags: StripLayoutFlags,
|
||||
max_rect: Rect,
|
||||
child_ui_id_salt: egui::Id,
|
||||
child_ui_id_salt: egui::IdSalt,
|
||||
add_cell_contents: impl FnOnce(&mut Ui),
|
||||
) -> Ui {
|
||||
let mut ui_builder = UiBuilder::new()
|
||||
|
||||
@@ -198,7 +198,7 @@ impl Strip<'_, '_> {
|
||||
flags,
|
||||
width,
|
||||
height,
|
||||
egui::Id::new(self.size_index),
|
||||
egui::IdSalt::new(self.size_index),
|
||||
add_contents,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
//! Takes all available height, so if you want something below the table, put it in a strip.
|
||||
|
||||
use egui::{
|
||||
Align, Id, NumExt as _, Rangef, Rect, Response, ScrollArea, Ui, Vec2, Vec2b,
|
||||
Align, NumExt as _, Rangef, Rect, Response, ScrollArea, Ui, Vec2, Vec2b,
|
||||
scroll_area::{ScrollAreaOutput, ScrollBarVisibility, ScrollSource},
|
||||
};
|
||||
|
||||
@@ -246,7 +246,7 @@ impl Default for TableScrollOptions {
|
||||
/// ```
|
||||
pub struct TableBuilder<'a> {
|
||||
ui: &'a mut Ui,
|
||||
id_salt: Id,
|
||||
id_salt: egui::IdSalt,
|
||||
columns: Vec<Column>,
|
||||
striped: Option<bool>,
|
||||
resizable: bool,
|
||||
@@ -260,7 +260,7 @@ impl<'a> TableBuilder<'a> {
|
||||
let cell_layout = *ui.layout();
|
||||
Self {
|
||||
ui,
|
||||
id_salt: Id::new("__table_state"),
|
||||
id_salt: egui::IdSalt::from("__table_state"),
|
||||
columns: Default::default(),
|
||||
striped: None,
|
||||
resizable: false,
|
||||
@@ -284,7 +284,7 @@ impl<'a> TableBuilder<'a> {
|
||||
/// This is required if you have multiple tables in the same [`Ui`].
|
||||
#[inline]
|
||||
pub fn id_salt(mut self, id_salt: impl Into<egui::IdSalt>) -> Self {
|
||||
self.id_salt = id_salt.into().id();
|
||||
self.id_salt = id_salt.into();
|
||||
self
|
||||
}
|
||||
|
||||
@@ -1314,7 +1314,7 @@ impl TableRow<'_, '_> {
|
||||
flags,
|
||||
width,
|
||||
height,
|
||||
egui::Id::new((self.row_index, col_index)),
|
||||
egui::IdSalt::new((self.row_index, col_index)),
|
||||
add_cell_contents,
|
||||
);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user