pub struct ColorPickerState { /* private fields */ }Expand description
State and interaction model for a color picker.
This owns the committed color, the transient preview shown while the user hovers or edits, the controlled open state, the active panel, and the hex field and component sliders that stay in sync with all of them. The application owns the palette, popup, layout, and every visual decision.
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 picker.
Sourcepub fn default_value(self, value: impl Into<Hsla>) -> ColorPickerState
pub fn default_value(self, value: impl Into<Hsla>) -> ColorPickerState
Sets the initial committed and previewed color.
Sourcepub fn displayed_color(&self) -> Option<Hsla>
pub fn displayed_color(&self) -> Option<Hsla>
Returns the previewed color, falling back to the committed color.
Sourcepub fn hex_input(&self) -> &Entity<InputBaseState<InputMode>>
pub fn hex_input(&self) -> &Entity<InputBaseState<InputMode>>
The hex text field. Render it with an application-owned input element.
Sourcepub fn sliders(&self) -> &HslaSliders
pub fn sliders(&self) -> &HslaSliders
The HSLA component sliders.
Sourcepub fn set_value(
&mut self,
value: impl Into<Hsla>,
window: &mut Window,
cx: &mut Context<'_, ColorPickerState>,
)
pub fn set_value( &mut self, value: impl Into<Hsla>, window: &mut Window, cx: &mut Context<'_, ColorPickerState>, )
Replaces the committed color without emitting a change.
Sourcepub fn clear_value(
&mut self,
window: &mut Window,
cx: &mut Context<'_, ColorPickerState>,
)
pub fn clear_value( &mut self, window: &mut Window, cx: &mut Context<'_, ColorPickerState>, )
Clears the committed color without emitting a change.
Sourcepub fn sync_pending_value(
&mut self,
window: &mut Window,
cx: &mut Context<'_, ColorPickerState>,
)
pub fn sync_pending_value( &mut self, window: &mut Window, cx: &mut Context<'_, ColorPickerState>, )
Applies a value supplied to Self::default_value to the hex field and
sliders. Call this from render; it is a no-op once nothing is pending.
Sourcepub fn preview_color(
&mut self,
value: Hsla,
window: &mut Window,
cx: &mut Context<'_, ColorPickerState>,
)
pub fn preview_color( &mut self, value: Hsla, window: &mut Window, cx: &mut Context<'_, ColorPickerState>, )
Updates the transient preview color and the hex field that shows it.
Sourcepub fn clear_preview(
&mut self,
window: &mut Window,
cx: &mut Context<'_, ColorPickerState>,
)
pub fn clear_preview( &mut self, window: &mut Window, cx: &mut Context<'_, ColorPickerState>, )
Drops the transient preview, restoring the committed color.
Sourcepub fn preview_hex(
&mut self,
value: &str,
_: &mut Window,
cx: &mut Context<'_, ColorPickerState>,
) -> bool
pub fn preview_hex( &mut self, value: &str, _: &mut Window, cx: &mut Context<'_, ColorPickerState>, ) -> bool
Parses a hex color into the transient preview.
Invalid or incomplete input leaves the current preview unchanged. This does not write the hex field, so it is safe to call while typing in it.
Sourcepub fn commit_hex(
&mut self,
value: &str,
window: &mut Window,
cx: &mut Context<'_, ColorPickerState>,
) -> Option<Hsla>
pub fn commit_hex( &mut self, value: &str, window: &mut Window, cx: &mut Context<'_, ColorPickerState>, ) -> Option<Hsla>
Parses and commits a hex color, closing the picker on success.
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 and closes the picker, as a palette selection does.
Sourcepub fn update_color(
&mut self,
value: Hsla,
window: &mut Window,
cx: &mut Context<'_, ColorPickerState>,
)
pub fn update_color( &mut self, value: Hsla, window: &mut Window, cx: &mut Context<'_, ColorPickerState>, )
Commits a color without changing the open state, as a slider drag does.
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 picker popup is open.
Sourcepub fn toggle_open(&mut self, cx: &mut Context<'_, ColorPickerState>)
pub fn toggle_open(&mut self, cx: &mut Context<'_, ColorPickerState>)
Toggles the picker popup.
Sourcepub fn set_active_tab(
&mut self,
tab: usize,
cx: &mut Context<'_, ColorPickerState>,
)
pub fn set_active_tab( &mut self, tab: usize, cx: &mut Context<'_, ColorPickerState>, )
Selects the application-defined picker panel.
Sourcepub fn active_tab(&self) -> usize
pub fn active_tab(&self) -> usize
Returns the selected application-defined picker panel.
Trait Implementations§
impl EventEmitter<ColorPickerEvent> for ColorPickerState
Source§impl Focusable for ColorPickerState
impl Focusable for ColorPickerState
Source§fn focus_handle(&self, _: &App) -> FocusHandle
fn focus_handle(&self, _: &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 Freeze for ColorPickerState
impl Unpin for ColorPickerState
impl UnsafeUnpin for ColorPickerState
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
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