mirror of
https://github.com/emilk/egui.git
synced 2026-08-31 13:50: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:
@@ -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