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