pub struct ImageButton { /* private fields */ }Expand description
State-specific segmented image button.
§State fallback (§5.D)
When a state’s middle source is absent, the widget walks a fallback chain until a middle source is found:
Pressed→ReleasedCheckedReleased→ReleasedCheckedPressed→CheckedReleased→Pressed→ReleasedDisabled→ReleasedCheckedDisabled→CheckedReleased→Released
§Event handling
Pointer PressDown inside bounds sets the visual pressed state.
PressRelease inside bounds activates the button (returns true).
Disabled buttons consume no activation.
Implementations§
Source§impl ImageButton
impl ImageButton
Sourcepub fn new(bounds: Rect) -> Self
pub fn new(bounds: Rect) -> Self
Create a new image button occupying bounds in the released state.
Sourcepub fn set_src(
&mut self,
state: ImageButtonState,
left: Option<ImageDescriptor<'static>>,
middle: Option<ImageDescriptor<'static>>,
right: Option<ImageDescriptor<'static>>,
)
pub fn set_src( &mut self, state: ImageButtonState, left: Option<ImageDescriptor<'static>>, middle: Option<ImageDescriptor<'static>>, right: Option<ImageDescriptor<'static>>, )
Set the left, middle, and right sources for state.
Pass None for any segment that should be absent. The middle segment
must be set for the button to draw content; a missing middle is allowed
but produces no visible image.
Sourcepub fn src_left(
&self,
state: ImageButtonState,
) -> Option<&ImageDescriptor<'static>>
pub fn src_left( &self, state: ImageButtonState, ) -> Option<&ImageDescriptor<'static>>
Return the left source configured for state (no fallback applied).
Sourcepub fn src_middle(
&self,
state: ImageButtonState,
) -> Option<&ImageDescriptor<'static>>
pub fn src_middle( &self, state: ImageButtonState, ) -> Option<&ImageDescriptor<'static>>
Return the middle source configured for state (no fallback applied).
Sourcepub fn src_right(
&self,
state: ImageButtonState,
) -> Option<&ImageDescriptor<'static>>
pub fn src_right( &self, state: ImageButtonState, ) -> Option<&ImageDescriptor<'static>>
Return the right source configured for state (no fallback applied).
Sourcepub fn set_state(&mut self, state: ImageButtonState)
pub fn set_state(&mut self, state: ImageButtonState)
Set the app-controlled base state.
Use ImageButtonState::Disabled or ImageButtonState::CheckedDisabled
to prevent pointer activation.
Sourcepub fn state(&self) -> ImageButtonState
pub fn state(&self) -> ImageButtonState
Return the app-controlled base state.
Sourcepub fn set_checked(&mut self, checked: bool)
pub fn set_checked(&mut self, checked: bool)
Set the checked (toggled on) state.
Sourcepub fn draw_state(&self) -> ImageButtonState
pub fn draw_state(&self) -> ImageButtonState
Compute the effective draw state from the base state, checked flag, and whether a pointer is currently held.
Trait Implementations§
Source§impl Widget for ImageButton
impl Widget for ImageButton
Source§fn set_bounds(&mut self, bounds: Rect)
fn set_bounds(&mut self, bounds: Rect)
Source§fn handle_event(&mut self, event: &Event) -> bool
fn handle_event(&mut self, event: &Event) -> bool
true if it was consumed. Read moreSource§fn clear_region(&mut self) -> Option<Rect>
fn clear_region(&mut self) -> Option<Rect>
None. Read more