Skip to main content

pfx_editor_style/widgets/
mod.rs

1mod dotted;
2mod header;
3mod keycap;
4mod number;
5mod pill;
6mod tabs;
7
8pub use dotted::Dotted;
9pub use header::Header;
10pub use keycap::KeyCap;
11pub use number::Number;
12pub use pill::{Pill, Tone};
13pub use tabs::Tabs;
14
15use std::sync::Arc;
16
17use egui::{Align2, Color32, FontId, Galley, Painter, Pos2, Rect, Response};
18
19use crate::theme::{Caps, Theme};
20
21#[derive(Clone, Copy, Debug, PartialEq, Eq)]
22pub enum State {
23    Rest,
24    Hovered,
25    Active,
26}
27
28impl State {
29    pub fn of(response: &Response, active: bool) -> State {
30        if active || response.is_pointer_button_down_on() {
31            State::Active
32        } else if response.hovered() {
33            State::Hovered
34        } else {
35            State::Rest
36        }
37    }
38
39    pub fn border(self, theme: &Theme) -> Color32 {
40        match self {
41            State::Rest => theme.line,
42            State::Hovered => theme.accent,
43            State::Active => theme.hot,
44        }
45    }
46}
47
48fn shaped(painter: &Painter, text: &str, font: FontId, colour: Color32, caps: Caps) -> Arc<Galley> {
49    painter.layout_job(caps.job(text, font, colour))
50}
51
52fn place(
53    painter: &Painter,
54    at: Pos2,
55    anchor: Align2,
56    galley: Arc<Galley>,
57    colour: Color32,
58) -> Rect {
59    let rect = anchor.anchor_size(at, galley.size());
60    painter.galley(rect.min, galley, colour);
61    rect
62}