pub struct Button<'a, Message, W = Element<'a, Message, Theme, Renderer<Renderer, Renderer>>, Theme = Theme>where
Theme: Catalog,{ /* private fields */ }Expand description
A generic widget that produces a message when pressed.
§Example
use iced::widget::button;
#[derive(Clone)]
enum Message {
ButtonPressed,
}
fn view(state: &State) -> impl Widget<Message> {
button("Press me!").on_press(Message::ButtonPressed)
}If a Button::on_press handler is not set, the resulting Button will
be disabled:
use iced::widget::button;
#[derive(Clone)]
enum Message {
ButtonPressed,
}
fn view(state: &State) -> impl Widget<Message> {
button("I am disabled!")
}Implementations§
Source§impl<'a, Message, W, Theme> Button<'a, Message, W, Theme>where
Theme: Catalog,
impl<'a, Message, W, Theme> Button<'a, Message, W, Theme>where
Theme: Catalog,
Sourcepub fn new(content: W) -> Button<'a, Message, W, Theme>
pub fn new(content: W) -> Button<'a, Message, W, Theme>
Creates a new Button with the given content.
Sourcepub fn width(self, width: impl Into<Length>) -> Button<'a, Message, W, Theme>
pub fn width(self, width: impl Into<Length>) -> Button<'a, Message, W, Theme>
Sets the width of the Button.
Sourcepub fn height(self, height: impl Into<Length>) -> Button<'a, Message, W, Theme>
pub fn height(self, height: impl Into<Length>) -> Button<'a, Message, W, Theme>
Sets the height of the Button.
Sourcepub fn on_press_with(
self,
on_press: impl Fn() -> Message + 'a,
) -> Button<'a, Message, W, Theme>
pub fn on_press_with( self, on_press: impl Fn() -> Message + 'a, ) -> Button<'a, Message, W, Theme>
Sets the message that will be produced when the Button is pressed.
This is analogous to Button::on_press, but using a closure to produce
the message.
This closure will only be called when the Button is actually pressed and,
therefore, this method is useful to reduce overhead if creating the resulting
message is slow.
Sourcepub fn on_press_maybe(
self,
on_press: Option<Message>,
) -> Button<'a, Message, W, Theme>
pub fn on_press_maybe( self, on_press: Option<Message>, ) -> Button<'a, Message, W, Theme>
Sourcepub fn on_press_maybe_with(
self,
on_press: Option<impl Fn() -> Message + 'a>,
) -> Button<'a, Message, W, Theme>
pub fn on_press_maybe_with( self, on_press: Option<impl Fn() -> Message + 'a>, ) -> Button<'a, Message, W, Theme>
Sets the message that will be produced when the Button is pressed,
if Some.
This is analogous to Button::on_press, but using a closure to produce
the message.
This closure will only be called when the Button is actually pressed and,
therefore, this method is useful to reduce overhead if creating the resulting
message is slow.
If None, the Button will be disabled.
Sourcepub fn clip(self, clip: bool) -> Button<'a, Message, W, Theme>
pub fn clip(self, clip: bool) -> Button<'a, Message, W, Theme>
Sets whether the contents of the Button should be clipped on
overflow.
Trait Implementations§
Source§impl<'a, Message, W, Theme, Renderer> Widget<Message, Theme, Renderer> for Button<'a, Message, W, Theme>
impl<'a, Message, W, Theme, Renderer> Widget<Message, Theme, Renderer> for Button<'a, Message, W, Theme>
Source§fn operate(
&mut self,
tree: &mut Tree,
layout: Layout,
viewport: &Rectangle,
renderer: &Renderer,
operation: &mut dyn Operation,
)
fn operate( &mut self, tree: &mut Tree, layout: Layout, viewport: &Rectangle, renderer: &Renderer, operation: &mut dyn Operation, )
Source§fn update(
&mut self,
tree: &mut Tree,
event: &Event,
layout: Layout,
cursor: Cursor,
renderer: &Renderer,
shell: &mut Shell<'_, Message>,
viewport: &Rectangle,
)
fn update( &mut self, tree: &mut Tree, event: &Event, layout: Layout, cursor: Cursor, renderer: &Renderer, shell: &mut Shell<'_, Message>, viewport: &Rectangle, )
Source§fn draw(
&self,
tree: &Tree,
renderer: &mut Renderer,
theme: &Theme,
_style: &Style,
layout: Layout,
cursor: Cursor,
viewport: &Rectangle,
)
fn draw( &self, tree: &Tree, renderer: &mut Renderer, theme: &Theme, _style: &Style, layout: Layout, cursor: Cursor, viewport: &Rectangle, )
Widget using the associated Renderer.Source§fn mouse_interaction(
&self,
_tree: &Tree,
layout: Layout,
cursor: Cursor,
_viewport: &Rectangle,
_renderer: &Renderer,
) -> Interaction
fn mouse_interaction( &self, _tree: &Tree, layout: Layout, cursor: Cursor, _viewport: &Rectangle, _renderer: &Renderer, ) -> Interaction
Source§fn overlay<'b>(
&'b mut self,
tree: &'b mut Tree,
layout: Layout,
renderer: &Renderer,
viewport: &Rectangle,
translation: Vector,
window: Size,
) -> Vec<Element<'b, Message, Theme, Renderer>>
fn overlay<'b>( &'b mut self, tree: &'b mut Tree, layout: Layout, renderer: &Renderer, viewport: &Rectangle, translation: Vector, window: Size, ) -> Vec<Element<'b, Message, Theme, Renderer>>
Widget.Auto Trait Implementations§
impl<'a, Message, W, Theme> Freeze for Button<'a, Message, W, Theme>
impl<'a, Message, W = Element<'a, Message, Theme, Renderer<Renderer, Renderer>>, Theme = Theme> !RefUnwindSafe for Button<'a, Message, W, Theme>
impl<'a, Message, W = Element<'a, Message, Theme, Renderer<Renderer, Renderer>>, Theme = Theme> !Send for Button<'a, Message, W, Theme>
impl<'a, Message, W = Element<'a, Message, Theme, Renderer<Renderer, Renderer>>, Theme = Theme> !Sync for Button<'a, Message, W, Theme>
impl<'a, Message, W, Theme> Unpin for Button<'a, Message, W, Theme>
impl<'a, Message, W, Theme> UnsafeUnpin for Button<'a, Message, W, Theme>
impl<'a, Message, W = Element<'a, Message, Theme, Renderer<Renderer, Renderer>>, Theme = Theme> !UnwindSafe for Button<'a, Message, W, Theme>
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<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<State, Message> IntoBoot<State, Message> for State
impl<State, Message> IntoBoot<State, Message> for State
Source§fn into_boot(self) -> (State, Task<Message>)
fn into_boot(self) -> (State, Task<Message>)
Application.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