diff --git a/docs/index.html b/docs/index.html index 06d51040f..8ed88ac34 100644 --- a/docs/index.html +++ b/docs/index.html @@ -81,6 +81,7 @@ mouse_pos: g_mouse_pos, screen_size: { x: window.innerWidth, y: window.innerHeight }, pixels_per_point: pixels_per_point(), + time: window.performance.now() / 1000.0, }; } diff --git a/emigui/src/style.rs b/emigui/src/style.rs index 084cfcaa1..cdda6bd7b 100644 --- a/emigui/src/style.rs +++ b/emigui/src/style.rs @@ -26,6 +26,10 @@ pub struct Style { /// For stuff like check marks in check boxes. pub line_width: f32, + // TODO: add ability to disable animations! + /// How many seconds a typical animation should last + pub animation_time: f32, + pub window: Window, } @@ -44,6 +48,7 @@ impl Default for Style { clickable_diameter: 34.0, start_icon_width: 20.0, line_width: 1.0, + animation_time: 1.0 / 20.0, window: Window::default(), } } diff --git a/emigui/src/types.rs b/emigui/src/types.rs index ce79be4ea..98c16c647 100644 --- a/emigui/src/types.rs +++ b/emigui/src/types.rs @@ -21,6 +21,9 @@ pub struct RawInput { /// Also known as device pixel ratio, > 1 for HDPI screens. pub pixels_per_point: f32, + + /// Time in seconds. Relative to whatever. Used for animation. + pub time: f64, } /// What the gui maintains @@ -46,6 +49,9 @@ pub struct GuiInput { /// Also known as device pixel ratio, > 1 for HDPI screens. pub pixels_per_point: f32, + + /// Time in seconds. Relative to whatever. Used for animation. + pub time: f64, } impl GuiInput { @@ -62,6 +68,7 @@ impl GuiInput { mouse_move, screen_size: new.screen_size, pixels_per_point: new.pixels_per_point, + time: new.time, } } } diff --git a/example_glium/src/main.rs b/example_glium/src/main.rs index 2055d383e..a9d4738fd 100644 --- a/example_glium/src/main.rs +++ b/example_glium/src/main.rs @@ -36,6 +36,9 @@ fn main() { let mut quit = false; + // used to keep track of time for animations + let start_time = Instant::now(); + let mut frame_start = Instant::now(); let mut example_app = ExampleApp::default(); @@ -50,6 +53,8 @@ fn main() { frame_start = Instant::now(); } + raw_input.time = start_time.elapsed().as_nanos() as f64 * 1e-9; + events_loop.poll_events(|event| { match event { glutin::Event::WindowEvent { event, .. } => match event {