mirror of
https://github.com/emilk/egui.git
synced 2026-09-01 14:20:04 -04:00
Replace chrono with jiff (#8008)
`jiff` is more modern, and seem to be where the ecosystem is heading.
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
use super::popup::DatePickerPopup;
|
||||
use chrono::NaiveDate;
|
||||
use egui::{Area, Button, Frame, InnerResponse, Key, Order, RichText, Ui, Widget};
|
||||
use jiff::civil::Date;
|
||||
use std::ops::RangeInclusive;
|
||||
|
||||
#[derive(Default, Clone)]
|
||||
@@ -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,
|
||||
selection: &'a mut Date,
|
||||
id_salt: Option<&'a str>,
|
||||
combo_boxes: bool,
|
||||
arrows: bool,
|
||||
@@ -20,13 +20,13 @@ pub struct DatePickerButton<'a> {
|
||||
show_icon: bool,
|
||||
format: String,
|
||||
highlight_weekends: bool,
|
||||
start_end_years: Option<RangeInclusive<i32>>,
|
||||
start_end_years: Option<RangeInclusive<i16>>,
|
||||
reverse_years: bool,
|
||||
year_scroll_to: Option<i32>,
|
||||
year_scroll_to: Option<i16>,
|
||||
}
|
||||
|
||||
impl<'a> DatePickerButton<'a> {
|
||||
pub fn new(selection: &'a mut NaiveDate) -> Self {
|
||||
pub fn new(selection: &'a mut Date) -> Self {
|
||||
Self {
|
||||
selection,
|
||||
id_salt: None,
|
||||
@@ -95,7 +95,7 @@ impl<'a> DatePickerButton<'a> {
|
||||
}
|
||||
|
||||
/// Change the format shown on the button. (Default: %Y-%m-%d)
|
||||
/// See [`chrono::format::strftime`] for valid formats.
|
||||
/// See [`jiff::fmt::strtime`] for valid formats.
|
||||
#[inline]
|
||||
pub fn format(mut self, format: impl Into<String>) -> Self {
|
||||
self.format = format.into();
|
||||
@@ -115,7 +115,7 @@ impl<'a> DatePickerButton<'a> {
|
||||
/// For example, if you want to provide the range of years from 2000 to 2035, you can use:
|
||||
/// `start_end_years(2000..=2035)`.
|
||||
#[inline]
|
||||
pub fn start_end_years(mut self, start_end_years: RangeInclusive<i32>) -> Self {
|
||||
pub fn start_end_years(mut self, start_end_years: RangeInclusive<i16>) -> Self {
|
||||
self.start_end_years = Some(start_end_years);
|
||||
self
|
||||
}
|
||||
@@ -130,7 +130,7 @@ impl<'a> DatePickerButton<'a> {
|
||||
/// Scroll the year dropdown to this year when the picker first opens.
|
||||
/// Defaults to the currently selected year.
|
||||
#[inline]
|
||||
pub fn year_scroll_to(mut self, year: i32) -> Self {
|
||||
pub fn year_scroll_to(mut self, year: i16) -> Self {
|
||||
self.year_scroll_to = Some(year);
|
||||
self
|
||||
}
|
||||
@@ -144,9 +144,9 @@ impl Widget for DatePickerButton<'_> {
|
||||
.unwrap_or_default();
|
||||
|
||||
let mut text = if self.show_icon {
|
||||
RichText::new(format!("{} 📆", self.selection.format(&self.format)))
|
||||
RichText::new(format!("{} 📆", self.selection.strftime(&self.format)))
|
||||
} else {
|
||||
RichText::new(format!("{}", self.selection.format(&self.format)))
|
||||
RichText::new(format!("{}", self.selection.strftime(&self.format)))
|
||||
};
|
||||
let visuals = ui.visuals().widgets.open;
|
||||
if button_state.picker_visible {
|
||||
|
||||
Reference in New Issue
Block a user