diff --git a/README.markdown b/README.markdown index ad774f3..4cbc5bb 100644 --- a/README.markdown +++ b/README.markdown @@ -10,9 +10,9 @@ ![Hello world](hello_world.png) ```rust -Window::new("Hello world") +ui.window("Hello world") .size([300.0, 100.0], Condition::FirstUseEver) - .build(&ui, || { + .build(|| { ui.text("Hello world!"); ui.text("こんにちは世界!"); ui.text("This...is...imgui-rs!"); diff --git a/imgui-examples/examples/collapsing_header.rs b/imgui-examples/examples/collapsing_header.rs index 74873d7..6667398 100644 --- a/imgui-examples/examples/collapsing_header.rs +++ b/imgui-examples/examples/collapsing_header.rs @@ -8,11 +8,11 @@ fn main() { }; let system = support::init(file!()); system.main_loop(move |run, ui| { - let w = Window::new("Collapsing header") + let w = ui.window("Collapsing header") .opened(run) .position([20.0, 20.0], Condition::Appearing) .size([700.0, 500.0], Condition::Appearing); - w.build(ui, || { + w.build(|| { if CollapsingHeader::new("I'm a collapsing header. Click me!").build(ui) { ui.text( "A collapsing header can be used to toggle rendering of a group of widgets", diff --git a/imgui-examples/examples/color_button.rs b/imgui-examples/examples/color_button.rs index 5c19746..6a3ed0a 100644 --- a/imgui-examples/examples/color_button.rs +++ b/imgui-examples/examples/color_button.rs @@ -17,12 +17,12 @@ fn main() { } fn example_selector(run: &mut bool, ui: &mut Ui, state: &mut State) { - let w = Window::new("Color button examples") + let w = ui.window("Color button examples") .opened(run) .position([20.0, 20.0], Condition::Appearing) .size([700.0, 100.0], Condition::Appearing) .resizable(false); - w.build(ui, || { + w.build(|| { let ex1 = ui.radio_button("Example 1: Basics", &mut state.example, 1); let ex2 = ui.radio_button("Example 2: Alpha component", &mut state.example, 2); let ex3 = ui.radio_button("Example 3: Input format", &mut state.example, 3); @@ -33,10 +33,10 @@ fn example_selector(run: &mut bool, ui: &mut Ui, state: &mut State) { } fn example_1(ui: &Ui, state: &mut State) { - let w = Window::new("Example 1: Basics") + let w = ui.window("Example 1: Basics") .size([700.0, 300.0], Condition::Appearing) .position([20.0, 140.0], Condition::Appearing); - w.build(ui, || { + w.build(|| { ui.text_wrapped( "Color button is a widget that displays a color value as a clickable rectangle. \ It also supports a tooltip with detailed information about the color value. \ @@ -73,10 +73,10 @@ fn example_1(ui: &Ui, state: &mut State) { } fn example_2(ui: &Ui) { - let w = Window::new("Example 2: Alpha component") + let w = ui.window("Example 2: Alpha component") .size([700.0, 320.0], Condition::Appearing) .position([20.0, 140.0], Condition::Appearing); - w.build(ui, || { + w.build(|| { ui.text_wrapped( "The displayed color is passed to the button as four float values between \ 0.0 - 1.0 (RGBA). If you don't care about the alpha component, it can be \ @@ -123,10 +123,10 @@ fn example_2(ui: &Ui) { } fn example_3(ui: &Ui) { - let w = Window::new("Example 3: Input format") + let w = ui.window("Example 3: Input format") .size([700.0, 320.0], Condition::Appearing) .position([20.0, 140.0], Condition::Appearing); - w.build(ui, || { + w.build(|| { ui.text("This button interprets the input value [1.0, 0.0, 0.0, 1.0] as RGB(A) (default):"); ColorButton::new("RGBA red", [1.0, 0.0, 0.0, 1.0]).build(ui); diff --git a/imgui-examples/examples/custom_textures.rs b/imgui-examples/examples/custom_textures.rs index a76b03f..6b8cfc5 100644 --- a/imgui-examples/examples/custom_textures.rs +++ b/imgui-examples/examples/custom_textures.rs @@ -78,9 +78,9 @@ impl CustomTexturesApp { } fn show_textures(&self, ui: &Ui) { - Window::new("Hello textures") + ui.window("Hello textures") .size([400.0, 400.0], Condition::FirstUseEver) - .build(ui, || { + .build(|| { ui.text("Hello textures!"); if let Some(my_texture_id) = self.my_texture_id { ui.text("Some generated texture"); diff --git a/imgui-examples/examples/disablement.rs b/imgui-examples/examples/disablement.rs index c5df984..fa7dd7a 100644 --- a/imgui-examples/examples/disablement.rs +++ b/imgui-examples/examples/disablement.rs @@ -1,3 +1,5 @@ +//! Demonstrates disabling widgets. Prevents mouse interaction and greys out widgets + use imgui::*; mod support; @@ -11,9 +13,9 @@ fn main() { let mut click_count = 0; system.main_loop(move |_, ui| { - Window::new("Disabling widgets") + ui.window("Disabling widgets") .size([300.0, 200.0], Condition::FirstUseEver) - .build(ui, || { + .build(|| { ui.checkbox("Edit mode", &mut edit_mode); ui.checkbox("Safe mode", &mut safe_mode); diff --git a/imgui-examples/examples/draw_list.rs b/imgui-examples/examples/draw_list.rs index dfd9125..f575e77 100644 --- a/imgui-examples/examples/draw_list.rs +++ b/imgui-examples/examples/draw_list.rs @@ -57,10 +57,10 @@ fn main() { ); } - Window::new("Draw list") + ui.window("Draw list") .size([300.0, 110.0], Condition::FirstUseEver) .scroll_bar(false) - .build(ui, || { + .build(|| { ui.button("random button"); let draw_list = ui.get_window_draw_list(); let o = ui.cursor_screen_pos(); diff --git a/imgui-examples/examples/hello_world.rs b/imgui-examples/examples/hello_world.rs index 56eb774..29f74ed 100644 --- a/imgui-examples/examples/hello_world.rs +++ b/imgui-examples/examples/hello_world.rs @@ -7,9 +7,9 @@ fn main() { let mut value = 0; let choices = ["test test this is 1", "test test this is 2"]; system.main_loop(move |_, ui| { - Window::new("Hello world") + ui.window("Hello world") .size([300.0, 110.0], Condition::FirstUseEver) - .build(ui, || { + .build(|| { ui.text_wrapped("Hello world!"); ui.text_wrapped("こんにちは世界!"); if ui.button(choices[value]) { diff --git a/imgui-examples/examples/keyboard.rs b/imgui-examples/examples/keyboard.rs index d2d9c3f..a6aaa05 100644 --- a/imgui-examples/examples/keyboard.rs +++ b/imgui-examples/examples/keyboard.rs @@ -14,9 +14,9 @@ fn main() { let mut text_buffer = String::new(); system.main_loop(move |_, ui| { - Window::new("Means of accessing key state") + ui.window("Means of accessing key state") .size([500.0, 300.0], Condition::FirstUseEver) - .build(ui, || { + .build(|| { // You can check if a key is currently held down if ui.is_key_down(Key::A) { ui.text("The A key is down!"); diff --git a/imgui-examples/examples/long_list.rs b/imgui-examples/examples/long_list.rs index 8a745e6..2204c53 100644 --- a/imgui-examples/examples/long_list.rs +++ b/imgui-examples/examples/long_list.rs @@ -15,9 +15,9 @@ fn main() { let system = support::init(file!()); system.main_loop(move |_, ui| { - Window::new("Hello long world") + ui.window("Hello long world") .size([300.0, 110.0], Condition::FirstUseEver) - .build(ui, || { + .build(|| { let mut clipper = imgui::ListClipper::new(lots_of_words.len() as i32) .items_height(ui.current_font_size()) .begin(ui); diff --git a/imgui-examples/examples/multiple_fonts.rs b/imgui-examples/examples/multiple_fonts.rs index 5e0e927..4043c51 100644 --- a/imgui-examples/examples/multiple_fonts.rs +++ b/imgui-examples/examples/multiple_fonts.rs @@ -19,7 +19,7 @@ fn main() { .reload_font_texture(&mut system.imgui) .expect("Failed to reload fonts"); system.main_loop(move |run, ui| { - Window::new("Hello world").opened(run).build(ui, || { + ui.window("Hello world").opened(run).build(|| { ui.text("Hello, I'm the default font!"); let _roboto = ui.push_font(roboto); ui.text("Hello, I'm Roboto Regular!"); diff --git a/imgui-examples/examples/progress_bar.rs b/imgui-examples/examples/progress_bar.rs index 9d11746..6915baa 100644 --- a/imgui-examples/examples/progress_bar.rs +++ b/imgui-examples/examples/progress_bar.rs @@ -5,11 +5,11 @@ mod support; fn main() { let system = support::init(file!()); system.main_loop(move |run, ui| { - let w = Window::new("Progress bar") + let w = ui.window("Progress bar") .opened(run) .position([20.0, 20.0], Condition::Appearing) .size([700.0, 200.0], Condition::Appearing); - w.build(ui, || { + w.build(|| { ui.text("This is a simple progress bar:"); ProgressBar::new(0.5).build(ui); diff --git a/imgui-examples/examples/radio_button.rs b/imgui-examples/examples/radio_button.rs index cb86a82..d1cffae 100644 --- a/imgui-examples/examples/radio_button.rs +++ b/imgui-examples/examples/radio_button.rs @@ -16,12 +16,12 @@ fn main() { } fn example_selector(run: &mut bool, ui: &mut Ui, state: &mut State) { - let w = Window::new("Radio button examples") + let w = ui.window("Radio button examples") .opened(run) .position([20.0, 20.0], Condition::Appearing) .size([700.0, 80.0], Condition::Appearing) .resizable(false); - w.build(ui, || { + w.build(|| { let mut clicked = false; clicked |= ui.radio_button("Example 1: Boolean radio buttons", &mut state.example, 1); clicked |= ui.radio_button("Example 2: Radio buttons", &mut state.example, 2); @@ -32,10 +32,10 @@ fn example_selector(run: &mut bool, ui: &mut Ui, state: &mut State) { } fn example_1(ui: &Ui, state: &mut State) { - let w = Window::new("Example 1: Boolean radio buttons") + let w = ui.window("Example 1: Boolean radio buttons") .size([700.0, 200.0], Condition::Appearing) .position([20.0, 120.0], Condition::Appearing); - w.build(ui, || { + w.build(|| { ui.text_wrapped( "Boolean radio buttons accept a boolean active state, which is passed as a value and \ not as a mutable reference. This means that it's not updated automatically, so you \ @@ -58,10 +58,10 @@ fn example_1(ui: &Ui, state: &mut State) { } fn example_2(ui: &Ui, state: &mut State) { - let w = Window::new("Example 2: Radio buttons") + let w = ui.window("Example 2: Radio buttons") .size([700.0, 300.0], Condition::Appearing) .position([20.0, 120.0], Condition::Appearing); - w.build(ui, || { + w.build(|| { ui.text_wrapped( "Normal radio buttons accept a mutable reference to state, and the value \ corresponding to this button. They are very flexible, because the value can be any \ diff --git a/imgui-examples/examples/slider.rs b/imgui-examples/examples/slider.rs index e5e5bcc..d8605ce 100644 --- a/imgui-examples/examples/slider.rs +++ b/imgui-examples/examples/slider.rs @@ -16,12 +16,12 @@ fn main() { } fn example_selector(run: &mut bool, ui: &mut Ui, state: &mut State) { - let w = Window::new("Slider examples") + let w = ui.window("Slider examples") .opened(run) .position([20.0, 20.0], Condition::Appearing) .size([700.0, 80.0], Condition::Appearing) .resizable(false); - w.build(ui, || { + w.build(|| { let mut clicked = false; clicked |= ui.radio_button("Example 1: Basic sliders", &mut state.example, 1); clicked |= ui.radio_button("Example 2: Slider arrays", &mut state.example, 2); @@ -32,10 +32,10 @@ fn example_selector(run: &mut bool, ui: &mut Ui, state: &mut State) { } fn example_1(ui: &Ui, state: &mut State) { - let w = Window::new("Example 1: Basic sliders") + let w = ui.window("Example 1: Basic sliders") .size([700.0, 340.0], Condition::Appearing) .position([20.0, 120.0], Condition::Appearing); - w.build(ui, || { + w.build(|| { ui.text("All of the following data types are supported:"); ui.text("Signed: i8 i16 i32 i64"); ui.text("Unsigned: u8 u16 u32 u64"); @@ -67,10 +67,10 @@ fn example_1(ui: &Ui, state: &mut State) { } fn example_2(ui: &Ui, state: &mut State) { - let w = Window::new("Example 2: Slider arrays") + let w = ui.window("Example 2: Slider arrays") .size([700.0, 260.0], Condition::Appearing) .position([20.0, 120.0], Condition::Appearing); - w.build(ui, || { + w.build(|| { ui.text("You can easily build a slider group from an array of values:"); Slider::new("[u8; 4]", 0, u8::MAX).build_array(ui, &mut state.array); diff --git a/imgui-examples/examples/tables_api.rs b/imgui-examples/examples/tables_api.rs index ae5c63e..47a1d7d 100644 --- a/imgui-examples/examples/tables_api.rs +++ b/imgui-examples/examples/tables_api.rs @@ -29,9 +29,9 @@ fn main() { | TableFlags::NO_BORDERS_IN_BODY; system.main_loop(move |_, ui| { - Window::new("Input text callbacks") + ui.window("Input text callbacks") .size([800.0, 400.0], Condition::FirstUseEver) - .build(ui, || { + .build(|| { if let Some(_t) = ui.begin_table("Basic-Table", 3) { // we must also call `next_row` here, because we declined // to set up header rows. If we set up header rows ourselves, diff --git a/imgui-examples/examples/test_window_impl.rs b/imgui-examples/examples/test_window_impl.rs index f47c4a2..413e18c 100644 --- a/imgui-examples/examples/test_window_impl.rs +++ b/imgui-examples/examples/test_window_impl.rs @@ -286,15 +286,15 @@ fn show_test_window(ui: &Ui, state: &mut State, opened: &mut bool) { ui.show_metrics_window(&mut state.show_app_metrics); } if state.show_app_style_editor { - Window::new("Style Editor") + ui.window("Style Editor") .opened(&mut state.show_app_style_editor) - .build(ui, || ui.show_default_style_editor()); + .build(|| ui.show_default_style_editor()); } if state.show_app_about { - Window::new("About ImGui") + ui.window("About ImGui") .always_auto_resize(true) .opened(&mut state.show_app_about) - .build(ui, || { + .build(|| { ui.text(format!("dear imgui, {}", imgui::dear_imgui_version())); ui.separator(); ui.text("By Omar Cornut and all github contributors."); @@ -317,7 +317,7 @@ fn show_test_window(ui: &Ui, state: &mut State, opened: &mut bool) { show_app_log(ui, &mut state.app_log); } - let mut window = Window::new("ImGui Demo") + let mut window = ui.window("ImGui Demo") .title_bar(!state.no_titlebar) .resizable(!state.no_resize) .movable(!state.no_move) @@ -328,7 +328,7 @@ fn show_test_window(ui: &Ui, state: &mut State, opened: &mut bool) { if !state.no_close { window = window.opened(opened) } - window.build(ui, || { + window.build(|| { ui.push_item_width(-140.0); ui.text(format!("dear imgui says hello. ({})", imgui::dear_imgui_version())); if let Some(menu_bar) = ui.begin_menu_bar() { @@ -872,10 +872,10 @@ fn show_example_menu_file<'a>(ui: &Ui<'a>, state: &mut FileMenuState) { ui.separator(); if let Some(menu) = ui.begin_menu("Options") { MenuItem::new("Enabled").build_with_ref(ui, &mut state.enabled); - ChildWindow::new("child") + ui.child_window("child") .size([0.0, 60.0]) .border(true) - .build(ui, || { + .build(|| { for i in 0..10 { ui.text(format!("Scrolling Text {}", i)); } @@ -900,10 +900,10 @@ fn show_example_menu_file<'a>(ui: &Ui<'a>, state: &mut FileMenuState) { } fn show_example_app_auto_resize(ui: &Ui, state: &mut AutoResizeState, opened: &mut bool) { - Window::new("Example: Auto-resizing window") + ui.window("Example: Auto-resizing window") .opened(opened) .always_auto_resize(true) - .build(ui, || { + .build(|| { ui.text( "Window will resize every-ui to the size of its content. Note that you probably don't want to query the window size to @@ -920,7 +920,7 @@ fn show_example_app_fixed_overlay(ui: &Ui, opened: &mut bool) { const DISTANCE: f32 = 10.0; let window_pos = [DISTANCE, DISTANCE]; let style = ui.push_style_color(StyleColor::WindowBg, [0.0, 0.0, 0.0, 0.3]); - Window::new("Example: Fixed Overlay") + ui.window("Example: Fixed Overlay") .opened(opened) .position(window_pos, Condition::Always) .title_bar(false) @@ -928,7 +928,7 @@ fn show_example_app_fixed_overlay(ui: &Ui, opened: &mut bool) { .always_auto_resize(true) .movable(false) .save_settings(false) - .build(ui, || { + .build(|| { ui.text( "Simple overlay\nin the corner of the screen.\n(right-click to change position)", ); @@ -943,17 +943,17 @@ fn show_example_app_fixed_overlay(ui: &Ui, opened: &mut bool) { } fn show_example_app_manipulating_window_title(ui: &Ui) { - Window::new("Same title as another window##1") + ui.window("Same title as another window##1") .position([100.0, 100.0], Condition::FirstUseEver) - .build(ui, || { + .build(|| { ui.text( "This is window 1. My title is the same as window 2, but my identifier is unique.", ); }); - Window::new("Same title as another window##2") + ui.window("Same title as another window##2") .position([100.0, 200.0], Condition::FirstUseEver) - .build(ui, || { + .build(|| { ui.text( "This is window 2. My title is the same as window 1, but my identifier is unique.", @@ -963,16 +963,16 @@ My title is the same as window 1, but my identifier is unique.", let ch_idx = (ui.time() / 0.25) as usize & 3; let num = ui.frame_count(); // The C++ version uses rand() here let title = format!("Animated title {} {}###AnimatedTitle", chars[ch_idx], num); - Window::new(title) + ui.window(title) .position([100.0, 300.0], Condition::FirstUseEver) - .build(ui, || ui.text("This window has a changing title")); + .build(|| ui.text("This window has a changing title")); } fn show_example_app_custom_rendering(ui: &Ui, state: &mut CustomRenderingState, opened: &mut bool) { - Window::new("Example: Custom rendering") + ui.window("Example: Custom rendering") .size([350.0, 560.0], Condition::FirstUseEver) .opened(opened) - .build(ui, || { + .build(|| { ui.text("Primitives"); // TODO: Add DragFloat to change value of sz ColorEdit::new("Color", &mut state.col).build(ui); @@ -1217,9 +1217,9 @@ fn show_example_app_custom_rendering(ui: &Ui, state: &mut CustomRenderingState, } fn show_app_log(ui: &Ui, app_log: &mut Vec) { - Window::new("Example: Log") + ui.window("Example: Log") .size([500.0, 400.0], Condition::FirstUseEver) - .build(ui, || { + .build(|| { if ui.small_button("[Debug] Add 5 entries") { let categories = ["info", "warn", "error"]; let words = [ @@ -1251,9 +1251,9 @@ fn show_app_log(ui: &Ui, app_log: &mut Vec) { ui.set_clipboard_text(&ImString::from(app_log.join("\n"))); } ui.separator(); - ChildWindow::new("logwindow") + ui.child_window("logwindow") .flags(WindowFlags::HORIZONTAL_SCROLLBAR) - .build(ui, || { + .build(|| { if !app_log.is_empty() { let mut clipper = ListClipper::new(app_log.len() as i32).begin(ui); while clipper.step() { diff --git a/imgui-examples/examples/text_callbacks.rs b/imgui-examples/examples/text_callbacks.rs index 4adcb4a..348ea28 100644 --- a/imgui-examples/examples/text_callbacks.rs +++ b/imgui-examples/examples/text_callbacks.rs @@ -7,9 +7,9 @@ fn main() { let mut buffers = vec![String::default(), String::default(), String::default()]; system.main_loop(move |_, ui| { - Window::new("Input text callbacks") + ui.window("Input text callbacks") .size([500.0, 300.0], Condition::FirstUseEver) - .build(ui, || { + .build(|| { ui.text("You can make a variety of buffer callbacks on an Input Text"); ui.text( "or on an InputTextMultiline. In this example, we'll use \ diff --git a/imgui-glow-renderer/examples/04_custom_textures.rs b/imgui-glow-renderer/examples/04_custom_textures.rs index efca79c..70e4d95 100644 --- a/imgui-glow-renderer/examples/04_custom_textures.rs +++ b/imgui-glow-renderer/examples/04_custom_textures.rs @@ -144,9 +144,9 @@ impl TexturesUi { } fn show(&self, ui: &imgui::Ui) { - imgui::Window::new("Hello textures") + ui.window("Hello textures") .size([400.0, 400.0], Condition::FirstUseEver) - .build(ui, || { + .build(|| { ui.text("Hello textures!"); ui.text("Some generated texture"); imgui::Image::new(self.generated_texture, [100.0, 100.0]).build(ui);