Struct DatePicker

Source
pub struct DatePicker<'a, Tz>
where Tz: TimeZone, Tz::Offset: Display,
{ /* private fields */ }
Expand description

Default values of fields are:

  • sunday_first: false
  • movable: false
  • format_string: "%Y-%m-%d"
  • weekend_func: date.weekday() == Weekday::Sat || date.weekday() == Weekday::Sun

Implementations§

Source§

impl<'a, Tz> DatePicker<'a, Tz>
where Tz: TimeZone, Tz::Offset: Display,

Source

pub fn new<T: Hash>(id: T, date: &'a mut Date<Tz>) -> Self

Create new date picker with unique id and mutable reference to date.

Examples found in repository?
examples/simple.rs (line 30)
25    fn update(&mut self, ctx: &egui::CtxRef, _frame: &epi::Frame) {
26        // ctx.set_debug_on_hover(true);
27        egui::CentralPanel::default().show(ctx, |ui| {
28            egui::Grid::new("exaamples_grid").show(ui, |ui| {
29                ui.label("Default");
30                ui.add(DatePicker::new("default", &mut self.date));
31                ui.end_row();
32                ui.label("Sunday first");
33                ui.add(DatePicker::new("sundayfirst", &mut self.date).sunday_first(true));
34                ui.end_row();
35                ui.label("Movable popup");
36                ui.add(DatePicker::new("movable", &mut self.date).movable(true));
37                ui.end_row();
38                ui.label("Different format");
39                ui.add(DatePicker::new("differentformat", &mut self.date).date_format(&"%d/%m/%Y"));
40                ui.end_row();
41                ui.label("Disable weekend highlight");
42                ui.add(
43                    DatePicker::new("noweekendhighlight", &mut self.date).highlight_weekend(false),
44                );
45                ui.end_row();
46                ui.label("Different weekend color");
47                ui.add(
48                    DatePicker::new("differentweekendcolor", &mut self.date)
49                        .highlight_weekend_color(Color32::from_rgb(0, 196, 0)),
50                );
51                ui.end_row();
52                ui.label("Different weekend days, i.e. holidays, Christmas, etc");
53                ui.add(
54                    DatePicker::new("differentweekenddays", &mut self.date)
55                        .weekend_days(|date| date.day() % 2 == 0),
56                );
57                ui.end_row();
58            });
59        });
60    }
Source

pub fn sunday_first(self, flag: bool) -> Self

If flag is set to true then first day in calendar will be sunday otherwise monday. Default is false

Examples found in repository?
examples/simple.rs (line 33)
25    fn update(&mut self, ctx: &egui::CtxRef, _frame: &epi::Frame) {
26        // ctx.set_debug_on_hover(true);
27        egui::CentralPanel::default().show(ctx, |ui| {
28            egui::Grid::new("exaamples_grid").show(ui, |ui| {
29                ui.label("Default");
30                ui.add(DatePicker::new("default", &mut self.date));
31                ui.end_row();
32                ui.label("Sunday first");
33                ui.add(DatePicker::new("sundayfirst", &mut self.date).sunday_first(true));
34                ui.end_row();
35                ui.label("Movable popup");
36                ui.add(DatePicker::new("movable", &mut self.date).movable(true));
37                ui.end_row();
38                ui.label("Different format");
39                ui.add(DatePicker::new("differentformat", &mut self.date).date_format(&"%d/%m/%Y"));
40                ui.end_row();
41                ui.label("Disable weekend highlight");
42                ui.add(
43                    DatePicker::new("noweekendhighlight", &mut self.date).highlight_weekend(false),
44                );
45                ui.end_row();
46                ui.label("Different weekend color");
47                ui.add(
48                    DatePicker::new("differentweekendcolor", &mut self.date)
49                        .highlight_weekend_color(Color32::from_rgb(0, 196, 0)),
50                );
51                ui.end_row();
52                ui.label("Different weekend days, i.e. holidays, Christmas, etc");
53                ui.add(
54                    DatePicker::new("differentweekenddays", &mut self.date)
55                        .weekend_days(|date| date.day() % 2 == 0),
56                );
57                ui.end_row();
58            });
59        });
60    }
Source

pub fn movable(self, flag: bool) -> Self

If flag is set to true then date picker popup will be movable. Default is false

Examples found in repository?
examples/simple.rs (line 36)
25    fn update(&mut self, ctx: &egui::CtxRef, _frame: &epi::Frame) {
26        // ctx.set_debug_on_hover(true);
27        egui::CentralPanel::default().show(ctx, |ui| {
28            egui::Grid::new("exaamples_grid").show(ui, |ui| {
29                ui.label("Default");
30                ui.add(DatePicker::new("default", &mut self.date));
31                ui.end_row();
32                ui.label("Sunday first");
33                ui.add(DatePicker::new("sundayfirst", &mut self.date).sunday_first(true));
34                ui.end_row();
35                ui.label("Movable popup");
36                ui.add(DatePicker::new("movable", &mut self.date).movable(true));
37                ui.end_row();
38                ui.label("Different format");
39                ui.add(DatePicker::new("differentformat", &mut self.date).date_format(&"%d/%m/%Y"));
40                ui.end_row();
41                ui.label("Disable weekend highlight");
42                ui.add(
43                    DatePicker::new("noweekendhighlight", &mut self.date).highlight_weekend(false),
44                );
45                ui.end_row();
46                ui.label("Different weekend color");
47                ui.add(
48                    DatePicker::new("differentweekendcolor", &mut self.date)
49                        .highlight_weekend_color(Color32::from_rgb(0, 196, 0)),
50                );
51                ui.end_row();
52                ui.label("Different weekend days, i.e. holidays, Christmas, etc");
53                ui.add(
54                    DatePicker::new("differentweekenddays", &mut self.date)
55                        .weekend_days(|date| date.day() % 2 == 0),
56                );
57                ui.end_row();
58            });
59        });
60    }
Source

pub fn date_format(self, new_format: &impl ToString) -> Self

Set date format. See the chrono::format::strftime for the specification.

Examples found in repository?
examples/simple.rs (line 39)
25    fn update(&mut self, ctx: &egui::CtxRef, _frame: &epi::Frame) {
26        // ctx.set_debug_on_hover(true);
27        egui::CentralPanel::default().show(ctx, |ui| {
28            egui::Grid::new("exaamples_grid").show(ui, |ui| {
29                ui.label("Default");
30                ui.add(DatePicker::new("default", &mut self.date));
31                ui.end_row();
32                ui.label("Sunday first");
33                ui.add(DatePicker::new("sundayfirst", &mut self.date).sunday_first(true));
34                ui.end_row();
35                ui.label("Movable popup");
36                ui.add(DatePicker::new("movable", &mut self.date).movable(true));
37                ui.end_row();
38                ui.label("Different format");
39                ui.add(DatePicker::new("differentformat", &mut self.date).date_format(&"%d/%m/%Y"));
40                ui.end_row();
41                ui.label("Disable weekend highlight");
42                ui.add(
43                    DatePicker::new("noweekendhighlight", &mut self.date).highlight_weekend(false),
44                );
45                ui.end_row();
46                ui.label("Different weekend color");
47                ui.add(
48                    DatePicker::new("differentweekendcolor", &mut self.date)
49                        .highlight_weekend_color(Color32::from_rgb(0, 196, 0)),
50                );
51                ui.end_row();
52                ui.label("Different weekend days, i.e. holidays, Christmas, etc");
53                ui.add(
54                    DatePicker::new("differentweekenddays", &mut self.date)
55                        .weekend_days(|date| date.day() % 2 == 0),
56                );
57                ui.end_row();
58            });
59        });
60    }
Source

pub fn highlight_weekend(self, highlight: bool) -> Self

If highlight is true then weekends text color will be weekend_color instead default text color.

Examples found in repository?
examples/simple.rs (line 43)
25    fn update(&mut self, ctx: &egui::CtxRef, _frame: &epi::Frame) {
26        // ctx.set_debug_on_hover(true);
27        egui::CentralPanel::default().show(ctx, |ui| {
28            egui::Grid::new("exaamples_grid").show(ui, |ui| {
29                ui.label("Default");
30                ui.add(DatePicker::new("default", &mut self.date));
31                ui.end_row();
32                ui.label("Sunday first");
33                ui.add(DatePicker::new("sundayfirst", &mut self.date).sunday_first(true));
34                ui.end_row();
35                ui.label("Movable popup");
36                ui.add(DatePicker::new("movable", &mut self.date).movable(true));
37                ui.end_row();
38                ui.label("Different format");
39                ui.add(DatePicker::new("differentformat", &mut self.date).date_format(&"%d/%m/%Y"));
40                ui.end_row();
41                ui.label("Disable weekend highlight");
42                ui.add(
43                    DatePicker::new("noweekendhighlight", &mut self.date).highlight_weekend(false),
44                );
45                ui.end_row();
46                ui.label("Different weekend color");
47                ui.add(
48                    DatePicker::new("differentweekendcolor", &mut self.date)
49                        .highlight_weekend_color(Color32::from_rgb(0, 196, 0)),
50                );
51                ui.end_row();
52                ui.label("Different weekend days, i.e. holidays, Christmas, etc");
53                ui.add(
54                    DatePicker::new("differentweekenddays", &mut self.date)
55                        .weekend_days(|date| date.day() % 2 == 0),
56                );
57                ui.end_row();
58            });
59        });
60    }
Source

pub fn highlight_weekend_color(self, color: Color32) -> Self

Set weekends highlighting color.

Examples found in repository?
examples/simple.rs (line 49)
25    fn update(&mut self, ctx: &egui::CtxRef, _frame: &epi::Frame) {
26        // ctx.set_debug_on_hover(true);
27        egui::CentralPanel::default().show(ctx, |ui| {
28            egui::Grid::new("exaamples_grid").show(ui, |ui| {
29                ui.label("Default");
30                ui.add(DatePicker::new("default", &mut self.date));
31                ui.end_row();
32                ui.label("Sunday first");
33                ui.add(DatePicker::new("sundayfirst", &mut self.date).sunday_first(true));
34                ui.end_row();
35                ui.label("Movable popup");
36                ui.add(DatePicker::new("movable", &mut self.date).movable(true));
37                ui.end_row();
38                ui.label("Different format");
39                ui.add(DatePicker::new("differentformat", &mut self.date).date_format(&"%d/%m/%Y"));
40                ui.end_row();
41                ui.label("Disable weekend highlight");
42                ui.add(
43                    DatePicker::new("noweekendhighlight", &mut self.date).highlight_weekend(false),
44                );
45                ui.end_row();
46                ui.label("Different weekend color");
47                ui.add(
48                    DatePicker::new("differentweekendcolor", &mut self.date)
49                        .highlight_weekend_color(Color32::from_rgb(0, 196, 0)),
50                );
51                ui.end_row();
52                ui.label("Different weekend days, i.e. holidays, Christmas, etc");
53                ui.add(
54                    DatePicker::new("differentweekenddays", &mut self.date)
55                        .weekend_days(|date| date.day() % 2 == 0),
56                );
57                ui.end_row();
58            });
59        });
60    }
Source

pub fn weekend_days(self, is_weekend: fn(&Date<Tz>) -> bool) -> Self

Set function, which will decide if date is a weekend day or not.

Examples found in repository?
examples/simple.rs (line 55)
25    fn update(&mut self, ctx: &egui::CtxRef, _frame: &epi::Frame) {
26        // ctx.set_debug_on_hover(true);
27        egui::CentralPanel::default().show(ctx, |ui| {
28            egui::Grid::new("exaamples_grid").show(ui, |ui| {
29                ui.label("Default");
30                ui.add(DatePicker::new("default", &mut self.date));
31                ui.end_row();
32                ui.label("Sunday first");
33                ui.add(DatePicker::new("sundayfirst", &mut self.date).sunday_first(true));
34                ui.end_row();
35                ui.label("Movable popup");
36                ui.add(DatePicker::new("movable", &mut self.date).movable(true));
37                ui.end_row();
38                ui.label("Different format");
39                ui.add(DatePicker::new("differentformat", &mut self.date).date_format(&"%d/%m/%Y"));
40                ui.end_row();
41                ui.label("Disable weekend highlight");
42                ui.add(
43                    DatePicker::new("noweekendhighlight", &mut self.date).highlight_weekend(false),
44                );
45                ui.end_row();
46                ui.label("Different weekend color");
47                ui.add(
48                    DatePicker::new("differentweekendcolor", &mut self.date)
49                        .highlight_weekend_color(Color32::from_rgb(0, 196, 0)),
50                );
51                ui.end_row();
52                ui.label("Different weekend days, i.e. holidays, Christmas, etc");
53                ui.add(
54                    DatePicker::new("differentweekenddays", &mut self.date)
55                        .weekend_days(|date| date.day() % 2 == 0),
56                );
57                ui.end_row();
58            });
59        });
60    }

Trait Implementations§

Source§

impl<'a, Tz> Widget for DatePicker<'a, Tz>
where Tz: TimeZone, Tz::Offset: Display,

Source§

fn ui(self, ui: &mut Ui) -> Response

Allocate space, interact, paint, and return a Response. Read more

Auto Trait Implementations§

§

impl<'a, Tz> Freeze for DatePicker<'a, Tz>

§

impl<'a, Tz> RefUnwindSafe for DatePicker<'a, Tz>
where <Tz as TimeZone>::Offset: RefUnwindSafe,

§

impl<'a, Tz> Send for DatePicker<'a, Tz>
where <Tz as TimeZone>::Offset: Send,

§

impl<'a, Tz> Sync for DatePicker<'a, Tz>
where <Tz as TimeZone>::Offset: Sync,

§

impl<'a, Tz> Unpin for DatePicker<'a, Tz>

§

impl<'a, Tz> !UnwindSafe for DatePicker<'a, Tz>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.