Struct widgetry::ButtonBuilder [−][src]
pub struct ButtonBuilder<'a, 'c> {
padding: EdgeInsets,
stack_spacing: f64,
hotkey: Option<MultiKey>,
tooltip: Option<Text>,
stack_axis: Option<Axis>,
is_label_before_image: bool,
corner_rounding: Option<CornerRounding>,
is_disabled: bool,
default_style: ButtonStateStyle<'a, 'c>,
hover_style: ButtonStateStyle<'a, 'c>,
disable_style: ButtonStateStyle<'a, 'c>,
disabled_tooltip: Option<Text>,
}
Fields
padding: EdgeInsets
stack_spacing: f64
hotkey: Option<MultiKey>
tooltip: Option<Text>
stack_axis: Option<Axis>
is_label_before_image: bool
corner_rounding: Option<CornerRounding>
is_disabled: bool
default_style: ButtonStateStyle<'a, 'c>
hover_style: ButtonStateStyle<'a, 'c>
disable_style: ButtonStateStyle<'a, 'c>
disabled_tooltip: Option<Text>
Implementations
Extra spacing around a button’s items (label and/or image).
If not specified, a default will be applied.
// Custom padding for each inset
let b = ButtonBuilder::new().padding(EdgeInsets{ top: 1.0, bottom: 2.0, left: 12.0, right: 14.0 });
// uniform padding
let b = ButtonBuilder::new().padding(6);
Extra spacing around a button’s items (label and/or image).
Extra spacing around a button’s items (label and/or image).
Extra spacing around a button’s items (label and/or image).
Extra spacing around a button’s items (label and/or image).
Set the text of the button’s label.
If label_text
is not set, the button will not have a label.
Set the text of the button’s label. The text will be decorated with an underline.
See label_styled_text
if you need something more customizable text styling.
Assign a pre-styled Text
instance if your button need something more than uniformly
colored text.
Set the color of the button’s label.
If not specified, a default font color will be used.
Set the font used by the button’s label.
If not specified, a default font will be used.
Set the size of the font of the button’s label.
If not specified, a default font size will be used.
Set the image for the button. If not set, the button will have no image.
This will replace any image previously set.
Set the image for the button. If not set, the button will have no image.
This will replace any image previously set.
labeled_bytes
: is a (label
,bytes
) tuple you can generate withinclude_labeled_bytes!
label
: a label to describe the bytes for debugging purposesbytes
: UTF-8 encoded bytes of the SVG
Set the image for the button. If not set, the button will have no image.
This will replace any image previously set.
This method is useful when doing more complex transforms. For example, to re-write more than one color for your button image, do so externally and pass in the resultant GeomBatch here.
Rewrite the color of the button’s image.
This has no effect if the button does not have an image.
If the style hasn’t been set for the current ControlState, the style for
ControlState::Default
will be used.
Set a background color for the image, other than the buttons background.
This has no effect if the button does not have an image.
If the style hasn’t been set for the current ControlState, the style for
ControlState::Default
will be used.
Scale the bounds containing the image. If image_dims
are not specified, the images
intrinsic size will be used.
See ButtonBuilder::image_content_mode
to control how the image scales to fit
its custom bounds.
If a custom image_dims
was set, control how the image should be scaled to its new bounds
If image_dims
were not specified, the image will not be scaled, so content_mode has no
affect.
The default, ContentMode::ScaleAspectFit
will only grow as much as it can while
maintaining its aspect ratio and not exceeding its bounds.
Set independent rounding for each of the button’s image’s corners
Set padding for the image
Set a background color for the button based on the button’s ControlState
.
If the style hasn’t been set for the current ControlState, the style for
ControlState::Default
will be used.
Set an outline for the button based on the button’s ControlState
.
If the style hasn’t been set for the current ControlState, the style for
ControlState::Default
will be used.
Set a pre-rendered GeomBatch to use for the button instead of individual fields.
This is useful for applying one-off button designs that can’t be accommodated by the the existing ButtonBuilder methods.
Set a non-default tooltip Text
to appear when hovering over the button.
If a tooltip
is not specified, a default tooltip will be applied.
If a tooltip
is not specified, a default tooltip will be applied. Use no_tooltip
when
you do not want even the default tooltip to appear.
Set a tooltip Text
to appear when hovering over the button, when the button is
disabled.
This tooltip is only displayed when disabled(true)
is also called.
The button’s items will be rendered in a vertical column
If the button doesn’t have both an image and label, this has no effect.
The button’s items will be rendered in a horizontal row
If the button doesn’t have both an image and label, this has no effect.
The button cannot be clicked and will be styled as ControlState::Disabled
Display the button’s label before the button’s image.
If the button doesn’t have both an image and label, this has no effect.
Display the button’s image before the button’s label.
If the button doesn’t have both an image and label, this has no effect.
Spacing between the image and text of a button. Has no effect if the button is text-only or image-only.
Set independent rounding for each of the button’s corners
Build a button.
action
: The event that will be fired when clicked
fn build_some_buttons(ctx: &EventCtx) {
let one_off_builder = ButtonBuilder::new().label_text("foo").build(ctx, "foo");
// If you'd like to build a series of similar buttons, `clone` the builder first.
let red_builder = ButtonBuilder::new()
.bg_color(Color::RED, ControlState::Default)
.bg_color(Color::RED.alpha(0.3), ControlState::Disabled)
.outline((2.0, Color::WHITE), ControlState::Default);
let red_button_1 = red_builder.clone().label_text("First red button").build(ctx, "first");
let red_button_2 = red_builder.clone().label_text("Second red button").build(ctx, "second");
let red_button_3 = red_builder.label_text("Last red button").build(ctx, "third");
}
Shorthand method to build a Button wrapped in a Widget
action
: The event that will be fired when clicked
Shorthand method to build a default widget whose action
is derived from the label’s text.
Trait Implementations
Returns the “default value” for a type. Read more
Auto Trait Implementations
impl<'a, 'c> RefUnwindSafe for ButtonBuilder<'a, 'c>
impl<'a, 'c> Send for ButtonBuilder<'a, 'c>
impl<'a, 'c> Sync for ButtonBuilder<'a, 'c>
impl<'a, 'c> Unpin for ButtonBuilder<'a, 'c> where
'a: 'c,
impl<'a, 'c> UnwindSafe for ButtonBuilder<'a, 'c>
Blanket Implementations
Mutably borrows from an owned value. Read more
impl<T> Downcast for T where
T: Any,
impl<T> Downcast for T where
T: Any,
Convert 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
. Read more
pub fn into_any_rc(self: Rc<T>) -> Rc<dyn Any + 'static>
pub fn into_any_rc(self: Rc<T>) -> Rc<dyn Any + 'static>
Convert Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
. Rc<Any>
can then be
further downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
. Read more
Convert &Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s. Read more
pub fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
pub fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Convert &mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s. Read more
type Output = T
type Output = T
Should always be Self