[][src]Struct widgetry::widgets::button::ButtonBuilder

pub struct ButtonBuilder<'a> {
    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>,
    hover_style: ButtonStateStyle<'a>,
    disable_style: ButtonStateStyle<'a>,
}

Fields

padding: EdgeInsetsstack_spacing: f64hotkey: Option<MultiKey>tooltip: Option<Text>stack_axis: Option<Axis>is_label_before_image: boolcorner_rounding: Option<CornerRounding>is_disabled: booldefault_style: ButtonStateStyle<'a>hover_style: ButtonStateStyle<'a>disable_style: ButtonStateStyle<'a>

Implementations

impl<'b, 'a: 'b> ButtonBuilder<'a>[src]

pub fn new() -> Self[src]

pub fn padding<EI: Into<EdgeInsets>>(self, padding: EI) -> Self[src]

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);

pub fn padding_top(self, padding: f32) -> Self[src]

Extra spacing around a button's items (label and/or image).

pub fn padding_left(self, padding: f32) -> Self[src]

Extra spacing around a button's items (label and/or image).

pub fn padding_bottom(self, padding: f32) -> Self[src]

Extra spacing around a button's items (label and/or image).

pub fn padding_right(self, padding: f32) -> Self[src]

Extra spacing around a button's items (label and/or image).

pub fn label_text(self, text: &'a str) -> Self[src]

Set the text of the button's label.

If label_text is not set, the button will not have a label.

pub fn label_styled_text(
    self,
    styled_text: Text,
    for_state: ControlState
) -> Self
[src]

Assign a pre-styled Text instance if your button need something more than uniformly colored text.

pub fn label_color(self, color: Color, for_state: ControlState) -> Self[src]

Set the color of the button's label.

If not specified, a default font color will be used.

pub fn font(self, font: Font) -> Self[src]

Set the font used by the button's label.

If not specified, a default font will be used.

pub fn font_size(self, font_size: usize) -> Self[src]

Set the size of the font of the button's label.

If not specified, a default font size will be used.

pub fn image_path(self, path: &'a str) -> Self[src]

Set the image for the button. If not set, the button will have no image.

This will replace any image previously set.

pub fn image_bytes(self, labeled_bytes: (&'a str, &'a [u8])) -> Self[src]

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 with include_labeled_bytes!
  • label: a label to describe the bytes for debugging purposes
  • bytes: utf-8 encoded bytes of the svg

pub fn image_batch(self, batch: GeomBatch, bounds: Bounds) -> Self[src]

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.

pub fn image_color<C: Into<RewriteColor>>(
    self,
    color: C,
    for_state: ControlState
) -> Self
[src]

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.

pub fn image_bg_color(self, color: Color, for_state: ControlState) -> Self[src]

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.

pub fn image_dims<D: Into<ScreenDims>>(self, dims: D) -> Self[src]

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.

pub fn image_content_mode(self, content_mode: ContentMode) -> Self[src]

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.

pub fn image_corner_rounding<R: Into<CornerRounding>>(self, value: R) -> Self[src]

Set independent rounding for each of the button's image's corners

pub fn image_padding<EI: Into<EdgeInsets>>(self, value: EI) -> Self[src]

Set padding for the image

pub fn bg_color(self, color: Color, for_state: ControlState) -> Self[src]

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.

pub fn outline(
    self,
    thickness: f64,
    color: Color,
    for_state: ControlState
) -> Self
[src]

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.

pub fn custom_batch(self, batch: GeomBatch, for_state: ControlState) -> Self[src]

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.

pub fn hotkey<MK: Into<MultiKey>>(self, key: MK) -> Self[src]

Set a hotkey for the button

pub fn tooltip(self, tooltip: Text) -> Self[src]

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.

pub fn no_tooltip(self) -> Self[src]

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.

pub fn vertical(self) -> Self[src]

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.

pub fn horizontal(self) -> Self[src]

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.

pub fn disabled(self, is_disabled: bool) -> Self[src]

The button cannot be clicked and will be styled as ControlState::Disabled

pub fn label_first(self) -> Self[src]

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.

pub fn image_first(self) -> Self[src]

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.

pub fn stack_spacing(self, value: f64) -> Self[src]

Spacing between the image and text of a button. Has no effect if the button is text-only or image-only.

pub fn corner_rounding<R: Into<CornerRounding>>(self, value: R) -> Self[src]

Set independent rounding for each of the button's corners

pub fn build(&self, ctx: &EventCtx<'_>, action: &str) -> Button[src]

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");
}

pub fn build_widget(&self, ctx: &EventCtx<'_>, action: &str) -> Widget[src]

Shorthand method to build a Button wrapped in a Widget

action: The event that will be fired when clicked

pub fn build_def(&self, ctx: &EventCtx<'_>) -> Widget[src]

Shorthand method to build a default widget whose action is derived from the label's text.

fn style_mut(&'b mut self, state: ControlState) -> &'b mut ButtonStateStyle<'a>[src]

fn style(&'b self, state: ControlState) -> &'b ButtonStateStyle<'a>[src]

fn batch(&self, ctx: &EventCtx<'_>, for_state: ControlState) -> GeomBatch[src]

Trait Implementations

impl<'a> Clone for ButtonBuilder<'a>[src]

impl<'a> Debug for ButtonBuilder<'a>[src]

impl<'a> Default for ButtonBuilder<'a>[src]

Auto Trait Implementations

impl<'a> RefUnwindSafe for ButtonBuilder<'a>[src]

impl<'a> Send for ButtonBuilder<'a>[src]

impl<'a> Sync for ButtonBuilder<'a>[src]

impl<'a> Unpin for ButtonBuilder<'a>[src]

impl<'a> UnwindSafe for ButtonBuilder<'a>[src]

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Downcast for T where
    T: Any

impl<T> DowncastSync for T where
    T: Send + Sync + Any

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> Same<T> for T

type Output = T

Should always be Self

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.