From 3a550208c9db633591376c2e8f5095a8c0549ee1 Mon Sep 17 00:00:00 2001 From: Joonas Javanainen Date: Sun, 23 Aug 2015 09:41:03 +0300 Subject: [PATCH] Frame -> Ui --- README.markdown | 16 +-- examples/hello_world.rs | 14 +-- examples/support/mod.rs | 10 +- examples/test_window.rs | 218 ++++++++++++++++++++-------------------- src/glium_renderer.rs | 6 +- src/lib.rs | 34 +++---- src/menus.rs | 14 +-- src/sliders.rs | 14 +-- src/widgets.rs | 8 +- src/window.rs | 10 +- 10 files changed, 172 insertions(+), 172 deletions(-) diff --git a/README.markdown b/README.markdown index 68eb210..7b4baec 100644 --- a/README.markdown +++ b/README.markdown @@ -5,15 +5,15 @@ ![Hello world](hello_world.png) ```rust -frame.window() +ui.window() .name(im_str!("Hello world")) .size((300.0, 100.0), ImGuiSetCond_FirstUseEver) .build(|| { - frame.text(im_str!("Hello world!")); - frame.text(im_str!("This...is...imgui-rs!")); - frame.separator(); - let mouse_pos = frame.imgui().mouse_pos(); - frame.text(im_str!("Mouse Position: ({:.1},{:.1})", mouse_pos.0, mouse_pos.1)); + ui.text(im_str!("Hello world!")); + ui.text(im_str!("This...is...imgui-rs!")); + ui.separator(); + let mouse_pos = ui.imgui().mouse_pos(); + ui.text(im_str!("Mouse Position: ({:.1},{:.1})", mouse_pos.0, mouse_pos.1)); }) ``` @@ -34,8 +34,8 @@ frame.window() * Closures VS begin/end pairs (current choice: closures) * Mutable references VS return values (current choice: mutable references) -* Passing around Frame<'fr> VS passing around &'fr Frame (current choice: Frame<'fr>) -* Splitting the API to smaller pieces VS all draw calls in Frame (current choice: all draw calls in Frame) +* Passing around Ui<'ui> VS passing around &'ui Ui (current choice: Ui<'ui>) +* Splitting the API to smaller pieces VS all draw calls in Ui (current choice: all draw calls in Ui) * Builder pattern for optional arguments VS something else (current choice: builder) * Mutation functions in builders VS self-consuming functions in builders (current choice: self-consuming) diff --git a/examples/hello_world.rs b/examples/hello_world.rs index 7931959..6d4dd23 100644 --- a/examples/hello_world.rs +++ b/examples/hello_world.rs @@ -23,15 +23,15 @@ fn main() { } } -fn hello_world<'a>(frame: &Frame<'a>) { - frame.window() +fn hello_world<'a>(ui: &Ui<'a>) { + ui.window() .name(im_str!("Hello world")) .size((300.0, 100.0), ImGuiSetCond_FirstUseEver) .build(|| { - frame.text(im_str!("Hello world!")); - frame.text(im_str!("This...is...imgui-rs!")); - frame.separator(); - let mouse_pos = frame.imgui().mouse_pos(); - frame.text(im_str!("Mouse Position: ({:.1},{:.1})", mouse_pos.0, mouse_pos.1)); + ui.text(im_str!("Hello world!")); + ui.text(im_str!("This...is...imgui-rs!")); + ui.separator(); + let mouse_pos = ui.imgui().mouse_pos(); + ui.text(im_str!("Mouse Position: ({:.1},{:.1})", mouse_pos.0, mouse_pos.1)); }) } diff --git a/examples/support/mod.rs b/examples/support/mod.rs index ef2d552..fd64a5f 100644 --- a/examples/support/mod.rs +++ b/examples/support/mod.rs @@ -2,7 +2,7 @@ use glium::{DisplayBuild, Surface}; use glium::backend::glutin_backend::GlutinFacade; use glium::glutin; use glium::glutin::{ElementState, Event, MouseButton, VirtualKeyCode}; -use imgui::{ImGui, Frame}; +use imgui::{ImGui, Ui}; use imgui::glium_renderer::Renderer; use time::SteadyTime; @@ -39,7 +39,7 @@ impl Support { self.imgui.set_mouse_down(&[self.mouse_pressed.0, self.mouse_pressed.1, self.mouse_pressed.2, false, false]); } - pub fn render<'fr, 'a: 'fr , F: FnMut(&Frame<'fr>)>( + pub fn render<'ui, 'a: 'ui , F: FnMut(&Ui<'ui>)>( &'a mut self, clear_color: (f32, f32, f32, f32), mut f: F) -> bool { let now = SteadyTime::now(); let delta = now - self.last_frame; @@ -53,9 +53,9 @@ impl Support { clear_color.2, clear_color.3); let (width, height) = target.get_dimensions(); - let frame = self.imgui.frame(width, height, delta_f); - f(&frame); - self.renderer.render(&mut target, frame).unwrap(); + let ui = self.imgui.frame(width, height, delta_f); + f(&ui); + self.renderer.render(&mut target, ui).unwrap(); target.finish().unwrap(); diff --git a/examples/test_window.rs b/examples/test_window.rs index 3cc6e7c..c053083 100644 --- a/examples/test_window.rs +++ b/examples/test_window.rs @@ -94,21 +94,21 @@ fn main() { let mut opened = true; loop { - let active = support.render(state.clear_color, |frame| { - show_test_window(frame, &mut state, &mut opened); + let active = support.render(state.clear_color, |ui| { + show_test_window(ui, &mut state, &mut opened); }); if !active || !opened { break } } } -fn show_user_guide<'a>(frame: &Frame<'a>) { - frame.bullet_text(im_str!("Double-click on title bar to collapse window.")); - frame.bullet_text(im_str!("Click and drag on lower right corner to resize window.")); - frame.bullet_text(im_str!("Click and drag on any empty space to move window.")); - frame.bullet_text(im_str!("Mouse Wheel to scroll.")); - frame.bullet_text(im_str!("TAB/SHIFT+TAB to cycle through keyboard editable fields.")); - frame.bullet_text(im_str!("CTRL+Click on a slider or drag box to input text.")); - frame.bullet_text(im_str!( +fn show_user_guide<'a>(ui: &Ui<'a>) { + 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(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!( "While editing text: - Hold SHIFT or use mouse to select text - CTRL+Left/Right to word jump @@ -120,35 +120,35 @@ fn show_user_guide<'a>(frame: &Frame<'a>) { Use +- to subtract.")); } -fn show_test_window<'a>(frame: &Frame<'a>, state: &mut State, opened: &mut bool) { +fn show_test_window<'a>(ui: &Ui<'a>, state: &mut State, opened: &mut bool) { if state.show_app_metrics { - frame.show_metrics_window(&mut state.show_app_metrics); + ui.show_metrics_window(&mut state.show_app_metrics); } - if state.show_app_main_menu_bar { show_example_app_main_menu_bar(frame, state) } + if state.show_app_main_menu_bar { show_example_app_main_menu_bar(ui, state) } if state.show_app_auto_resize { - show_example_app_auto_resize(frame, &mut state.auto_resize_state, &mut state.show_app_auto_resize); + show_example_app_auto_resize(ui, &mut state.auto_resize_state, &mut state.show_app_auto_resize); } if state.show_app_fixed_overlay { - show_example_app_fixed_overlay(frame, &mut state.show_app_fixed_overlay); + show_example_app_fixed_overlay(ui, &mut state.show_app_fixed_overlay); } if state.show_app_manipulating_window_title { - show_example_app_manipulating_window_title(frame); + show_example_app_manipulating_window_title(ui); } if state.show_app_about { - frame.window() + ui.window() .name(im_str!("About ImGui")) .always_auto_resize(true) .opened(&mut state.show_app_about) .build(|| { - frame.text(ImStr::from_str(&format!("ImGui {}", imgui::get_version()))); - frame.separator(); - frame.text(im_str!("By Omar Cornut and all github contributors.")); - frame.text(im_str!("ImGui is licensed under the MIT License, see LICENSE for more information.")); - show_user_guide(frame); + ui.text(ImStr::from_str(&format!("ImGui {}", imgui::get_version()))); + ui.separator(); + ui.text(im_str!("By Omar Cornut and all github contributors.")); + ui.text(im_str!("ImGui is licensed under the MIT License, see LICENSE for more information.")); + show_user_guide(ui); }) } - frame.window().name(im_str!("ImGui Demo")) + ui.window().name(im_str!("ImGui Demo")) .title_bar(!state.no_titlebar) .show_borders(!state.no_border) .resizable(!state.no_resize) @@ -160,128 +160,128 @@ fn show_test_window<'a>(frame: &Frame<'a>, state: &mut State, opened: &mut bool) .size((550.0, 680.0), ImGuiSetCond_FirstUseEver) .opened(opened) .build(|| { - frame.text(im_str!("ImGui says hello.")); - frame.menu_bar(|| { - frame.menu(im_str!("Menu")).build(|| { - show_example_menu_file(frame, &mut state.file_menu); + ui.text(im_str!("ImGui says hello.")); + ui.menu_bar(|| { + ui.menu(im_str!("Menu")).build(|| { + show_example_menu_file(ui, &mut state.file_menu); }); - frame.menu(im_str!("Examples")).build(|| { - frame.menu_item(im_str!("Main menu bar")) + ui.menu(im_str!("Examples")).build(|| { + ui.menu_item(im_str!("Main menu bar")) .selected(&mut state.show_app_main_menu_bar).build(); - frame.menu_item(im_str!("Console")) + ui.menu_item(im_str!("Console")) .selected(&mut state.show_app_console).build(); - frame.menu_item(im_str!("Simple layout")) + ui.menu_item(im_str!("Simple layout")) .selected(&mut state.show_app_layout).build(); - frame.menu_item(im_str!("Long text display")) + ui.menu_item(im_str!("Long text display")) .selected(&mut state.show_app_long_text).build(); - frame.menu_item(im_str!("Auto-resizing window")) + ui.menu_item(im_str!("Auto-resizing window")) .selected(&mut state.show_app_auto_resize).build(); - frame.menu_item(im_str!("Simple overlay")) + ui.menu_item(im_str!("Simple overlay")) .selected(&mut state.show_app_fixed_overlay).build(); - frame.menu_item(im_str!("Manipulating window title")) + ui.menu_item(im_str!("Manipulating window title")) .selected(&mut state.show_app_manipulating_window_title).build(); - frame.menu_item(im_str!("Custom rendering")) + ui.menu_item(im_str!("Custom rendering")) .selected(&mut state.show_app_custom_rendering).build(); }); - frame.menu(im_str!("Help")).build(|| { - frame.menu_item(im_str!("Metrics")) + ui.menu(im_str!("Help")).build(|| { + ui.menu_item(im_str!("Metrics")) .selected(&mut state.show_app_metrics).build(); - frame.menu_item(im_str!("About ImGui")) + ui.menu_item(im_str!("About ImGui")) .selected(&mut state.show_app_about).build(); }); }); - frame.spacing(); - if frame.collapsing_header(im_str!("Help")).build() { - frame.text_wrapped(im_str!("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(frame); + ui.spacing(); + if ui.collapsing_header(im_str!("Help")).build() { + ui.text_wrapped(im_str!("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 frame.collapsing_header(im_str!("Window options")).build() { - frame.checkbox(im_str!("no titlebar"), &mut state.no_titlebar); - frame.same_line(150.0); - frame.checkbox(im_str!("no border"), &mut state.no_border); - frame.same_line(300.0); - frame.checkbox(im_str!("no resize"), &mut state.no_resize); - frame.checkbox(im_str!("no move"), &mut state.no_move); - frame.same_line(150.0); - frame.checkbox(im_str!("no scrollbar"), &mut state.no_scrollbar); - frame.same_line(300.0); - frame.checkbox(im_str!("no collapse"), &mut state.no_collapse); - frame.checkbox(im_str!("no menu"), &mut state.no_menu); - frame.slider_f32(im_str!("bg alpha"), &mut state.bg_alpha, 0.0, 1.0).build(); + if ui.collapsing_header(im_str!("Window options")).build() { + ui.checkbox(im_str!("no titlebar"), &mut state.no_titlebar); + ui.same_line(150.0); + ui.checkbox(im_str!("no border"), &mut state.no_border); + ui.same_line(300.0); + ui.checkbox(im_str!("no resize"), &mut state.no_resize); + ui.checkbox(im_str!("no move"), &mut state.no_move); + ui.same_line(150.0); + ui.checkbox(im_str!("no scrollbar"), &mut state.no_scrollbar); + ui.same_line(300.0); + ui.checkbox(im_str!("no collapse"), &mut state.no_collapse); + ui.checkbox(im_str!("no menu"), &mut state.no_menu); + ui.slider_f32(im_str!("bg alpha"), &mut state.bg_alpha, 0.0, 1.0).build(); } }) } -fn show_example_app_main_menu_bar<'a>(frame: &Frame<'a>, state: &mut State) { - frame.main_menu_bar(|| { - frame.menu(im_str!("File")).build(|| { - show_example_menu_file(frame, &mut state.file_menu); +fn show_example_app_main_menu_bar<'a>(ui: &Ui<'a>, state: &mut State) { + ui.main_menu_bar(|| { + ui.menu(im_str!("File")).build(|| { + show_example_menu_file(ui, &mut state.file_menu); }); - frame.menu(im_str!("Edit")).build(|| { - frame.menu_item(im_str!("Undo")).shortcut(im_str!("CTRL+Z")).build(); - frame.menu_item(im_str!("Redo")) + ui.menu(im_str!("Edit")).build(|| { + ui.menu_item(im_str!("Undo")).shortcut(im_str!("CTRL+Z")).build(); + ui.menu_item(im_str!("Redo")) .shortcut(im_str!("CTRL+Y")).enabled(false).build(); - frame.separator(); - frame.menu_item(im_str!("Cut")).shortcut(im_str!("CTRL+X")).build(); - frame.menu_item(im_str!("Copy")).shortcut(im_str!("CTRL+C")).build(); - frame.menu_item(im_str!("Paste")).shortcut(im_str!("CTRL+V")).build(); + ui.separator(); + ui.menu_item(im_str!("Cut")).shortcut(im_str!("CTRL+X")).build(); + ui.menu_item(im_str!("Copy")).shortcut(im_str!("CTRL+C")).build(); + ui.menu_item(im_str!("Paste")).shortcut(im_str!("CTRL+V")).build(); }); }); } -fn show_example_menu_file<'a>(frame: &Frame<'a>, state: &mut FileMenuState) { - frame.menu_item(im_str!("(dummy menu)")).enabled(false).build(); - frame.menu_item(im_str!("New")).build(); - frame.menu_item(im_str!("Open")).shortcut(im_str!("Ctrl+O")).build(); - frame.menu(im_str!("Open Recent")).build(|| { - frame.menu_item(im_str!("fish_hat.c")).build(); - frame.menu_item(im_str!("fish_hat.inl")).build(); - frame.menu_item(im_str!("fish_hat.h")).build(); - frame.menu(im_str!("More..")).build(|| { - frame.menu_item(im_str!("Hello")); - frame.menu_item(im_str!("Sailor")); - frame.menu(im_str!("Recurse..")).build(|| { - show_example_menu_file(frame, state); +fn show_example_menu_file<'a>(ui: &Ui<'a>, state: &mut FileMenuState) { + ui.menu_item(im_str!("(dummy menu)")).enabled(false).build(); + ui.menu_item(im_str!("New")).build(); + ui.menu_item(im_str!("Open")).shortcut(im_str!("Ctrl+O")).build(); + ui.menu(im_str!("Open Recent")).build(|| { + ui.menu_item(im_str!("fish_hat.c")).build(); + ui.menu_item(im_str!("fish_hat.inl")).build(); + ui.menu_item(im_str!("fish_hat.h")).build(); + ui.menu(im_str!("More..")).build(|| { + ui.menu_item(im_str!("Hello")); + ui.menu_item(im_str!("Sailor")); + ui.menu(im_str!("Recurse..")).build(|| { + show_example_menu_file(ui, state); }); }); }); - frame.menu_item(im_str!("Save")).shortcut(im_str!("Ctrl+S")).build(); - frame.menu_item(im_str!("Save As..")).build(); - frame.separator(); - frame.menu(im_str!("Options")).build(|| { - frame.menu_item(im_str!("Enabled")).selected(&mut state.enabled).build(); + ui.menu_item(im_str!("Save")).shortcut(im_str!("Ctrl+S")).build(); + ui.menu_item(im_str!("Save As..")).build(); + ui.separator(); + ui.menu(im_str!("Options")).build(|| { + ui.menu_item(im_str!("Enabled")).selected(&mut state.enabled).build(); // TODO }); - frame.menu(im_str!("Colors")).build(|| { + ui.menu(im_str!("Colors")).build(|| { // TODO }); - frame.menu(im_str!("Disabled")).enabled(false).build(|| { + ui.menu(im_str!("Disabled")).enabled(false).build(|| { unreachable!(); }); let mut checked = true; - frame.menu_item(im_str!("Checked")).selected(&mut checked).build(); - frame.menu_item(im_str!("Quit")).shortcut(im_str!("Alt+F4")).build(); + ui.menu_item(im_str!("Checked")).selected(&mut checked).build(); + ui.menu_item(im_str!("Quit")).shortcut(im_str!("Alt+F4")).build(); } -fn show_example_app_auto_resize<'a>(frame: &Frame<'a>, state: &mut AutoResizeState, opened: &mut bool) { - frame.window() +fn show_example_app_auto_resize<'a>(ui: &Ui<'a>, state: &mut AutoResizeState, opened: &mut bool) { + ui.window() .name(im_str!("Example: Auto-resizing window")) .opened(opened) .always_auto_resize(true) .build(|| { - frame.text(im_str!("Window will resize every-frame to the size of its content. + ui.text(im_str!("Window will resize every-ui to the size of its content. Note that you probably don't want to query the window size to output your content because that would create a feedback loop.")); - frame.slider_i32(im_str!("Number of lines"), &mut state.lines, 1, 20).build(); + ui.slider_i32(im_str!("Number of lines"), &mut state.lines, 1, 20).build(); for i in 0 .. state.lines { - frame.text(im_str!("{:2$}This is line {}", "", i, i as usize * 4)); + ui.text(im_str!("{:2$}This is line {}", "", i, i as usize * 4)); } }) } -fn show_example_app_fixed_overlay<'a>(frame: &Frame<'a>, opened: &mut bool) { - frame.window() +fn show_example_app_fixed_overlay<'a>(ui: &Ui<'a>, opened: &mut bool) { + ui.window() .name(im_str!("Example: Fixed Overlay")) .opened(opened) .bg_alpha(0.3) @@ -290,36 +290,36 @@ fn show_example_app_fixed_overlay<'a>(frame: &Frame<'a>, opened: &mut bool) { .movable(false) .save_settings(false) .build(|| { - frame.text(im_str!("Simple overlay\non the top-left side of the screen.")); - frame.separator(); - let mouse_pos = frame.imgui().mouse_pos(); - frame.text(im_str!("Mouse Position: ({:.1},{:.1})", mouse_pos.0, mouse_pos.1)); + ui.text(im_str!("Simple overlay\non the top-left side of the screen.")); + ui.separator(); + let mouse_pos = ui.imgui().mouse_pos(); + ui.text(im_str!("Mouse Position: ({:.1},{:.1})", mouse_pos.0, mouse_pos.1)); }) } -fn show_example_app_manipulating_window_title<'a>(frame: &Frame<'a>) { - frame.window() +fn show_example_app_manipulating_window_title<'a>(ui: &Ui<'a>) { + ui.window() .name(im_str!("Same title as another window##1")) .position((100.0, 100.0), ImGuiSetCond_FirstUseEver) .build(|| { - frame.text(im_str!("This is window 1. + ui.text(im_str!("This is window 1. My title is the same as window 2, but my identifier is unique.")); }); - frame.window() + ui.window() .name(im_str!("Same title as another window##2")) .position((100.0, 200.0), ImGuiSetCond_FirstUseEver) .build(|| { - frame.text(im_str!("This is window 2. + ui.text(im_str!("This is window 2. My title is the same as window 1, but my identifier is unique.")); }); let chars = ['|', '/', '-', '\\']; - let ch_idx = (frame.imgui().get_time() / 0.25) as usize & 3; - let num = frame.imgui().get_frame_count(); // The C++ version uses rand() here + let ch_idx = (ui.imgui().get_time() / 0.25) as usize & 3; + let num = ui.imgui().get_frame_count(); // The C++ version uses rand() here let title = im_str!("Animated title {} {}###AnimatedTitle", chars[ch_idx], num); - frame.window() + ui.window() .name(title) .position((100.0, 300.0), ImGuiSetCond_FirstUseEver) .build(|| { - frame.text(im_str!("This window has a changing title")); + ui.text(im_str!("This window has a changing title")); }); } diff --git a/src/glium_renderer.rs b/src/glium_renderer.rs index 5c07bb0..d58c7c5 100644 --- a/src/glium_renderer.rs +++ b/src/glium_renderer.rs @@ -13,7 +13,7 @@ use std::fmt; use std::mem; use std::rc::Rc; -use super::{DrawList, Frame, ImDrawIdx, ImDrawVert, ImGui, ImVec2, ImVec4}; +use super::{DrawList, Ui, ImDrawIdx, ImDrawVert, ImGui, ImVec2, ImVec4}; pub type RendererResult = Result; @@ -106,8 +106,8 @@ impl Renderer { }) } pub fn render<'a, S: Surface>(&mut self, surface: &mut S, - frame: Frame<'a>) -> RendererResult<()> { - frame.render(|draw_list| self.render_draw_list(surface, draw_list)) + ui: Ui<'a>) -> RendererResult<()> { + ui.render(|draw_list| self.render_draw_list(surface, draw_list)) } fn render_draw_list<'a, S: Surface>(&mut self, surface: &mut S, draw_list: DrawList<'a>) -> RendererResult<()> { diff --git a/src/lib.rs b/src/lib.rs index 2f89f6a..7cffba4 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -139,7 +139,7 @@ impl ImGui { } pub fn get_time(&self) -> f32 { unsafe { ffi::igGetTime() } } pub fn get_frame_count(&self) -> i32 { unsafe { ffi::igGetFrameCount() } } - pub fn frame<'fr, 'a: 'fr>(&'a mut self, width: u32, height: u32, delta_time: f32) -> Frame<'fr> { + pub fn frame<'ui, 'a: 'ui>(&'a mut self, width: u32, height: u32, delta_time: f32) -> Ui<'ui> { unsafe { let io: &mut ffi::ImGuiIO = mem::transmute(ffi::igGetIO()); io.display_size.x = width as c_float; @@ -148,7 +148,7 @@ impl ImGui { ffi::igNewFrame(); } - Frame { + Ui { imgui: self } } @@ -185,18 +185,18 @@ pub struct DrawList<'a> { pub vtx_buffer: &'a [ffi::ImDrawVert] } -pub struct Frame<'fr> { - imgui: &'fr ImGui +pub struct Ui<'ui> { + imgui: &'ui ImGui } static FMT: &'static [u8] = b"%s\0"; fn fmt_ptr() -> *const c_char { FMT.as_ptr() as *const c_char } -impl<'fr> Frame<'fr> { +impl<'ui> Ui<'ui> { pub fn imgui(&self) -> &ImGui { self.imgui } pub fn render(self, mut f: F) -> Result<(), E> - where F: FnMut(DrawList<'fr>) -> Result<(), E> { + where F: FnMut(DrawList<'ui>) -> Result<(), E> { unsafe { let mut im_draw_data = mem::zeroed(); RENDER_DRAW_LISTS_STATE.0 = &mut im_draw_data; @@ -229,12 +229,12 @@ impl<'fr> Frame<'fr> { } // Window -impl<'fr> Frame<'fr> { - pub fn window<'p>(&self) -> Window<'fr, 'p> { Window::new() } +impl<'ui> Ui<'ui> { + pub fn window<'p>(&self) -> Window<'ui, 'p> { Window::new() } } // Layout -impl<'fr> Frame<'fr> { +impl<'ui> Ui<'ui> { pub fn separator(&self) { unsafe { ffi::igSeparator() }; } pub fn same_line(&self, pos_x: f32) { unsafe { @@ -250,7 +250,7 @@ impl<'fr> Frame<'fr> { } // Widgets -impl<'fr> Frame<'fr> { +impl<'ui> Ui<'ui> { pub fn text<'b>(&self, text: ImStr<'b>) { // TODO: use igTextUnformatted unsafe { @@ -287,7 +287,7 @@ impl<'fr> Frame<'fr> { ffi::igBulletText(fmt_ptr(), text.as_ptr()); } } - pub fn collapsing_header<'p>(&self, label: ImStr<'p>) -> CollapsingHeader<'fr, 'p> { + pub fn collapsing_header<'p>(&self, label: ImStr<'p>) -> CollapsingHeader<'ui, 'p> { CollapsingHeader::new(label) } pub fn checkbox<'p>(&self, label: ImStr<'p>, value: &'p mut bool) -> bool { @@ -296,19 +296,19 @@ impl<'fr> Frame<'fr> { } // Widgets: Sliders -impl<'fr> Frame<'fr> { +impl<'ui> Ui<'ui> { pub fn slider_f32<'p>(&self, label: ImStr<'p>, - value: &'p mut f32, min: f32, max: f32) -> SliderFloat<'fr, 'p> { + value: &'p mut f32, min: f32, max: f32) -> SliderFloat<'ui, 'p> { SliderFloat::new(label, value, min, max) } pub fn slider_i32<'p>(&self, label: ImStr<'p>, - value: &'p mut i32, min: i32, max: i32) -> SliderInt<'fr, 'p> { + value: &'p mut i32, min: i32, max: i32) -> SliderInt<'ui, 'p> { SliderInt::new(label, value, min, max) } } // Widgets: Menus -impl<'fr> Frame<'fr> { +impl<'ui> Ui<'ui> { pub fn main_menu_bar(&self, f: F) where F: FnOnce() { let render = unsafe { ffi::igBeginMainMenuBar() }; if render { @@ -323,8 +323,8 @@ impl<'fr> Frame<'fr> { unsafe { ffi::igEndMenuBar() }; } } - pub fn menu<'p>(&self, label: ImStr<'p>) -> Menu<'fr, 'p> { Menu::new(label) } - pub fn menu_item<'p>(&self, label: ImStr<'p>) -> MenuItem<'fr, 'p> { MenuItem::new(label) } + pub fn menu<'p>(&self, label: ImStr<'p>) -> Menu<'ui, 'p> { Menu::new(label) } + pub fn menu_item<'p>(&self, label: ImStr<'p>) -> MenuItem<'ui, 'p> { MenuItem::new(label) } } struct RenderDrawListsState(*mut ffi::ImDrawData); diff --git a/src/menus.rs b/src/menus.rs index 56f8398..ce13837 100644 --- a/src/menus.rs +++ b/src/menus.rs @@ -2,15 +2,15 @@ use std::marker::PhantomData; use std::ptr; use super::ffi; -use super::{Frame, ImStr}; +use super::{Ui, ImStr}; -pub struct Menu<'fr, 'p> { +pub struct Menu<'ui, 'p> { label: ImStr<'p>, enabled: bool, - _phantom: PhantomData<&'fr Frame<'fr>> + _phantom: PhantomData<&'ui Ui<'ui>> } -impl<'fr, 'p> Menu<'fr, 'p> { +impl<'ui, 'p> Menu<'ui, 'p> { pub fn new(label: ImStr<'p>) -> Self { Menu { label: label, @@ -34,15 +34,15 @@ impl<'fr, 'p> Menu<'fr, 'p> { } } -pub struct MenuItem<'fr, 'p> { +pub struct MenuItem<'ui, 'p> { label: ImStr<'p>, shortcut: Option>, selected: Option<&'p mut bool>, enabled: bool, - _phantom: PhantomData<&'fr Frame<'fr>> + _phantom: PhantomData<&'ui Ui<'ui>> } -impl<'fr, 'p> MenuItem<'fr, 'p> { +impl<'ui, 'p> MenuItem<'ui, 'p> { pub fn new(label: ImStr<'p>) -> Self { MenuItem { label: label, diff --git a/src/sliders.rs b/src/sliders.rs index 34ba152..039109e 100644 --- a/src/sliders.rs +++ b/src/sliders.rs @@ -1,20 +1,20 @@ use std::marker::PhantomData; use super::ffi; -use super::{Frame, ImStr}; +use super::{Ui, ImStr}; // TODO: Consider using Range, even though it is half-open -pub struct SliderInt<'fr, 'p> { +pub struct SliderInt<'ui, 'p> { label: ImStr<'p>, value: &'p mut i32, min: i32, max: i32, display_format: ImStr<'p>, - _phantom: PhantomData<&'fr Frame<'fr>> + _phantom: PhantomData<&'ui Ui<'ui>> } -impl<'fr, 'p> SliderInt<'fr, 'p> { +impl<'ui, 'p> SliderInt<'ui, 'p> { pub fn new(label: ImStr<'p>, value: &'p mut i32, min: i32, max: i32) -> Self { SliderInt { label: label, @@ -41,17 +41,17 @@ impl<'fr, 'p> SliderInt<'fr, 'p> { } } -pub struct SliderFloat<'fr, 'p> { +pub struct SliderFloat<'ui, 'p> { label: ImStr<'p>, value: &'p mut f32, min: f32, max: f32, display_format: ImStr<'p>, power: f32, - _phantom: PhantomData<&'fr Frame<'fr>> + _phantom: PhantomData<&'ui Ui<'ui>> } -impl<'fr, 'p> SliderFloat<'fr, 'p> { +impl<'ui, 'p> SliderFloat<'ui, 'p> { pub fn new(label: ImStr<'p>, value: &'p mut f32, min: f32, max: f32) -> Self { SliderFloat { label: label, diff --git a/src/widgets.rs b/src/widgets.rs index c8741fd..8208d7e 100644 --- a/src/widgets.rs +++ b/src/widgets.rs @@ -2,17 +2,17 @@ use std::marker::PhantomData; use std::ptr; use super::ffi; -use super::{Frame, ImStr}; +use super::{Ui, ImStr}; -pub struct CollapsingHeader<'fr, 'p> { +pub struct CollapsingHeader<'ui, 'p> { label: ImStr<'p>, str_id: Option>, display_frame: bool, default_open: bool, - _phantom: PhantomData<&'fr Frame<'fr>> + _phantom: PhantomData<&'ui Ui<'ui>> } -impl<'fr, 'p> CollapsingHeader<'fr, 'p> { +impl<'ui, 'p> CollapsingHeader<'ui, 'p> { pub fn new(label: ImStr<'p>) -> Self { CollapsingHeader { label: label, diff --git a/src/window.rs b/src/window.rs index e568445..dc275c4 100644 --- a/src/window.rs +++ b/src/window.rs @@ -3,7 +3,7 @@ use std::ptr; use super::ffi; use super::{ - Frame, + Ui, ImGuiSetCond, ImGuiWindowFlags, ImGuiWindowFlags_NoTitleBar, ImGuiWindowFlags_NoResize, ImGuiWindowFlags_NoMove, @@ -13,7 +13,7 @@ use super::{ ImStr, ImVec2 }; -pub struct Window<'fr, 'p> { +pub struct Window<'ui, 'p> { pos: (f32, f32), pos_cond: ImGuiSetCond, size: (f32, f32), @@ -22,11 +22,11 @@ pub struct Window<'fr, 'p> { opened: Option<&'p mut bool>, bg_alpha: f32, flags: ImGuiWindowFlags, - _phantom: PhantomData<&'fr Frame<'fr>> + _phantom: PhantomData<&'ui Ui<'ui>> } -impl<'fr, 'p> Window<'fr, 'p> { - pub fn new() -> Window<'fr, 'p> { +impl<'ui, 'p> Window<'ui, 'p> { + pub fn new() -> Window<'ui, 'p> { Window { pos: (0.0, 0.0), pos_cond: ImGuiSetCond::empty(),