functora-egui 0.4.2

shadcn/ui-inspired widget library for egui - buttons, inputs, selects, dialogs, and 70+ more components with light/dark theming
Documentation
//! Maps button variant + size + interaction state to concrete style values.

use crate::paint::interpolate_color::with_alpha;
/// Resolves concrete button style from variant, size, and interaction state.
#[must_use]
pub fn resolve_button_style(
    theme: &crate::theme::shadcn_theme::ShadcnTheme,
    spacing: &crate::responsive::Spacing,
    variant: crate::tokens::button_variant::ButtonVariant,
    size: crate::tokens::component_size::ComponentSize,
    interaction: &crate::widgets::interaction::Interaction,
) -> super::resolved_button_style::ResolvedButtonStyle {
    let (height, h_padding, font_size) = size.metrics_for(spacing);
    let corner_radius = theme.radius; // rounded-lg (full radius, not radius - 2)

    let (mut bg, mut fg, border, underline) = match variant {
        crate::tokens::button_variant::ButtonVariant::Default => {
            (theme.primary, theme.primary_foreground, None, false)
        }
        crate::tokens::button_variant::ButtonVariant::Destructive => {
            // Nova: bg-destructive/10 text-destructive (tinted, not solid)
            let tint = crate::tokens::semantic_color::SemanticColor::Destructive.tint(theme);
            (tint, theme.destructive, None, false)
        }
        crate::tokens::button_variant::ButtonVariant::Outline => (
            theme.background,
            theme.foreground,
            Some(theme.border),
            false,
        ),
        crate::tokens::button_variant::ButtonVariant::Secondary => {
            (theme.secondary, theme.secondary_foreground, None, false)
        }
        crate::tokens::button_variant::ButtonVariant::Ghost => {
            (egui::Color32::TRANSPARENT, theme.foreground, None, false)
        }
        crate::tokens::button_variant::ButtonVariant::Link => {
            (egui::Color32::TRANSPARENT, theme.primary, None, true)
        }
    };

    if interaction.disabled {
        // Keep transparent backgrounds transparent (Ghost, Link) so
        // disabled menu items don't get a gray box.
        if bg.a() > 0 {
            bg = with_alpha(bg, 128);
        }
        fg = theme.muted_foreground;
    } else if interaction.pressed {
        match variant {
            crate::tokens::button_variant::ButtonVariant::Ghost
            | crate::tokens::button_variant::ButtonVariant::Outline => {
                // A translucent tint of a transparent/background color would
                // collapse to near-black (or be invisible against the surface),
                // leaving label text unreadable; use the opaque accent pair.
                bg = theme.accent;
                fg = theme.accent_foreground;
            }
            crate::tokens::button_variant::ButtonVariant::Default
            | crate::tokens::button_variant::ButtonVariant::Destructive
            | crate::tokens::button_variant::ButtonVariant::Secondary
            | crate::tokens::button_variant::ButtonVariant::Link => {
                bg = with_alpha(bg, 204); // 80% = /80
            }
        }
    } else if interaction.hovered {
        match variant {
            crate::tokens::button_variant::ButtonVariant::Ghost
            | crate::tokens::button_variant::ButtonVariant::Outline => {
                bg = theme.muted;
                fg = theme.foreground;
            }
            crate::tokens::button_variant::ButtonVariant::Link => {}
            crate::tokens::button_variant::ButtonVariant::Default
            | crate::tokens::button_variant::ButtonVariant::Destructive
            | crate::tokens::button_variant::ButtonVariant::Secondary => {
                bg = with_alpha(bg, 204); // 80% = /80
            }
        }
    }

    super::resolved_button_style::ResolvedButtonStyle {
        bg,
        fg,
        border,
        corner_radius,
        height,
        h_padding,
        font_size,
        underline,
    }
}