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

egui_extras: Enable setting DatePickerButton start and end year explicitly (#7061)

Add the ability to set the `DatePickerButton`'s start and end years via
new `start_year` and `end_year` methods.

Continue to use the existing today - 100 years and today + 10 years
behavior if a year is not specified.

* This more fully closes <https://github.com/emilk/egui/issues/3597> and
expands on <https://github.com/emilk/egui/pull/3599>.
* [x] I have followed the instructions in the PR template
This commit is contained in:
Zach Bateman
2025-06-16 11:27:26 -05:00
committed by GitHub
parent 5194c0df3e
commit 011e0d261a
2 changed files with 21 additions and 1 deletions

View File

@@ -35,6 +35,7 @@ pub(crate) struct DatePickerPopup<'a> {
pub calendar: bool,
pub calendar_week: bool,
pub highlight_weekends: bool,
pub start_end_years: Option<std::ops::RangeInclusive<i32>>,
}
impl DatePickerPopup<'_> {
@@ -84,7 +85,11 @@ impl DatePickerPopup<'_> {
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 {
let (start_year, end_year) = match &self.start_end_years {
Some(range) => (*range.start(), *range.end()),
None => (today.year() - 100, today.year() + 10),
};
for year in start_year..=end_year {
if ui
.selectable_value(
&mut popup_state.year,