Skip to content

Commit

Permalink
Added int array inputs
Browse files Browse the repository at this point in the history
Also added aliases for input_f32 and input_i32. I don't think this
naming works so well with the arrays.
  • Loading branch information
bitshifter committed Jan 14, 2016
1 parent 3c1e1e1 commit 9a288b6
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 4 deletions.
22 changes: 19 additions & 3 deletions examples/test_window_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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()
}
Expand Down Expand Up @@ -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();
});
}
})
}
Expand Down
38 changes: 38 additions & 0 deletions src/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
21 changes: 20 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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)
}
Expand All @@ -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
Expand Down

0 comments on commit 9a288b6

Please sign in to comment.