mirror of
https://github.com/eliasstepanik/imgui-rs.git
synced 2026-01-13 14:38:36 +00:00
Added support for combo widget
This commit is contained in:
parent
4739953a94
commit
2d9f63a1b8
@ -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)
|
||||
|
||||
@ -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,
|
||||
|
||||
@ -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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user