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:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user