pfx_editor_style/widgets/
dotted.rs1use egui::{Pos2, Response, Sense, Shape, Stroke, Ui, Vec2, Widget};
2
3use crate::theme::Theme;
4
5#[derive(Default)]
6pub struct Dotted {
7 active: bool,
8}
9
10impl Dotted {
11 pub fn new() -> Dotted {
12 Dotted::default()
13 }
14
15 pub fn active(mut self, active: bool) -> Dotted {
16 self.active = active;
17 self
18 }
19}
20
21impl Widget for Dotted {
22 fn ui(self, ui: &mut Ui) -> Response {
23 let size = Vec2::new(ui.available_width(), 7.0);
24 let (rect, response) = ui.allocate_exact_size(size, Sense::hover());
25 if !ui.is_rect_visible(rect) {
26 return response;
27 }
28 let theme = Theme::of(ui.ctx());
29 let colour = if self.active {
30 theme.accent_bright
31 } else {
32 theme.track
33 };
34 let y = rect.center().y.floor() + 0.5;
35 ui.painter().extend(Shape::dashed_line(
36 &[Pos2::new(rect.left(), y), Pos2::new(rect.right(), y)],
37 Stroke::new(theme.stroke, colour),
38 theme.dash,
39 theme.dash,
40 ));
41 response
42 }
43}