Skip to main content

Card

Struct Card 

Source
pub struct Card<'a> {
    pub title: Option<&'a str>,
    pub variant: CardVariant,
    pub clickable: bool,
    pub width: Option<f32>,
    pub height: Option<f32>,
    pub min_height: Option<f32>,
    pub max_height: Option<f32>,
    pub inner_margin: Option<f32>,
    pub margin: Option<Margin>,
    pub fill_color: Option<Color32>,
    pub stroke_color: Option<Color32>,
    pub corner_radius: Option<f32>,
}
Expand description

Card component styled like shadcn/ui

Fields§

§title: Option<&'a str>

Optional title for the card

§variant: CardVariant

Card variant (Filled, Outlined, Elevated)

§clickable: bool

Whether the card is clickable (adds hover effect)

§width: Option<f32>

Custom width (None = fill available)

§height: Option<f32>

Custom height (None = determined by content)

§min_height: Option<f32>

Custom min height

§max_height: Option<f32>

Custom max height

§inner_margin: Option<f32>

Custom inner margin (None = use theme default)

§margin: Option<Margin>

Custom asymmetric margin (overrides inner_margin if set)

§fill_color: Option<Color32>

Custom background color (None = use theme default)

§stroke_color: Option<Color32>

Custom border color (None = use theme default)

§corner_radius: Option<f32>

Custom corner radius (None = use theme default)

Implementations§

Source§

impl<'a> Card<'a>

Source

pub const fn new() -> Self

Create a new card with default Filled variant

Source

pub const fn title(self, title: &'a str) -> Self

Set the card title

Source

pub const fn height(self, height: f32) -> Self

Set custom height (forces exact height regardless of content)

Source

pub const fn min_height(self, height: f32) -> Self

Set minimum height

Source

pub const fn max_height(self, height: f32) -> Self

Set maximum height

Source

pub const fn variant(self, variant: CardVariant) -> Self

Set the card variant

Source

pub const fn clickable(self, clickable: bool) -> Self

Make the card clickable (adds hover effect)

Source

pub const fn width(self, width: f32) -> Self

Set custom width

Source

pub const fn inner_margin(self, margin: f32) -> Self

Set custom inner margin (overrides theme default)

Source

pub const fn margin(self, margin: Margin) -> Self

Set custom asymmetric margin (overrides inner_margin) Use this for different padding on each side

Source

pub const fn fill(self, color: Color32) -> Self

Set custom fill/background color (overrides theme default)

Source

pub const fn stroke(self, color: Color32) -> Self

Set custom stroke/border color (overrides theme default)

Source

pub const fn corner_radius(self, radius: f32) -> Self

Set custom corner radius (overrides theme default)

Source

pub const fn rounding(self, radius: f32) -> Self

Alias for corner_radius for backwards compatibility

Source

pub const fn hover_effect(self, enable: bool) -> Self

Enable hover effect (same as clickable)

Source

pub fn show<R>( self, ui: &mut Ui, content: impl FnOnce(&mut Ui) -> R, ) -> CardResponse<R>

Show the card with content

§Panics

Panics if the content closure is not invoked during frame rendering.

Trait Implementations§

Source§

impl Default for Card<'_>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for Card<'a>

§

impl<'a> RefUnwindSafe for Card<'a>

§

impl<'a> Send for Card<'a>

§

impl<'a> Sync for Card<'a>

§

impl<'a> Unpin for Card<'a>

§

impl<'a> UnsafeUnpin for Card<'a>

§

impl<'a> UnwindSafe for Card<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.