Skip to main content

bhoo/systems/material/
link.rs

1use crate::*;
2
3impl Frame<'_> {
4    /// Text link; the caller handles navigation after activation.
5    pub fn link(&mut self, id: u64, label: &str, enabled: bool) -> Response {
6        let row = self.reserve(32.0);
7        let style = TextStyle {
8            size: 16.0,
9            ..TextStyle::default()
10        };
11        let bounds = Rect {
12            width: self.text_width(label, style).min(row.width),
13            ..row
14        };
15        let r = self.target(id, bounds, label, enabled, Role::Link);
16        let color = self
17            .ui
18            .theme
19            .primary
20            .opacity(if r.enabled { 1.0 } else { 0.38 });
21        self.styled_text(bounds, label, color, style);
22        self.paint_rect(
23            Rect {
24                x: bounds.x,
25                y: bounds.y + 25.0,
26                width: bounds.width,
27                height: 1.0,
28            },
29            0.0,
30            color.opacity(if r.hovered || r.focused { 1.0 } else { 0.4 }),
31        );
32        self.focus_ring(r);
33        r
34    }
35}
36
37#[cfg(test)]
38#[path = "link.spec.rs"]
39mod tests;