GButton

A customizable button widget with hover and press animations, configurable colors, cursor behavior, and text properties.

Example

#![allow(unused)]
fn main() {
use makepad_widgets::*;

live_design! {
    import makepad_widgets::base::*;
    import makepad_widgets::theme_desktop_dark::*; 
    import gen_components::components::*;

    GButtonExample = <ScrollYView>{
        height: 200.0,
        width: Fill,
        flow: Down,
        spacing: 10.0,
        <Label>{
            text: "GButton"
        }
        <GButton>{
            text: "Default Button"
        }
        <GButton>{
            theme: Dark,
            text: "Theme Dark"
        }
        <GButton>{
            theme: Success,
            text: "Theme Success"
        }
        <GButton>{
            theme: Warning,
            text: "Theme Warning"
        }
        <GButton>{
            theme: Error,
            text: "Theme Error",
        }
        <GButton>{
            theme: Error,
            text: "unvisible button!",
            visible: false,
        }
        <GButton>{
            round: true,
            text: "Round Button",
        }
        <GButton>{
            height: 46,
            width: 160,
            theme: Success,
            border_width: 1.4,
            border_color: #FFF,
            border_radius: 11.0,
            text: "Rounded Button!",
        }
        <GButton>{
            theme: Dark,
            border_width: 1.2,
            hover_color: #FF0000,
            pressed_color: #00FF00,
            text: "GButton!",
            font_family: dep("E:/Rust/try/makepad/Gen-UI/examples/gen_widget_example/resources/GoNotoKurrent-Bold.ttf"),
            font_size: 12.0,
            color: #000,
        }
    }
}
}

Props

decoratenametypedescription
livethemeThemesThe theme applied to the button.
livebackground_colorOption<Vec4>The background color of the button.
livehover_colorOption<Vec4>The color of the button when hovered.
livepressed_colorOption<Vec4>The color of the button when pressed.
liveborder_colorOption<Vec4>The border color of the button.
liveborder_widthf32The width of the button's border.
liveborder_radiusf32The radius of the button's border.
liveroundboolWhether the button has rounded corners.
livetextRcStringMutThe text displayed on the button.
livefont_sizef64The font size of the button text.
livecolorOption<Vec4>The color of the button text.
livefont_familyLiveDependencyThe font family used for the button text.
livecursorOption<MouseCursor>The cursor type when hovering over the button.
livevisibleboolWhether the button is visible.
livedraw_textDrawTextThe component used for drawing the button text.
livetext_walkWalkThe positioning properties for the button text.
livegrab_key_focusboolWhether the button grabs key focus when clicked.
animatoranimatorAnimatorThe animation properties for the button.
redrawdraw_buttonDrawCardThe component used for drawing the button.
walkwalkWalkThe positioning properties for the button.
layoutlayoutLayoutThe layout properties for the button.

Event

namedescription
HoveredTriggered when the button is hovered.
ClickedTriggered when the button is clicked.
ReleasedTriggered when the button is released.
PressedTriggered when the button is pressed.