Skip to main content

ColorPicker

Struct ColorPicker 

Source
pub struct ColorPicker<'a> { /* private fields */ }
Expand description

A click-to-open color picker bound to a Color32.

The widget paints a compact swatch-and-hex trigger; the picker UI lives in a Popover. Configure which sub-controls the popover shows via the builder. By default the popover contains a continuous picker (saturation/value plane plus hue slider), an alpha slider, and a hex input.

Implementations§

Source§

impl<'a> ColorPicker<'a>

Source

pub fn new(id_salt: impl Hash, color: &'a mut Color32) -> Self

Create a color picker keyed by id_salt and bound to color. Defaults: continuous picker on, alpha slider on, hex input on, recents tracked, opens below the trigger.

Source

pub fn label(self, label: impl Into<WidgetText>) -> Self

Show a label above the trigger.

Source

pub fn palette(self, palette: impl IntoIterator<Item = Color32>) -> Self

Supply a curated palette grid above the recents row. When unset (the default) no palette is shown. Use ColorPicker::default_palette for a 30-swatch starter palette inspired by Tailwind.

Source

pub fn palette_columns(self, n: usize) -> Self

Number of columns in the palette grid. Default: 10.

Source

pub fn continuous(self, on: bool) -> Self

Toggle the continuous saturation/value plane and hue slider. Default: on.

Source

pub fn alpha(self, on: bool) -> Self

Toggle the alpha slider. Default: on. Disable for opaque-only colors.

Source

pub fn hex_input(self, on: bool) -> Self

Toggle the hex input row inside the popover. Default: on.

Source

pub fn hex_label(self, on: bool) -> Self

Show or hide the hex string next to the swatch on the trigger button. Default: shown.

Source

pub fn recents(self, on: bool) -> Self

Toggle the recents row. The recent picks are persisted in egui context memory keyed by the picker’s id_salt. Default: on.

Source

pub fn recents_max(self, n: usize) -> Self

Maximum number of recent picks remembered. Default: 10.

Source

pub fn side(self, side: PopoverSide) -> Self

Which side of the trigger the popover opens on. Default: below.

Source

pub fn default_palette() -> Vec<Color32>

A 30-swatch curated palette: a row of neutrals, a row of cool accents, and a row of warm accents. Pass to ColorPicker::palette.

Trait Implementations§

Source§

impl<'a> Debug for ColorPicker<'a>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'a> Widget for ColorPicker<'a>

Source§

fn ui(self, ui: &mut Ui) -> Response

Allocate space, interact, paint, and return a Response. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for ColorPicker<'a>

§

impl<'a> RefUnwindSafe for ColorPicker<'a>

§

impl<'a> Send for ColorPicker<'a>

§

impl<'a> Sync for ColorPicker<'a>

§

impl<'a> Unpin for ColorPicker<'a>

§

impl<'a> UnsafeUnpin for ColorPicker<'a>

§

impl<'a> !UnwindSafe for ColorPicker<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, S> SimdFrom<T, S> for T
where S: Simd,

Source§

fn simd_from(value: T, _simd: S) -> T

Source§

impl<F, T, S> SimdInto<T, S> for F
where T: SimdFrom<F, S>, S: Simd,

Source§

fn simd_into(self, simd: S) -> T

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.