mirror of
https://github.com/emilk/egui.git
synced 2026-09-01 14:20:04 -04:00
Remove "seconds_since_midnight" from epi/eframe. Use chrono instead
chrono works both natively and on web. Related: https://github.com/emilk/egui/issues/212
This commit is contained in:
@@ -26,6 +26,7 @@ all-features = true
|
||||
egui = { version = "0.14.0", path = "../egui", default-features = false }
|
||||
epi = { version = "0.14.0", path = "../epi" }
|
||||
|
||||
chrono = { version = "0.4", features = ["js-sys", "wasmbind"], optional = true }
|
||||
enum-map = { version = "1", features = ["serde"] }
|
||||
unicode_names2 = { version = "0.4.0", default-features = false }
|
||||
|
||||
@@ -43,7 +44,7 @@ serde = { version = "1", features = ["derive"], optional = true }
|
||||
criterion = { version = "0.3", default-features = false }
|
||||
|
||||
[features]
|
||||
default = []
|
||||
default = ["chrono"]
|
||||
|
||||
# Enable additional checks if debug assertions are enabled (debug builds).
|
||||
extra_debug_asserts = ["egui/extra_debug_asserts"]
|
||||
|
||||
@@ -37,10 +37,10 @@ impl epi::App for FractalClock {
|
||||
"🕑 Fractal Clock"
|
||||
}
|
||||
|
||||
fn update(&mut self, ctx: &egui::CtxRef, frame: &mut epi::Frame<'_>) {
|
||||
fn update(&mut self, ctx: &egui::CtxRef, _frame: &mut epi::Frame<'_>) {
|
||||
egui::CentralPanel::default()
|
||||
.frame(Frame::dark_canvas(&ctx.style()))
|
||||
.show(ctx, |ui| self.ui(ui, frame.info().seconds_since_midnight));
|
||||
.show(ctx, |ui| self.ui(ui, crate::seconds_since_midnight()));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -154,3 +154,19 @@ fn test_egui_zero_window_size() {
|
||||
assert!(clipped_meshes.is_empty(), "There should be nothing to show");
|
||||
}
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
/// Time of day as seconds since midnight. Used for clock in demo app.
|
||||
pub(crate) fn seconds_since_midnight() -> Option<f64> {
|
||||
#[cfg(feature = "chrono")]
|
||||
{
|
||||
use chrono::Timelike;
|
||||
let time = chrono::Local::now().time();
|
||||
let seconds_since_midnight =
|
||||
time.num_seconds_from_midnight() as f64 + 1e-9 * (time.nanosecond() as f64);
|
||||
Some(seconds_since_midnight)
|
||||
}
|
||||
#[cfg(not(feature = "chrono"))]
|
||||
None
|
||||
}
|
||||
|
||||
@@ -133,7 +133,7 @@ impl WrapApp {
|
||||
ui.with_layout(egui::Layout::right_to_left(), |ui| {
|
||||
if false {
|
||||
// TODO: fix the overlap on small screens
|
||||
if let Some(seconds_since_midnight) = frame.info().seconds_since_midnight {
|
||||
if let Some(seconds_since_midnight) = crate::seconds_since_midnight() {
|
||||
if clock_button(ui, seconds_since_midnight).clicked() {
|
||||
self.selected_anchor = "clock".to_owned();
|
||||
if frame.is_web() {
|
||||
|
||||
Reference in New Issue
Block a user