1
0
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:
Nicolas
2024-09-02 09:29:01 +02:00
committed by GitHub
parent edea5a40b9
commit be944f0915
19 changed files with 169 additions and 121 deletions

View File

@@ -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)

View File

@@ -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() {