mirror of
https://github.com/eliasstepanik/imgui-rs.git
synced 2026-01-11 21:48:36 +00:00
Added color editing widgets
This commit is contained in:
parent
9a288b63f0
commit
9bcb3cb0d5
@ -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();
|
||||
|
||||
@ -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,
|
||||
|
||||
53
src/input.rs
53
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -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)
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user