Fix sh/check.sh (#1446)

* Don't bother serializing date in widget gallery
* Make egui_extras non-optional dependency of egui_demo_lib
This commit is contained in:
Emil Ernerfeldt 2022-04-03 18:14:40 +02:00 committed by GitHub
parent 10f30a0c52
commit 861b0e11ba
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 34 deletions

View file

@ -28,7 +28,7 @@ extra_debug_asserts = ["egui/extra_debug_asserts"]
extra_asserts = ["egui/extra_asserts"]
datetime = ["egui_extras/chrono", "chrono"]
http = ["egui_extras", "ehttp", "image", "poll-promise"]
http = ["ehttp", "image", "poll-promise"]
persistence = [
"egui/persistence",
"epi/persistence",
@ -42,6 +42,10 @@ syntax_highlighting = ["syntect"]
[dependencies]
egui = { version = "0.17.0", path = "../egui", default-features = false }
epi = { version = "0.17.0", path = "../epi" }
egui_extras = { version = "0.17.0", path = "../egui_extras", features = [
"image",
"datepicker",
] }
chrono = { version = "0.4", optional = true, features = ["js-sys", "wasmbind"] }
enum-map = { version = "2", features = ["serde"] }
@ -49,10 +53,6 @@ tracing = "0.1"
unicode_names2 = { version = "0.5.0", default-features = false }
# feature "http":
egui_extras = { version = "0.17.0", path = "../egui_extras", optional = true, features = [
"image",
"datepicker",
] }
ehttp = { version = "0.2.0", optional = true }
image = { version = "0.24", optional = true, default-features = false, features = [
"jpeg",

View file

@ -1,6 +1,3 @@
#[cfg(feature = "datetime")]
mod serde_date_format;
#[derive(Debug, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
enum Enum {
@ -20,9 +17,11 @@ 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>,
#[cfg_attr(feature = "serde", serde(skip))]
date: Option<chrono::Date<chrono::Utc>>,
#[cfg_attr(feature = "serde", serde(skip))]
texture: Option<egui::TextureHandle>,
}
@ -39,7 +38,7 @@ impl Default for WidgetGallery {
color: egui::Color32::LIGHT_BLUE.linear_multiply(0.5),
animate_progress_bar: false,
#[cfg(feature = "datetime")]
date: chrono::offset::Utc::now().date(),
date: None,
texture: None,
}
}
@ -110,6 +109,7 @@ impl WidgetGallery {
string,
color,
animate_progress_bar,
#[cfg(feature = "datetime")]
date,
texture,
} = self;
@ -212,6 +212,7 @@ impl WidgetGallery {
#[cfg(feature = "datetime")]
{
let date = date.get_or_insert_with(|| chrono::offset::Utc::now().date());
ui.add(doc_link_label("DatePickerButton", "DatePickerButton"));
ui.add(egui_extras::DatePickerButton::new(date));
ui.end_row();

View file

@ -1,23 +0,0 @@
use chrono::{Date, NaiveDate, Utc};
use serde::{self, Deserialize, Deserializer, Serializer};
const FORMAT: &str = "%Y-%m-%d";
pub fn serialize<S>(date: &Date<Utc>, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
let s = date.format(FORMAT).to_string();
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)
}