Card

A customizable card widget with hover and press animations, configurable colors, cursor behavior, and optional scroll bars.

Example

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

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

    GCardExample = <ScrollYView>{
        height: 660.0,
        width: Fill,
        flow: Down,
        spacing: 10.0,
        <Label>{
            text: "GCard",
        }
        <GCard>{
            height: 30.0,
            width: 30.0,
        }
        <GCard>{
            theme: Dark,
            height: 30.0,
            width: 30.0,
        }
        <GCard>{
            theme: Error,
            height: 30.0,
            width: 30.0,
        }
        <GCard>{
            theme: Warning,
            height: 30.0,
            width: 30.0,
            animator_key: true,
        }
        <GCard>{
            theme: Success,
            height: 30.0,
            width: 160.0,
            cursor: Help,
            align: {x: 0.5, y: 0.5},
            <GLabel>{
                text: "cursor: Help",
            }
        }
        <GCard>{
            theme: Error,
            height: Fit,
            width: 180.0,
            transparent: true,
            border_width: 1.0,
            border_radius: 0.0,
            align: {x: 0.5, y: 0.5},
            <GLabel>{
                margin: 20.0,
                text: "Transparent GCard",
            }
        }
        <GCard>{
            theme: Success,
            height: 60.0,
            width: 60.0,
            border_color: #FF0000,
            border_width: 1.0,
            border_radius: 15.0,
        }
        <GCard>{
            height: Fit,
            width: 300,
            flow: Down,
            background_color: #FFFFFF,
            spacing: 10.0,
            <GLabel>{
                text: "GCard flow Down",
                color: #0,
                margin: 10.0,
            }
            <GCard>{
                theme: Error,
                height: 30.0,
                width: 30.0,
            }
            <GCard>{
                theme: Warning,
                height: 30.0,
                width: 30.0,
            }
            <GButton>{
                text: "hello"
            }
        }
        
        <GCard>{
            height: 100.0,
            width: 300,
            flow: Down,
            background_color: #FF0000,
            spacing: 10.0,
            // transparent: true,
            scroll_bars: <GScrollBars> {}
            <GLabel>{
                text: "Card can scroll",
                color: #0,
                margin: 10.0,
            }
            <GCard>{
                theme: Error,
                height: 30.0,
                width: 30.0,
            }
            <GCard>{
                theme: Warning,
                height: 30.0,
                width: 30.0,
            }
            <GButton>{
                text: "hello"
            }
        }
    }
}
}

Props

decoratenametypedescription
livethemeThemesThe theme applied to the card.
livebackground_colorOption<Vec4>The background color of the card.
livehover_colorOption<Vec4>The color of the card when hovered.
livepressed_colorOption<Vec4>The color of the card when pressed.
liveborder_colorOption<Vec4>The border color of the card.
liveborder_widthf32The width of the card's border.
liveborder_radiusf32The radius of the card's border.
livevisibleboolWhether the card is visible.
livetransparentboolWhether the card background is transparent.
livecursorOption<MouseCursor>The cursor type when hovering over the card.
liveanimator_keyboolWhether the card uses an animation key.
livescroll_barsOption<LivePtr>The optional scroll bars for the card.
rustscroll_bars_objOption<Box<ScrollBars>>The scroll bars object.
livegrab_key_focusboolWhether the card grabs key focus when clicked.
liveblock_signal_eventboolWhether the card blocks signal events.
livedraw_cardDrawCardThe component used for drawing the card.
walkwalkWalkThe positioning properties for the card.
layoutlayoutLayoutThe layout properties for the card.
rustdraw_stateDrawStateWrap<DrawState>The draw state of the card.
rustchildrenComponentMap<LiveId, WidgetRef>The children components of the card.
rustdraw_orderVec<LiveId>The draw order of the card's children.
liveevent_orderEventOrderThe event order for the card.
rustdefer_walksVec<(LiveId, DeferWalk)>The deferred walks for the card.
animatoranimatorAnimatorThe animation properties for the card.

Event

namedescription
KeyDownTriggered when a key is pressed down.
KeyUpTriggered when a key is released.
FingerDownTriggered when a finger touches the card.
FingerMoveTriggered when a finger moves over the card.
FingerHoverInTriggered when a finger hovers over the card.
FingerHoverOverTriggered when a finger moves while hovering over the card.
FingerHoverOutTriggered when a finger stops hovering over the card.
FingerUpTriggered when a finger is lifted from the card.