From f635fd6438ee7442d1b1b94868f824eb0bb2569a Mon Sep 17 00:00:00 2001 From: Jack Mac Date: Sun, 12 Sep 2021 17:16:53 -0400 Subject: [PATCH] fixed examples, removing warnings (i think) --- imgui-examples/examples/collapsing_header.rs | 16 +- imgui-examples/examples/color_button.rs | 73 ++- imgui-examples/examples/custom_textures.rs | 10 +- imgui-examples/examples/draw_list.rs | 12 +- imgui-examples/examples/hello_world.rs | 4 +- imgui-examples/examples/keyboard.rs | 6 +- imgui-examples/examples/long_list.rs | 2 +- imgui-examples/examples/multiple_fonts.rs | 2 +- imgui-examples/examples/progress_bar.rs | 2 +- imgui-examples/examples/radio_button.rs | 44 +- imgui-examples/examples/slider.rs | 24 +- imgui-examples/examples/test_window_impl.rs | 504 +++++++++--------- imgui-examples/examples/text_callbacks.rs | 2 +- .../examples/gfx_custom_textures.rs | 4 +- .../examples/gfx_hello_world.rs | 10 +- .../examples/04_custom_textures.rs | 12 +- imgui/src/widget/menu.rs | 26 +- imgui/src/widget/slider.rs | 140 +++-- 18 files changed, 468 insertions(+), 425 deletions(-) diff --git a/imgui-examples/examples/collapsing_header.rs b/imgui-examples/examples/collapsing_header.rs index 8c4e7c4..74873d7 100644 --- a/imgui-examples/examples/collapsing_header.rs +++ b/imgui-examples/examples/collapsing_header.rs @@ -8,19 +8,19 @@ fn main() { }; let system = support::init(file!()); system.main_loop(move |run, ui| { - let w = Window::new(im_str!("Collapsing header")) + let w = Window::new("Collapsing header") .opened(run) .position([20.0, 20.0], Condition::Appearing) .size([700.0, 500.0], Condition::Appearing); w.build(ui, || { - if CollapsingHeader::new(im_str!("I'm a collapsing header. Click me!")).build(ui) { + 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", ); } ui.spacing(); - if CollapsingHeader::new(im_str!("I'm open by default")) + if CollapsingHeader::new("I'm open by default") .default_open(true) .build(ui) { @@ -28,7 +28,7 @@ fn main() { } ui.spacing(); - if CollapsingHeader::new(im_str!("I only open with double-click")) + if CollapsingHeader::new("I only open with double-click") .open_on_double_click(true) .build(ui) { @@ -36,7 +36,7 @@ fn main() { } ui.spacing(); - if CollapsingHeader::new(im_str!("I don't have an arrow")) + if CollapsingHeader::new("I don't have an arrow") .bullet(true) .build(ui) { @@ -44,7 +44,7 @@ fn main() { } ui.spacing(); - if CollapsingHeader::new(im_str!("I only open if you click the arrow")) + if CollapsingHeader::new("I only open if you click the arrow") .open_on_arrow(true) .build(ui) { @@ -53,10 +53,10 @@ fn main() { ui.spacing(); ui.checkbox( - im_str!("Toggle rendering of the next example"), + "Toggle rendering of the next example", &mut state.render_closable, ); - if CollapsingHeader::new(im_str!("I've got a separate close button")) + if CollapsingHeader::new("I've got a separate close button") .build_with_close_button(ui, &mut state.render_closable) { ui.text("I've got contents just like any other collapsing header"); diff --git a/imgui-examples/examples/color_button.rs b/imgui-examples/examples/color_button.rs index 390b89d..3c48aab 100644 --- a/imgui-examples/examples/color_button.rs +++ b/imgui-examples/examples/color_button.rs @@ -17,15 +17,15 @@ fn main() { } fn example_selector(run: &mut bool, ui: &mut Ui, state: &mut State) { - let w = Window::new(im_str!("Color button examples")) + let w = Window::new("Color button examples") .opened(run) .position([20.0, 20.0], Condition::Appearing) .size([700.0, 100.0], Condition::Appearing) .resizable(false); w.build(ui, || { - let ex1 = ui.radio_button(im_str!("Example 1: Basics"), &mut state.example, 1); - let ex2 = ui.radio_button(im_str!("Example 2: Alpha component"), &mut state.example, 2); - let ex3 = ui.radio_button(im_str!("Example 3: Input format"), &mut state.example, 3); + 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); if ex1 || ex2 || ex3 { state.reset(); } @@ -33,29 +33,29 @@ fn example_selector(run: &mut bool, ui: &mut Ui, state: &mut State) { } fn example_1(ui: &Ui, state: &mut State) { - let w = Window::new(im_str!("Example 1: Basics")) + let w = Window::new("Example 1: Basics") .size([700.0, 300.0], Condition::Appearing) .position([20.0, 140.0], Condition::Appearing); w.build(ui, || { - ui.text_wrapped(im_str!( + 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. \ - Try hovering over and clicking these buttons!" - )); + Try hovering over and clicking these buttons!", + ); ui.text(state.notify_text); ui.text("This button is black:"); - if ColorButton::new(im_str!("Black color"), [0.0, 0.0, 0.0, 1.0]).build(ui) { + if ColorButton::new("Black color", [0.0, 0.0, 0.0, 1.0]).build(ui) { state.notify_text = "*** Black button was clicked"; } ui.text("This button is red:"); - if ColorButton::new(im_str!("Red color"), [1.0, 0.0, 0.0, 1.0]).build(ui) { + if ColorButton::new("Red color", [1.0, 0.0, 0.0, 1.0]).build(ui) { state.notify_text = "*** Red button was clicked"; } ui.text("This button is BIG because it has a custom size:"); - if ColorButton::new(im_str!("Green color"), [0.0, 1.0, 0.0, 1.0]) + if ColorButton::new("Green color", [0.0, 1.0, 0.0, 1.0]) .size([100.0, 50.0]) .build(ui) { @@ -63,7 +63,7 @@ fn example_1(ui: &Ui, state: &mut State) { } ui.text("This button doesn't use the tooltip at all:"); - if ColorButton::new(im_str!("No tooltip"), [0.0, 0.0, 1.0, 1.0]) + if ColorButton::new("No tooltip", [0.0, 0.0, 1.0, 1.0]) .tooltip(false) .build(ui) { @@ -73,71 +73,66 @@ fn example_1(ui: &Ui, state: &mut State) { } fn example_2(ui: &Ui) { - let w = Window::new(im_str!("Example 2: Alpha component")) + let w = Window::new("Example 2: Alpha component") .size([700.0, 320.0], Condition::Appearing) .position([20.0, 140.0], Condition::Appearing); w.build(ui, || { - ui.text_wrapped(im_str!( + 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 \ - disabled and it won't show up in the tooltip" - )); + disabled and it won't show up in the tooltip", + ); ui.text("This button ignores the alpha component:"); - ColorButton::new(im_str!("Red color"), [1.0, 0.0, 0.0, 0.5]) + ColorButton::new("Red color", [1.0, 0.0, 0.0, 0.5]) .alpha(false) .build(ui); ui.spacing(); ui.spacing(); ui.spacing(); - ui.text_wrapped(im_str!( + ui.text_wrapped( "If you *do* care about the alpha component, you can choose how it's \ - displayed in the button and the tooltip" - )); + displayed in the button and the tooltip", + ); ui.separator(); - ui.text_wrapped(im_str!( - "ColorPreview::Opaque (default) doesn't show the alpha component at all" - )); - ColorButton::new(im_str!("Red + ColorPreview::Opaque"), [1.0, 0.0, 0.0, 0.5]) + ui.text_wrapped("ColorPreview::Opaque (default) doesn't show the alpha component at all"); + ColorButton::new("Red + ColorPreview::Opaque", [1.0, 0.0, 0.0, 0.5]) .preview(ColorPreview::Opaque) .build(ui); ui.separator(); - ui.text_wrapped(im_str!( + ui.text_wrapped( "ColorPreview::HalfAlpha divides the color area into two halves and uses a \ - checkerboard pattern in one half to illustrate the alpha component" - )); - ColorButton::new( - im_str!("Red + ColorPreview::HalfAlpha"), - [1.0, 0.0, 0.0, 0.5], - ) - .preview(ColorPreview::HalfAlpha) - .build(ui); + checkerboard pattern in one half to illustrate the alpha component", + ); + ColorButton::new("Red + ColorPreview::HalfAlpha", [1.0, 0.0, 0.0, 0.5]) + .preview(ColorPreview::HalfAlpha) + .build(ui); ui.separator(); - ui.text_wrapped(im_str!( + ui.text_wrapped( "ColorPreview::Alpha uses a checkerboard pattern in the entire color area to \ illustrate the alpha component" - )); - ColorButton::new(im_str!("Red + ColorPreview::Alpha"), [1.0, 0.0, 0.0, 0.5]) + ); + ColorButton::new("Red + ColorPreview::Alpha", [1.0, 0.0, 0.0, 0.5]) .preview(ColorPreview::Alpha) .build(ui); }); } fn example_3(ui: &Ui) { - let w = Window::new(im_str!("Example 3: Input format")) + let w = Window::new("Example 3: Input format") .size([700.0, 320.0], Condition::Appearing) .position([20.0, 140.0], Condition::Appearing); w.build(ui, || { ui.text("This button interprets the input value [1.0, 0.0, 0.0, 1.0] as RGB(A) (default):"); - ColorButton::new(im_str!("RGBA red"), [1.0, 0.0, 0.0, 1.0]).build(ui); + ColorButton::new("RGBA red", [1.0, 0.0, 0.0, 1.0]).build(ui); ui.separator(); ui.text("This button interprets the input value [1.0, 0.0, 0.0, 1.0] as HSV(A):"); - ColorButton::new(im_str!("HSVA black"), [1.0, 0.0, 0.0, 1.0]) + ColorButton::new("HSVA black", [1.0, 0.0, 0.0, 1.0]) .input_mode(ColorEditInputMode::HSV) .build(ui); }); diff --git a/imgui-examples/examples/custom_textures.rs b/imgui-examples/examples/custom_textures.rs index c1cce95..a76b03f 100644 --- a/imgui-examples/examples/custom_textures.rs +++ b/imgui-examples/examples/custom_textures.rs @@ -78,10 +78,10 @@ impl CustomTexturesApp { } fn show_textures(&self, ui: &Ui) { - Window::new(im_str!("Hello textures")) + Window::new("Hello textures") .size([400.0, 400.0], Condition::FirstUseEver) .build(ui, || { - ui.text(im_str!("Hello textures!")); + ui.text("Hello textures!"); if let Some(my_texture_id) = self.my_texture_id { ui.text("Some generated texture"); Image::new(my_texture_id, [100.0, 100.0]).build(ui); @@ -97,7 +97,7 @@ impl CustomTexturesApp { ui.text("The Lenna buttons"); { - ui.invisible_button(im_str!("Boring Button"), [100.0, 100.0]); + ui.invisible_button("Boring Button", [100.0, 100.0]); // See also `imgui::Ui::style_color` let tint_none = [1.0, 1.0, 1.0, 1.0]; let tint_green = [0.5, 1.0, 0.5, 1.0]; @@ -124,7 +124,7 @@ impl CustomTexturesApp { ui.same_line(); // Button using quad positioned image - ui.invisible_button(im_str!("Exciting Button"), [100.0, 100.0]); + ui.invisible_button("Exciting Button", [100.0, 100.0]); // Button bounds let min = ui.item_rect_min(); @@ -151,7 +151,7 @@ impl CustomTexturesApp { // Rounded image { ui.same_line(); - ui.invisible_button(im_str!("Smooth Button"), [100.0, 100.0]); + ui.invisible_button("Smooth Button", [100.0, 100.0]); let draw_list = ui.get_window_draw_list(); draw_list diff --git a/imgui-examples/examples/draw_list.rs b/imgui-examples/examples/draw_list.rs index 9d1a5b2..dfd9125 100644 --- a/imgui-examples/examples/draw_list.rs +++ b/imgui-examples/examples/draw_list.rs @@ -7,7 +7,7 @@ fn draw_text_centered( ui: &Ui, draw_list: &DrawListMut, rect: [f32; 4], - text: &ImStr, + text: &str, color: [f32; 3], ) { let text_size = ui.calc_text_size(text); @@ -37,7 +37,7 @@ fn main() { ui, &bg_draw_list, [0.0, 0.0, 300.0, 300.0], - im_str!("background draw list"), + "background draw list", [0.0, 0.0, 0.0], ); } @@ -52,16 +52,16 @@ fn main() { ui, &fg_draw_list, [w - 300.0, h - 300.0, 300.0, 300.0], - im_str!("foreground draw list"), + "foreground draw list", [1.0, 0.0, 0.0], ); } - Window::new(im_str!("Draw list")) + Window::new("Draw list") .size([300.0, 110.0], Condition::FirstUseEver) .scroll_bar(false) .build(ui, || { - ui.button(im_str!("random button")); + ui.button("random button"); let draw_list = ui.get_window_draw_list(); let o = ui.cursor_screen_pos(); let ws = ui.content_region_avail(); @@ -89,7 +89,7 @@ fn main() { ui, &draw_list, [o[0], o[1], ws[0], ws[1]], - im_str!("window draw list"), + "window draw list", [1.0, 1.0, 1.0], ); }); diff --git a/imgui-examples/examples/hello_world.rs b/imgui-examples/examples/hello_world.rs index 0c87a99..56eb774 100644 --- a/imgui-examples/examples/hello_world.rs +++ b/imgui-examples/examples/hello_world.rs @@ -7,7 +7,7 @@ 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(im_str!("Hello world")) + Window::new("Hello world") .size([300.0, 110.0], Condition::FirstUseEver) .build(ui, || { ui.text_wrapped("Hello world!"); @@ -16,7 +16,7 @@ fn main() { value += 1; value %= 2; } - + ui.button("This...is...imgui-rs!"); ui.separator(); let mouse_pos = ui.io().mouse_pos; diff --git a/imgui-examples/examples/keyboard.rs b/imgui-examples/examples/keyboard.rs index 1114c0c..d2d9c3f 100644 --- a/imgui-examples/examples/keyboard.rs +++ b/imgui-examples/examples/keyboard.rs @@ -14,7 +14,7 @@ fn main() { let mut text_buffer = String::new(); system.main_loop(move |_, ui| { - Window::new(im_str!("Means of accessing key state")) + Window::new("Means of accessing key state") .size([500.0, 300.0], Condition::FirstUseEver) .build(ui, || { // You can check if a key is currently held down @@ -81,12 +81,12 @@ fn main() { // example, if you try to type into this input, the // above interaction still counts the key presses. ui.input_text_multiline( - im_str!("##Dummy text input widget"), + "##Dummy text input widget", &mut text_buffer, [100.0, 100.0], ) // .do_not_resize() if you pass this, then this won't resize! - // .hint(im_str!("Example text input")) + // .hint("Example text input") .build(); // If you want to check if a widget is capturing diff --git a/imgui-examples/examples/long_list.rs b/imgui-examples/examples/long_list.rs index 79278af..8a745e6 100644 --- a/imgui-examples/examples/long_list.rs +++ b/imgui-examples/examples/long_list.rs @@ -15,7 +15,7 @@ fn main() { let system = support::init(file!()); system.main_loop(move |_, ui| { - Window::new(im_str!("Hello long world")) + Window::new("Hello long world") .size([300.0, 110.0], Condition::FirstUseEver) .build(ui, || { let mut clipper = imgui::ListClipper::new(lots_of_words.len() as i32) diff --git a/imgui-examples/examples/multiple_fonts.rs b/imgui-examples/examples/multiple_fonts.rs index e78a17b..8517593 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(im_str!("Hello world")) + Window::new("Hello world") .opened(run) .build(ui, || { ui.text("Hello, I'm the default font!"); diff --git a/imgui-examples/examples/progress_bar.rs b/imgui-examples/examples/progress_bar.rs index 65cbcd5..2419ae8 100644 --- a/imgui-examples/examples/progress_bar.rs +++ b/imgui-examples/examples/progress_bar.rs @@ -5,7 +5,7 @@ mod support; fn main() { let system = support::init(file!()); system.main_loop(move |run, ui| { - let w = Window::new(im_str!("Progress bar")) + let w = Window::new("Progress bar") .opened(run) .position([20.0, 20.0], Condition::Appearing) .size([700.0, 200.0], Condition::Appearing); diff --git a/imgui-examples/examples/radio_button.rs b/imgui-examples/examples/radio_button.rs index d968c1d..cb86a82 100644 --- a/imgui-examples/examples/radio_button.rs +++ b/imgui-examples/examples/radio_button.rs @@ -16,19 +16,15 @@ fn main() { } fn example_selector(run: &mut bool, ui: &mut Ui, state: &mut State) { - let w = Window::new(im_str!("Radio button examples")) + let w = Window::new("Radio button examples") .opened(run) .position([20.0, 20.0], Condition::Appearing) .size([700.0, 80.0], Condition::Appearing) .resizable(false); w.build(ui, || { let mut clicked = false; - clicked |= ui.radio_button( - im_str!("Example 1: Boolean radio buttons"), - &mut state.example, - 1, - ); - clicked |= ui.radio_button(im_str!("Example 2: Radio buttons"), &mut state.example, 2); + 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); if clicked { state.reset(); } @@ -36,25 +32,25 @@ fn example_selector(run: &mut bool, ui: &mut Ui, state: &mut State) { } fn example_1(ui: &Ui, state: &mut State) { - let w = Window::new(im_str!("Example 1: Boolean radio buttons")) + let w = Window::new("Example 1: Boolean radio buttons") .size([700.0, 200.0], Condition::Appearing) .position([20.0, 120.0], Condition::Appearing); w.build(ui, || { - ui.text_wrapped(im_str!( + 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 \ can implement any click behaviour you want. The return value is true if the button \ - was clicked." - )); + was clicked.", + ); ui.text(state.notify_text); - if ui.radio_button_bool(im_str!("I'm permanently active"), true) { + if ui.radio_button_bool("I'm permanently active", true) { state.notify_text = "*** Permanently active radio button was clicked"; } - if ui.radio_button_bool(im_str!("I'm permanently inactive"), false) { + if ui.radio_button_bool("I'm permanently inactive", false) { state.notify_text = "*** Permanently inactive radio button was clicked"; } - if ui.radio_button_bool(im_str!("I toggle my state on click"), state.simple_bool) { + if ui.radio_button_bool("I toggle my state on click", state.simple_bool) { state.simple_bool = !state.simple_bool; // flip state on click state.notify_text = "*** Toggling radio button was clicked"; } @@ -62,36 +58,36 @@ fn example_1(ui: &Ui, state: &mut State) { } fn example_2(ui: &Ui, state: &mut State) { - let w = Window::new(im_str!("Example 2: Radio buttons")) + let w = Window::new("Example 2: Radio buttons") .size([700.0, 300.0], Condition::Appearing) .position([20.0, 120.0], Condition::Appearing); w.build(ui, || { - ui.text_wrapped(im_str!( + 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 \ - type that is both Copy and PartialEq. This is especially useful with Rust enums" - )); + type that is both Copy and PartialEq. This is especially useful with Rust enums", + ); ui.text(state.notify_text); ui.separator(); - if ui.radio_button(im_str!("I'm number 1"), &mut state.number, 1) { + if ui.radio_button("I'm number 1", &mut state.number, 1) { state.notify_text = "*** Number 1 was clicked"; } - if ui.radio_button(im_str!("I'm number 2"), &mut state.number, 2) { + if ui.radio_button("I'm number 2", &mut state.number, 2) { state.notify_text = "*** Number 2 was clicked"; } - if ui.radio_button(im_str!("I'm number 3"), &mut state.number, 3) { + if ui.radio_button("I'm number 3", &mut state.number, 3) { state.notify_text = "*** Number 3 was clicked"; } ui.separator(); - if ui.radio_button(im_str!("I'm choice A"), &mut state.choice, Some(Choice::A)) { + if ui.radio_button("I'm choice A", &mut state.choice, Some(Choice::A)) { state.notify_text = "*** Choice A was clicked"; } - if ui.radio_button(im_str!("I'm choice B"), &mut state.choice, Some(Choice::B)) { + if ui.radio_button("I'm choice B", &mut state.choice, Some(Choice::B)) { state.notify_text = "*** Choice B was clicked"; } - if ui.radio_button(im_str!("I'm choice C"), &mut state.choice, Some(Choice::C)) { + if ui.radio_button("I'm choice C", &mut state.choice, Some(Choice::C)) { state.notify_text = "*** Choice C was clicked"; } }); diff --git a/imgui-examples/examples/slider.rs b/imgui-examples/examples/slider.rs index 00c1428..e5e5bcc 100644 --- a/imgui-examples/examples/slider.rs +++ b/imgui-examples/examples/slider.rs @@ -16,15 +16,15 @@ fn main() { } fn example_selector(run: &mut bool, ui: &mut Ui, state: &mut State) { - let w = Window::new(im_str!("Slider examples")) + let w = Window::new("Slider examples") .opened(run) .position([20.0, 20.0], Condition::Appearing) .size([700.0, 80.0], Condition::Appearing) .resizable(false); w.build(ui, || { let mut clicked = false; - clicked |= ui.radio_button(im_str!("Example 1: Basic sliders"), &mut state.example, 1); - clicked |= ui.radio_button(im_str!("Example 2: Slider arrays"), &mut state.example, 2); + clicked |= ui.radio_button("Example 1: Basic sliders", &mut state.example, 1); + clicked |= ui.radio_button("Example 2: Slider arrays", &mut state.example, 2); if clicked { state.reset(); } @@ -32,7 +32,7 @@ fn example_selector(run: &mut bool, ui: &mut Ui, state: &mut State) { } fn example_1(ui: &Ui, state: &mut State) { - let w = Window::new(im_str!("Example 1: Basic sliders")) + let w = Window::new("Example 1: Basic sliders") .size([700.0, 340.0], Condition::Appearing) .position([20.0, 120.0], Condition::Appearing); w.build(ui, || { @@ -41,42 +41,42 @@ fn example_1(ui: &Ui, state: &mut State) { ui.text("Unsigned: u8 u16 u32 u64"); ui.text("Floats: f32 f64"); - Slider::new(im_str!("u8 value"), 0, 255) + Slider::new("u8 value", 0, 255) .build(ui, &mut state.u8_value); - Slider::new(im_str!("f32 value"), -f32::MIN, f32::MAX) + Slider::new("f32 value", -f32::MIN, f32::MAX) .build(ui, &mut state.f32_value); ui.separator(); ui.text("Slider range can be limited:"); - Slider::new(im_str!("i32 value with range"), -999, 999) + Slider::new("i32 value with range", -999, 999) .build(ui, &mut state.i32_value); ui.text("Note that for 32-bit/64-bit types, sliders are always limited to half of the natural type range!"); ui.separator(); ui.text("Value formatting can be customized with a C-style printf string:"); - Slider::new(im_str!("f64 value with custom formatting"), -999_999_999.0, 999_999_999.0) + Slider::new("f64 value with custom formatting", -999_999_999.0, 999_999_999.0) .display_format("%09.0f") .build(ui, &mut state.f64_formatted); ui.separator(); ui.text("Vertical sliders require a size parameter but otherwise work in a similar way:"); - VerticalSlider::new(im_str!("vertical\nu8 value"), [50.0, 50.0], u8::MIN, u8::MAX) + VerticalSlider::new("vertical\nu8 value", [50.0, 50.0], u8::MIN, u8::MAX) .build(ui, &mut state.u8_value); }); } fn example_2(ui: &Ui, state: &mut State) { - let w = Window::new(im_str!("Example 2: Slider arrays")) + let w = Window::new("Example 2: Slider arrays") .size([700.0, 260.0], Condition::Appearing) .position([20.0, 120.0], Condition::Appearing); w.build(ui, || { ui.text("You can easily build a slider group from an array of values:"); - Slider::new(im_str!("[u8; 4]"), 0, u8::MAX).build_array(ui, &mut state.array); + Slider::new("[u8; 4]", 0, u8::MAX).build_array(ui, &mut state.array); ui.text("You don't need to use arrays with known length; arbitrary slices can be used:"); let slice: &mut [u8] = &mut state.array[1..=2]; - Slider::new(im_str!("subslice"), 0, u8::MAX).build_array(ui, slice); + Slider::new("subslice", 0, u8::MAX).build_array(ui, slice); }); } diff --git a/imgui-examples/examples/test_window_impl.rs b/imgui-examples/examples/test_window_impl.rs index 29e1acf..f47c4a2 100644 --- a/imgui-examples/examples/test_window_impl.rs +++ b/imgui-examples/examples/test_window_impl.rs @@ -236,7 +236,7 @@ fn main() { } fn show_help_marker(ui: &Ui, desc: &str) { - ui.text_disabled(im_str!("(?)")); + ui.text_disabled("(?)"); if ui.is_item_hovered() { ui.tooltip(|| { ui.text(desc); @@ -245,18 +245,14 @@ fn show_help_marker(ui: &Ui, desc: &str) { } fn show_user_guide(ui: &Ui) { - ui.bullet_text(im_str!("Double-click on title bar to collapse window.")); - ui.bullet_text(im_str!( - "Click and drag on lower right corner to resize window." - )); - ui.bullet_text(im_str!("Click and drag on any empty space to move window.")); - ui.bullet_text(im_str!("Mouse Wheel to scroll.")); + ui.bullet_text("Double-click on title bar to collapse window."); + ui.bullet_text("Click and drag on lower right corner to resize window."); + ui.bullet_text("Click and drag on any empty space to move window."); + ui.bullet_text("Mouse Wheel to scroll."); // TODO: check font_allow_user_scaling - ui.bullet_text(im_str!( - "TAB/SHIFT+TAB to cycle through keyboard editable fields." - )); - ui.bullet_text(im_str!("CTRL+Click on a slider or drag box to input text.")); - ui.bullet_text(im_str!( + ui.bullet_text("TAB/SHIFT+TAB to cycle through keyboard editable fields."); + ui.bullet_text("CTRL+Click on a slider or drag box to input text."); + ui.bullet_text( "While editing text: - Hold SHIFT or use mouse to select text - CTRL+Left/Right to word jump @@ -265,8 +261,8 @@ fn show_user_guide(ui: &Ui) { - CTRL+Z,CTRL+Y undo/redo - ESCAPE to revert - You can apply arithmetic operators +,*,/ on numerical values. - Use +- to subtract.\n" - )); + Use +- to subtract.\n", + ); } fn show_test_window(ui: &Ui, state: &mut State, opened: &mut bool) { @@ -290,12 +286,12 @@ 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(im_str!("Style Editor")) + Window::new("Style Editor") .opened(&mut state.show_app_style_editor) .build(ui, || ui.show_default_style_editor()); } if state.show_app_about { - Window::new(im_str!("About ImGui")) + Window::new("About ImGui") .always_auto_resize(true) .opened(&mut state.show_app_about) .build(ui, || { @@ -321,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(im_str!("ImGui Demo")) + let mut window = Window::new("ImGui Demo") .title_bar(!state.no_titlebar) .resizable(!state.no_resize) .movable(!state.no_move) @@ -336,182 +332,182 @@ fn show_test_window(ui: &Ui, state: &mut State, opened: &mut bool) { 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() { - if let Some(menu) = ui.begin_menu(im_str!("Menu")) { + if let Some(menu) = ui.begin_menu("Menu") { show_example_menu_file(ui, &mut state.file_menu); menu.end(); } - if let Some(menu) = ui.begin_menu(im_str!("Examples")) { - MenuItem::new(im_str!("Main menu bar")) + if let Some(menu) = ui.begin_menu("Examples") { + MenuItem::new("Main menu bar") .build_with_ref(ui, &mut state.show_app_main_menu_bar); - MenuItem::new(im_str!("Console")) + MenuItem::new("Console") .build_with_ref(ui, &mut state.show_app_console); - MenuItem::new(im_str!("Log")) + MenuItem::new("Log") .build_with_ref(ui, &mut state.show_app_log); - MenuItem::new(im_str!("Simple layout")) + MenuItem::new("Simple layout") .build_with_ref(ui, &mut state.show_app_layout); - MenuItem::new(im_str!("Property editor")) + MenuItem::new("Property editor") .build_with_ref(ui, &mut state.show_app_property_editor); - MenuItem::new(im_str!("Long text display")) + MenuItem::new("Long text display") .build_with_ref(ui, &mut state.show_app_long_text); - MenuItem::new(im_str!("Auto-resizing window")) + MenuItem::new("Auto-resizing window") .build_with_ref(ui, &mut state.show_app_auto_resize); - MenuItem::new(im_str!("Constrained-resizing window")) + MenuItem::new("Constrained-resizing window") .build_with_ref(ui, &mut state.show_app_constrained_resize); - MenuItem::new(im_str!("Simple overlay")) + MenuItem::new("Simple overlay") .build_with_ref(ui, &mut state.show_app_fixed_overlay); - MenuItem::new(im_str!("Manipulating window title")) + MenuItem::new("Manipulating window title") .build_with_ref(ui, &mut state.show_app_manipulating_window_title); - MenuItem::new(im_str!("Custom rendering")) + MenuItem::new("Custom rendering") .build_with_ref(ui, &mut state.show_app_custom_rendering); menu.end(); } - if let Some(menu) = ui.begin_menu(im_str!("Help")) { - MenuItem::new(im_str!("Metrics")) + if let Some(menu) = ui.begin_menu("Help") { + MenuItem::new("Metrics") .build_with_ref(ui, &mut state.show_app_metrics); - MenuItem::new(im_str!("Style Editor")) + MenuItem::new("Style Editor") .build_with_ref(ui, &mut state.show_app_style_editor); - MenuItem::new(im_str!("About ImGui")) + MenuItem::new("About ImGui") .build_with_ref(ui, &mut state.show_app_about); menu.end(); } menu_bar.end(); } ui.spacing(); - if CollapsingHeader::new(im_str!("Help")).build(ui) { - ui.text_wrapped(im_str!( + if CollapsingHeader::new("Help").build(ui) { + ui.text_wrapped( "This window is being created by the show_test_window() \ function. Please refer to the code for programming \ reference.\n\nUser Guide:" - )); + ); show_user_guide(ui); } - if CollapsingHeader::new(im_str!("Window options")).build(ui) { - ui.checkbox(im_str!("No titlebar"), &mut state.no_titlebar); + if CollapsingHeader::new("Window options").build(ui) { + ui.checkbox("No titlebar", &mut state.no_titlebar); ui.same_line_with_pos(150.0); - ui.checkbox(im_str!("No scrollbar"), &mut state.no_scrollbar); + ui.checkbox("No scrollbar", &mut state.no_scrollbar); ui.same_line_with_pos(300.0); - ui.checkbox(im_str!("No menu"), &mut state.no_menu); - ui.checkbox(im_str!("No move"), &mut state.no_move); + ui.checkbox("No menu", &mut state.no_menu); + ui.checkbox("No move", &mut state.no_move); ui.same_line_with_pos(150.0); - ui.checkbox(im_str!("No resize"), &mut state.no_resize); + ui.checkbox("No resize", &mut state.no_resize); ui.same_line_with_pos(300.0); - ui.checkbox(im_str!("No collapse"), &mut state.no_collapse); - ui.checkbox(im_str!("No close"), &mut state.no_close); + ui.checkbox("No collapse", &mut state.no_collapse); + ui.checkbox("No close", &mut state.no_close); - TreeNode::new(im_str!("Style")).build(ui, || { + TreeNode::new("Style").build(ui, || { ui.show_default_style_editor(); }); } - if CollapsingHeader::new(im_str!("Widgets")).build(ui) { - TreeNode::new(im_str!("Tree")).build(ui, || { + if CollapsingHeader::new("Widgets").build(ui) { + TreeNode::new("Tree").build(ui, || { for i in 0..5 { - TreeNode::new(&im_str!("Child {}", i)).build(ui, || { - ui.text(im_str!("blah blah")); + TreeNode::new(format!("Child {}", i)).build(ui, || { + ui.text("blah blah"); ui.same_line(); - if ui.small_button(im_str!("print")) { + if ui.small_button("print") { println!("Child {} pressed", i); } }); } }); - TreeNode::new(im_str!("Bullets")).build(ui, || { - ui.bullet_text(im_str!("Bullet point 1")); - ui.bullet_text(im_str!("Bullet point 2\nOn multiple lines")); + TreeNode::new("Bullets").build(ui, || { + ui.bullet_text("Bullet point 1"); + ui.bullet_text("Bullet point 2\nOn multiple lines"); ui.bullet(); - ui.text(im_str!("Bullet point 3 (two calls)")); + ui.text("Bullet point 3 (two calls)"); ui.bullet(); - ui.small_button(im_str!("Button")); + ui.small_button("Button"); }); - TreeNode::new(im_str!("Colored text")).build(ui, || { - ui.text_colored([1.0, 0.0, 1.0, 1.0], im_str!("Pink")); - ui.text_colored([1.0, 1.0, 0.0, 1.0], im_str!("Yellow")); - ui.text_disabled(im_str!("Disabled")); + TreeNode::new("Colored text").build(ui, || { + ui.text_colored([1.0, 0.0, 1.0, 1.0], "Pink"); + ui.text_colored([1.0, 1.0, 0.0, 1.0], "Yellow"); + ui.text_disabled("Disabled"); }); - TreeNode::new(im_str!("Multi-line text")).build(ui, || { + TreeNode::new("Multi-line text").build(ui, || { ui.input_text_multiline( - im_str!("multiline"), + "multiline", &mut state.text_multiline, [300., 100.], ).build(); }); - TreeNode::new(im_str!("Word wrapping")).build(ui, || { - ui.text_wrapped(im_str!( + TreeNode::new("Word wrapping").build(ui, || { + ui.text_wrapped( "This text should automatically wrap on the edge of \ the window.The current implementation for text \ wrapping follows simple rulessuitable for English \ and possibly other languages." - )); + ); ui.spacing(); - Slider::new(im_str!("Wrap width"), -20.0, 600.0) + Slider::new("Wrap width", -20.0, 600.0) .display_format("%.0f") .build(ui, &mut state.wrap_width); - ui.text(im_str!("Test paragraph 1:")); + ui.text("Test paragraph 1:"); // TODO - ui.text(im_str!("Test paragraph 2:")); + ui.text("Test paragraph 2:"); // TODO }); - TreeNode::new(im_str!("UTF-8 Text")).build(ui, || { - ui.text_wrapped(im_str!( + TreeNode::new("UTF-8 Text").build(ui, || { + ui.text_wrapped( "CJK text will only appear if the font was loaded \ with theappropriate CJK character ranges. Call \ io.Font->LoadFromFileTTF()manually to load extra \ character ranges." - )); + ); - ui.text(im_str!("Hiragana: かきくけこ (kakikukeko)")); - ui.text(im_str!("Kanjis: 日本語 (nihongo)")); - ui.input_text(im_str!("UTF-8 input"), &mut state.buf) + ui.text("Hiragana: かきくけこ (kakikukeko)"); + ui.text("Kanjis: 日本語 (nihongo)"); + ui.input_text("UTF-8 input", &mut state.buf) .build(); }); - ui.radio_button(im_str!("radio a"), &mut state.radio_button, 0); + ui.radio_button("radio a", &mut state.radio_button, 0); ui.same_line(); - ui.radio_button(im_str!("radio b"), &mut state.radio_button, 1); + ui.radio_button("radio b", &mut state.radio_button, 1); ui.same_line(); - ui.radio_button(im_str!("radio c"), &mut state.radio_button, 2); + ui.radio_button("radio c", &mut state.radio_button, 2); ui.separator(); - ui.label_text(im_str!("label"), im_str!("Value")); + ui.label_text("label", "Value"); ui.combo_simple_string("combo", &mut state.item, &[ - im_str!("aaaa"), - im_str!("bbbb"), - im_str!("cccc"), - im_str!("dddd"), - im_str!("eeee"), + "aaaa", + "bbbb", + "cccc", + "dddd", + "eeee", ]); let items = [ - im_str!("AAAA"), - im_str!("BBBB"), - im_str!("CCCC"), - im_str!("DDDD"), - im_str!("EEEE"), - im_str!("FFFF"), - im_str!("GGGG"), - im_str!("HHHH"), - im_str!("IIII"), - im_str!("JJJJ"), - im_str!("KKKK"), + "AAAA", + "BBBB", + "CCCC", + "DDDD", + "EEEE", + "FFFF", + "GGGG", + "HHHH", + "IIII", + "JJJJ", + "KKKK", ]; ui.combo_simple_string("combo scroll", &mut state.item2, &items); - ui.list_box(im_str!("list"), &mut state.item3, &items, 8); + ui.list_box("list", &mut state.item3, &items, 8); let names = [ - im_str!("Bream"), - im_str!("Haddock"), - im_str!("Mackerel"), - im_str!("Pollock"), - im_str!("Tilefish"), + "Bream", + "Haddock", + "Mackerel", + "Pollock", + "Tilefish", ]; ListBox::new("selectables list").build(ui, || { @@ -524,7 +520,7 @@ fn show_test_window(ui: &Ui, state: &mut State, opened: &mut bool) { }); let last_size = ui.item_rect_size(); - ListBox::new(im_str!("selectable list 2")).size([0.0, last_size[1] * 0.66]).build(ui, || { + ListBox::new("selectable list 2").size([0.0, last_size[1] * 0.66]).build(ui, || { for (index, name) in names.iter().enumerate() { let selected = matches!(state.selected_fish2, Some(i) if i == index ); if Selectable::new(name).selected(selected).build(ui) { @@ -533,40 +529,40 @@ fn show_test_window(ui: &Ui, state: &mut State, opened: &mut bool) { } }); - ui.input_text(im_str!("input text"), &mut state.text) + ui.input_text("input text", &mut state.text) .build(); - ui.input_text(im_str!("input text with hint"), &mut state.text_with_hint) - .hint(im_str!("enter text here")) + ui.input_text("input text with hint", &mut state.text_with_hint) + .hint("enter text here") .build(); - ui.input_int(im_str!("input int"), &mut state.i0).build(); - // Drag::new(im_str!("drag int")).build(ui, &mut state.i0); - ui.input_float(im_str!("input float"), &mut state.f0) + ui.input_int("input int", &mut state.i0).build(); + // Drag::new("drag int").build(ui, &mut state.i0); + ui.input_float("input float", &mut state.f0) .step(0.01) .step_fast(1.0) .build(); - Drag::new(im_str!("drag float")).range(-1.0, 1.0).speed(0.001).build(ui, &mut state.f0); - ui.input_float3(im_str!("input float3"), &mut state.vec3f) + Drag::new("drag float").range(-1.0, 1.0).speed(0.001).build(ui, &mut state.f0); + ui.input_float3("input float3", &mut state.vec3f) .build(); - ColorEdit::new(im_str!("color 1"), &mut state.col1).build(ui); - ColorEdit::new(im_str!("color 2"), &mut state.col2).build(ui); + ColorEdit::new("color 1", &mut state.col1).build(ui); + ColorEdit::new("color 2", &mut state.col2).build(ui); - TreeNode::new(im_str!("Multi-component Widgets")).build(ui, || { - ui.input_float2(im_str!("input float2"), &mut state.vec2f) + TreeNode::new("Multi-component Widgets").build(ui, || { + ui.input_float2("input float2", &mut state.vec2f) .build(); - ui.input_int2(im_str!("input int2"), &mut state.vec2i) + ui.input_int2("input int2", &mut state.vec2i) .build(); ui.spacing(); - ui.input_float3(im_str!("input float3"), &mut state.vec3f) + ui.input_float3("input float3", &mut state.vec3f) .build(); - ui.input_int3(im_str!("input int3"), &mut state.vec3i) + ui.input_int3("input int3", &mut state.vec3i) .build(); ui.spacing(); }); - TreeNode::new(im_str!("Color/Picker Widgets")).build(ui, || { + TreeNode::new("Color/Picker Widgets").build(ui, || { let s = &mut state.color_edit; - ui.checkbox(im_str!("With HDR"), &mut s.hdr); + ui.checkbox("With HDR", &mut s.hdr); ui.same_line(); show_help_marker( ui, @@ -574,12 +570,12 @@ fn show_test_window(ui: &Ui, state: &mut State, opened: &mut bool) { limits on dragging widgets.", ); - ui.checkbox(im_str!("With Alpha Preview"), &mut s.alpha_preview); + ui.checkbox("With Alpha Preview", &mut s.alpha_preview); ui.checkbox( - im_str!("With Half Alpha Preview"), + "With Half Alpha Preview", &mut s.alpha_half_preview, ); - ui.checkbox(im_str!("With Options Menu"), &mut s.options_menu); + ui.checkbox("With Options Menu", &mut s.options_menu); ui.same_line(); show_help_marker( ui, @@ -597,31 +593,31 @@ fn show_test_window(ui: &Ui, state: &mut State, opened: &mut bool) { f }; - ui.text(im_str!("Color widget:")); + ui.text("Color widget:"); ui.same_line(); show_help_marker( ui, "Click on the colored square to open a color picker. CTRL+click on individual component to input value.\n", ); - ColorEdit::new(im_str!("MyColor##1"), &mut s.color) + ColorEdit::new("MyColor##1", &mut s.color) .flags(misc_flags) .alpha(false) .build(ui); - ui.text(im_str!("Color widget HSV with Alpha:")); - ColorEdit::new(im_str!("MyColor##2"), &mut s.color) + ui.text("Color widget HSV with Alpha:"); + ColorEdit::new("MyColor##2", &mut s.color) .flags(misc_flags) .input_mode(ColorEditInputMode::HSV) .build(ui); - ui.text(im_str!("Color widget with Float Display:")); - ColorEdit::new(im_str!("MyColor##2f"), &mut s.color) + ui.text("Color widget with Float Display:"); + ColorEdit::new("MyColor##2f", &mut s.color) .flags(misc_flags) .format(ColorFormat::Float) .build(ui); - ui.text(im_str!("Color button with Picker:")); + ui.text("Color button with Picker:"); ui.same_line(); show_help_marker( ui, @@ -630,29 +626,29 @@ CTRL+click on individual component to input value.\n", With the label(false) function you can pass a non-empty label which \ will only be used for the tooltip and picker popup.", ); - ColorEdit::new(im_str!("MyColor##3"), &mut s.color) + ColorEdit::new("MyColor##3", &mut s.color) .flags(misc_flags) .inputs(false) .label(false) .build(ui); - ui.text(im_str!("Color picker:")); - ui.checkbox(im_str!("With Alpha"), &mut s.alpha); - ui.checkbox(im_str!("With Alpha Bar"), &mut s.alpha_bar); - ui.checkbox(im_str!("With Side Preview"), &mut s.side_preview); + ui.text("Color picker:"); + ui.checkbox("With Alpha", &mut s.alpha); + ui.checkbox("With Alpha Bar", &mut s.alpha_bar); + ui.checkbox("With Side Preview", &mut s.side_preview); if s.side_preview { ui.same_line(); - ui.checkbox(im_str!("With Ref Color"), &mut s.ref_color); + ui.checkbox("With Ref Color", &mut s.ref_color); if s.ref_color { ui.same_line(); - ColorEdit::new(im_str!("##RefColor"), &mut s.ref_color_v) + ColorEdit::new("##RefColor", &mut s.ref_color_v) .flags(misc_flags) .inputs(false) .build(ui); } } let mut b = ColorPicker::new - (im_str!("MyColor##4"), &mut s.color) + ("MyColor##4", &mut s.color) .flags(misc_flags) .alpha(s.alpha) .alpha_bar(s.alpha_bar) @@ -666,48 +662,48 @@ CTRL+click on individual component to input value.\n", }); } - if CollapsingHeader::new(im_str!("Layout")).build(ui) { - TreeNode::new(im_str!("Tabs")).build(ui, || { - TreeNode::new(im_str!("Basic")).build(ui, || { - TabBar::new(im_str!("basictabbar")).build(ui, || { - TabItem::new(im_str!("Avocado")).build(ui, || { - ui.text(im_str!("This is the Avocado tab!")); - ui.text(im_str!("blah blah blah blah blah")); + if CollapsingHeader::new("Layout").build(ui) { + TreeNode::new("Tabs").build(ui, || { + TreeNode::new("Basic").build(ui, || { + TabBar::new("basictabbar").build(ui, || { + TabItem::new("Avocado").build(ui, || { + ui.text("This is the Avocado tab!"); + ui.text("blah blah blah blah blah"); }); - TabItem::new(im_str!("Broccoli")).build(ui, || { - ui.text(im_str!("This is the Broccoli tab!")); - ui.text(im_str!("blah blah blah blah blah")); + TabItem::new("Broccoli").build(ui, || { + ui.text("This is the Broccoli tab!"); + ui.text("blah blah blah blah blah"); }); - TabItem::new(im_str!("Cucumber")).build(ui, || { - ui.text(im_str!("This is the Cucumber tab!")); - ui.text(im_str!("blah blah blah blah blah")); + TabItem::new("Cucumber").build(ui, || { + ui.text("This is the Cucumber tab!"); + ui.text("blah blah blah blah blah"); }); }); }); - TreeNode::new(im_str!("Advanced & Close button")).build(ui, || { + TreeNode::new("Advanced & Close button").build(ui, || { ui.separator(); let s = &mut state.tabs; - ui.checkbox(im_str!("ImGuiTabBarFlags_Reorderable"), &mut s.reorderable); - ui.checkbox(im_str!("ImGuiTabBarFlags_AutoSelectNewTabs"), &mut s.autoselect); - ui.checkbox(im_str!("ImGuiTabBarFlags_TabListPopupButton"), &mut s.listbutton); - ui.checkbox(im_str!("ImGuiTabBarFlags_NoCloseWithMiddleMouseButton"), &mut s.noclose_middlebutton); - if ui.checkbox(im_str!("ImGuiTabBarFlags_FittingPolicyResizeDown"), &mut s.fitting_resizedown) { + ui.checkbox("ImGuiTabBarFlags_Reorderable", &mut s.reorderable); + ui.checkbox("ImGuiTabBarFlags_AutoSelectNewTabs", &mut s.autoselect); + ui.checkbox("ImGuiTabBarFlags_TabListPopupButton", &mut s.listbutton); + ui.checkbox("ImGuiTabBarFlags_NoCloseWithMiddleMouseButton", &mut s.noclose_middlebutton); + if ui.checkbox("ImGuiTabBarFlags_FittingPolicyResizeDown", &mut s.fitting_resizedown) { s.fitting_scroll = !s.fitting_resizedown; } - if ui.checkbox(im_str!("ImGuiTabBarFlags_FittingPolicyScroll"), &mut s.fitting_scroll) { + if ui.checkbox("ImGuiTabBarFlags_FittingPolicyScroll", &mut s.fitting_scroll) { s.fitting_resizedown = !s.fitting_scroll; } let style = ui.push_style_var(StyleVar::FramePadding([0.0, 0.0])); - ui.checkbox(im_str!("Artichoke"), &mut s.artichoke_tab); + ui.checkbox("Artichoke", &mut s.artichoke_tab); ui.same_line(); - ui.checkbox(im_str!("Beetroot"), &mut s.beetroot_tab); + ui.checkbox("Beetroot", &mut s.beetroot_tab); ui.same_line(); - ui.checkbox(im_str!("Celery"), &mut s.celery_tab); + ui.checkbox("Celery", &mut s.celery_tab); ui.same_line(); - ui.checkbox(im_str!("Daikon"), &mut s.daikon_tab); + ui.checkbox("Daikon", &mut s.daikon_tab); style.pop(); let flags = { @@ -721,48 +717,48 @@ CTRL+click on individual component to input value.\n", f }; - TabBar::new(im_str!("tabbar")).flags(flags).build(ui, || { - TabItem::new(im_str!("Artichoke")).opened(&mut s.artichoke_tab).build(ui, || { - ui.text(im_str!("This is the Artichoke tab!")); + TabBar::new("tabbar").flags(flags).build(ui, || { + TabItem::new("Artichoke").opened(&mut s.artichoke_tab).build(ui, || { + ui.text("This is the Artichoke tab!"); }); - TabItem::new(im_str!("Beetroot")).opened(&mut s.beetroot_tab).build(ui, || { - ui.text(im_str!("This is the Beetroot tab!")); + TabItem::new("Beetroot").opened(&mut s.beetroot_tab).build(ui, || { + ui.text("This is the Beetroot tab!"); }); - TabItem::new(im_str!("Celery")).opened(&mut s.celery_tab).build(ui, || { - ui.text(im_str!("This is the Celery tab!")); + TabItem::new("Celery").opened(&mut s.celery_tab).build(ui, || { + ui.text("This is the Celery tab!"); }); - TabItem::new(im_str!("Daikon")).opened(&mut s.daikon_tab).build(ui, || { - ui.text(im_str!("This is the Daikon tab!")); + TabItem::new("Daikon").opened(&mut s.daikon_tab).build(ui, || { + ui.text("This is the Daikon tab!"); }); }); }); }); } - if CollapsingHeader::new(im_str!("Popups & Modal windows")).build(ui) { - TreeNode::new(im_str!("Popups")).build(ui, || { - ui.text_wrapped(im_str!( + if CollapsingHeader::new("Popups & Modal windows").build(ui) { + TreeNode::new("Popups").build(ui, || { + ui.text_wrapped( "When a popup is active, it inhibits interacting \ with windows that are behind the popup. Clicking \ outside the popup closes it." - )); + ); let names = [ - im_str!("Bream"), - im_str!("Haddock"), - im_str!("Mackerel"), - im_str!("Pollock"), - im_str!("Tilefish"), + "Bream", + "Haddock", + "Mackerel", + "Pollock", + "Tilefish", ]; - if ui.small_button(im_str!("Select..")) { - ui.open_popup(im_str!("select")); + if ui.small_button("Select..") { + ui.open_popup("select"); } ui.same_line(); ui.text(match state.selected_fish { Some(index) => names[index], - None => im_str!(""), + None => "", }); - ui.popup(im_str!("select"), || { - ui.text(im_str!("Aquarium")); + ui.popup("select", || { + ui.text("Aquarium"); ui.separator(); for (index, name) in names.iter().enumerate() { if Selectable::new(name).build(ui) { @@ -772,56 +768,56 @@ CTRL+click on individual component to input value.\n", }); }); - TreeNode::new(im_str!("Modals")).build(ui, || { - ui.text_wrapped(im_str!( + TreeNode::new("Modals").build(ui, || { + ui.text_wrapped( "Modal windows are like popups but the user cannot close \ them by clicking outside the window." - )); + ); - if ui.button(im_str!("Delete..")) { - ui.open_popup(im_str!("Delete?")); + if ui.button("Delete..") { + ui.open_popup("Delete?"); } - PopupModal::new(im_str!("Delete?")).always_auto_resize(true).build(ui, || { + PopupModal::new("Delete?").always_auto_resize(true).build(ui, || { ui.text("All those beautiful files will be deleted.\nThis operation cannot be undone!\n\n"); ui.separator(); let style = ui.push_style_var(StyleVar::FramePadding([0.0, 0.0])); - ui.checkbox(im_str!("Don't ask me next time"), &mut state.dont_ask_me_next_time); + ui.checkbox("Don't ask me next time", &mut state.dont_ask_me_next_time); - if ui.button_with_size(im_str!("OK"), [120.0, 0.0]) { + if ui.button_with_size("OK", [120.0, 0.0]) { ui.close_current_popup(); } ui.same_line(); - if ui.button_with_size(im_str!("Cancel"), [120.0, 0.0]) { + if ui.button_with_size("Cancel", [120.0, 0.0]) { ui.close_current_popup(); } style.pop(); }); - if ui.button(im_str!("Stacked modals..")) { - ui.open_popup(im_str!("Stacked 1")); + if ui.button("Stacked modals..") { + ui.open_popup("Stacked 1"); } - PopupModal::new(im_str!("Stacked 1")).build(ui, || { + PopupModal::new("Stacked 1").build(ui, || { ui.text( "Hello from Stacked The First\n\ Using style[StyleColor::ModalWindowDarkening] for darkening." ); - let items = &[im_str!("aaaa"), im_str!("bbbb"), im_str!("cccc"), im_str!("dddd"), im_str!("eeee")]; + let items = &["aaaa", "bbbb", "cccc", "dddd", "eeee"]; ui.combo_simple_string("Combo", &mut state.stacked_modals_item, items); - ColorEdit::new(im_str!("color"), &mut state.stacked_modals_color).build(ui); + ColorEdit::new("color", &mut state.stacked_modals_color).build(ui); - if ui.button(im_str!("Add another modal..")) { - ui.open_popup(im_str!("Stacked 2")) ; + if ui.button("Add another modal..") { + ui.open_popup("Stacked 2") ; } - PopupModal::new(im_str!("Stacked 2")).build(ui, || { + PopupModal::new("Stacked 2").build(ui, || { ui.text("Hello from Stacked The Second"); - if ui.button(im_str!("Close")) { + if ui.button("Close") { ui.close_current_popup(); } }); - if ui.button(im_str!("Close")) { + if ui.button("Close") { ui.close_current_popup(); } }); @@ -832,20 +828,20 @@ CTRL+click on individual component to input value.\n", fn show_example_app_main_menu_bar<'a>(ui: &Ui<'a>, state: &mut State) { if let Some(menu_bar) = ui.begin_main_menu_bar() { - if let Some(menu) = ui.begin_menu(im_str!("File")) { + if let Some(menu) = ui.begin_menu("File") { show_example_menu_file(ui, &mut state.file_menu); menu.end(); } - if let Some(menu) = ui.begin_menu(im_str!("Edit")) { - MenuItem::new(im_str!("Undo")).shortcut("CTRL+Z").build(ui); - MenuItem::new(im_str!("Redo")) + if let Some(menu) = ui.begin_menu("Edit") { + MenuItem::new("Undo").shortcut("CTRL+Z").build(ui); + MenuItem::new("Redo") .shortcut("CTRL+Y") .enabled(false) .build(ui); ui.separator(); - MenuItem::new(im_str!("Cut")).shortcut("CTRL+X").build(ui); - MenuItem::new(im_str!("Copy")).shortcut("CTRL+C").build(ui); - MenuItem::new(im_str!("Paste")).shortcut("CTRL+V").build(ui); + MenuItem::new("Cut").shortcut("CTRL+X").build(ui); + MenuItem::new("Copy").shortcut("CTRL+C").build(ui); + MenuItem::new("Paste").shortcut("CTRL+V").build(ui); menu.end(); } menu_bar.end(); @@ -853,19 +849,17 @@ fn show_example_app_main_menu_bar<'a>(ui: &Ui<'a>, state: &mut State) { } fn show_example_menu_file<'a>(ui: &Ui<'a>, state: &mut FileMenuState) { - MenuItem::new(im_str!("(dummy menu)")) - .enabled(false) - .build(ui); - MenuItem::new(im_str!("New")).build(ui); - MenuItem::new(im_str!("Open")).shortcut("Ctrl+O").build(ui); - if let Some(menu) = ui.begin_menu(im_str!("Open Recent")) { - MenuItem::new(im_str!("fish_hat.c")).build(ui); - MenuItem::new(im_str!("fish_hat.inl")).build(ui); - MenuItem::new(im_str!("fish_hat.h")).build(ui); - if let Some(menu) = ui.begin_menu(im_str!("More..")) { - MenuItem::new(im_str!("Hello")).build(ui); - MenuItem::new(im_str!("Sailor")).build(ui); - if let Some(menu) = ui.begin_menu(im_str!("Recurse..")) { + MenuItem::new("(dummy menu)").enabled(false).build(ui); + MenuItem::new("New").build(ui); + MenuItem::new("Open").shortcut("Ctrl+O").build(ui); + if let Some(menu) = ui.begin_menu("Open Recent") { + MenuItem::new("fish_hat.c").build(ui); + MenuItem::new("fish_hat.inl").build(ui); + MenuItem::new("fish_hat.h").build(ui); + if let Some(menu) = ui.begin_menu("More..") { + MenuItem::new("Hello").build(ui); + MenuItem::new("Sailor").build(ui); + if let Some(menu) = ui.begin_menu("Recurse..") { show_example_menu_file(ui, state); menu.end(); } @@ -873,11 +867,11 @@ fn show_example_menu_file<'a>(ui: &Ui<'a>, state: &mut FileMenuState) { } menu.end(); } - MenuItem::new(im_str!("Save")).shortcut("Ctrl+S").build(ui); - MenuItem::new(im_str!("Save As..")).build(ui); + MenuItem::new("Save").shortcut("Ctrl+S").build(ui); + MenuItem::new("Save As..").build(ui); ui.separator(); - if let Some(menu) = ui.begin_menu(im_str!("Options")) { - MenuItem::new(im_str!("Enabled")).build_with_ref(ui, &mut state.enabled); + if let Some(menu) = ui.begin_menu("Options") { + MenuItem::new("Enabled").build_with_ref(ui, &mut state.enabled); ChildWindow::new("child") .size([0.0, 60.0]) .border(true) @@ -886,31 +880,27 @@ fn show_example_menu_file<'a>(ui: &Ui<'a>, state: &mut FileMenuState) { ui.text(format!("Scrolling Text {}", i)); } }); - Slider::new(im_str!("Value"), 0.0, 1.0).build(ui, &mut state.f); + Slider::new("Value", 0.0, 1.0).build(ui, &mut state.f); - ui.input_float(im_str!("Input"), &mut state.f) - .step(0.1) - .build(); + ui.input_float("Input", &mut state.f).step(0.1).build(); let items = ["Yes", "No", "Maybe"]; ui.combo_simple_string("Combo", &mut state.n, &items); - ui.checkbox(im_str!("Check"), &mut state.b); + ui.checkbox("Check", &mut state.b); menu.end(); } - if let Some(menu) = ui.begin_menu(im_str!("Colors")) { + if let Some(menu) = ui.begin_menu("Colors") { for &col in StyleColor::VARIANTS.iter() { - MenuItem::new(&im_str!("{:?}", col)).build(ui); + MenuItem::new(format!("{:?}", col)).build(ui); } menu.end(); } - assert!(ui - .begin_menu_with_enabled(im_str!("Disabled"), false) - .is_none()); - MenuItem::new(im_str!("Checked")).selected(true).build(ui); - MenuItem::new(im_str!("Quit")).shortcut("Alt+F4").build(ui); + assert!(ui.begin_menu_with_enabled("Disabled", false).is_none()); + MenuItem::new("Checked").selected(true).build(ui); + MenuItem::new("Quit").shortcut("Alt+F4").build(ui); } fn show_example_app_auto_resize(ui: &Ui, state: &mut AutoResizeState, opened: &mut bool) { - Window::new(im_str!("Example: Auto-resizing window")) + Window::new("Example: Auto-resizing window") .opened(opened) .always_auto_resize(true) .build(ui, || { @@ -919,7 +909,7 @@ fn show_example_app_auto_resize(ui: &Ui, state: &mut AutoResizeState, opened: &m Note that you probably don't want to query the window size to output your content because that would create a feedback loop.", ); - Slider::new(im_str!("Number of lines"), 1, 20).build(ui, &mut state.lines); + Slider::new("Number of lines", 1, 20).build(ui, &mut state.lines); for i in 0..state.lines { ui.text(format!("{:2$}This is line {}", "", i, i as usize * 4)); } @@ -930,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(im_str!("Example: Fixed Overlay")) + Window::new("Example: Fixed Overlay") .opened(opened) .position(window_pos, Condition::Always) .title_bar(false) @@ -953,7 +943,7 @@ fn show_example_app_fixed_overlay(ui: &Ui, opened: &mut bool) { } fn show_example_app_manipulating_window_title(ui: &Ui) { - Window::new(im_str!("Same title as another window##1")) + Window::new("Same title as another window##1") .position([100.0, 100.0], Condition::FirstUseEver) .build(ui, || { ui.text( @@ -961,7 +951,7 @@ fn show_example_app_manipulating_window_title(ui: &Ui) { My title is the same as window 2, but my identifier is unique.", ); }); - Window::new(im_str!("Same title as another window##2")) + Window::new("Same title as another window##2") .position([100.0, 200.0], Condition::FirstUseEver) .build(ui, || { ui.text( @@ -972,20 +962,20 @@ My title is the same as window 1, but my identifier is unique.", let chars = ['|', '/', '-', '\\']; let ch_idx = (ui.time() / 0.25) as usize & 3; let num = ui.frame_count(); // The C++ version uses rand() here - let title = im_str!("Animated title {} {}###AnimatedTitle", chars[ch_idx], num); - Window::new(&title) + let title = format!("Animated title {} {}###AnimatedTitle", chars[ch_idx], num); + Window::new(title) .position([100.0, 300.0], Condition::FirstUseEver) .build(ui, || ui.text("This window has a changing title")); } fn show_example_app_custom_rendering(ui: &Ui, state: &mut CustomRenderingState, opened: &mut bool) { - Window::new(im_str!("Example: Custom rendering")) + Window::new("Example: Custom rendering") .size([350.0, 560.0], Condition::FirstUseEver) .opened(opened) .build(ui, || { ui.text("Primitives"); // TODO: Add DragFloat to change value of sz - ColorEdit::new(im_str!("Color"), &mut state.col).build(ui); + ColorEdit::new("Color", &mut state.col).build(ui); let draw_list = ui.get_window_draw_list(); let p = ui.cursor_screen_pos(); let spacing = 8.0; @@ -1114,20 +1104,18 @@ fn show_example_app_custom_rendering(ui: &Ui, state: &mut CustomRenderingState, ui.dummy([(state.sz + spacing) * 8.0, (state.sz + spacing) * 3.0]); ui.separator(); - ui.text(im_str!("Canvas example")); - if ui.button(im_str!("Clear")) { + ui.text("Canvas example"); + if ui.button("Clear") { state.points.clear(); } if state.points.len() >= 2 { ui.same_line(); - if ui.button(im_str!("Undo")) { + if ui.button("Undo") { state.points.pop(); state.points.pop(); } } - ui.text(im_str!( - "Left-click and drag to add lines,\nRight-click to undo" - )); + ui.text("Left-click and drag to add lines,\nRight-click to undo"); // Here we are using InvisibleButton() as a convenience to // 1) advance the cursor, and // 2) allows us to use IsItemHovered() @@ -1175,7 +1163,7 @@ fn show_example_app_custom_rendering(ui: &Ui, state: &mut CustomRenderingState, .build(); let mut adding_preview = false; - ui.invisible_button(im_str!("canvas"), canvas_size); + ui.invisible_button("canvas", canvas_size); let mouse_pos = ui.io().mouse_pos; let mouse_pos_in_canvas = [mouse_pos[0] - canvas_pos[0], mouse_pos[1] - canvas_pos[1]]; if state.adding_line { @@ -1229,10 +1217,10 @@ fn show_example_app_custom_rendering(ui: &Ui, state: &mut CustomRenderingState, } fn show_app_log(ui: &Ui, app_log: &mut Vec) { - Window::new(im_str!("Example: Log")) + Window::new("Example: Log") .size([500.0, 400.0], Condition::FirstUseEver) .build(ui, || { - if ui.small_button(im_str!("[Debug] Add 5 entries")) { + if ui.small_button("[Debug] Add 5 entries") { let categories = ["info", "warn", "error"]; let words = [ "Bumfuzzled", @@ -1255,11 +1243,11 @@ fn show_app_log(ui: &Ui, app_log: &mut Vec) { app_log.push(text); } } - if ui.button(im_str!("Clear")) { + if ui.button("Clear") { app_log.clear(); } ui.same_line(); - if ui.button(im_str!("Copy")) { + if ui.button("Copy") { ui.set_clipboard_text(&ImString::from(app_log.join("\n"))); } ui.separator(); diff --git a/imgui-examples/examples/text_callbacks.rs b/imgui-examples/examples/text_callbacks.rs index 7c19523..4adcb4a 100644 --- a/imgui-examples/examples/text_callbacks.rs +++ b/imgui-examples/examples/text_callbacks.rs @@ -51,7 +51,7 @@ fn main() { println!("History was fired by pressing {:?}", dir); } - fn on_always(&mut self, txt: TextCallbackData<'_>) { + fn on_always(&mut self, _: TextCallbackData<'_>) { // We don't actually print this out because it will flood your log a lot! // println!("The always callback fired! It always fires."); } diff --git a/imgui-gfx-examples/examples/gfx_custom_textures.rs b/imgui-gfx-examples/examples/gfx_custom_textures.rs index 8446b8e..4c92217 100644 --- a/imgui-gfx-examples/examples/gfx_custom_textures.rs +++ b/imgui-gfx-examples/examples/gfx_custom_textures.rs @@ -62,10 +62,10 @@ impl CustomTexturesApp { } fn show_textures(&self, ui: &Ui) { - Window::new(im_str!("Hello textures")) + Window::new("Hello textures") .size([400.0, 600.0], Condition::FirstUseEver) .build(ui, || { - ui.text(im_str!("Hello textures!")); + ui.text("Hello textures!"); if let Some(my_texture_id) = self.my_texture_id { ui.text("Some generated texture"); Image::new(my_texture_id, [100.0, 100.0]).build(ui); diff --git a/imgui-gfx-examples/examples/gfx_hello_world.rs b/imgui-gfx-examples/examples/gfx_hello_world.rs index 42a6b75..6c96b76 100644 --- a/imgui-gfx-examples/examples/gfx_hello_world.rs +++ b/imgui-gfx-examples/examples/gfx_hello_world.rs @@ -6,18 +6,18 @@ fn main() { let system = support::init(file!()); let window_title = if cfg!(all(feature = "directx", windows)) { - im_str!("Hello world (OpenGL)") + "Hello world (OpenGL)" } else { - im_str!("Hello world (DirectX)") + "Hello world (DirectX)" }; system.main_loop(|_, ui| { Window::new(window_title) .size([300.0, 100.0], Condition::FirstUseEver) .build(ui, || { - ui.text(im_str!("Hello world!")); - ui.text(im_str!("こんにちは世界!")); - ui.text(im_str!("This...is...imgui-rs!")); + ui.text("Hello world!"); + ui.text("こんにちは世界!"); + ui.text("This...is...imgui-rs!"); ui.separator(); let mouse_pos = ui.io().mouse_pos; ui.text(format!( diff --git a/imgui-glow-renderer/examples/04_custom_textures.rs b/imgui-glow-renderer/examples/04_custom_textures.rs index 2741203..efca79c 100644 --- a/imgui-glow-renderer/examples/04_custom_textures.rs +++ b/imgui-glow-renderer/examples/04_custom_textures.rs @@ -9,7 +9,7 @@ use std::{io::Cursor, time::Instant}; use glow::HasContext; use image::{jpeg::JpegDecoder, ImageDecoder}; -use imgui::{im_str, Condition}; +use imgui::Condition; use imgui_glow_renderer::Renderer; @@ -144,10 +144,10 @@ impl TexturesUi { } fn show(&self, ui: &imgui::Ui) { - imgui::Window::new(im_str!("Hello textures")) + imgui::Window::new("Hello textures") .size([400.0, 400.0], Condition::FirstUseEver) .build(ui, || { - ui.text(im_str!("Hello textures!")); + ui.text("Hello textures!"); ui.text("Some generated texture"); imgui::Image::new(self.generated_texture, [100.0, 100.0]).build(ui); @@ -157,7 +157,7 @@ impl TexturesUi { // Example of using custom textures on a button ui.text("The Lenna buttons"); { - ui.invisible_button(im_str!("Boring Button"), [100.0, 100.0]); + ui.invisible_button("Boring Button", [100.0, 100.0]); // See also `imgui::Ui::style_color` let tint_none = [1.0, 1.0, 1.0, 1.0]; let tint_green = [0.5, 1.0, 0.5, 1.0]; @@ -187,7 +187,7 @@ impl TexturesUi { ui.same_line(); // Button using quad positioned image - ui.invisible_button(im_str!("Exciting Button"), [100.0, 100.0]); + ui.invisible_button("Exciting Button", [100.0, 100.0]); // Button bounds let min = ui.item_rect_min(); @@ -214,7 +214,7 @@ impl TexturesUi { // Rounded image { ui.same_line(); - ui.invisible_button(im_str!("Smooth Button"), [100.0, 100.0]); + ui.invisible_button("Smooth Button", [100.0, 100.0]); let draw_list = ui.get_window_draw_list(); draw_list diff --git a/imgui/src/widget/menu.rs b/imgui/src/widget/menu.rs index 76a428a..81a417c 100644 --- a/imgui/src/widget/menu.rs +++ b/imgui/src/widget/menu.rs @@ -112,16 +112,16 @@ impl<'ui> Ui<'ui> { /// Builder for a menu item. #[derive(Copy, Clone, Debug)] #[must_use] -pub struct MenuItem<'a, T> { - label: T, - shortcut: Option<&'a str>, +pub struct MenuItem { + label: Label, + shortcut: Option, selected: bool, enabled: bool, } -impl<'a, T: 'a + AsRef> MenuItem<'a, T> { +impl> MenuItem