pub struct ColorPickerState { /* private fields */ }Expand description
Retained state for a Material 3 ColorPicker.
Keeps swatches, HSLA sliders, the hex text field, transient hover previews, and the
popover open state synchronized. Use Self::argb to feed the committed color directly
into MaterialTheme::from_seed(...) when dynamic-color is enabled.
Implementations§
Source§impl ColorPickerState
impl ColorPickerState
Sourcepub fn new(
window: &mut Window,
cx: &mut Context<'_, ColorPickerState>,
) -> ColorPickerState
pub fn new( window: &mut Window, cx: &mut Context<'_, ColorPickerState>, ) -> ColorPickerState
Creates an empty, closed color picker state.
Sourcepub fn default_argb(
self,
argb: Argb,
window: &mut Window,
cx: &mut Context<'_, ColorPickerState>,
) -> ColorPickerState
pub fn default_argb( self, argb: Argb, window: &mut Window, cx: &mut Context<'_, ColorPickerState>, ) -> ColorPickerState
Sets the initial color from an Argb during state construction.
Sourcepub fn default_color(
self,
value: Hsla,
window: &mut Window,
cx: &mut Context<'_, ColorPickerState>,
) -> ColorPickerState
pub fn default_color( self, value: Hsla, window: &mut Window, cx: &mut Context<'_, ColorPickerState>, ) -> ColorPickerState
Sets the initial color from an Hsla during state construction.
Sourcepub fn preview(&self, cx: &App) -> Option<Hsla>
pub fn preview(&self, cx: &App) -> Option<Hsla>
Returns the transient hovered or typed preview color as Hsla.
Sourcepub fn preview_argb(&self, cx: &App) -> Option<Argb>
pub fn preview_argb(&self, cx: &App) -> Option<Argb>
Returns the transient preview color as Argb.
Sourcepub fn displayed_color(&self, cx: &App) -> Option<Hsla>
pub fn displayed_color(&self, cx: &App) -> Option<Hsla>
Returns the preview color, falling back to the committed color.
Sourcepub fn hex(&self, cx: &App) -> SharedString
pub fn hex(&self, cx: &App) -> SharedString
Returns the formatted hex string (#RRGGBB or #RRGGBBAA) of the displayed color,
or an empty string if no color is set.
Sourcepub fn set_color(
&mut self,
value: Hsla,
window: &mut Window,
cx: &mut Context<'_, ColorPickerState>,
)
pub fn set_color( &mut self, value: Hsla, window: &mut Window, cx: &mut Context<'_, ColorPickerState>, )
Replaces the committed color without emitting ColorPickerEvent::Change.
Sourcepub fn set_argb(
&mut self,
argb: Argb,
window: &mut Window,
cx: &mut Context<'_, ColorPickerState>,
)
pub fn set_argb( &mut self, argb: Argb, window: &mut Window, cx: &mut Context<'_, ColorPickerState>, )
Replaces the committed color from an Argb without emitting ColorPickerEvent::Change.
Sourcepub fn select_color(
&mut self,
value: Hsla,
window: &mut Window,
cx: &mut Context<'_, ColorPickerState>,
)
pub fn select_color( &mut self, value: Hsla, window: &mut Window, cx: &mut Context<'_, ColorPickerState>, )
Commits a color, closes the popover if open, and emits ColorPickerEvent::Change.
Sourcepub fn select_argb(
&mut self,
argb: Argb,
window: &mut Window,
cx: &mut Context<'_, ColorPickerState>,
)
pub fn select_argb( &mut self, argb: Argb, window: &mut Window, cx: &mut Context<'_, ColorPickerState>, )
Commits an Argb color, closes the popover if open, and emits ColorPickerEvent::Change.
Sourcepub fn clear(
&mut self,
window: &mut Window,
cx: &mut Context<'_, ColorPickerState>,
)
pub fn clear( &mut self, window: &mut Window, cx: &mut Context<'_, ColorPickerState>, )
Clears the committed color without emitting ColorPickerEvent::Change.
Sourcepub fn set_open(&mut self, open: bool, cx: &mut Context<'_, ColorPickerState>)
pub fn set_open(&mut self, open: bool, cx: &mut Context<'_, ColorPickerState>)
Sets whether the popover panel is open.
Sourcepub fn toggle_open(&mut self, cx: &mut Context<'_, ColorPickerState>)
pub fn toggle_open(&mut self, cx: &mut Context<'_, ColorPickerState>)
Toggles the popover panel open state.
Sourcepub fn focus(&self, window: &mut Window, cx: &mut Context<'_, ColorPickerState>)
pub fn focus(&self, window: &mut Window, cx: &mut Context<'_, ColorPickerState>)
Focuses the picker trigger.
Trait Implementations§
impl EventEmitter<ColorPickerEvent> for ColorPickerState
Source§impl Focusable for ColorPickerState
impl Focusable for ColorPickerState
Source§fn focus_handle(&self, cx: &App) -> FocusHandle
fn focus_handle(&self, cx: &App) -> FocusHandle
Source§impl Render for ColorPickerState
impl Render for ColorPickerState
Source§fn render(
&mut self,
_: &mut Window,
_: &mut Context<'_, ColorPickerState>,
) -> impl IntoElement
fn render( &mut self, _: &mut Window, _: &mut Context<'_, ColorPickerState>, ) -> impl IntoElement
Auto Trait Implementations§
impl !RefUnwindSafe for ColorPickerState
impl !Send for ColorPickerState
impl !Sync for ColorPickerState
impl !UnwindSafe for ColorPickerState
impl Forget for ColorPickerState
impl Freeze for ColorPickerStatewhere
NonZero<u32>: Freeze,
*const (): Freeze,
*const ArcInner<RwLock<RawRwLock, EntityRefCounts>> is !null: Freeze,
PhantomData<fn(ColorPickerState) -> ColorPickerState>: Freeze,
*const u8 is !null: Freeze,
PhantomData<Subscription>: Freeze,
impl Move for ColorPickerState
impl Unpin for ColorPickerState
impl UnsafeUnpin for ColorPickerStatewhere
NonZeroU32Inner: UnsafeUnpin,
*const (): UnsafeUnpin,
*const ArcInner<RwLock<RawRwLock, EntityRefCounts>> is !null: UnsafeUnpin,
PhantomData<fn(ColorPickerState) -> ColorPickerState>: UnsafeUnpin,
*const u8 is !null: UnsafeUnpin,
PhantomData<Subscription>: UnsafeUnpin,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
impl<T> ErasedDestructor for Twhere
T: 'static,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more