Browse Source

imgui 0.5 works

Johann Woelper 4 năm trước cách đây
mục cha
commit
6935aeeb46
2 tập tin đã thay đổi với 17 bổ sung13 xóa
  1. 14 12
      src/main.rs
  2. 3 1
      src/support_ogl/mod.rs

+ 14 - 12
src/main.rs

@@ -134,12 +134,14 @@ fn main() {
             .position([800.0, 0.0], Condition::Appearing)
             .size([200.0, 500.0], Condition::FirstUseEver)
             .build(ui, || {
+
                 for (k, snds) in &soundlib {
-                    ui.tree_node(&im_str!("{}", k))
+
+                    TreeNode::new(&im_str!("{}", k))
                         .opened(true, Condition::Appearing)
-                        .build(|| {
+                        .build(ui, || {
                             for s in snds {
-                                ui.tree_node(&im_str!("{}", s.name)).build(|| {
+                                TreeNode::new(&im_str!("{}", s.name)).build(ui, || {
                                     // ui.same_line(0.0);
                                     // if ui.small_button(im_str!("add to pattern")) {
                                     //     active_pattern.sounds[pattern_row][pattern_col] = Some(s.clone());
@@ -162,11 +164,11 @@ fn main() {
             .position([800.0, 500.0], Condition::Appearing)
             .size([200.0, 300.0], Condition::FirstUseEver)
             .build(ui, || {
-                ui.tree_node(im_str!("patterns"))
+                TreeNode::new(im_str!("patterns"))
                     .opened(true, Condition::Appearing)
-                    .build(|| {
+                    .build(ui,|| {
                         for p in &mut patterns {
-                            ui.tree_node(&im_str!("{}", p.name)).build(|| {
+                            TreeNode::new(&im_str!("{}", p.name)).build(ui,|| {
                                 // ui.same_line(0.0);
                                 if ui.small_button(im_str!("load")) {
                                     *active_pattern = p.clone();
@@ -216,15 +218,15 @@ fn main() {
                     active_pattern.name = imstr_name.to_string();
                 };
 
-                ui.drag_int(im_str!("beats/bar"), &mut active_pattern.resolution)
-                    .max(64)
+                imgui::Drag::new(im_str!("beats/bar"))
+                    .range(0..=64)
                     .speed(0.1)
-                    .build();
+                    .build(ui, &mut active_pattern.resolution);
 
-                ui.drag_int(im_str!("repeat"), &mut active_pattern.repeat)
-                    .max(32)
+                imgui::Drag::new(im_str!("repeat"))
+                    .range(0..=32)
                     .speed(0.05)
-                    .build();
+                    .build(ui, &mut active_pattern.repeat);
 
                 // The grid header labels
 

+ 3 - 1
src/support_ogl/mod.rs

@@ -130,7 +130,9 @@ impl System {
             platform
                 .prepare_frame(io, render_sys.window())
                 .expect("Failed to start frame");
-            last_frame = io.update_delta_time(last_frame);
+                let now = Instant::now();
+                io.update_delta_time(now - last_frame);
+                last_frame = now;
             let mut ui = imgui.frame();
             run_ui(&mut run, &mut ui);