Skip to content

Commit ea20254

Browse files
bircnihacknus
authored andcommitted
Rename id_source to id_salt (emilk#5025)
* Closes <emilk#5020 > * [x] I have followed the instructions in the PR template
1 parent 2eab6db commit ea20254

File tree

19 files changed

+169
-121
lines changed

19 files changed

+169
-121
lines changed

crates/egui/src/containers/collapsing_header.rs

+17-8
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ pub struct CollapsingHeader {
372372
text: WidgetText,
373373
default_open: bool,
374374
open: Option<bool>,
375-
id_source: Id,
375+
id_salt: Id,
376376
enabled: bool,
377377
selectable: bool,
378378
selected: bool,
@@ -386,15 +386,15 @@ impl CollapsingHeader {
386386
/// The label is used as an [`Id`] source.
387387
/// If the label is unique and static this is fine,
388388
/// but if it changes or there are several [`CollapsingHeader`] with the same title
389-
/// you need to provide a unique id source with [`Self::id_source`].
389+
/// you need to provide a unique id source with [`Self::id_salt`].
390390
pub fn new(text: impl Into<WidgetText>) -> Self {
391391
let text = text.into();
392-
let id_source = Id::new(text.text());
392+
let id_salt = Id::new(text.text());
393393
Self {
394394
text,
395395
default_open: false,
396396
open: None,
397-
id_source,
397+
id_salt,
398398
enabled: true,
399399
selectable: false,
400400
selected: false,
@@ -425,8 +425,17 @@ impl CollapsingHeader {
425425
/// Explicitly set the source of the [`Id`] of this widget, instead of using title label.
426426
/// This is useful if the title label is dynamic or not unique.
427427
#[inline]
428-
pub fn id_source(mut self, id_source: impl Hash) -> Self {
429-
self.id_source = Id::new(id_source);
428+
pub fn id_salt(mut self, id_salt: impl Hash) -> Self {
429+
self.id_salt = Id::new(id_salt);
430+
self
431+
}
432+
433+
/// Explicitly set the source of the [`Id`] of this widget, instead of using title label.
434+
/// This is useful if the title label is dynamic or not unique.
435+
#[deprecated = "Renamed id_salt"]
436+
#[inline]
437+
pub fn id_source(mut self, id_salt: impl Hash) -> Self {
438+
self.id_salt = Id::new(id_salt);
430439
self
431440
}
432441

@@ -494,7 +503,7 @@ impl CollapsingHeader {
494503
text,
495504
default_open,
496505
open,
497-
id_source,
506+
id_salt,
498507
enabled: _,
499508
selectable,
500509
selected,
@@ -503,7 +512,7 @@ impl CollapsingHeader {
503512

504513
// TODO(emilk): horizontal layout, with icon and text as labels. Insert background behind using Frame.
505514

506-
let id = ui.make_persistent_id(id_source);
515+
let id = ui.make_persistent_id(id_salt);
507516
let button_padding = ui.spacing().button_padding;
508517

509518
let available = ui.available_rect_before_wrap();

crates/egui/src/containers/combo_box.rs

+15-9
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ pub type IconPainter = Box<dyn FnOnce(&Ui, Rect, &WidgetVisuals, bool, AboveOrBe
3838
/// ```
3939
#[must_use = "You should call .show*"]
4040
pub struct ComboBox {
41-
id_source: Id,
41+
id_salt: Id,
4242
label: Option<WidgetText>,
4343
selected_text: WidgetText,
4444
width: Option<f32>,
@@ -49,9 +49,9 @@ pub struct ComboBox {
4949

5050
impl ComboBox {
5151
/// Create new [`ComboBox`] with id and label
52-
pub fn new(id_source: impl std::hash::Hash, label: impl Into<WidgetText>) -> Self {
52+
pub fn new(id_salt: impl std::hash::Hash, label: impl Into<WidgetText>) -> Self {
5353
Self {
54-
id_source: Id::new(id_source),
54+
id_salt: Id::new(id_salt),
5555
label: Some(label.into()),
5656
selected_text: Default::default(),
5757
width: None,
@@ -65,7 +65,7 @@ impl ComboBox {
6565
pub fn from_label(label: impl Into<WidgetText>) -> Self {
6666
let label = label.into();
6767
Self {
68-
id_source: Id::new(label.text()),
68+
id_salt: Id::new(label.text()),
6969
label: Some(label),
7070
selected_text: Default::default(),
7171
width: None,
@@ -76,9 +76,9 @@ impl ComboBox {
7676
}
7777

7878
/// Without label.
79-
pub fn from_id_source(id_source: impl std::hash::Hash) -> Self {
79+
pub fn from_id_salt(id_salt: impl std::hash::Hash) -> Self {
8080
Self {
81-
id_source: Id::new(id_source),
81+
id_salt: Id::new(id_salt),
8282
label: Default::default(),
8383
selected_text: Default::default(),
8484
width: None,
@@ -88,6 +88,12 @@ impl ComboBox {
8888
}
8989
}
9090

91+
/// Without label.
92+
#[deprecated = "Renamed id_salt"]
93+
pub fn from_id_source(id_salt: impl std::hash::Hash) -> Self {
94+
Self::from_id_salt(id_salt)
95+
}
96+
9197
/// Set the outer width of the button and menu.
9298
///
9399
/// Default is [`Spacing::combo_width`].
@@ -138,7 +144,7 @@ impl ComboBox {
138144
/// ));
139145
/// }
140146
///
141-
/// egui::ComboBox::from_id_source("my-combobox")
147+
/// egui::ComboBox::from_id_salt("my-combobox")
142148
/// .selected_text(text)
143149
/// .icon(filled_triangle)
144150
/// .show_ui(ui, |_ui| {});
@@ -195,7 +201,7 @@ impl ComboBox {
195201
menu_contents: Box<dyn FnOnce(&mut Ui) -> R + 'c>,
196202
) -> InnerResponse<Option<R>> {
197203
let Self {
198-
id_source,
204+
id_salt,
199205
label,
200206
selected_text,
201207
width,
@@ -204,7 +210,7 @@ impl ComboBox {
204210
wrap_mode,
205211
} = self;
206212

207-
let button_id = ui.make_persistent_id(id_source);
213+
let button_id = ui.make_persistent_id(id_salt);
208214

209215
ui.horizontal(|ui| {
210216
let mut ir = combo_box_dyn(

crates/egui/src/containers/panel.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ impl SidePanel {
266266

267267
let mut panel_ui = ui.new_child(
268268
UiBuilder::new()
269-
.id_source(id)
269+
.id_salt(id)
270270
.ui_stack_info(UiStackInfo::new(match side {
271271
Side::Left => UiKind::LeftPanel,
272272
Side::Right => UiKind::RightPanel,
@@ -761,7 +761,7 @@ impl TopBottomPanel {
761761

762762
let mut panel_ui = ui.new_child(
763763
UiBuilder::new()
764-
.id_source(id)
764+
.id_salt(id)
765765
.ui_stack_info(UiStackInfo::new(match side {
766766
TopBottomSide::Top => UiKind::TopPanel,
767767
TopBottomSide::Bottom => UiKind::BottomPanel,

crates/egui/src/containers/resize.rs

+13-6
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ impl State {
3434
#[must_use = "You should call .show()"]
3535
pub struct Resize {
3636
id: Option<Id>,
37-
id_source: Option<Id>,
37+
id_salt: Option<Id>,
3838

3939
/// If false, we are no enabled
4040
resizable: Vec2b,
@@ -51,7 +51,7 @@ impl Default for Resize {
5151
fn default() -> Self {
5252
Self {
5353
id: None,
54-
id_source: None,
54+
id_salt: None,
5555
resizable: Vec2b::TRUE,
5656
min_size: Vec2::splat(16.0),
5757
max_size: Vec2::splat(f32::INFINITY),
@@ -71,8 +71,15 @@ impl Resize {
7171

7272
/// A source for the unique [`Id`], e.g. `.id_source("second_resize_area")` or `.id_source(loop_index)`.
7373
#[inline]
74-
pub fn id_source(mut self, id_source: impl std::hash::Hash) -> Self {
75-
self.id_source = Some(Id::new(id_source));
74+
#[deprecated = "Renamed id_salt"]
75+
pub fn id_source(self, id_salt: impl std::hash::Hash) -> Self {
76+
self.id_salt(id_salt)
77+
}
78+
79+
/// A source for the unique [`Id`], e.g. `.id_salt("second_resize_area")` or `.id_salt(loop_index)`.
80+
#[inline]
81+
pub fn id_salt(mut self, id_salt: impl std::hash::Hash) -> Self {
82+
self.id_salt = Some(Id::new(id_salt));
7683
self
7784
}
7885

@@ -201,8 +208,8 @@ impl Resize {
201208
fn begin(&mut self, ui: &mut Ui) -> Prepared {
202209
let position = ui.available_rect_before_wrap().min;
203210
let id = self.id.unwrap_or_else(|| {
204-
let id_source = self.id_source.unwrap_or_else(|| Id::new("resize"));
205-
ui.make_persistent_id(id_source)
211+
let id_salt = self.id_salt.unwrap_or_else(|| Id::new("resize"));
212+
ui.make_persistent_id(id_salt)
206213
});
207214

208215
let mut state = State::load(ui.ctx(), id).unwrap_or_else(|| {

crates/egui/src/containers/scroll_area.rs

+14-7
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ pub struct ScrollArea {
171171
max_size: Vec2,
172172
min_scrolled_size: Vec2,
173173
scroll_bar_visibility: ScrollBarVisibility,
174-
id_source: Option<Id>,
174+
id_salt: Option<Id>,
175175
offset_x: Option<f32>,
176176
offset_y: Option<f32>,
177177

@@ -223,7 +223,7 @@ impl ScrollArea {
223223
max_size: Vec2::INFINITY,
224224
min_scrolled_size: Vec2::splat(64.0),
225225
scroll_bar_visibility: Default::default(),
226-
id_source: None,
226+
id_salt: None,
227227
offset_x: None,
228228
offset_y: None,
229229
scrolling_enabled: true,
@@ -290,8 +290,15 @@ impl ScrollArea {
290290

291291
/// A source for the unique [`Id`], e.g. `.id_source("second_scroll_area")` or `.id_source(loop_index)`.
292292
#[inline]
293-
pub fn id_source(mut self, id_source: impl std::hash::Hash) -> Self {
294-
self.id_source = Some(Id::new(id_source));
293+
#[deprecated = "Renamed id_salt"]
294+
pub fn id_source(self, id_salt: impl std::hash::Hash) -> Self {
295+
self.id_salt(id_salt)
296+
}
297+
298+
/// A source for the unique [`Id`], e.g. `.id_salt("second_scroll_area")` or `.id_salt(loop_index)`.
299+
#[inline]
300+
pub fn id_salt(mut self, id_salt: impl std::hash::Hash) -> Self {
301+
self.id_salt = Some(Id::new(id_salt));
295302
self
296303
}
297304

@@ -490,7 +497,7 @@ impl ScrollArea {
490497
max_size,
491498
min_scrolled_size,
492499
scroll_bar_visibility,
493-
id_source,
500+
id_salt,
494501
offset_x,
495502
offset_y,
496503
scrolling_enabled,
@@ -502,8 +509,8 @@ impl ScrollArea {
502509
let ctx = ui.ctx().clone();
503510
let scrolling_enabled = scrolling_enabled && ui.is_enabled();
504511

505-
let id_source = id_source.unwrap_or_else(|| Id::new("scroll_area"));
506-
let id = ui.make_persistent_id(id_source);
512+
let id_salt = id_salt.unwrap_or_else(|| Id::new("scroll_area"));
513+
let id = ui.make_persistent_id(id_salt);
507514
ctx.check_for_id_clash(
508515
id,
509516
Rect::from_min_size(ui.available_rect_before_wrap().min, Vec2::ZERO),

crates/egui/src/context.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1022,7 +1022,7 @@ impl Context {
10221022
tooltip_pos,
10231023
format!("Widget is {} this text.\n\n\
10241024
ID clashes happens when things like Windows or CollapsingHeaders share names,\n\
1025-
or when things like Plot and Grid:s aren't given unique id_source:s.\n\n\
1025+
or when things like Plot and Grid:s aren't given unique id_salt:s.\n\n\
10261026
Sometimes the solution is to use ui.push_id.",
10271027
if below { "above" } else { "below" })
10281028
);

crates/egui/src/grid.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ impl GridLayout {
299299
/// ```
300300
#[must_use = "You should call .show()"]
301301
pub struct Grid {
302-
id_source: Id,
302+
id_salt: Id,
303303
num_columns: Option<usize>,
304304
min_col_width: Option<f32>,
305305
min_row_height: Option<f32>,
@@ -311,9 +311,9 @@ pub struct Grid {
311311

312312
impl Grid {
313313
/// Create a new [`Grid`] with a locally unique identifier.
314-
pub fn new(id_source: impl std::hash::Hash) -> Self {
314+
pub fn new(id_salt: impl std::hash::Hash) -> Self {
315315
Self {
316-
id_source: Id::new(id_source),
316+
id_salt: Id::new(id_salt),
317317
num_columns: None,
318318
min_col_width: None,
319319
min_row_height: None,
@@ -407,7 +407,7 @@ impl Grid {
407407
add_contents: Box<dyn FnOnce(&mut Ui) -> R + 'c>,
408408
) -> InnerResponse<R> {
409409
let Self {
410-
id_source,
410+
id_salt,
411411
num_columns,
412412
min_col_width,
413413
min_row_height,
@@ -423,7 +423,7 @@ impl Grid {
423423
color_picker = Some(Box::new(striped_row_color));
424424
}
425425

426-
let id = ui.make_persistent_id(id_source);
426+
let id = ui.make_persistent_id(id_salt);
427427
let prev_state = State::load(ui.ctx(), id);
428428

429429
// Each grid cell is aligned LEFT_CENTER.

crates/egui/src/style.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1537,7 +1537,7 @@ impl Style {
15371537
ui.end_row();
15381538

15391539
ui.label("Override text style");
1540-
crate::ComboBox::from_id_source("Override text style")
1540+
crate::ComboBox::from_id_salt("Override text style")
15411541
.selected_text(match override_text_style {
15421542
None => "None".to_owned(),
15431543
Some(override_text_style) => override_text_style.to_string(),
@@ -1554,7 +1554,7 @@ impl Style {
15541554
ui.end_row();
15551555

15561556
ui.label("Text style of DragValue");
1557-
crate::ComboBox::from_id_source("drag_value_text_style")
1557+
crate::ComboBox::from_id_salt("drag_value_text_style")
15581558
.selected_text(drag_value_text_style.to_string())
15591559
.show_ui(ui, |ui| {
15601560
let all_text_styles = ui.style().text_styles();
@@ -1567,7 +1567,7 @@ impl Style {
15671567
ui.end_row();
15681568

15691569
ui.label("Text Wrap Mode");
1570-
crate::ComboBox::from_id_source("text_wrap_mode")
1570+
crate::ComboBox::from_id_salt("text_wrap_mode")
15711571
.selected_text(format!("{wrap_mode:?}"))
15721572
.show_ui(ui, |ui| {
15731573
let all_wrap_mode: Vec<Option<TextWrapMode>> = vec![

0 commit comments

Comments
 (0)