egui_charts/ui_kit/buttons/
mod.rs1use crate::localization as l10n;
7mod button;
8mod icon_button;
9mod split_button;
10mod variant;
11
12pub use button::{Button, ButtonExt};
13pub use icon_button::IconButton;
14pub use split_button::SplitButton;
15pub use variant::ButtonVariant;
16
17use crate::tokens::DESIGN_TOKENS;
18use egui::{Response, Role, Ui, WidgetInfo};
19
20#[derive(Debug, Clone, Copy, PartialEq, Default)]
22pub enum ButtonSize {
23 SM,
25 #[default]
27 MD,
28 LG,
30 XL,
32}
33
34impl ButtonSize {
35 #[inline]
37 pub fn pixels(&self) -> f32 {
38 match self {
39 ButtonSize::SM => DESIGN_TOKENS.sizing.button_sm,
40 ButtonSize::MD => DESIGN_TOKENS.sizing.button_md,
41 ButtonSize::LG => DESIGN_TOKENS.sizing.button_lg,
42 ButtonSize::XL => DESIGN_TOKENS.sizing.button_xl,
43 }
44 }
45
46 fn icon_pixels(&self, scale: Option<f32>) -> f32 {
48 scale.map_or(
49 match self {
50 ButtonSize::SM => DESIGN_TOKENS.sizing.icon_sm,
51 ButtonSize::MD => DESIGN_TOKENS.sizing.icon_md,
52 ButtonSize::LG | ButtonSize::XL => DESIGN_TOKENS.sizing.icon_lg,
53 },
54 |scale| self.pixels() * scale,
55 )
56 }
57}
58
59fn finish(
61 response: Response,
62 selected: Option<bool>,
63 label: &str,
64 tooltip: Option<&str>,
65) -> Response {
66 let translated_label = l10n::text(&response.ctx, label);
67 response.widget_info(|| {
68 if let Some(selected) = selected {
69 WidgetInfo::selected(
70 Role::Button,
71 response.enabled(),
72 selected,
73 &translated_label,
74 )
75 } else {
76 WidgetInfo::labeled(Role::Button, response.enabled(), &translated_label)
77 }
78 });
79 match tooltip {
80 Some(tip) => {
81 let tip = l10n::text(&response.ctx, tip);
82 response.on_hover_text(&tip).on_disabled_hover_text(&tip)
83 }
84 None => response,
85 }
86}
87
88pub fn dialog_close_button(ui: &mut Ui) -> Response {
108 IconButton::new(&crate::icons::icons::CLOSE)
109 .tooltip("Close")
110 .show(ui)
111}
112
113pub(crate) fn combo_chevron(
115 ui: &Ui,
116 rect: egui::Rect,
117 visuals: &egui::style::WidgetVisuals,
118 _open: bool,
119) {
120 use egui::emath::GuiRounding;
121 let rect = egui::Rect::from_center_size(
122 rect.center(),
123 egui::Vec2::splat(DESIGN_TOKENS.sizing.icon_sm),
124 )
125 .round_to_pixels(ui.pixels_per_point());
126 crate::icons::icons::CHEVRON_DOWN
127 .as_image_tinted(rect.size(), visuals.fg_stroke.color)
128 .paint_at(ui, rect);
129}