Skip to main content

Badge

Struct Badge 

Source
pub struct Badge { /* private fields */ }
Expand description

Small status indicator badge styled like shadcn/ui

§Example

use armas_basic::components::{Badge, BadgeVariant};

fn ui(ui: &mut egui::Ui) {
    // Default badge
    Badge::new("New").show(ui);

    // Secondary badge
    Badge::new("Draft").variant(BadgeVariant::Secondary).show(ui);

    // Destructive badge
    Badge::new("Error").variant(BadgeVariant::Destructive).show(ui);

    // Outline badge
    Badge::new("Outline").variant(BadgeVariant::Outline).show(ui);
}

Implementations§

Source§

impl Badge

Source

pub fn new(text: impl Into<String>) -> Self

Create a new badge

Source

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

Set badge variant

Source

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

Set custom color (overrides variant colors)

Source

pub const fn destructive(self) -> Self

Make this a destructive badge (shorthand)

Source

pub const fn dot(self) -> Self

Show dot indicator

Source

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

Set text size

Source

pub const fn removable(self) -> Self

Make badge removable

Source

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

Set corner radius

Source

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

Set vertical padding

Source

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

Set explicit height (overrides computed height)

Source

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

Set minimum width

Source

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

Set selected state (for interactive badge use)

Source

pub fn show(self, ui: &mut Ui) -> BadgeResponse

Show the badge

Source

pub fn show_ui( self, ui: &mut Ui, content: impl FnOnce(&mut Ui, &ContentContext), ) -> BadgeResponse

Show the badge with custom content instead of a text label.

The closure receives a &mut Ui (with override text color set) and a ContentContext with the state-dependent color.

Use min_width to control the badge width. Dot and removable features still work alongside custom content.

§Example
use armas_basic::components::Badge;

Badge::new("")
    .min_width(60.0)
    .show_ui(ui, |ui, ctx| {
        // Render icon + text using ctx.color
        ui.label("New");
    });

Trait Implementations§

Source§

impl Default for Badge

Source§

fn default() -> Self

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

Auto Trait Implementations§

§

impl Freeze for Badge

§

impl RefUnwindSafe for Badge

§

impl Send for Badge

§

impl Sync for Badge

§

impl Unpin for Badge

§

impl UnsafeUnpin for Badge

§

impl UnwindSafe for Badge

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.