Browse Source

Add time as input to emigui to enable animations

pull/2/head
Emil Ernerfeldt 5 years ago
parent
commit
0ed578341b
  1. 1
      docs/index.html
  2. 5
      emigui/src/style.rs
  3. 7
      emigui/src/types.rs
  4. 5
      example_glium/src/main.rs

1
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,
};
}

5
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(),
}
}

7
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,
}
}
}

5
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 {

Loading…
Cancel
Save