1pub mod button;
13pub mod chips;
14pub mod chrome_parts;
15pub mod chrome_toolbar;
16pub mod dropdown;
17pub mod gallery;
18pub mod icon_button;
19pub mod input;
20pub mod paint;
21pub mod preview;
22pub mod surface;
23pub mod tabs;
24pub mod toggle;
25pub mod canvas;
26pub mod status;
27
28pub use button::{Button, Size, Variant};
29pub use chips::{reference_field, Chip, ReferenceField, ReferenceOutput};
30pub use dropdown::{dropdown, Dropdown};
31pub use icon_button::{BarSide, IconButton};
32pub use input::{number_input, search_input, text_input, NumberInput, TextInput};
33pub use tabs::{document_tabs, tab_bar, DocumentTab, DocumentTabsOutput};
34pub use toggle::{checkbox, slider, switch, Check};
35
36use eframe::egui;
37
38#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
42pub enum Show {
43 #[default]
44 Live,
45 Hover,
46 Pressed,
47 Focus,
48}
49
50#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
52pub(crate) struct Interact {
53 pub hovered: bool,
54 pub pressed: bool,
55 pub focused: bool,
56}
57
58impl Interact {
59 pub fn of(response: &egui::Response, show: Show, enabled: bool) -> Self {
60 if !enabled {
61 return Interact::default();
62 }
63 Interact {
64 hovered: response.hovered() || matches!(show, Show::Hover | Show::Pressed),
65 pressed: response.is_pointer_button_down_on() || show == Show::Pressed,
66 focused: response.has_focus() || show == Show::Focus,
67 }
68 }
69}
70
71pub fn themed<R>(ui: &mut egui::Ui, theme: std::sync::Arc<crate::theme::Theme>, contents: impl FnOnce(&mut egui::Ui) -> R) -> R {
74 let before = crate::theme::stored(ui.ctx());
75 crate::theme::set(ui.ctx(), theme.clone());
76 let out = ui
77 .scope(|ui| {
78 let style = theme.style(ui.style());
79 ui.set_style(style);
80 contents(ui)
81 })
82 .inner;
83 match before {
84 Some(theme) => crate::theme::set(ui.ctx(), theme),
85 None => crate::theme::clear(ui.ctx()),
86 }
87 out
88}
89