Skip to main content

egui_components/
common.rs

1//! Shared types used across components.
2
3/// Visual variant — used by [`Button`](crate::button::Button),
4/// [`Badge`](crate::badge::Badge), [`Alert`](crate::alert::Alert) and
5/// [`Tag`](crate::tag::Tag).
6///
7/// Mirrors the variants in `gpui-component`'s `ButtonVariant` / `BadgeVariant`.
8#[derive(Clone, Copy, Debug, PartialEq, Eq, Default)]
9pub enum Variant {
10    #[default]
11    Primary,
12    Secondary,
13    Ghost,
14    Outline,
15    Link,
16    Danger,
17    Success,
18    Warning,
19    Info,
20}
21
22/// Standard size scale used by sized components.
23#[derive(Clone, Copy, Debug, PartialEq, Eq, Default)]
24pub enum Size {
25    Small,
26    #[default]
27    Medium,
28    Large,
29}
30
31impl Size {
32    pub fn button_height(&self, m: &egui_components_theme::ThemeMetrics) -> f32 {
33        match self {
34            Size::Small => m.button_height_sm,
35            Size::Medium => m.button_height_md,
36            Size::Large => m.button_height_lg,
37        }
38    }
39
40    pub fn input_height(&self, m: &egui_components_theme::ThemeMetrics) -> f32 {
41        match self {
42            Size::Small => m.input_height_sm,
43            Size::Medium => m.input_height,
44            Size::Large => m.input_height_lg,
45        }
46    }
47
48    pub fn button_padding_x(&self, m: &egui_components_theme::ThemeMetrics) -> f32 {
49        match self {
50            Size::Small => m.button_padding_x_sm,
51            Size::Medium => m.button_padding_x_md,
52            Size::Large => m.button_padding_x_lg,
53        }
54    }
55
56    pub fn font_size(&self, m: &egui_components_theme::ThemeMetrics) -> f32 {
57        match self {
58            Size::Small => m.font_size_sm,
59            Size::Medium => m.font_size_md,
60            Size::Large => m.font_size_lg,
61        }
62    }
63}