mirror of
https://github.com/emilk/egui.git
synced 2026-09-02 06:40:06 -04:00
integrate into egui
This commit is contained in:
@@ -10,12 +10,7 @@ readme = "README.md"
|
||||
repository = "https://github.com/emilk/egui/tree/master/egui_demo_lib"
|
||||
categories = ["gui", "graphics"]
|
||||
keywords = ["glium", "egui", "gui", "gamedev"]
|
||||
include = [
|
||||
"../LICENSE-APACHE",
|
||||
"../LICENSE-MIT",
|
||||
"**/*.rs",
|
||||
"Cargo.toml",
|
||||
]
|
||||
include = ["../LICENSE-APACHE", "../LICENSE-MIT", "**/*.rs", "Cargo.toml"]
|
||||
|
||||
[package.metadata.docs.rs]
|
||||
all-features = true
|
||||
@@ -25,6 +20,7 @@ all-features = true
|
||||
[dependencies]
|
||||
egui = { version = "0.15.0", path = "../egui", default-features = false }
|
||||
epi = { version = "0.15.0", path = "../epi" }
|
||||
egui_datepicker = { version = "0.15.0", path = "../egui_datepicker", optional = true }
|
||||
|
||||
chrono = { version = "0.4", features = ["js-sys", "wasmbind"], optional = true }
|
||||
enum-map = { version = "1", features = ["serde"] }
|
||||
@@ -32,10 +28,15 @@ unicode_names2 = { version = "0.4.0", default-features = false }
|
||||
|
||||
# feature "http":
|
||||
ehttp = { version = "0.1.0", optional = true }
|
||||
image = { version = "0.23", default-features = false, features = ["jpeg", "png"], optional = true }
|
||||
image = { version = "0.23", default-features = false, features = [
|
||||
"jpeg",
|
||||
"png",
|
||||
], optional = true }
|
||||
|
||||
# feature "syntax_highlighting":
|
||||
syntect = { version = "4", default-features = false, features = ["default-fancy"], optional = true }
|
||||
syntect = { version = "4", default-features = false, features = [
|
||||
"default-fancy",
|
||||
], optional = true }
|
||||
|
||||
# feature "persistence":
|
||||
serde = { version = "1", features = ["derive"], optional = true }
|
||||
@@ -44,7 +45,8 @@ serde = { version = "1", features = ["derive"], optional = true }
|
||||
criterion = { version = "0.3", default-features = false }
|
||||
|
||||
[features]
|
||||
default = ["chrono"]
|
||||
default = ["datetime"]
|
||||
datetime = ["egui_datepicker", "chrono"]
|
||||
|
||||
# Enable additional checks if debug assertions are enabled (debug builds).
|
||||
extra_debug_asserts = ["egui/extra_debug_asserts"]
|
||||
@@ -53,7 +55,7 @@ extra_asserts = ["egui/extra_asserts"]
|
||||
|
||||
http = ["ehttp", "image"]
|
||||
persistence = ["egui/persistence", "epi/persistence", "serde"]
|
||||
serialize = ["egui/serialize", "serde"]
|
||||
serialize = ["egui/serialize", "serde"]
|
||||
syntax_highlighting = ["syntect"]
|
||||
|
||||
[[bench]]
|
||||
|
||||
@@ -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