//! Small elements shared between pages. use super::*; /// A small status badge: a faint accent-tinted pill with an accent dot and the /// theme's own text colour. (The toolkit's `Tag::success()` is a fixed green /// that ignores the palette and reads poorly on the Dynamic theme; coloured /// text on a tint of itself falls under 4.5:1 on some wallpapers.) pub(super) fn accent_badge(text: impl Into, accent: Hsla, ink: Hsla) -> Div { div() .flex() .flex_row() .items_center() .gap_1p5() .px_2() .py_0p5() .rounded_full() .text_xs() .font_weight(FontWeight::MEDIUM) .bg(Hsla { a: 0.20, ..accent }) .text_color(ink) .child(div().size(px(6.)).flex_none().rounded_full().bg(accent)) .child(text.into()) } /// The track a row of chips sits in, so they read as one control. pub(super) fn segmented(cx: &App) -> Div { h_flex() .flex_wrap() .self_start() .gap_0p5() .p_0p5() .rounded_lg() .bg(Hsla { a: 0.05, ..cx.theme().foreground }) } /// The surface a group of settings sits on: solid enough that the backdrop art /// does not run through the text. pub(super) fn panel(cx: &App) -> Div { div() .flex() .flex_col() .gap_3() .p_4() .rounded_xl() .border_1() .border_color(Hsla { a: 0.55, ..cx.theme().border }) .bg(Hsla { a: 0.82, ..cx.theme().sidebar }) } impl AppView { /// Mouse artwork in a `side` x `side` box. Placement is in fractions of /// the box (the Tauri app's `deviceArtStyle` normalisation, so every /// model's subject comes out a comparable size); `zoom` scales that up /// where the art should dominate. pub(super) fn device_art(&self, tile: &Tile, side: f32, zoom: f32) -> Div { let frame = div().relative().flex_none().w(px(side)).h(px(side)).overflow_hidden(); if tile.keyboard && tile.art.is_none() { static PICTURE: std::sync::LazyLock> = std::sync::LazyLock::new(|| { let bytes = include_bytes!("../../assets/unknown-keyboard.png"); std::sync::Arc::new(Image::from_bytes(ImageFormat::Png, bytes.to_vec())) }); return frame.child(img(PICTURE.clone()).size_full().object_fit(ObjectFit::Contain)); } let Some(art) = &tile.art else { return frame }; let image = img(art.path.clone()); match &art.placement { Some(p) => { let h = p.height / 100.0 * zoom; let w = h * p.aspect; let left = 0.5 - w / 2.0 + p.offset_x / 100.0 * w; let top = 0.5 - h / 2.0 + p.offset_y / 100.0 * h; frame.child( image .absolute() .left(relative(left)) .top(relative(top)) .w(relative(w)) .h(relative(h)) .object_fit(ObjectFit::Fill), ) } None => frame.child(image.size_full().object_fit(ObjectFit::Contain)), } } /// Selectable pill used for the page's option lists. pub(super) fn chip( &self, id: String, label: String, selected: bool, cx: &mut Context, on_click: impl Fn(&mut Self, &mut Context) + 'static, ) -> Stateful
{ let primary = cx.theme().primary; let fg = cx.theme().foreground; div() .id(SharedString::from(id)) .cursor_pointer() .px_3() .py_1() .rounded_md() .text_sm() .when(selected, |chip| chip.bg(Hsla { a: 0.22, ..primary }).font_weight(FontWeight::MEDIUM).text_color(fg)) .when(!selected, |chip| { chip.text_color(cx.theme().muted_foreground) .hover(move |chip| chip.bg(Hsla { a: 0.07, ..fg }).text_color(fg)) }) .child(label) .on_click(cx.listener(move |this, _, _, cx| on_click(this, cx))) } /// A slider for a Buttons/Advanced/Performance control: accent-filled track /// and thumb, with its value in a fixed-width pill so rows line up. pub(super) fn control_slider_row(slider: Option>, value: String, cx: &mut Context) -> AnyElement { let accent = cx.theme().primary; let fg = cx.theme().foreground; h_flex() .gap_3() .items_center() .max_w_full() .children(slider.map(|s| div().w(px(200.)).max_w_full().child(Slider::new(&s).bg(accent).text_color(fg)))) .child( div() .min_w(px(64.)) .flex_none() .text_sm() .text_right() .text_color(fg) .child(value), ) .into_any_element() } }