diff --git a/imgui-examples/examples/test_window_impl.rs b/imgui-examples/examples/test_window_impl.rs index f08300d..8d0d483 100644 --- a/imgui-examples/examples/test_window_impl.rs +++ b/imgui-examples/examples/test_window_impl.rs @@ -544,8 +544,8 @@ fn show_test_window(ui: &Ui, state: &mut State, opened: &mut bool) { Drag::new("drag float").range(-1.0, 1.0).speed(0.001).build(ui, &mut state.f0); ui.input_float3("input float3", &mut state.vec3f) .build(); - ColorEdit::new("color 1", &mut state.col1).build(ui); - ColorEdit::new("color 2", &mut state.col2).build(ui); + ColorEdit3::new("color 1", &mut state.col1).build(ui); + ColorEdit3::new("color 2", &mut state.col2).build(ui); TreeNode::new("Multi-component Widgets").build(ui, || { ui.input_float2("input float2", &mut state.vec2f) @@ -601,19 +601,19 @@ fn show_test_window(ui: &Ui, state: &mut State, opened: &mut bool) { "Click on the colored square to open a color picker. CTRL+click on individual component to input value.\n", ); - ColorEdit::new("MyColor##1", &mut s.color) + ColorEdit3::new("MyColor##1", &mut s.color) .flags(misc_flags) .alpha(false) .build(ui); ui.text("Color widget HSV with Alpha:"); - ColorEdit::new("MyColor##2", &mut s.color) + ColorEdit3::new("MyColor##2", &mut s.color) .flags(misc_flags) .input_mode(ColorEditInputMode::HSV) .build(ui); ui.text("Color widget with Float Display:"); - ColorEdit::new("MyColor##2f", &mut s.color) + ColorEdit3::new("MyColor##2f", &mut s.color) .flags(misc_flags) .format(ColorFormat::Float) .build(ui); @@ -627,7 +627,7 @@ CTRL+click on individual component to input value.\n", With the label(false) function you can pass a non-empty label which \ will only be used for the tooltip and picker popup.", ); - ColorEdit::new("MyColor##3", &mut s.color) + ColorEdit3::new("MyColor##3", &mut s.color) .flags(misc_flags) .inputs(false) .label(false) @@ -642,13 +642,13 @@ CTRL+click on individual component to input value.\n", ui.checkbox("With Ref Color", &mut s.ref_color); if s.ref_color { ui.same_line(); - ColorEdit::new("##RefColor", &mut s.ref_color_v) + ColorEdit3::new("##RefColor", &mut s.ref_color_v) .flags(misc_flags) .inputs(false) .build(ui); } } - let mut b = ColorPicker::new + let mut b = ColorPicker3::new ("MyColor##4", &mut s.color) .flags(misc_flags) .alpha(s.alpha) @@ -806,7 +806,7 @@ CTRL+click on individual component to input value.\n", let items = &["aaaa", "bbbb", "cccc", "dddd", "eeee"]; ui.combo_simple_string("Combo", &mut state.stacked_modals_item, items); - ColorEdit::new("color", &mut state.stacked_modals_color).build(ui); + ColorEdit3::new("color", &mut state.stacked_modals_color).build(ui); if ui.button("Add another modal..") { ui.open_popup("Stacked 2") ; @@ -976,7 +976,7 @@ fn show_example_app_custom_rendering(ui: &Ui, state: &mut CustomRenderingState, .build(|| { ui.text("Primitives"); // TODO: Add DragFloat to change value of sz - ColorEdit::new("Color", &mut state.col).build(ui); + ColorEdit3::new("Color", &mut state.col).build(ui); let draw_list = ui.get_window_draw_list(); let p = ui.cursor_screen_pos(); let spacing = 8.0; diff --git a/imgui/src/input/mouse.rs b/imgui/src/input/mouse.rs index b92b3d0..7aa66ab 100644 --- a/imgui/src/input/mouse.rs +++ b/imgui/src/input/mouse.rs @@ -1,5 +1,6 @@ use std::ptr; +use crate::math::MintVec2; use crate::sys; use crate::Ui; @@ -133,8 +134,12 @@ impl<'ui> Ui<'ui> { /// /// Clipped by current clipping settings, but disregards other factors like focus, window /// ordering, modal popup blocking. - pub fn is_mouse_hovering_rect(&self, r_min: [f32; 2], r_max: [f32; 2]) -> bool { - unsafe { sys::igIsMouseHoveringRect(r_min.into(), r_max.into(), true) } + pub fn is_mouse_hovering_rect( + &self, + r_min: impl Into, + r_max: impl Into, + ) -> bool { + unsafe { sys::igIsMouseHoveringRect(r_min.into().into(), r_max.into().into(), true) } } /// Returns the mouse position backed up at the time of opening a popup #[doc(alias = "GetMousePosOnOpeningCurrentPopup")] @@ -221,8 +226,8 @@ impl<'ui> Ui<'ui> { unsafe { sys::igIsMousePosValid(ptr::null()) } } #[doc(alias = "IsMousePosValid")] - pub fn is_mouse_pos_valid(&self, mouse_pos: [f32; 2]) -> bool { - unsafe { sys::igIsMousePosValid(&mouse_pos.into()) } + pub fn is_mouse_pos_valid(&self, mouse_pos: impl Into) -> bool { + unsafe { sys::igIsMousePosValid(&mouse_pos.into().into()) } } } diff --git a/imgui/src/math.rs b/imgui/src/math.rs index c3f0269..fe71d1a 100644 --- a/imgui/src/math.rs +++ b/imgui/src/math.rs @@ -1 +1,3 @@ -pub type MintVec2 = mint::Vector2; +pub(crate) type MintVec2 = mint::Vector2; +pub(crate) type MintVec3 = mint::Vector3; +pub(crate) type MintVec4 = mint::Vector4; diff --git a/imgui/src/render/draw_data.rs b/imgui/src/render/draw_data.rs index 0bd3e49..56fed63 100644 --- a/imgui/src/render/draw_data.rs +++ b/imgui/src/render/draw_data.rs @@ -1,6 +1,7 @@ use std::slice; use crate::internal::{RawCast, RawWrapper}; +use crate::math::MintVec2; use crate::render::renderer::TextureId; use crate::sys; @@ -72,7 +73,7 @@ impl DrawData { /// Can be used if your final output buffer is at a different scale than imgui-rs expects, or /// if there is a difference between your window resolution and framebuffer resolution. #[doc(alias = "ScaleClipRects")] - pub fn scale_clip_rects(&mut self, fb_scale: [f32; 2]) { + pub fn scale_clip_rects(&mut self, fb_scale: MintVec2) { unsafe { sys::ImDrawData_ScaleClipRects(self.raw_mut(), fb_scale.into()); } diff --git a/imgui/src/widget/color_editors.rs b/imgui/src/widget/color_editors.rs index 0790634..b04a6b4 100644 --- a/imgui/src/widget/color_editors.rs +++ b/imgui/src/widget/color_editors.rs @@ -1,41 +1,44 @@ use bitflags::bitflags; use std::ptr; +use crate::math::MintVec2; +use crate::math::MintVec3; +use crate::math::MintVec4; use crate::sys; use crate::Ui; -/// Mutable reference to an editable color value. -#[derive(Debug)] -pub enum EditableColor<'a> { - /// Color value with three float components (e.g. RGB). - Float3(&'a mut [f32; 3]), - /// Color value with four float components (e.g. RGBA). - Float4(&'a mut [f32; 4]), -} +// /// Mutable reference to an editable color value. +// #[derive(Debug)] +// pub enum EditableColor<'a, T> { +// /// Color value with three float components (e.g. RGB). +// Float3(&'a mut T), +// /// Color value with four float components (e.g. RGBA). +// Float4(&'a mut T), +// } -impl<'a> EditableColor<'a> { - /// Returns an unsafe mutable pointer to the color slice's buffer. - fn as_mut_ptr(&mut self) -> *mut f32 { - match *self { - EditableColor::Float3(ref mut value) => value.as_mut_ptr(), - EditableColor::Float4(ref mut value) => value.as_mut_ptr(), - } - } -} +// impl<'a> EditableColor<'a> { +// /// Returns an unsafe mutable pointer to the color slice's buffer. +// fn as_mut_ptr(&mut self) -> *mut f32 { +// match *self { +// EditableColor::Float3(ref mut value) => value.as_mut_ptr(), +// EditableColor::Float4(ref mut value) => value.as_mut_ptr(), +// } +// } +// } -impl<'a> From<&'a mut [f32; 3]> for EditableColor<'a> { - #[inline] - fn from(value: &'a mut [f32; 3]) -> EditableColor<'a> { - EditableColor::Float3(value) - } -} +// impl<'a> From<&'a mut [f32; 3]> for EditableColor<'a> { +// #[inline] +// fn from(value: &'a mut [f32; 3]) -> EditableColor<'a> { +// EditableColor::Float3(value) +// } +// } -impl<'a> From<&'a mut [f32; 4]> for EditableColor<'a> { - #[inline] - fn from(value: &'a mut [f32; 4]) -> EditableColor<'a> { - EditableColor::Float4(value) - } -} +// impl<'a> From<&'a mut [f32; 4]> for EditableColor<'a> { +// #[inline] +// fn from(value: &'a mut [f32; 4]) -> EditableColor<'a> { +// EditableColor::Float4(value) +// } +// } /// Color editor input mode. #[derive(Copy, Clone, Debug, PartialEq, Eq)] @@ -183,19 +186,24 @@ bitflags! { /// ``` #[derive(Debug)] #[must_use] -pub struct ColorEdit<'a, T: AsRef + 'a> { +pub struct ColorEdit3<'a, T, C> { label: T, - value: EditableColor<'a>, + value: &'a mut C, flags: ColorEditFlags, } -impl<'a, T: AsRef + 'a> ColorEdit<'a, T> { +impl<'a, T, C> ColorEdit3<'a, T, C> +where + T: AsRef, + MintVec3: From, + C: From + Copy, +{ /// Constructs a new color editor builder. - #[doc(alias = "ColorEdit3", alias = "ColorEdit4")] - pub fn new(label: T, value: impl Into>) -> ColorEdit<'a, T> { - ColorEdit { + #[doc(alias = "ColorEdit3")] + pub fn new(label: T, value: &'a mut C) -> Self { + ColorEdit3 { label, - value: value.into(), + value, flags: ColorEditFlags::empty(), } } @@ -319,26 +327,208 @@ impl<'a, T: AsRef + 'a> ColorEdit<'a, T> { /// /// Returns true if the color value was changed. pub fn build(mut self, ui: &Ui<'_>) -> bool { - if let EditableColor::Float3(_) = self.value { - self.flags.insert(ColorEditFlags::NO_ALPHA); + // if let EditableColor::Float3(_) = self.value { + self.flags.insert(ColorEditFlags::NO_ALPHA); + + let as_vec3: MintVec3 = (*self.value).into(); + let mut as_vec3: [f32; 3] = as_vec3.into(); + + let changed = unsafe { + sys::igColorEdit3( + ui.scratch_txt(self.label), + as_vec3.as_mut_ptr(), + self.flags.bits() as _, + ) + }; + + // and go backwards... + if changed { + let as_vec3: MintVec3 = as_vec3.into(); + + *self.value = as_vec3.into(); } - match self.value { - EditableColor::Float3(value) => unsafe { - sys::igColorEdit3( - ui.scratch_txt(self.label), - value.as_mut_ptr(), - self.flags.bits() as _, - ) - }, - EditableColor::Float4(value) => unsafe { - sys::igColorEdit4( - ui.scratch_txt(self.label), - value.as_mut_ptr(), - self.flags.bits() as _, - ) - }, + + changed + } +} + +/// Builder for a color editor widget. +/// +/// # Examples +/// +/// ```no_run +/// # use imgui::*; +/// # let mut imgui = Context::create(); +/// # let ui = imgui.frame(); +/// # let mut color = [0.0, 0.0, 0.0, 1.0]; +/// let ce = ColorEdit::new(im_str!("color_edit"), &mut color); +/// if ce.build(&ui) { +/// println!("The color was changed"); +/// } +/// ``` +#[derive(Debug)] +#[must_use] +pub struct ColorEdit4<'a, T, C> { + label: T, + value: &'a mut C, + flags: ColorEditFlags, +} + +impl<'a, T, C> ColorEdit4<'a, T, C> +where + T: AsRef, + MintVec4: From, + C: From + Copy, +{ + /// Constructs a new color editor builder. + #[doc(alias = "ColorEdit4")] + pub fn new(label: T, value: &'a mut C) -> Self { + Self { + label, + value, + flags: ColorEditFlags::empty(), } } + /// Replaces all current settings with the given flags. + #[inline] + pub fn flags(mut self, flags: ColorEditFlags) -> Self { + self.flags = flags; + self + } + /// Enables/disables the use of the alpha component. + #[inline] + pub fn alpha(mut self, value: bool) -> Self { + self.flags.set(ColorEditFlags::NO_ALPHA, !value); + self + } + /// Enables/disables the picker that appears when clicking on colored square. + #[inline] + pub fn picker(mut self, value: bool) -> Self { + self.flags.set(ColorEditFlags::NO_PICKER, !value); + self + } + /// Enables/disables toggling of the options menu when right-clicking on inputs or the small + /// preview. + #[inline] + pub fn options(mut self, value: bool) -> Self { + self.flags.set(ColorEditFlags::NO_OPTIONS, !value); + self + } + /// Enables/disables the colored square preview next to the inputs. + #[inline] + pub fn small_preview(mut self, value: bool) -> Self { + self.flags.set(ColorEditFlags::NO_SMALL_PREVIEW, !value); + self + } + /// Enables/disables the input sliders/text widgets. + #[inline] + pub fn inputs(mut self, value: bool) -> Self { + self.flags.set(ColorEditFlags::NO_INPUTS, !value); + self + } + /// Enables/disables the tooltip that appears when hovering the preview. + #[inline] + pub fn tooltip(mut self, value: bool) -> Self { + self.flags.set(ColorEditFlags::NO_TOOLTIP, !value); + self + } + /// Enables/disables display of the inline text label (the label is in any case forwarded to + /// the tooltip and picker). + #[inline] + pub fn label(mut self, value: bool) -> Self { + self.flags.set(ColorEditFlags::NO_LABEL, !value); + self + } + /// Enables/disables the vertical alpha bar/gradient in the color picker. + #[inline] + pub fn alpha_bar(mut self, value: bool) -> Self { + self.flags.set(ColorEditFlags::ALPHA_BAR, value); + self + } + /// Sets the preview style. + #[inline] + pub fn preview(mut self, preview: ColorPreview) -> Self { + self.flags.set( + ColorEditFlags::ALPHA_PREVIEW_HALF, + preview == ColorPreview::HalfAlpha, + ); + self.flags.set( + ColorEditFlags::ALPHA_PREVIEW, + preview == ColorPreview::Alpha, + ); + self + } + /// (WIP) Currently only disables 0.0..1.0 limits in RGBA edition. + /// + /// Note: you probably want to use ColorFormat::Float as well. + #[inline] + pub fn hdr(mut self, value: bool) -> Self { + self.flags.set(ColorEditFlags::HDR, value); + self + } + /// Sets the data format for input and output data. + #[inline] + pub fn input_mode(mut self, input_mode: ColorEditInputMode) -> Self { + self.flags.set( + ColorEditFlags::INPUT_RGB, + input_mode == ColorEditInputMode::RGB, + ); + self.flags.set( + ColorEditFlags::INPUT_HSV, + input_mode == ColorEditInputMode::HSV, + ); + self + } + /// Sets the color editor display mode. + #[inline] + pub fn display_mode(mut self, mode: ColorEditDisplayMode) -> Self { + self.flags.set( + ColorEditFlags::DISPLAY_RGB, + mode == ColorEditDisplayMode::RGB, + ); + self.flags.set( + ColorEditFlags::DISPLAY_HSV, + mode == ColorEditDisplayMode::HSV, + ); + self.flags.set( + ColorEditFlags::DISPLAY_HEX, + mode == ColorEditDisplayMode::HEX, + ); + self + } + /// Sets the formatting style of color components. + #[inline] + pub fn format(mut self, format: ColorFormat) -> Self { + self.flags + .set(ColorEditFlags::UINT8, format == ColorFormat::U8); + self.flags + .set(ColorEditFlags::FLOAT, format == ColorFormat::Float); + self + } + /// Builds the color editor. + /// + /// Returns true if the color value was changed. + pub fn build(self, ui: &Ui<'_>) -> bool { + let as_vec4: MintVec4 = (*self.value).into(); + let mut as_vec4: [f32; 4] = as_vec4.into(); + + let changed = unsafe { + sys::igColorEdit4( + ui.scratch_txt(self.label), + as_vec4.as_mut_ptr(), + self.flags.bits() as _, + ) + }; + + // and go backwards... + if changed { + let as_vec4: MintVec4 = as_vec4.into(); + + *self.value = as_vec4.into(); + } + + changed + } } /// Builder for a color picker widget. @@ -357,20 +547,209 @@ impl<'a, T: AsRef + 'a> ColorEdit<'a, T> { /// ``` #[derive(Debug)] #[must_use] -pub struct ColorPicker<'a, T: AsRef + 'a> { - label: T, - value: EditableColor<'a>, +pub struct ColorPicker3<'a, Label, Color> { + label: Label, + value: &'a mut Color, flags: ColorEditFlags, - ref_color: Option<&'a [f32; 4]>, } -impl<'a, T: AsRef> ColorPicker<'a, T> { +impl<'a, Label, Color> ColorPicker3<'a, Label, Color> +where + Label: AsRef, + MintVec3: From, + Color: From + Copy, +{ /// Constructs a new color picker builder. - #[doc(alias = "ColorButton")] - pub fn new(label: T, value: impl Into>) -> Self { - ColorPicker { + #[doc(alias = "ColorPicker3")] + pub fn new(label: Label, value: &'a mut Color) -> Self { + ColorPicker3 { label, - value: value.into(), + value, + flags: ColorEditFlags::empty(), + } + } + /// Replaces all current settings with the given flags. + #[inline] + pub fn flags(mut self, flags: ColorEditFlags) -> Self { + self.flags = flags; + self + } + /// Enables/disables the use of the alpha component. + #[inline] + pub fn alpha(mut self, value: bool) -> Self { + self.flags.set(ColorEditFlags::NO_ALPHA, !value); + self + } + /// Enables/disables toggling of the options menu when right-clicking on inputs or the small + /// preview. + #[inline] + pub fn options(mut self, value: bool) -> Self { + self.flags.set(ColorEditFlags::NO_OPTIONS, !value); + self + } + /// Enables/disables the colored square preview next to the inputs. + #[inline] + pub fn small_preview(mut self, value: bool) -> Self { + self.flags.set(ColorEditFlags::NO_SMALL_PREVIEW, !value); + self + } + /// Enables/disables the input sliders/text widgets. + #[inline] + pub fn inputs(mut self, value: bool) -> Self { + self.flags.set(ColorEditFlags::NO_INPUTS, !value); + self + } + /// Enables/disables the tooltip that appears when hovering the preview. + #[inline] + pub fn tooltip(mut self, value: bool) -> Self { + self.flags.set(ColorEditFlags::NO_TOOLTIP, !value); + self + } + /// Enables/disables display of the inline text label (the label is in any case forwarded to + /// the tooltip and picker). + #[inline] + pub fn label(mut self, value: bool) -> Self { + self.flags.set(ColorEditFlags::NO_LABEL, !value); + self + } + /// Enables/disables the bigger color preview on the right side of the picker. + #[inline] + pub fn side_preview(mut self, value: bool) -> Self { + self.flags.set(ColorEditFlags::NO_SIDE_PREVIEW, !value); + self + } + /// Enables/disables the vertical alpha bar/gradient in the color picker. + #[inline] + pub fn alpha_bar(mut self, value: bool) -> Self { + self.flags.set(ColorEditFlags::ALPHA_BAR, value); + self + } + /// Sets the preview style. + #[inline] + pub fn preview(mut self, preview: ColorPreview) -> Self { + self.flags.set( + ColorEditFlags::ALPHA_PREVIEW_HALF, + preview == ColorPreview::HalfAlpha, + ); + self.flags.set( + ColorEditFlags::ALPHA_PREVIEW, + preview == ColorPreview::Alpha, + ); + self + } + /// Sets the data format for input and output data. + #[inline] + pub fn input_mode(mut self, input_mode: ColorEditInputMode) -> Self { + self.flags.set( + ColorEditFlags::INPUT_RGB, + input_mode == ColorEditInputMode::RGB, + ); + self.flags.set( + ColorEditFlags::INPUT_HSV, + input_mode == ColorEditInputMode::HSV, + ); + self + } + /// Enables/disables displaying the value as RGB. + #[inline] + pub fn display_rgb(mut self, value: bool) -> Self { + self.flags.set(ColorEditFlags::DISPLAY_RGB, value); + self + } + /// Enables/disables displaying the value as HSV. + #[inline] + pub fn display_hsv(mut self, value: bool) -> Self { + self.flags.set(ColorEditFlags::DISPLAY_HSV, value); + self + } + /// Enables/disables displaying the value as hex. + #[inline] + pub fn display_hex(mut self, value: bool) -> Self { + self.flags.set(ColorEditFlags::DISPLAY_HEX, value); + self + } + /// Sets the hue/saturation/value editor mode. + #[inline] + pub fn mode(mut self, mode: ColorPickerMode) -> Self { + self.flags.set( + ColorEditFlags::PICKER_HUE_BAR, + mode == ColorPickerMode::HueBar, + ); + self.flags.set( + ColorEditFlags::PICKER_HUE_WHEEL, + mode == ColorPickerMode::HueWheel, + ); + self + } + /// Sets the formatting style of color components. + #[inline] + pub fn format(mut self, format: ColorFormat) -> Self { + self.flags + .set(ColorEditFlags::UINT8, format == ColorFormat::U8); + self.flags + .set(ColorEditFlags::FLOAT, format == ColorFormat::Float); + self + } + + /// Builds the color picker. + /// + /// Returns true if the color value was changed. + pub fn build(mut self, ui: &Ui<'_>) -> bool { + self.flags.insert(ColorEditFlags::NO_ALPHA); + let mut value: [f32; 3] = MintVec3::from(*self.value).into(); + let changed = unsafe { + sys::igColorPicker3( + ui.scratch_txt(self.label), + value.as_mut_ptr(), + self.flags.bits() as _, + ) + }; + + if changed { + let as_vec3: MintVec3 = value.into(); + + *self.value = as_vec3.into(); + } + + changed + } +} + +// Builder for a color picker widget. +/// +/// # Examples +/// +/// ```no_run +/// # use imgui::*; +/// # let mut imgui = Context::create(); +/// # let ui = imgui.frame(); +/// # let mut color = [0.0, 0.0, 0.0, 1.0]; +/// let cp = ColorPicker::new(im_str!("color_picker"), &mut color); +/// if cp.build(&ui) { +/// println!("A color was picked"); +/// } +/// ``` +#[derive(Debug)] +#[must_use] +pub struct ColorPicker4<'a, Label, Color> { + label: Label, + value: &'a mut Color, + flags: ColorEditFlags, + ref_color: Option<[f32; 4]>, +} + +impl<'a, Label, Color> ColorPicker4<'a, Label, Color> +where + Label: AsRef, + MintVec4: From, + Color: From + Copy, +{ + /// Constructs a new color picker builder. + #[doc(alias = "ColorPicker4")] + pub fn new(label: Label, value: &'a mut Color) -> Self { + Self { + label, + value, flags: ColorEditFlags::empty(), ref_color: None, } @@ -499,26 +878,35 @@ impl<'a, T: AsRef> ColorPicker<'a, T> { } /// Sets the shown reference color. #[inline] - pub fn reference_color(mut self, ref_color: &'a [f32; 4]) -> Self { - self.ref_color = Some(ref_color); + pub fn reference_color(mut self, ref_color: impl Into) -> Self { + self.ref_color = Some(ref_color.into().into()); self } + /// Builds the color picker. /// /// Returns true if the color value was changed. pub fn build(mut self, ui: &Ui<'_>) -> bool { - if let EditableColor::Float3(_) = self.value { - self.flags.insert(ColorEditFlags::NO_ALPHA); - } + self.flags.insert(ColorEditFlags::NO_ALPHA); + let mut value: [f32; 4] = MintVec4::from(*self.value).into(); let ref_color = self.ref_color.map(|c| c.as_ptr()).unwrap_or(ptr::null()); - unsafe { + + let changed = unsafe { sys::igColorPicker4( ui.scratch_txt(self.label), - self.value.as_mut_ptr(), + value.as_mut_ptr(), self.flags.bits() as _, ref_color, ) + }; + + if changed { + let as_vec3: MintVec4 = value.into(); + + *self.value = as_vec3.into(); } + + changed } } @@ -544,10 +932,10 @@ pub struct ColorButton { impl> ColorButton { /// Constructs a new color button builder. - pub fn new(desc_id: T, color: [f32; 4]) -> Self { + pub fn new(desc_id: T, color: impl Into) -> Self { ColorButton { desc_id, - color, + color: color.into().into(), flags: ColorEditFlags::empty(), size: [0.0, 0.0], } @@ -614,8 +1002,8 @@ impl> ColorButton { /// /// Use 0.0 for width and/or height to use the default size. #[inline] - pub fn size(mut self, size: [f32; 2]) -> Self { - self.size = size; + pub fn size(mut self, size: impl Into) -> Self { + self.size = size.into().into(); self } /// Builds the color button.