mirror of
https://github.com/emilk/egui.git
synced 2026-08-31 05:40:03 -04:00
Rename id_source to id_salt (#5025)
* Closes <https://github.com/emilk/egui/issues/5020 > * [x] I have followed the instructions in the PR template
This commit is contained in:
@@ -11,7 +11,7 @@ pub(crate) struct DatePickerButtonState {
|
||||
/// Shows a date, and will open a date picker popup when clicked.
|
||||
pub struct DatePickerButton<'a> {
|
||||
selection: &'a mut NaiveDate,
|
||||
id_source: Option<&'a str>,
|
||||
id_salt: Option<&'a str>,
|
||||
combo_boxes: bool,
|
||||
arrows: bool,
|
||||
calendar: bool,
|
||||
@@ -25,7 +25,7 @@ impl<'a> DatePickerButton<'a> {
|
||||
pub fn new(selection: &'a mut NaiveDate) -> Self {
|
||||
Self {
|
||||
selection,
|
||||
id_source: None,
|
||||
id_salt: None,
|
||||
combo_boxes: true,
|
||||
arrows: true,
|
||||
calendar: true,
|
||||
@@ -39,11 +39,19 @@ impl<'a> DatePickerButton<'a> {
|
||||
/// Add id source.
|
||||
/// Must be set if multiple date picker buttons are in the same Ui.
|
||||
#[inline]
|
||||
pub fn id_source(mut self, id_source: &'a str) -> Self {
|
||||
self.id_source = Some(id_source);
|
||||
pub fn id_salt(mut self, id_salt: &'a str) -> Self {
|
||||
self.id_salt = Some(id_salt);
|
||||
self
|
||||
}
|
||||
|
||||
/// Add id source.
|
||||
/// Must be set if multiple date picker buttons are in the same Ui.
|
||||
#[inline]
|
||||
#[deprecated = "Renamed id_salt"]
|
||||
pub fn id_source(self, id_salt: &'a str) -> Self {
|
||||
self.id_salt(id_salt)
|
||||
}
|
||||
|
||||
/// Show combo boxes in date picker popup. (Default: true)
|
||||
#[inline]
|
||||
pub fn combo_boxes(mut self, combo_boxes: bool) -> Self {
|
||||
@@ -97,7 +105,7 @@ impl<'a> DatePickerButton<'a> {
|
||||
|
||||
impl<'a> Widget for DatePickerButton<'a> {
|
||||
fn ui(self, ui: &mut Ui) -> egui::Response {
|
||||
let id = ui.make_persistent_id(self.id_source);
|
||||
let id = ui.make_persistent_id(self.id_salt);
|
||||
let mut button_state = ui
|
||||
.data_mut(|data| data.get_persisted::<DatePickerButtonState>(id))
|
||||
.unwrap_or_default();
|
||||
@@ -140,7 +148,7 @@ impl<'a> Widget for DatePickerButton<'a> {
|
||||
let InnerResponse {
|
||||
inner: saved,
|
||||
response: area_response,
|
||||
} = Area::new(ui.make_persistent_id(self.id_source))
|
||||
} = Area::new(ui.make_persistent_id(self.id_salt))
|
||||
.kind(egui::UiKind::Picker)
|
||||
.order(Order::Foreground)
|
||||
.fixed_pos(pos)
|
||||
|
||||
@@ -81,7 +81,7 @@ impl<'a> DatePickerPopup<'a> {
|
||||
strip.strip(|builder| {
|
||||
builder.sizes(Size::remainder(), 3).horizontal(|mut strip| {
|
||||
strip.cell(|ui| {
|
||||
ComboBox::from_id_source("date_picker_year")
|
||||
ComboBox::from_id_salt("date_picker_year")
|
||||
.selected_text(popup_state.year.to_string())
|
||||
.show_ui(ui, |ui| {
|
||||
for year in today.year() - 100..today.year() + 10 {
|
||||
@@ -105,7 +105,7 @@ impl<'a> DatePickerPopup<'a> {
|
||||
});
|
||||
});
|
||||
strip.cell(|ui| {
|
||||
ComboBox::from_id_source("date_picker_month")
|
||||
ComboBox::from_id_salt("date_picker_month")
|
||||
.selected_text(month_name(popup_state.month))
|
||||
.show_ui(ui, |ui| {
|
||||
for month in 1..=12 {
|
||||
@@ -129,7 +129,7 @@ impl<'a> DatePickerPopup<'a> {
|
||||
});
|
||||
});
|
||||
strip.cell(|ui| {
|
||||
ComboBox::from_id_source("date_picker_day")
|
||||
ComboBox::from_id_salt("date_picker_day")
|
||||
.selected_text(popup_state.day.to_string())
|
||||
.show_ui(ui, |ui| {
|
||||
for day in 1..=popup_state.last_day_of_month() {
|
||||
|
||||
@@ -116,7 +116,7 @@ impl<'l> StripLayout<'l> {
|
||||
flags: StripLayoutFlags,
|
||||
width: CellSize,
|
||||
height: CellSize,
|
||||
child_ui_id_source: Id,
|
||||
child_ui_id_salt: Id,
|
||||
add_cell_contents: impl FnOnce(&mut Ui),
|
||||
) -> (Rect, Response) {
|
||||
let max_rect = self.cell_rect(&width, &height);
|
||||
@@ -149,7 +149,7 @@ impl<'l> StripLayout<'l> {
|
||||
);
|
||||
}
|
||||
|
||||
let child_ui = self.cell(flags, max_rect, child_ui_id_source, add_cell_contents);
|
||||
let child_ui = self.cell(flags, max_rect, child_ui_id_salt, add_cell_contents);
|
||||
|
||||
let used_rect = child_ui.min_rect();
|
||||
|
||||
@@ -197,11 +197,11 @@ impl<'l> StripLayout<'l> {
|
||||
&mut self,
|
||||
flags: StripLayoutFlags,
|
||||
max_rect: Rect,
|
||||
child_ui_id_source: egui::Id,
|
||||
child_ui_id_salt: egui::Id,
|
||||
add_cell_contents: impl FnOnce(&mut Ui),
|
||||
) -> Ui {
|
||||
let mut ui_builder = UiBuilder::new()
|
||||
.id_source(child_ui_id_source)
|
||||
.id_salt(child_ui_id_salt)
|
||||
.ui_stack_info(egui::UiStackInfo::new(egui::UiKind::TableCell))
|
||||
.max_rect(max_rect)
|
||||
.layout(self.cell_layout);
|
||||
|
||||
@@ -213,7 +213,7 @@ impl Default for TableScrollOptions {
|
||||
/// You must pre-allocate all columns with [`Self::column`]/[`Self::columns`].
|
||||
///
|
||||
/// If you have multiple [`Table`]:s in the same [`Ui`]
|
||||
/// you will need to give them unique id:s by with [`Self::id_source`].
|
||||
/// you will need to give them unique id:s by with [`Self::id_salt`].
|
||||
///
|
||||
/// ### Example
|
||||
/// ```
|
||||
@@ -244,7 +244,7 @@ impl Default for TableScrollOptions {
|
||||
/// ```
|
||||
pub struct TableBuilder<'a> {
|
||||
ui: &'a mut Ui,
|
||||
id_source: Id,
|
||||
id_salt: Id,
|
||||
columns: Vec<Column>,
|
||||
striped: Option<bool>,
|
||||
resizable: bool,
|
||||
@@ -258,7 +258,7 @@ impl<'a> TableBuilder<'a> {
|
||||
let cell_layout = *ui.layout();
|
||||
Self {
|
||||
ui,
|
||||
id_source: Id::new("__table_state"),
|
||||
id_salt: Id::new("__table_state"),
|
||||
columns: Default::default(),
|
||||
striped: None,
|
||||
resizable: false,
|
||||
@@ -272,8 +272,17 @@ impl<'a> TableBuilder<'a> {
|
||||
///
|
||||
/// This is required if you have multiple tables in the same [`Ui`].
|
||||
#[inline]
|
||||
pub fn id_source(mut self, id_source: impl std::hash::Hash) -> Self {
|
||||
self.id_source = Id::new(id_source);
|
||||
#[deprecated = "Renamed id_salt"]
|
||||
pub fn id_source(self, id_salt: impl std::hash::Hash) -> Self {
|
||||
self.id_salt(id_salt)
|
||||
}
|
||||
|
||||
/// Give this table a unique id within the parent [`Ui`].
|
||||
///
|
||||
/// This is required if you have multiple tables in the same [`Ui`].
|
||||
#[inline]
|
||||
pub fn id_salt(mut self, id_salt: impl std::hash::Hash) -> Self {
|
||||
self.id_salt = Id::new(id_salt);
|
||||
self
|
||||
}
|
||||
|
||||
@@ -431,7 +440,7 @@ impl<'a> TableBuilder<'a> {
|
||||
|
||||
/// Reset all column widths.
|
||||
pub fn reset(&mut self) {
|
||||
let state_id = self.ui.id().with(self.id_source);
|
||||
let state_id = self.ui.id().with(self.id_salt);
|
||||
TableState::reset(self.ui, state_id);
|
||||
}
|
||||
|
||||
@@ -441,7 +450,7 @@ impl<'a> TableBuilder<'a> {
|
||||
|
||||
let Self {
|
||||
ui,
|
||||
id_source,
|
||||
id_salt,
|
||||
columns,
|
||||
striped,
|
||||
resizable,
|
||||
@@ -452,7 +461,7 @@ impl<'a> TableBuilder<'a> {
|
||||
|
||||
let striped = striped.unwrap_or(ui.visuals().striped);
|
||||
|
||||
let state_id = ui.id().with(id_source);
|
||||
let state_id = ui.id().with(id_salt);
|
||||
|
||||
let (is_sizing_pass, state) =
|
||||
TableState::load(ui, state_id, resizable, &columns, available_width);
|
||||
@@ -509,7 +518,7 @@ impl<'a> TableBuilder<'a> {
|
||||
|
||||
let Self {
|
||||
ui,
|
||||
id_source,
|
||||
id_salt,
|
||||
columns,
|
||||
striped,
|
||||
resizable,
|
||||
@@ -520,7 +529,7 @@ impl<'a> TableBuilder<'a> {
|
||||
|
||||
let striped = striped.unwrap_or(ui.visuals().striped);
|
||||
|
||||
let state_id = ui.id().with(id_source);
|
||||
let state_id = ui.id().with(id_salt);
|
||||
|
||||
let (is_sizing_pass, state) =
|
||||
TableState::load(ui, state_id, resizable, &columns, available_width);
|
||||
|
||||
Reference in New Issue
Block a user