mirror of
https://github.com/emilk/egui.git
synced 2026-08-30 21:30:03 -04:00
integrate into egui
This commit is contained in:
@@ -1,3 +1,8 @@
|
||||
use egui_datepicker::DatePickerButton;
|
||||
|
||||
#[cfg(feature = "datetime")]
|
||||
mod serde_date_format;
|
||||
|
||||
#[derive(Debug, PartialEq)]
|
||||
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
|
||||
enum Enum {
|
||||
@@ -17,6 +22,9 @@ pub struct WidgetGallery {
|
||||
string: String,
|
||||
color: egui::Color32,
|
||||
animate_progress_bar: bool,
|
||||
#[cfg(feature = "datetime")]
|
||||
#[serde(with = "serde_date_format")]
|
||||
date: chrono::Date<chrono::Utc>,
|
||||
}
|
||||
|
||||
impl Default for WidgetGallery {
|
||||
@@ -30,6 +38,8 @@ impl Default for WidgetGallery {
|
||||
string: Default::default(),
|
||||
color: egui::Color32::LIGHT_BLUE.linear_multiply(0.5),
|
||||
animate_progress_bar: false,
|
||||
#[cfg(feature = "datetime")]
|
||||
date: chrono::offset::Utc::now().date(),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -99,6 +109,7 @@ impl WidgetGallery {
|
||||
string,
|
||||
color,
|
||||
animate_progress_bar,
|
||||
date,
|
||||
} = self;
|
||||
|
||||
ui.add(doc_link_label("Label", "label,heading"));
|
||||
@@ -195,6 +206,13 @@ impl WidgetGallery {
|
||||
}
|
||||
ui.end_row();
|
||||
|
||||
#[cfg(feature = "datetime")]
|
||||
{
|
||||
ui.add(doc_link_label("DatePickerButton", "DatePickerButton"));
|
||||
ui.add(DatePickerButton::new(date));
|
||||
ui.end_row();
|
||||
}
|
||||
|
||||
ui.add(doc_link_label("Separator", "separator"));
|
||||
ui.separator();
|
||||
ui.end_row();
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
use chrono::{Date, NaiveDate, Utc};
|
||||
use serde::{self, Deserialize, Deserializer, Serializer};
|
||||
|
||||
const FORMAT: &str = "%d.%m.%Y";
|
||||
|
||||
pub fn serialize<S>(date: &Date<Utc>, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: Serializer,
|
||||
{
|
||||
let s = format!("{}", date.format(FORMAT));
|
||||
serializer.serialize_str(&s)
|
||||
}
|
||||
|
||||
pub fn deserialize<'de, D>(deserializer: D) -> Result<Date<Utc>, D::Error>
|
||||
where
|
||||
D: Deserializer<'de>,
|
||||
{
|
||||
let s = String::deserialize(deserializer)?;
|
||||
|
||||
NaiveDate::parse_from_str(&s, FORMAT)
|
||||
.map(|naive_date| Date::from_utc(naive_date, Utc))
|
||||
.map_err(serde::de::Error::custom)
|
||||
}
|
||||
Reference in New Issue
Block a user