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