From 1c13208c223abc15dc4d4db26d34cba8b4298f86 Mon Sep 17 00:00:00 2001 From: Cameron Hart Date: Thu, 14 Jan 2016 00:18:23 +1100 Subject: [PATCH 01/13] Added input for single int. --- examples/test_window_impl.rs | 12 ++ src/input.rs | 281 +++++++++++++++++++++-------------- src/lib.rs | 5 +- 3 files changed, 186 insertions(+), 112 deletions(-) diff --git a/examples/test_window_impl.rs b/examples/test_window_impl.rs index 1856363..a4b83d2 100644 --- a/examples/test_window_impl.rs +++ b/examples/test_window_impl.rs @@ -33,6 +33,8 @@ struct State { bg_alpha: f32, wrap_width: f32, buf: String, + text: String, + int: i32, auto_resize_state: AutoResizeState, file_menu: FileMenuState } @@ -42,6 +44,10 @@ impl Default for State { let mut buf = "日本語".to_owned(); buf.extend(repeat('\0').take(32)); buf.truncate(32); + let mut text = String::with_capacity(128); + text.push_str("Hello, world!"); + let remaining = text.capacity() - text.len(); + text.extend(repeat('\0').take(remaining)); State { clear_color: (114.0 / 255.0, 144.0 / 255.0, 154.0 / 255.0, 1.0), show_app_metrics: false, @@ -64,6 +70,8 @@ impl Default for State { bg_alpha: 0.65, wrap_width: 200.0, buf: buf, + text: text, + int: 123, auto_resize_state: Default::default(), file_menu: Default::default() } @@ -281,6 +289,10 @@ fn show_test_window<'a>(ui: &Ui<'a>, state: &mut State, opened: &mut bool) { ui.text(im_str!("Kanjis: 日本語 (nihongo)")); ui.input_text(im_str!("UTF-8 input"), &mut state.buf).build(); }); + ui.separator(); + ui.label_text(im_str!("label"), im_str!("Value")); + ui.input_text(im_str!("input text"), &mut state.text).build(); + ui.input_int(im_str!("input int"), &mut state.int).build(); } }) } diff --git a/src/input.rs b/src/input.rs index 3948e54..aeb85fc 100644 --- a/src/input.rs +++ b/src/input.rs @@ -15,6 +15,123 @@ use super::{ ImStr }; +macro_rules! impl_text_flags { + ($T:ident) => { + #[inline] + pub fn flags(self, flags: ImGuiInputTextFlags) -> Self { + $T { + flags: flags, + .. self + } + } + + #[inline] + pub fn chars_decimal(self, value: bool) -> Self { + $T { + flags: self.flags.with(ImGuiInputTextFlags_CharsDecimal, value), + .. self + } + } + + #[inline] + pub fn chars_hexadecimal(self, value: bool) -> Self { + $T { + flags: self.flags.with(ImGuiInputTextFlags_CharsHexadecimal, value), + .. self + } + } + + #[inline] + pub fn chars_uppercase(self, value: bool) -> Self { + $T { + flags: self.flags.with(ImGuiInputTextFlags_CharsUppercase, value), + .. self + } + } + + #[inline] + pub fn chars_noblank(self, value: bool) -> Self { + $T { + flags: self.flags.with(ImGuiInputTextFlags_CharsNoBlank, value), + .. self + } + } + + #[inline] + pub fn auto_select_all(self, value: bool) -> Self { + $T { + flags: self.flags.with(ImGuiInputTextFlags_AutoSelectAll, value), + .. self + } + } + + #[inline] + pub fn enter_returns_true(self, value: bool) -> Self { + $T { + flags: self.flags.with(ImGuiInputTextFlags_EnterReturnsTrue, value), + .. self + } + } + + #[inline] + pub fn callback_completion(self, value: bool) -> Self { + $T { + flags: self.flags.with(ImGuiInputTextFlags_CallbackCompletion, value), + .. self + } + } + + #[inline] + pub fn callback_history(self, value: bool) -> Self { + $T { + flags: self.flags.with(ImGuiInputTextFlags_CallbackHistory, value), + .. self + } + } + + #[inline] + pub fn callback_always(self, value: bool) -> Self { + $T { + flags: self.flags.with(ImGuiInputTextFlags_CallbackAlways, value), + .. self + } + } + + #[inline] + pub fn callback_char_filter(self, value: bool) -> Self { + $T { + flags: self.flags.with(ImGuiInputTextFlags_CallbackCharFilter, value), + .. self + } + } + + #[inline] + pub fn allow_tab_input(self, value: bool) -> Self { + $T { + flags: self.flags.with(ImGuiInputTextFlags_AllowTabInput, value), + .. self + } + } + + #[inline] + pub fn no_horizontal_scroll(self, value: bool) -> Self { + $T { + flags: self.flags.with(ImGuiInputTextFlags_NoHorizontalScroll, value), + .. self + } + } + + #[inline] + pub fn always_insert_mode(self, value: bool) -> Self { + $T { + flags: self.flags.with(ImGuiInputTextFlags_AlwaysInsertMode, value), + .. self + } + } + + } +} + #[must_use] pub struct InputText<'ui, 'p> { label: ImStr<'p>, @@ -33,117 +150,7 @@ impl<'ui, 'p> InputText<'ui, 'p> { } } - #[inline] - pub fn flags(self, flags: ImGuiInputTextFlags) -> Self { - InputText { - flags: flags, - .. self - } - } - - #[inline] - pub fn chars_decimal(self, value: bool) -> Self { - InputText { - flags: self.flags.with(ImGuiInputTextFlags_CharsDecimal, value), - .. self - } - } - - #[inline] - pub fn chars_hexadecimal(self, value: bool) -> Self { - InputText { - flags: self.flags.with(ImGuiInputTextFlags_CharsHexadecimal, value), - .. self - } - } - - #[inline] - pub fn chars_uppercase(self, value: bool) -> Self { - InputText { - flags: self.flags.with(ImGuiInputTextFlags_CharsUppercase, value), - .. self - } - } - - #[inline] - pub fn chars_noblank(self, value: bool) -> Self { - InputText { - flags: self.flags.with(ImGuiInputTextFlags_CharsNoBlank, value), - .. self - } - } - - #[inline] - pub fn auto_select_all(self, value: bool) -> Self { - InputText { - flags: self.flags.with(ImGuiInputTextFlags_AutoSelectAll, value), - .. self - } - } - - #[inline] - pub fn enter_returns_true(self, value: bool) -> Self { - InputText { - flags: self.flags.with(ImGuiInputTextFlags_EnterReturnsTrue, value), - .. self - } - } - - #[inline] - pub fn callback_completion(self, value: bool) -> Self { - InputText { - flags: self.flags.with(ImGuiInputTextFlags_CallbackCompletion, value), - .. self - } - } - - #[inline] - pub fn callback_history(self, value: bool) -> Self { - InputText { - flags: self.flags.with(ImGuiInputTextFlags_CallbackHistory, value), - .. self - } - } - - #[inline] - pub fn callback_always(self, value: bool) -> Self { - InputText { - flags: self.flags.with(ImGuiInputTextFlags_CallbackAlways, value), - .. self - } - } - - #[inline] - pub fn callback_char_filter(self, value: bool) -> Self { - InputText { - flags: self.flags.with(ImGuiInputTextFlags_CallbackCharFilter, value), - .. self - } - } - - #[inline] - pub fn allow_tab_input(self, value: bool) -> Self { - InputText { - flags: self.flags.with(ImGuiInputTextFlags_AllowTabInput, value), - .. self - } - } - - #[inline] - pub fn no_horizontal_scroll(self, value: bool) -> Self { - InputText { - flags: self.flags.with(ImGuiInputTextFlags_NoHorizontalScroll, value), - .. self - } - } - - #[inline] - pub fn always_insert_mode(self, value: bool) -> Self { - InputText { - flags: self.flags.with(ImGuiInputTextFlags_AlwaysInsertMode, value), - .. self - } - } + impl_text_flags!(InputText); // TODO: boxed closure...? // pub fn callback(self) -> Self { } @@ -161,3 +168,55 @@ impl<'ui, 'p> InputText<'ui, 'p> { } } } + +#[must_use] +pub struct InputInt<'ui, 'p> { + label: ImStr<'p>, + value: &'p mut i32, + step: i32, + step_fast: i32, + flags: ImGuiInputTextFlags, + _phantom: PhantomData<&'ui Ui<'ui>> +} + +impl<'ui, 'p> InputInt<'ui, 'p> { + pub fn new(label: ImStr<'p>, value: &'p mut i32) -> Self { + InputInt { + label: label, + value: value, + step: 1, + step_fast: 100, + flags: ImGuiInputTextFlags::empty(), + _phantom: PhantomData + } + } + + #[inline] + pub fn step(self, value: i32) -> Self { + InputInt { + step: value, + .. self + } + } + + #[inline] + pub fn step_fast(self, value: i32) -> Self { + InputInt { + step_fast: value, + .. self + } + } + + impl_text_flags!(InputInt); + + pub fn build(self) -> bool { + unsafe { + imgui_sys::igInputInt( + self.label.as_ptr(), + self.value as *mut i32, + self.step, + self.step_fast, + self.flags) + } + } +} diff --git a/src/lib.rs b/src/lib.rs index 459b9a2..73de401 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -39,7 +39,7 @@ pub use imgui_sys::{ ImVec2, ImVec4, ImGuiKey }; -pub use input::{InputText}; +pub use input::{InputInt, InputText}; pub use menus::{Menu, MenuItem}; pub use sliders::{SliderFloat, SliderInt}; pub use trees::{TreeNode}; @@ -447,6 +447,9 @@ impl<'ui> Ui<'ui> { // Widgets: Input impl<'ui> Ui<'ui> { + pub fn input_int<'p>(&self, label: ImStr<'p>, value: &'p mut i32) -> InputInt<'ui, 'p> { + InputInt::new(label, value) + } pub fn input_text<'p>(&self, label: ImStr<'p>, buf: &'p mut str) -> InputText<'ui, 'p> { InputText::new(label, buf) } From c4fdf854ca5093593173abd8c064db55f0d355a5 Mon Sep 17 00:00:00 2001 From: Cameron Hart Date: Thu, 14 Jan 2016 22:55:12 +1100 Subject: [PATCH 02/13] Added input_float, some change in macros and formatting --- examples/test_window_impl.rs | 4 ++ src/input.rs | 119 ++++++++++++++++++++++++----------- src/lib.rs | 11 ++-- 3 files changed, 93 insertions(+), 41 deletions(-) diff --git a/examples/test_window_impl.rs b/examples/test_window_impl.rs index a4b83d2..c63d9c2 100644 --- a/examples/test_window_impl.rs +++ b/examples/test_window_impl.rs @@ -35,6 +35,7 @@ struct State { buf: String, text: String, int: i32, + float: f32, auto_resize_state: AutoResizeState, file_menu: FileMenuState } @@ -72,6 +73,7 @@ impl Default for State { buf: buf, text: text, int: 123, + float: 0.001, auto_resize_state: Default::default(), file_menu: Default::default() } @@ -293,6 +295,8 @@ fn show_test_window<'a>(ui: &Ui<'a>, state: &mut State, opened: &mut bool) { ui.label_text(im_str!("label"), im_str!("Value")); ui.input_text(im_str!("input text"), &mut state.text).build(); ui.input_int(im_str!("input int"), &mut state.int).build(); + ui.input_float(im_str!("input float"), &mut state.float) + .step(0.01).step_fast(1.0).build(); } }) } diff --git a/src/input.rs b/src/input.rs index aeb85fc..af3adec 100644 --- a/src/input.rs +++ b/src/input.rs @@ -16,10 +16,10 @@ use super::{ }; macro_rules! impl_text_flags { - ($T:ident) => { + ($InputType:ident) => { #[inline] pub fn flags(self, flags: ImGuiInputTextFlags) -> Self { - $T { + $InputType { flags: flags, .. self } @@ -27,7 +27,7 @@ macro_rules! impl_text_flags { #[inline] pub fn chars_decimal(self, value: bool) -> Self { - $T { + $InputType { flags: self.flags.with(ImGuiInputTextFlags_CharsDecimal, value), .. self } @@ -35,7 +35,7 @@ macro_rules! impl_text_flags { #[inline] pub fn chars_hexadecimal(self, value: bool) -> Self { - $T { + $InputType { flags: self.flags.with(ImGuiInputTextFlags_CharsHexadecimal, value), .. self } @@ -43,7 +43,7 @@ macro_rules! impl_text_flags { #[inline] pub fn chars_uppercase(self, value: bool) -> Self { - $T { + $InputType { flags: self.flags.with(ImGuiInputTextFlags_CharsUppercase, value), .. self } @@ -51,7 +51,7 @@ macro_rules! impl_text_flags { #[inline] pub fn chars_noblank(self, value: bool) -> Self { - $T { + $InputType { flags: self.flags.with(ImGuiInputTextFlags_CharsNoBlank, value), .. self } @@ -59,7 +59,7 @@ macro_rules! impl_text_flags { #[inline] pub fn auto_select_all(self, value: bool) -> Self { - $T { + $InputType { flags: self.flags.with(ImGuiInputTextFlags_AutoSelectAll, value), .. self } @@ -67,7 +67,7 @@ macro_rules! impl_text_flags { #[inline] pub fn enter_returns_true(self, value: bool) -> Self { - $T { + $InputType { flags: self.flags.with(ImGuiInputTextFlags_EnterReturnsTrue, value), .. self } @@ -75,7 +75,7 @@ macro_rules! impl_text_flags { #[inline] pub fn callback_completion(self, value: bool) -> Self { - $T { + $InputType { flags: self.flags.with(ImGuiInputTextFlags_CallbackCompletion, value), .. self } @@ -83,7 +83,7 @@ macro_rules! impl_text_flags { #[inline] pub fn callback_history(self, value: bool) -> Self { - $T { + $InputType { flags: self.flags.with(ImGuiInputTextFlags_CallbackHistory, value), .. self } @@ -91,7 +91,7 @@ macro_rules! impl_text_flags { #[inline] pub fn callback_always(self, value: bool) -> Self { - $T { + $InputType { flags: self.flags.with(ImGuiInputTextFlags_CallbackAlways, value), .. self } @@ -99,7 +99,7 @@ macro_rules! impl_text_flags { #[inline] pub fn callback_char_filter(self, value: bool) -> Self { - $T { + $InputType { flags: self.flags.with(ImGuiInputTextFlags_CallbackCharFilter, value), .. self } @@ -107,7 +107,7 @@ macro_rules! impl_text_flags { #[inline] pub fn allow_tab_input(self, value: bool) -> Self { - $T { + $InputType { flags: self.flags.with(ImGuiInputTextFlags_AllowTabInput, value), .. self } @@ -115,7 +115,7 @@ macro_rules! impl_text_flags { #[inline] pub fn no_horizontal_scroll(self, value: bool) -> Self { - $T { + $InputType { flags: self.flags.with(ImGuiInputTextFlags_NoHorizontalScroll, value), .. self } @@ -123,7 +123,7 @@ macro_rules! impl_text_flags { #[inline] pub fn always_insert_mode(self, value: bool) -> Self { - $T { + $InputType { flags: self.flags.with(ImGuiInputTextFlags_AlwaysInsertMode, value), .. self } @@ -132,6 +132,26 @@ macro_rules! impl_text_flags { } } +macro_rules! impl_step_params { + ($InputType:ident, $Value:ty) => { + #[inline] + pub fn step(self, value: $Value) -> Self { + $InputType { + step: value, + .. self + } + } + + #[inline] + pub fn step_fast(self, value: $Value) -> Self { + $InputType { + step_fast: value, + .. self + } + } + } +} + #[must_use] pub struct InputText<'ui, 'p> { label: ImStr<'p>, @@ -173,8 +193,8 @@ impl<'ui, 'p> InputText<'ui, 'p> { pub struct InputInt<'ui, 'p> { label: ImStr<'p>, value: &'p mut i32, - step: i32, - step_fast: i32, + step: i32, + step_fast: i32, flags: ImGuiInputTextFlags, _phantom: PhantomData<&'ui Ui<'ui>> } @@ -184,29 +204,14 @@ impl<'ui, 'p> InputInt<'ui, 'p> { InputInt { label: label, value: value, - step: 1, - step_fast: 100, + step: 1, + step_fast: 100, flags: ImGuiInputTextFlags::empty(), _phantom: PhantomData } } - #[inline] - pub fn step(self, value: i32) -> Self { - InputInt { - step: value, - .. self - } - } - - #[inline] - pub fn step_fast(self, value: i32) -> Self { - InputInt { - step_fast: value, - .. self - } - } - + impl_step_params!(InputInt, i32); impl_text_flags!(InputInt); pub fn build(self) -> bool { @@ -214,8 +219,48 @@ impl<'ui, 'p> InputInt<'ui, 'p> { imgui_sys::igInputInt( self.label.as_ptr(), self.value as *mut i32, - self.step, - self.step_fast, + self.step, + self.step_fast, + self.flags) + } + } +} + +#[must_use] +pub struct InputFloat<'ui, 'p> { + label: ImStr<'p>, + value: &'p mut f32, + step: f32, + step_fast: f32, + decimal_precision: i32, + flags: ImGuiInputTextFlags, + _phantom: PhantomData<&'ui Ui<'ui>> +} + +impl<'ui, 'p> InputFloat<'ui, 'p> { + pub fn new(label: ImStr<'p>, value: &'p mut f32) -> Self { + InputFloat { + label: label, + value: value, + step: 0.0, + step_fast: 0.0, + decimal_precision: -1, + flags: ImGuiInputTextFlags::empty(), + _phantom: PhantomData + } + } + + impl_step_params!(InputFloat, f32); + impl_text_flags!(InputFloat); + + pub fn build(self) -> bool { + unsafe { + imgui_sys::igInputFloat( + self.label.as_ptr(), + self.value as *mut f32, + self.step, + self.step_fast, + self.decimal_precision, self.flags) } } diff --git a/src/lib.rs b/src/lib.rs index 73de401..c913fca 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -39,7 +39,7 @@ pub use imgui_sys::{ ImVec2, ImVec4, ImGuiKey }; -pub use input::{InputInt, InputText}; +pub use input::{InputFloat, InputInt, InputText}; pub use menus::{Menu, MenuItem}; pub use sliders::{SliderFloat, SliderInt}; pub use trees::{TreeNode}; @@ -447,12 +447,15 @@ impl<'ui> Ui<'ui> { // Widgets: Input impl<'ui> Ui<'ui> { - pub fn input_int<'p>(&self, label: ImStr<'p>, value: &'p mut i32) -> InputInt<'ui, 'p> { - InputInt::new(label, value) - } pub fn input_text<'p>(&self, label: ImStr<'p>, buf: &'p mut str) -> InputText<'ui, 'p> { InputText::new(label, buf) } + pub fn input_float<'p>(&self, label: ImStr<'p>, value: &'p mut f32) -> InputFloat<'ui, 'p> { + InputFloat::new(label, value) + } + pub fn input_int<'p>(&self, label: ImStr<'p>, value: &'p mut i32) -> InputInt<'ui, 'p> { + InputInt::new(label, value) + } } // Widgets: Sliders From 8e2c5640e4a7c660945fa3a4026ee59793db7236 Mon Sep 17 00:00:00 2001 From: Cameron Hart Date: Thu, 14 Jan 2016 23:08:12 +1100 Subject: [PATCH 03/13] Forgot to expose decimal_precision. --- src/input.rs | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/input.rs b/src/input.rs index af3adec..b8bcd86 100644 --- a/src/input.rs +++ b/src/input.rs @@ -211,9 +211,6 @@ impl<'ui, 'p> InputInt<'ui, 'p> { } } - impl_step_params!(InputInt, i32); - impl_text_flags!(InputInt); - pub fn build(self) -> bool { unsafe { imgui_sys::igInputInt( @@ -224,6 +221,9 @@ impl<'ui, 'p> InputInt<'ui, 'p> { self.flags) } } + + impl_step_params!(InputInt, i32); + impl_text_flags!(InputInt); } #[must_use] @@ -250,8 +250,12 @@ impl<'ui, 'p> InputFloat<'ui, 'p> { } } - impl_step_params!(InputFloat, f32); - impl_text_flags!(InputFloat); + pub fn decimal_precision(self, value: i32) -> Self { + InputFloat { + decimal_precision: value, + .. self + } + } pub fn build(self) -> bool { unsafe { @@ -264,4 +268,8 @@ impl<'ui, 'p> InputFloat<'ui, 'p> { self.flags) } } + + impl_step_params!(InputFloat, f32); + impl_text_flags!(InputFloat); + } From 3c1e1e129a41cb14343092f07b7cd35b5b2f5e79 Mon Sep 17 00:00:00 2001 From: Cameron Hart Date: Fri, 15 Jan 2016 00:17:43 +1100 Subject: [PATCH 04/13] Added float array inputs --- examples/test_window_impl.rs | 15 +++++---- src/input.rs | 63 +++++++++++++++++++++++++++++++----- src/lib.rs | 11 ++++++- 3 files changed, 74 insertions(+), 15 deletions(-) diff --git a/examples/test_window_impl.rs b/examples/test_window_impl.rs index c63d9c2..f5556e4 100644 --- a/examples/test_window_impl.rs +++ b/examples/test_window_impl.rs @@ -34,8 +34,9 @@ struct State { wrap_width: f32, buf: String, text: String, - int: i32, - float: f32, + i0: i32, + f0: f32, + vec3: [f32;3], auto_resize_state: AutoResizeState, file_menu: FileMenuState } @@ -72,8 +73,9 @@ impl Default for State { wrap_width: 200.0, buf: buf, text: text, - int: 123, - float: 0.001, + i0: 123, + f0: 0.001, + vec3: [0.10, 0.20, 0.30], auto_resize_state: Default::default(), file_menu: Default::default() } @@ -294,9 +296,10 @@ fn show_test_window<'a>(ui: &Ui<'a>, state: &mut State, opened: &mut bool) { ui.separator(); ui.label_text(im_str!("label"), im_str!("Value")); ui.input_text(im_str!("input text"), &mut state.text).build(); - ui.input_int(im_str!("input int"), &mut state.int).build(); - ui.input_float(im_str!("input float"), &mut state.float) + ui.input_int(im_str!("input int"), &mut state.i0).build(); + ui.input_float(im_str!("input float"), &mut state.f0) .step(0.01).step_fast(1.0).build(); + ui.input_float3(im_str!("input float3"), &mut state.vec3).build(); } }) } diff --git a/src/input.rs b/src/input.rs index b8bcd86..41a7c0a 100644 --- a/src/input.rs +++ b/src/input.rs @@ -152,6 +152,18 @@ macro_rules! impl_step_params { } } +macro_rules! impl_precision_params { + ($InputType:ident) => { + #[inline] + pub fn decimal_precision(self, value: i32) -> Self { + $InputType { + decimal_precision: value, + .. self + } + } + } +} + #[must_use] pub struct InputText<'ui, 'p> { label: ImStr<'p>, @@ -250,13 +262,6 @@ impl<'ui, 'p> InputFloat<'ui, 'p> { } } - pub fn decimal_precision(self, value: i32) -> Self { - InputFloat { - decimal_precision: value, - .. self - } - } - pub fn build(self) -> bool { unsafe { imgui_sys::igInputFloat( @@ -270,6 +275,48 @@ impl<'ui, 'p> InputFloat<'ui, 'p> { } impl_step_params!(InputFloat, f32); + impl_precision_params!(InputFloat); impl_text_flags!(InputFloat); - } + +macro_rules! impl_input_floatn { + ($InputFloatN:ident, $N:expr, $igInputFloatN:ident) => { + #[must_use] + pub struct $InputFloatN<'ui, 'p> { + label: ImStr<'p>, + value: &'p mut [f32;$N], + decimal_precision: i32, + flags: ImGuiInputTextFlags, + _phantom: PhantomData<&'ui Ui<'ui>> + } + + impl<'ui, 'p> $InputFloatN<'ui, 'p> { + pub fn new(label: ImStr<'p>, value: &'p mut [f32;$N]) -> Self { + $InputFloatN { + label: label, + value: value, + decimal_precision: -1, + flags: ImGuiInputTextFlags::empty(), + _phantom: PhantomData + } + } + + pub fn build(self) -> bool { + unsafe { + imgui_sys::$igInputFloatN( + self.label.as_ptr(), + self.value.as_mut_ptr(), + self.decimal_precision, + self.flags) + } + } + + impl_precision_params!($InputFloatN); + impl_text_flags!($InputFloatN); + } + } +} + +impl_input_floatn!(InputFloat2, 2, igInputFloat2); +impl_input_floatn!(InputFloat3, 3, igInputFloat3); +impl_input_floatn!(InputFloat4, 4, igInputFloat4); diff --git a/src/lib.rs b/src/lib.rs index c913fca..63bec83 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -39,7 +39,7 @@ pub use imgui_sys::{ ImVec2, ImVec4, ImGuiKey }; -pub use input::{InputFloat, InputInt, InputText}; +pub use input::{InputFloat, InputFloat2, InputFloat3, InputFloat4, InputInt, InputText}; pub use menus::{Menu, MenuItem}; pub use sliders::{SliderFloat, SliderInt}; pub use trees::{TreeNode}; @@ -453,6 +453,15 @@ impl<'ui> Ui<'ui> { pub fn input_float<'p>(&self, label: ImStr<'p>, value: &'p mut f32) -> InputFloat<'ui, 'p> { InputFloat::new(label, value) } + pub fn input_float2<'p>(&self, label: ImStr<'p>, value: &'p mut [f32;2]) -> InputFloat2<'ui, 'p> { + InputFloat2::new(label, value) + } + pub fn input_float3<'p>(&self, label: ImStr<'p>, value: &'p mut [f32;3]) -> InputFloat3<'ui, 'p> { + InputFloat3::new(label, value) + } + pub fn input_float4<'p>(&self, label: ImStr<'p>, value: &'p mut [f32;4]) -> InputFloat4<'ui, 'p> { + InputFloat4::new(label, value) + } pub fn input_int<'p>(&self, label: ImStr<'p>, value: &'p mut i32) -> InputInt<'ui, 'p> { InputInt::new(label, value) } From 9a288b63f0524586133727dd864fd2324378b013 Mon Sep 17 00:00:00 2001 From: Cameron Hart Date: Fri, 15 Jan 2016 07:49:00 +1100 Subject: [PATCH 05/13] Added int array inputs Also added aliases for input_f32 and input_i32. I don't think this naming works so well with the arrays. --- examples/test_window_impl.rs | 22 ++++++++++++++++++--- src/input.rs | 38 ++++++++++++++++++++++++++++++++++++ src/lib.rs | 21 +++++++++++++++++++- 3 files changed, 77 insertions(+), 4 deletions(-) diff --git a/examples/test_window_impl.rs b/examples/test_window_impl.rs index f5556e4..17960c1 100644 --- a/examples/test_window_impl.rs +++ b/examples/test_window_impl.rs @@ -36,7 +36,10 @@ struct State { text: String, i0: i32, f0: f32, - vec3: [f32;3], + vec2f: [f32;2], + vec3f: [f32;3], + vec2i: [i32;2], + vec3i: [i32;3], auto_resize_state: AutoResizeState, file_menu: FileMenuState } @@ -75,7 +78,10 @@ impl Default for State { text: text, i0: 123, f0: 0.001, - vec3: [0.10, 0.20, 0.30], + vec2f: [0.10, 0.20], + vec3f: [0.10, 0.20, 0.30], + vec2i: [10, 20], + vec3i: [10, 20, 30], auto_resize_state: Default::default(), file_menu: Default::default() } @@ -299,7 +305,17 @@ fn show_test_window<'a>(ui: &Ui<'a>, state: &mut State, opened: &mut bool) { ui.input_int(im_str!("input int"), &mut state.i0).build(); ui.input_float(im_str!("input float"), &mut state.f0) .step(0.01).step_fast(1.0).build(); - ui.input_float3(im_str!("input float3"), &mut state.vec3).build(); + ui.input_float3(im_str!("input float3"), &mut state.vec3f).build(); + + ui.tree_node(im_str!("Multi-component Widgets")).build(|| { + ui.input_float2(im_str!("input float2"), &mut state.vec2f).build(); + ui.input_int2(im_str!("input int2"), &mut state.vec2i).build(); + ui.spacing(); + + ui.input_float3(im_str!("input float3"), &mut state.vec3f).build(); + ui.input_int3(im_str!("input int3"), &mut state.vec3i).build(); + ui.spacing(); + }); } }) } diff --git a/src/input.rs b/src/input.rs index 41a7c0a..c6003e9 100644 --- a/src/input.rs +++ b/src/input.rs @@ -320,3 +320,41 @@ macro_rules! impl_input_floatn { impl_input_floatn!(InputFloat2, 2, igInputFloat2); impl_input_floatn!(InputFloat3, 3, igInputFloat3); impl_input_floatn!(InputFloat4, 4, igInputFloat4); + +macro_rules! impl_input_intn { + ($InputIntN:ident, $N:expr, $igInputIntN:ident) => { + #[must_use] + pub struct $InputIntN<'ui, 'p> { + label: ImStr<'p>, + value: &'p mut [i32;$N], + flags: ImGuiInputTextFlags, + _phantom: PhantomData<&'ui Ui<'ui>> + } + + impl<'ui, 'p> $InputIntN<'ui, 'p> { + pub fn new(label: ImStr<'p>, value: &'p mut [i32;$N]) -> Self { + $InputIntN { + label: label, + value: value, + flags: ImGuiInputTextFlags::empty(), + _phantom: PhantomData + } + } + + pub fn build(self) -> bool { + unsafe { + imgui_sys::$igInputIntN( + self.label.as_ptr(), + self.value.as_mut_ptr(), + self.flags) + } + } + + impl_text_flags!($InputIntN); + } + } +} + +impl_input_intn!(InputInt2, 2, igInputInt2); +impl_input_intn!(InputInt3, 3, igInputInt3); +impl_input_intn!(InputInt4, 4, igInputInt4); diff --git a/src/lib.rs b/src/lib.rs index 63bec83..4526b7d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -39,7 +39,11 @@ pub use imgui_sys::{ ImVec2, ImVec4, ImGuiKey }; -pub use input::{InputFloat, InputFloat2, InputFloat3, InputFloat4, InputInt, InputText}; +pub use input::{ + InputFloat, InputFloat2, InputFloat3, InputFloat4, + InputInt, InputInt2, InputInt3, InputInt4, + InputText +}; pub use menus::{Menu, MenuItem}; pub use sliders::{SliderFloat, SliderInt}; pub use trees::{TreeNode}; @@ -450,6 +454,9 @@ impl<'ui> Ui<'ui> { pub fn input_text<'p>(&self, label: ImStr<'p>, buf: &'p mut str) -> InputText<'ui, 'p> { InputText::new(label, buf) } + pub fn input_f32<'p>(&self, label: ImStr<'p>, value: &'p mut f32) -> InputFloat<'ui, 'p> { + InputFloat::new(label, value) + } pub fn input_float<'p>(&self, label: ImStr<'p>, value: &'p mut f32) -> InputFloat<'ui, 'p> { InputFloat::new(label, value) } @@ -462,9 +469,21 @@ impl<'ui> Ui<'ui> { pub fn input_float4<'p>(&self, label: ImStr<'p>, value: &'p mut [f32;4]) -> InputFloat4<'ui, 'p> { InputFloat4::new(label, value) } + pub fn input_i32<'p>(&self, label: ImStr<'p>, value: &'p mut i32) -> InputInt<'ui, 'p> { + InputInt::new(label, value) + } pub fn input_int<'p>(&self, label: ImStr<'p>, value: &'p mut i32) -> InputInt<'ui, 'p> { InputInt::new(label, value) } + pub fn input_int2<'p>(&self, label: ImStr<'p>, value: &'p mut [i32;2]) -> InputInt2<'ui, 'p> { + InputInt2::new(label, value) + } + pub fn input_int3<'p>(&self, label: ImStr<'p>, value: &'p mut [i32;3]) -> InputInt3<'ui, 'p> { + InputInt3::new(label, value) + } + pub fn input_int4<'p>(&self, label: ImStr<'p>, value: &'p mut [i32;4]) -> InputInt4<'ui, 'p> { + InputInt4::new(label, value) + } } // Widgets: Sliders From 9bcb3cb0d5709fadc99188b0e2dbc718c1cfa0fb Mon Sep 17 00:00:00 2001 From: Cameron Hart Date: Fri, 15 Jan 2016 08:23:33 +1100 Subject: [PATCH 06/13] Added color editing widgets --- examples/test_window_impl.rs | 7 +++++ imgui-sys/src/lib.rs | 4 +-- src/input.rs | 53 ++++++++++++++++++++++++++++++++++++ src/lib.rs | 7 +++++ 4 files changed, 69 insertions(+), 2 deletions(-) diff --git a/examples/test_window_impl.rs b/examples/test_window_impl.rs index 17960c1..f96c3b5 100644 --- a/examples/test_window_impl.rs +++ b/examples/test_window_impl.rs @@ -40,6 +40,8 @@ struct State { vec3f: [f32;3], vec2i: [i32;2], vec3i: [i32;3], + col1: [f32;3], + col2: [f32;4], auto_resize_state: AutoResizeState, file_menu: FileMenuState } @@ -82,6 +84,8 @@ impl Default for State { vec3f: [0.10, 0.20, 0.30], vec2i: [10, 20], vec3i: [10, 20, 30], + col1: [1.0, 0.0, 0.2], + col2: [0.4, 0.7, 0.0, 0.5], auto_resize_state: Default::default(), file_menu: Default::default() } @@ -299,6 +303,7 @@ fn show_test_window<'a>(ui: &Ui<'a>, state: &mut State, opened: &mut bool) { ui.text(im_str!("Kanjis: 日本語 (nihongo)")); ui.input_text(im_str!("UTF-8 input"), &mut state.buf).build(); }); + ui.separator(); ui.label_text(im_str!("label"), im_str!("Value")); ui.input_text(im_str!("input text"), &mut state.text).build(); @@ -306,6 +311,8 @@ fn show_test_window<'a>(ui: &Ui<'a>, state: &mut State, opened: &mut bool) { ui.input_float(im_str!("input float"), &mut state.f0) .step(0.01).step_fast(1.0).build(); ui.input_float3(im_str!("input float3"), &mut state.vec3f).build(); + ui.color_edit3(im_str!("color 1"), &mut state.col1).build(); + ui.color_edit4(im_str!("color 2"), &mut state.col2).build(); ui.tree_node(im_str!("Multi-component Widgets")).build(|| { ui.input_float2(im_str!("input float2"), &mut state.vec2f).build(); diff --git a/imgui-sys/src/lib.rs b/imgui-sys/src/lib.rs index d2f5104..a72b3ff 100644 --- a/imgui-sys/src/lib.rs +++ b/imgui-sys/src/lib.rs @@ -792,8 +792,8 @@ extern "C" { data: *mut c_void, items_count: c_int, height_in_items: c_int) -> bool; pub fn igColorButton(col: ImVec4, small_height: bool, outline_border: bool) -> bool; - pub fn igColorEdit3(label: *const c_char, col: [c_float; 3]) -> bool; - pub fn igColorEdit4(label: *const c_char, col: [c_float; 4], show_alpha: bool) -> bool; + pub fn igColorEdit3(label: *const c_char, col: *mut f32) -> bool; + pub fn igColorEdit4(label: *const c_char, col: *mut f32, show_alpha: bool) -> bool; pub fn igColorEditMode(mode: ImGuiColorEditMode); pub fn igPlotLines(label: *const c_char, values: *const c_float, values_count: c_int, values_offset: c_int, diff --git a/src/input.rs b/src/input.rs index c6003e9..de50f85 100644 --- a/src/input.rs +++ b/src/input.rs @@ -358,3 +358,56 @@ macro_rules! impl_input_intn { impl_input_intn!(InputInt2, 2, igInputInt2); impl_input_intn!(InputInt3, 3, igInputInt3); impl_input_intn!(InputInt4, 4, igInputInt4); + +#[must_use] +pub struct ColorEdit3<'ui, 'p> { + label: ImStr<'p>, + value: &'p mut [f32;3], + _phantom: PhantomData<&'ui Ui<'ui>> +} + +impl<'ui, 'p> ColorEdit3<'ui, 'p> { + pub fn new(label: ImStr<'p>, value: &'p mut [f32;3]) -> Self { + ColorEdit3 { + label: label, + value: value, + _phantom: PhantomData + } + } + + pub fn build(self) -> bool { + unsafe { + imgui_sys::igColorEdit3( + self.label.as_ptr(), + self.value.as_mut_ptr()) + } + } +} + +#[must_use] +pub struct ColorEdit4<'ui, 'p> { + label: ImStr<'p>, + value: &'p mut [f32;4], + show_alpha: bool, + _phantom: PhantomData<&'ui Ui<'ui>> +} + +impl<'ui, 'p> ColorEdit4<'ui, 'p> { + pub fn new(label: ImStr<'p>, value: &'p mut [f32;4]) -> Self { + ColorEdit4 { + label: label, + value: value, + show_alpha: true, + _phantom: PhantomData + } + } + + pub fn build(self) -> bool { + unsafe { + imgui_sys::igColorEdit4( + self.label.as_ptr(), + self.value.as_mut_ptr(), + self.show_alpha) + } + } +} diff --git a/src/lib.rs b/src/lib.rs index 4526b7d..217265b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -40,6 +40,7 @@ pub use imgui_sys::{ ImGuiKey }; pub use input::{ + ColorEdit3, ColorEdit4, InputFloat, InputFloat2, InputFloat3, InputFloat4, InputInt, InputInt2, InputInt3, InputInt4, InputText @@ -451,6 +452,12 @@ impl<'ui> Ui<'ui> { // Widgets: Input impl<'ui> Ui<'ui> { + pub fn color_edit3<'p>(&self, label: ImStr<'p>, value: &'p mut [f32;3]) -> ColorEdit3<'ui, 'p> { + ColorEdit3::new(label, value) + } + pub fn color_edit4<'p>(&self, label: ImStr<'p>, value: &'p mut [f32;4]) -> ColorEdit4<'ui, 'p> { + ColorEdit4::new(label, value) + } pub fn input_text<'p>(&self, label: ImStr<'p>, buf: &'p mut str) -> InputText<'ui, 'p> { InputText::new(label, buf) } From 4739953a941f559c9ac326b738f98b7cbac2a964 Mon Sep 17 00:00:00 2001 From: Cameron Hart Date: Sun, 17 Jan 2016 00:50:56 +1100 Subject: [PATCH 07/13] Removed unused convert::From --- src/lib.rs | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 217265b..44338c3 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -8,7 +8,6 @@ extern crate libc; use libc::{c_char, c_float, c_int, c_uchar}; use std::borrow::Cow; -use std::convert::From; use std::ffi::CStr; use std::mem; use std::ptr; @@ -93,16 +92,6 @@ impl<'a> ImStr<'a> { fn as_ptr(&self) -> *const c_char { self.bytes.as_ptr() as *const c_char } } -impl<'a> From<&'a str> for ImStr<'a> { - fn from(value: &'a str) -> ImStr<'a> { - let mut bytes: Vec = value.bytes().collect(); - bytes.push(0); - ImStr { - bytes: Cow::Owned(bytes) - } - } -} - impl From for ImStr<'static> { fn from(mut value: String) -> ImStr<'static> { value.push('\0'); From 2d9f63a1b83e6a91652bb1eea2b6962af93ee620 Mon Sep 17 00:00:00 2001 From: Cameron Hart Date: Sun, 17 Jan 2016 00:51:46 +1100 Subject: [PATCH 08/13] Added support for combo widget --- examples/test_window_impl.rs | 11 +++++++++++ imgui-sys/src/lib.rs | 2 +- src/lib.rs | 7 +++++++ 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/examples/test_window_impl.rs b/examples/test_window_impl.rs index f96c3b5..28a645c 100644 --- a/examples/test_window_impl.rs +++ b/examples/test_window_impl.rs @@ -33,6 +33,8 @@ struct State { bg_alpha: f32, wrap_width: f32, buf: String, + item: i32, + item2: i32, text: String, i0: i32, f0: f32, @@ -77,6 +79,8 @@ impl Default for State { bg_alpha: 0.65, wrap_width: 200.0, buf: buf, + item: 0, + item2: 0, text: text, i0: 123, f0: 0.001, @@ -306,6 +310,13 @@ fn show_test_window<'a>(ui: &Ui<'a>, state: &mut State, opened: &mut bool) { ui.separator(); ui.label_text(im_str!("label"), im_str!("Value")); + ui.combo(im_str!("combo"), &mut state.item, &[im_str!("aaaa"), im_str!("bbbb"), + im_str!("cccc"), im_str!("dddd"), im_str!("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")]; + ui.combo(im_str!("combo scroll"), &mut state.item2, &items); ui.input_text(im_str!("input text"), &mut state.text).build(); ui.input_int(im_str!("input int"), &mut state.i0).build(); ui.input_float(im_str!("input float"), &mut state.f0) diff --git a/imgui-sys/src/lib.rs b/imgui-sys/src/lib.rs index a72b3ff..02afb90 100644 --- a/imgui-sys/src/lib.rs +++ b/imgui-sys/src/lib.rs @@ -783,7 +783,7 @@ extern "C" { pub fn igRadioButton(label: *const c_char, v: *mut c_int, v_button: c_int) -> bool; pub fn igCombo(label: *const c_char, current_item: *mut c_int, - items: *mut *const c_char, items_count: c_int, height_in_items: c_int) -> bool; + items: *const *const c_char, items_count: c_int, height_in_items: c_int) -> bool; pub fn igCombo2(label: *const c_char, current_item: *mut c_int, items_separated_by_zeros: *const c_char, height_in_items: c_int) -> bool; pub fn igCombo3(label: *const c_char, current_item: *mut c_int, diff --git a/src/lib.rs b/src/lib.rs index 44338c3..bb48094 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -437,6 +437,13 @@ impl<'ui> Ui<'ui> { pub fn checkbox<'p>(&self, label: ImStr<'p>, value: &'p mut bool) -> bool { unsafe { imgui_sys::igCheckbox(label.as_ptr(), value) } } + pub fn combo<'p>(&self, label: ImStr<'p>, current_item: &'p mut i32, items: &'p[ImStr<'p>]) -> bool { + // TODO: the callback version could avoid allocating this Vec + let c_items : Vec<*const c_char> = items.iter().map(|s| s.as_ptr()).collect(); + unsafe { + imgui_sys::igCombo(label.as_ptr(), current_item, c_items.as_ptr(), c_items.len() as c_int, -1) + } + } } // Widgets: Input From 05cb9ccc3f14a861aeb3ae3d7b90e7dbdccfb93b Mon Sep 17 00:00:00 2001 From: Cameron Hart Date: Sun, 17 Jan 2016 08:37:02 +1100 Subject: [PATCH 09/13] Add this back. Still don't seem to need the import std::convert::From, maybe it's implicit. --- src/lib.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index bb48094..aae068c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -92,6 +92,16 @@ impl<'a> ImStr<'a> { fn as_ptr(&self) -> *const c_char { self.bytes.as_ptr() as *const c_char } } +impl<'a> From<&'a str> for ImStr<'a> { + fn from(value: &'a str) -> ImStr<'a> { + let mut bytes: Vec = value.bytes().collect(); + bytes.push(0); + ImStr { + bytes: Cow::Owned(bytes) + } + } +} + impl From for ImStr<'static> { fn from(mut value: String) -> ImStr<'static> { value.push('\0'); From 9e78e860000a14e1609d09adf4a0c1cd1b5527a6 Mon Sep 17 00:00:00 2001 From: Cameron Hart Date: Sun, 17 Jan 2016 20:05:30 +1100 Subject: [PATCH 10/13] Add support for popups and selectable widgets. --- examples/test_window_impl.rs | 26 ++++++++++++++++++++++++++ src/lib.rs | 23 +++++++++++++++++++++++ 2 files changed, 49 insertions(+) diff --git a/examples/test_window_impl.rs b/examples/test_window_impl.rs index 28a645c..e2bcfb9 100644 --- a/examples/test_window_impl.rs +++ b/examples/test_window_impl.rs @@ -44,6 +44,7 @@ struct State { vec3i: [i32;3], col1: [f32;3], col2: [f32;4], + selected_fish: Option, auto_resize_state: AutoResizeState, file_menu: FileMenuState } @@ -90,6 +91,7 @@ impl Default for State { vec3i: [10, 20, 30], col1: [1.0, 0.0, 0.2], col2: [0.4, 0.7, 0.0, 0.5], + selected_fish: None, auto_resize_state: Default::default(), file_menu: Default::default() } @@ -335,6 +337,30 @@ fn show_test_window<'a>(ui: &Ui<'a>, state: &mut State, opened: &mut bool) { ui.spacing(); }); } + if ui.collapsing_header(im_str!("Popups & Modal windows")).build() { + ui.tree_node(im_str!("Popups")).build(|| { + ui.text_wrapped(im_str!("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")]; + if ui.small_button(im_str!("Select..")) { + ui.open_popup(im_str!("select")); + } + ui.same_line(0.0); + ui.text( + match state.selected_fish { + Some(index) => names[index].clone(), + None => im_str!("") + }); + ui.popup(im_str!("select"), || { + ui.text(im_str!("Aquarium")); + ui.separator(); + for (index, name) in names.iter().enumerate() { + if ui.selectable(name.clone()) { + state.selected_fish = Some(index); + } + } + }); + }); + } }) } diff --git a/src/lib.rs b/src/lib.rs index aae068c..5341feb 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -24,6 +24,8 @@ pub use imgui_sys::{ ImGuiInputTextFlags_AllowTabInput, ImGuiInputTextFlags_CtrlEnterForNewLine, ImGuiInputTextFlags_NoHorizontalScroll, ImGuiInputTextFlags_AlwaysInsertMode, ImGuiInputTextFlags_ReadOnly, + ImGuiSelectableFlags, + ImGuiSelectableFlags_DontClosePopups, ImGuiSelectableFlags_SpanAllColumns, ImGuiSetCond, ImGuiSetCond_Always, ImGuiSetCond_Once, ImGuiSetCond_FirstUseEver, ImGuiSetCond_Appearing, @@ -518,6 +520,13 @@ impl<'ui> Ui<'ui> { } } +// Widgets: Selectable / Lists +impl<'ui> Ui<'ui> { + pub fn selectable<'p>(&self, label: ImStr<'p>) -> bool { + unsafe { imgui_sys::igSelectable(label.as_ptr(), false, ImGuiSelectableFlags::empty(), ImVec2::new(0.0,0.0)) } + } +} + // Widgets: Menus impl<'ui> Ui<'ui> { pub fn main_menu_bar(&self, f: F) where F: FnOnce() { @@ -537,3 +546,17 @@ impl<'ui> Ui<'ui> { 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) } } + +// Widgets: Popups +impl<'ui> Ui<'ui> { + pub fn open_popup<'p>(&self, str_id: ImStr<'p>) { + unsafe { imgui_sys::igOpenPopup(str_id.as_ptr()) }; + } + pub fn popup<'p, F>(&self, str_id: ImStr<'p>, f: F) where F: FnOnce() { + let render = unsafe { imgui_sys::igBeginPopup(str_id.as_ptr()) }; + if render { + f(); + unsafe { imgui_sys::igEndPopup() }; + } + } +} From 73abfc21b49dc72e6cd5db814108e1122033f802 Mon Sep 17 00:00:00 2001 From: Cameron Hart Date: Sun, 5 Jun 2016 09:51:10 +1000 Subject: [PATCH 11/13] Make parameters to igCombo match signature. --- imgui-sys/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/imgui-sys/src/lib.rs b/imgui-sys/src/lib.rs index 4c615fe..2d7290d 100644 --- a/imgui-sys/src/lib.rs +++ b/imgui-sys/src/lib.rs @@ -785,7 +785,7 @@ extern "C" { pub fn igRadioButton(label: *const c_char, v: *mut c_int, v_button: c_int) -> bool; pub fn igCombo(label: *const c_char, current_item: *mut c_int, - items: *const *const c_char, items_count: c_int, height_in_items: c_int) -> bool; + items: *mut *const c_char, items_count: c_int, height_in_items: c_int) -> bool; pub fn igCombo2(label: *const c_char, current_item: *mut c_int, items_separated_by_zeros: *const c_char, height_in_items: c_int) -> bool; pub fn igCombo3(label: *const c_char, current_item: *mut c_int, From 27bbe101074c35b761780ff26319b94de944ed3c Mon Sep 17 00:00:00 2001 From: Cameron Hart Date: Sun, 5 Jun 2016 09:51:49 +1000 Subject: [PATCH 12/13] Expose parameters to igSelectable. --- examples/test_window_impl.rs | 2 +- src/lib.rs | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/examples/test_window_impl.rs b/examples/test_window_impl.rs index dcca1d7..1d76a05 100644 --- a/examples/test_window_impl.rs +++ b/examples/test_window_impl.rs @@ -354,7 +354,7 @@ fn show_test_window<'a>(ui: &Ui<'a>, state: &mut State, opened: &mut bool) { ui.text(im_str!("Aquarium")); ui.separator(); for (index, name) in names.iter().enumerate() { - if ui.selectable(name.clone()) { + if ui.selectable(name.clone(), false, ImGuiSelectableFlags::empty(), ImVec2::new(0.0, 0.0)) { state.selected_fish = Some(index); } } diff --git a/src/lib.rs b/src/lib.rs index 770228a..e9bf230 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -552,8 +552,9 @@ impl<'ui> Ui<'ui> { // Widgets: Selectable / Lists impl<'ui> Ui<'ui> { - pub fn selectable<'p>(&self, label: ImStr<'p>) -> bool { - unsafe { imgui_sys::igSelectable(label.as_ptr(), false, ImGuiSelectableFlags::empty(), ImVec2::new(0.0,0.0)) } + pub fn selectable<'p>(&self, label: ImStr<'p>, selected: bool, flags: ImGuiSelectableFlags, + size: ImVec2) -> bool { + unsafe { imgui_sys::igSelectable(label.as_ptr(), selected, flags, size) } } } From bbb46c74460666f75c7bb8d6328f9f6147f00c8c Mon Sep 17 00:00:00 2001 From: Cameron Hart Date: Thu, 9 Jun 2016 08:12:40 +1000 Subject: [PATCH 13/13] Removed i32 and f32 variants of input and slider. --- examples/test_window_impl.rs | 6 +++--- src/lib.rs | 10 ++-------- 2 files changed, 5 insertions(+), 11 deletions(-) diff --git a/examples/test_window_impl.rs b/examples/test_window_impl.rs index 1d76a05..309890b 100644 --- a/examples/test_window_impl.rs +++ b/examples/test_window_impl.rs @@ -241,7 +241,7 @@ fn show_test_window<'a>(ui: &Ui<'a>, state: &mut State, opened: &mut bool) { 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(); + ui.slider_float(im_str!("bg alpha"), &mut state.bg_alpha, 0.0, 1.0).build(); ui.tree_node(im_str!("Style")).build(|| { // TODO: Reimplement style editor @@ -289,7 +289,7 @@ fn show_test_window<'a>(ui: &Ui<'a>, state: &mut State, opened: &mut bool) { suitable for English and possibly other languages.")); ui.spacing(); - ui.slider_f32(im_str!("Wrap width"), &mut state.wrap_width, -20.0, 600.0) + ui.slider_float(im_str!("Wrap width"), &mut state.wrap_width, -20.0, 600.0) .display_format(im_str!("%.0f")) .build(); @@ -423,7 +423,7 @@ fn show_example_app_auto_resize<'a>(ui: &Ui<'a>, state: &mut AutoResizeState, op 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.")); - ui.slider_i32(im_str!("Number of lines"), &mut state.lines, 1, 20).build(); + ui.slider_int(im_str!("Number of lines"), &mut state.lines, 1, 20).build(); for i in 0 .. state.lines { ui.text(im_str!("{:2$}This is line {}", "", i, i as usize * 4)); } diff --git a/src/lib.rs b/src/lib.rs index e9bf230..1a8dc9a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -499,9 +499,6 @@ impl<'ui> Ui<'ui> { pub fn input_text<'p>(&self, label: ImStr<'p>, buf: &'p mut str) -> InputText<'ui, 'p> { InputText::new(label, buf) } - pub fn input_f32<'p>(&self, label: ImStr<'p>, value: &'p mut f32) -> InputFloat<'ui, 'p> { - InputFloat::new(label, value) - } pub fn input_float<'p>(&self, label: ImStr<'p>, value: &'p mut f32) -> InputFloat<'ui, 'p> { InputFloat::new(label, value) } @@ -514,9 +511,6 @@ impl<'ui> Ui<'ui> { pub fn input_float4<'p>(&self, label: ImStr<'p>, value: &'p mut [f32;4]) -> InputFloat4<'ui, 'p> { InputFloat4::new(label, value) } - pub fn input_i32<'p>(&self, label: ImStr<'p>, value: &'p mut i32) -> InputInt<'ui, 'p> { - InputInt::new(label, value) - } pub fn input_int<'p>(&self, label: ImStr<'p>, value: &'p mut i32) -> InputInt<'ui, 'p> { InputInt::new(label, value) } @@ -533,11 +527,11 @@ impl<'ui> Ui<'ui> { // Widgets: Sliders impl<'ui> Ui<'ui> { - pub fn slider_f32<'p>(&self, label: ImStr<'p>, + pub fn slider_float<'p>(&self, label: ImStr<'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>, + pub fn slider_int<'p>(&self, label: ImStr<'p>, value: &'p mut i32, min: i32, max: i32) -> SliderInt<'ui, 'p> { SliderInt::new(label, value, min, max) }