mirror of
https://github.com/anomalyco/hex.git
synced 2026-11-28 13:02:21 +01:00
* Fix #1518: detect a digitally silent meeting microphone * Add French, Portuguese, and Russian for the silent microphone strings * meeting: keep the silent microphone warning live and gated on the call app A digitally silent microphone stream now warns only while the call app reports recording from the same input, so a gated or noise-suppressed microphone that goes quiet between speech no longer reopens or warns. The warning is kept as a live state that clears when audio returns, even in a stream reopened after a supervisor restart, and a sticky flag that records the microphone was silent at some point. The sticky flag is written as soon as it is raised so a crash keeps it, and the manifest means "silent during this recording" rather than the last moment. Reopen claims are atomic, a dropped controller update no longer commits a live value the UI never saw, a device switch restarts the zero count without clearing the warning, and the recording capsule shows the elapsed time beside "Microphone is silent". The per-chunk decision is a pure policy in meeting/warning.rs with tests for the shared reopen budget, clearing, gating, and the sticky flag. error_panel takes a Tone instead of having a duplicate warning_panel. * meeting: log gated digital silence and align the silence docs When the microphone delivers 3 s of exact zeros but the call app does not report recording from the opened input, log the decision once per silence episode at info level with the device name, device UID, and the UIDs the call app reports. Nothing else changes. The feature docs now list each digital silence test under the file that owns it, and note that a live warning stays until nonzero audio returns when the call app leaves the input, and that a gated microphone the call app also uses can still trigger the two reopens and the warning.
746 lines
23 KiB
Rust
746 lines
23 KiB
Rust
//! Pieces the list-and-detail panes (Meetings) and the OS-only Settings rows
|
||
//! share: list rows and group labels, the detail header and facts, tinted
|
||
//! status tags, and the permission control.
|
||
|
||
use std::sync::LazyLock;
|
||
|
||
use rune::{
|
||
Beat, Color, Easing, Edge, El, Sequence, Shadow, Spring, SpringPair, Transition, Tx, col, el,
|
||
row, text,
|
||
};
|
||
|
||
use super::Ui;
|
||
use super::controls::{
|
||
ButtonKind, DESCRIPTION, METRICS, Paint, PushSize, button, pulsing_dot, status_dot,
|
||
};
|
||
use crate::desktop::i18n::tr;
|
||
|
||
const LIST_WIDTH: f32 = 320.0;
|
||
/// A [`list_row`]'s text inset.
|
||
const LIST_ROW_PX: f32 = 10.0;
|
||
/// A list column's leading padding, which puts its rows' text on the pane
|
||
/// title's edge.
|
||
pub(super) const LIST_COLUMN_PL: f32 = METRICS.gutter - LIST_ROW_PX;
|
||
static CLOSE: &rune::Icon = &rune_theme_opencode::icons::CLOSE;
|
||
|
||
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
|
||
pub(super) enum Tone {
|
||
Neutral,
|
||
Accent,
|
||
Success,
|
||
Warning,
|
||
Danger,
|
||
}
|
||
|
||
impl Tone {
|
||
/// The tinted fill, border, and ink this tone paints.
|
||
fn colors(self, p: Paint) -> (Color, Color, Color) {
|
||
let c = &p.k.c;
|
||
let state = match self {
|
||
Self::Neutral => return (c.layer_02, c.border_base, c.text_muted),
|
||
Self::Accent => &c.info,
|
||
Self::Success => &c.success,
|
||
Self::Warning => &c.warning,
|
||
Self::Danger => &c.danger,
|
||
};
|
||
(state.bg, state.border, state.fg)
|
||
}
|
||
}
|
||
|
||
/// A small tinted status label, never pressable.
|
||
pub(super) fn tone_tag(p: Paint, key: &str, label: &str, tone: Tone) -> El {
|
||
let (fill, border, ink) = tone.colors(p);
|
||
row()
|
||
.key(key)
|
||
.role("status")
|
||
.label(label)
|
||
.h(18.0)
|
||
.px(6.0)
|
||
.gap(4.0)
|
||
.center()
|
||
.radius(p.k.radius.xs)
|
||
.fill(fill)
|
||
.border(0.5, border)
|
||
.child(
|
||
text(label)
|
||
.key("label")
|
||
.font(p.k.ty.small_medium.lh(12.0))
|
||
.color(ink),
|
||
)
|
||
}
|
||
|
||
/// A list's group heading (a task, a day).
|
||
pub(super) fn group_label(p: Paint, key: &str, label: &str, first: bool) -> El {
|
||
text(label)
|
||
.key(key)
|
||
.role("heading")
|
||
.level(3)
|
||
.font(p.k.ty.small_medium)
|
||
.color(p.faint())
|
||
.px(10.0)
|
||
.pt(group_label_top(first))
|
||
.pb(GROUP_LABEL_BOTTOM)
|
||
}
|
||
|
||
const GROUP_LABEL_BOTTOM: f32 = 6.0;
|
||
|
||
fn group_label_top(first: bool) -> f32 {
|
||
if first { 4.0 } else { 16.0 }
|
||
}
|
||
|
||
/// A source list, as in a native sidebar: Tab enters at the selected row,
|
||
/// Up and Down select as they move, and typing selects a row by its name.
|
||
pub(super) fn source_list(list: El) -> El {
|
||
list.role("list").focus_group().focus_follows()
|
||
}
|
||
|
||
/// A row of a [`source_list`]. It draws no focus ring: focus follows the
|
||
/// selection, so the selected fill shows where focus is, as in a native
|
||
/// sidebar.
|
||
pub(super) fn source_item(item: El, selected: bool) -> El {
|
||
item.focusable(true).focus_selected(selected)
|
||
}
|
||
|
||
/// Selects a list row as fast as it can: on the pointer's press, as the
|
||
/// sidebar does, with nothing animated. The selected fill and the detail
|
||
/// beside the list swap in that frame. The keyboard (Space, and the arrows
|
||
/// in a [`source_list`]) selects through `on_press`, which leaves a selected
|
||
/// row alone, so a click's release doesn't select it again.
|
||
pub(super) fn select_at_once(row: El, selected: bool, select: impl Fn(&mut Ui) + 'static) -> El {
|
||
let select = std::rc::Rc::new(select);
|
||
let on_down = select.clone();
|
||
row.on_drag(move |ui: &mut Ui, d: &mut rune::Drag, tx: &mut Tx| {
|
||
if d.phase == rune::Phase::Down {
|
||
tx.instant();
|
||
on_down(ui);
|
||
}
|
||
})
|
||
.on_press_tx(move |ui: &mut Ui, tx: &mut Tx| {
|
||
if !selected {
|
||
tx.instant();
|
||
select(ui);
|
||
}
|
||
})
|
||
}
|
||
|
||
/// A selectable list row: title (with trailing pieces) over a meta line.
|
||
pub(super) fn list_row(
|
||
p: Paint,
|
||
key: &str,
|
||
title: &str,
|
||
trailing: Vec<El>,
|
||
meta: &str,
|
||
selected: bool,
|
||
select: impl Fn(&mut Ui) + 'static,
|
||
) -> El {
|
||
let c = &p.k.c;
|
||
// Named by its title and described by its meta line; the texts that
|
||
// show them stay out of the tree.
|
||
let mut item = col()
|
||
.key(key)
|
||
.role("listitem")
|
||
.label(title)
|
||
.description(meta)
|
||
.px(LIST_ROW_PX)
|
||
.py(8.0)
|
||
.gap(2.0)
|
||
.radius(p.k.radius.md)
|
||
.hover(c.hover)
|
||
.child(
|
||
row()
|
||
.key("top")
|
||
.gap(8.0)
|
||
.center_y()
|
||
.child(
|
||
text(title)
|
||
.key("title")
|
||
.font(p.k.ty.ui_medium)
|
||
.color(p.text())
|
||
.grow(1.0)
|
||
.shrink()
|
||
.truncate()
|
||
.a11y_hidden(),
|
||
)
|
||
.children(trailing),
|
||
)
|
||
.child(
|
||
text(meta)
|
||
.key("meta")
|
||
.font(p.k.ty.small)
|
||
.color(p.muted())
|
||
.truncate()
|
||
.a11y_hidden(),
|
||
);
|
||
if selected {
|
||
item = item.fill(c.layer_02);
|
||
}
|
||
source_item(select_at_once(item, selected, select), selected)
|
||
}
|
||
|
||
/// A quiet message in a list or detail (empty, no matches, failed load).
|
||
pub(super) fn message(p: Paint, key: &str, title: &str, detail: Option<&str>) -> El {
|
||
col()
|
||
.key(key)
|
||
.px(10.0)
|
||
.py(24.0)
|
||
.gap(4.0)
|
||
.child(
|
||
text(title)
|
||
.key("title")
|
||
.font(p.k.ty.ui)
|
||
.color(p.muted())
|
||
.wrap(),
|
||
)
|
||
.children(detail.map(|detail| {
|
||
text(detail)
|
||
.key("detail")
|
||
.font(DESCRIPTION)
|
||
.color(p.danger())
|
||
.wrap()
|
||
}))
|
||
}
|
||
|
||
/// An error or warning title and its detail, as a tinted panel.
|
||
pub(super) fn error_panel(p: Paint, key: &str, title: &str, detail: &str, tone: Tone) -> El {
|
||
let (fill, border, ink) = tone.colors(p);
|
||
col()
|
||
.key(key)
|
||
.px(12.0)
|
||
.py(10.0)
|
||
.gap(2.0)
|
||
.radius(p.k.radius.md)
|
||
.fill(fill)
|
||
.border(0.5, border)
|
||
.child(text(title).key("title").font(p.k.ty.ui_medium).color(ink))
|
||
.child(
|
||
text(detail)
|
||
.key("detail")
|
||
.font(DESCRIPTION)
|
||
.color(p.muted())
|
||
.wrap(),
|
||
)
|
||
}
|
||
|
||
/// An [`error_panel`] with a close button, for an error that stays until the
|
||
/// user dismisses it.
|
||
pub(super) fn dismissible_error_panel(
|
||
p: Paint,
|
||
key: &str,
|
||
title: &str,
|
||
detail: &str,
|
||
dismiss: impl Fn(&mut Ui) + 'static,
|
||
) -> El {
|
||
let d = &p.k.c.danger;
|
||
row()
|
||
.key(key)
|
||
.pl(12.0)
|
||
.pr(6.0)
|
||
.py(6.0)
|
||
.gap(8.0)
|
||
.radius(p.k.radius.md)
|
||
.fill(d.bg)
|
||
.border(0.5, d.border)
|
||
.child(
|
||
col()
|
||
.key("message")
|
||
.grow(1.0)
|
||
.shrink()
|
||
.py(4.0)
|
||
.gap(2.0)
|
||
.child(text(title).key("title").font(p.k.ty.ui_medium).color(d.fg))
|
||
.child(
|
||
text(detail)
|
||
.key("detail")
|
||
.font(DESCRIPTION)
|
||
.color(p.muted())
|
||
.wrap(),
|
||
),
|
||
)
|
||
.child(
|
||
rune_kit::IconButton::new(CLOSE)
|
||
.variant(rune_kit::IconButtonVariant::Ghost)
|
||
.label(tr("Close"))
|
||
.on_press(dismiss)
|
||
.build(p.k)
|
||
.key("dismiss"),
|
||
)
|
||
}
|
||
|
||
/// The list column and the detail beside it, split by a hairline.
|
||
pub(super) fn split(p: Paint, key: &str, list: El, detail: El) -> El {
|
||
row()
|
||
.key(key)
|
||
.grow(1.0)
|
||
.shrink()
|
||
.child(
|
||
col()
|
||
.key("list-column")
|
||
.w(LIST_WIDTH)
|
||
.h_full()
|
||
.pl(LIST_COLUMN_PL)
|
||
.pr(8.0)
|
||
.child(list),
|
||
)
|
||
.child(
|
||
el().key("rule")
|
||
.w(p.hair)
|
||
.h_full()
|
||
.fill(p.k.c.border_weak)
|
||
.a11y_hidden(),
|
||
)
|
||
.child(detail)
|
||
}
|
||
|
||
pub(super) fn placeholder(p: Paint, key: &str, copy: &str) -> El {
|
||
col().key(key).grow(1.0).shrink().center().child(
|
||
text(copy)
|
||
.key("placeholder")
|
||
.font(p.k.ty.ui)
|
||
.color(p.muted())
|
||
.align(rune::Align::Center)
|
||
.wrap()
|
||
.w(280.0),
|
||
)
|
||
}
|
||
|
||
/// The detail's title block: the title (or a rename field), a line of tags
|
||
/// and meta, and the actions on the right.
|
||
pub(super) fn detail_header(title: El, meta: Vec<El>, actions: Vec<El>) -> El {
|
||
row()
|
||
.key("detail-header")
|
||
.gap(8.0)
|
||
.center_y()
|
||
.flex_wrap()
|
||
.child(
|
||
col()
|
||
.key("title")
|
||
.grow(1.0)
|
||
.shrink()
|
||
.min_w(160.0)
|
||
.gap(4.0)
|
||
.child(title)
|
||
.child(row().key("meta").gap(8.0).center_y().children(meta)),
|
||
)
|
||
.child(row().key("actions").gap(8.0).center_y().children(actions))
|
||
}
|
||
|
||
pub(super) fn detail_title(p: Paint, title: &str) -> El {
|
||
text(title)
|
||
.key("detail-title")
|
||
.font(p.k.ty.body_medium)
|
||
.color(p.text())
|
||
.wrap()
|
||
}
|
||
|
||
pub(super) fn section_label(p: Paint, key: &str, label: &str) -> El {
|
||
text(label)
|
||
.key(key)
|
||
.font(p.k.ty.small_medium)
|
||
.color(p.muted())
|
||
}
|
||
|
||
/// A label and its value, side by side.
|
||
pub(super) fn fact(p: Paint, key: &str, label: &str, value: &str) -> El {
|
||
row()
|
||
.key(key)
|
||
.gap(16.0)
|
||
.child(
|
||
text(label)
|
||
.key("label")
|
||
.font(DESCRIPTION)
|
||
.color(p.muted())
|
||
.w(120.0),
|
||
)
|
||
.child(
|
||
text(value)
|
||
.key("value")
|
||
.font(DESCRIPTION)
|
||
.color(p.text())
|
||
.wrap()
|
||
.grow(1.0)
|
||
.shrink(),
|
||
)
|
||
}
|
||
|
||
/// How a permission's control reads, everywhere Hex asks for one.
|
||
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
|
||
pub(super) enum PermissionControl {
|
||
Allow,
|
||
/// Asked: macOS's prompt or System Settings is up; Allow opens it again.
|
||
Waiting,
|
||
/// Returned from System Settings still untrusted: resets stale TCC
|
||
/// entries and reopens the prompt and guide.
|
||
Stale,
|
||
Allowed,
|
||
}
|
||
|
||
/// A grant's first beat, the gather: the control dips to `DIP` while the
|
||
/// pill's chrome drains and the waiting dot contracts to a point. Every
|
||
/// layout move rides this spring and lands inside the beat, so nothing that
|
||
/// snaps to pixels is still creeping when the control comes to rest.
|
||
const GATHER: Spring = Spring::new(0.16, 0.0);
|
||
const GATHER_SECS: f64 = 0.14;
|
||
const DIP: f32 = 0.94;
|
||
/// The second beat, the release: the control springs back to full size as
|
||
/// the check draws on and "ed" wipes in.
|
||
const RELEASE: Spring = Spring::new(0.3, 0.2);
|
||
/// Long enough for `RELEASE` to come within a hundredth of a point of rest,
|
||
/// so the sequence's last keyframe is no step.
|
||
const RELEASE_SECS: f64 = 0.45;
|
||
const DRAW: Spring = Spring::new(0.42, 0.0);
|
||
const SUFFIX: Spring = Spring::new(0.4, 0.0);
|
||
/// The label's colour, green by the time "ed" has arrived.
|
||
const INK: Spring = Spring::new(0.3, 0.0);
|
||
/// The check and "ed" stay hidden through the gather (masks can't wait, so
|
||
/// their wipes start with it), then appear quickly: the dot has gone.
|
||
const APPEAR: &[Beat] = &[
|
||
Beat::new(0.0).opacity(0.0),
|
||
Beat::new(0.1).opacity(0.0),
|
||
Beat::new(0.15).opacity(1.0).easing(Easing::EASE_OUT),
|
||
];
|
||
/// The Allow button's padding, which Allowed keeps on the left so "Allow"
|
||
/// keeps its place in the pill and "ed" follows it.
|
||
const PILL_PADDING: f32 = 11.0;
|
||
/// The check's ink inside its 16-point icon: OpenCode's `check-small` path
|
||
/// (6.5,6.5)–(13.5,13.5) of 20, scaled to 16, plus the stroke's half-width.
|
||
const CHECK_INK: [f32; 4] = [4.6, 4.6, 6.8, 6.8];
|
||
/// Where the stroke starts, the point the waiting dot contracts into.
|
||
const CHECK_START: [f32; 2] = [5.2, 9.15];
|
||
/// The icon's place in its 9-point mark; the ink overhangs into the gap.
|
||
const CHECK_X: f32 = 4.0;
|
||
|
||
/// The one control every permission uses, in the tour and in Settings:
|
||
/// Allow, a pulsing dot while macOS is asked, then a green Allowed.
|
||
///
|
||
/// Every state is the same keyed button, so a grant morphs instead of
|
||
/// cross-fading, in two beats. The control gathers (dips, drains its
|
||
/// chrome, contracts the dot to the start of the check), then releases:
|
||
/// it springs back as the check draws on from that point and "ed" wipes in
|
||
/// after "Allow", whose glyphs never change.
|
||
pub(super) fn permission_control(
|
||
p: Paint,
|
||
key: &str,
|
||
control: PermissionControl,
|
||
kind: ButtonKind,
|
||
allow: impl Fn(&mut Ui) + 'static,
|
||
) -> El {
|
||
let (mark, gap, pill) = match control {
|
||
PermissionControl::Allow => (
|
||
None,
|
||
12.0,
|
||
button(p, key, tr("Allow"), kind, move |ui: &mut Ui, _| allow(ui)),
|
||
),
|
||
PermissionControl::Waiting | PermissionControl::Stale => (
|
||
Some(
|
||
el().key("mark")
|
||
.size(8.0, 8.0)
|
||
.child(pulsing_dot(p.accent()).absolute(0.0, 0.0)),
|
||
),
|
||
12.0,
|
||
button(
|
||
p,
|
||
key,
|
||
if control == PermissionControl::Stale {
|
||
tr("Still grey? Fix it")
|
||
} else {
|
||
tr("Allow")
|
||
},
|
||
ButtonKind::Secondary,
|
||
move |ui: &mut Ui, _| allow(ui),
|
||
),
|
||
),
|
||
PermissionControl::Allowed => (Some(check_mark(p)), 6.0, allowed_pill(p, key, kind)),
|
||
};
|
||
let control_row = row()
|
||
.key(format!("{key}-control"))
|
||
.gap(gap)
|
||
.center_y()
|
||
.motion(GATHER)
|
||
.children(mark.map(El::a11y_hidden))
|
||
.child(pill.motion(GATHER));
|
||
if control == PermissionControl::Allowed {
|
||
control_row.sequence(Sequence::new(grant_beats()))
|
||
} else {
|
||
control_row
|
||
}
|
||
}
|
||
|
||
/// The control's scale through a grant: an eased dip, then `RELEASE`
|
||
/// baked into the sequence's last segment, which only takes easings.
|
||
fn grant_beats() -> &'static [Beat] {
|
||
static BEATS: LazyLock<[Beat; 3]> = LazyLock::new(|| {
|
||
static CURVE: LazyLock<Vec<[f32; 2]>> = LazyLock::new(|| {
|
||
const STOPS: usize = 48;
|
||
(0..=STOPS)
|
||
.map(|i| {
|
||
let x = i as f32 / STOPS as f32;
|
||
let t = x * RELEASE_SECS as f32;
|
||
let y = if i == STOPS {
|
||
1.0
|
||
} else {
|
||
RELEASE.sample(0.0, 0.0, 1.0, t).0
|
||
};
|
||
[x, y]
|
||
})
|
||
.collect()
|
||
});
|
||
[
|
||
Beat::new(0.0),
|
||
Beat::new(GATHER_SECS).scale(DIP).easing(Easing::EASE_IN),
|
||
Beat::new(GATHER_SECS + RELEASE_SECS).easing(Easing::Piecewise(&CURVE)),
|
||
]
|
||
});
|
||
&*BEATS
|
||
}
|
||
|
||
/// The check, drawn on left to right from the point the dot contracted to.
|
||
fn check_mark(p: Paint) -> El {
|
||
let [x, y, w, h] = CHECK_INK;
|
||
el().key("mark")
|
||
.size(9.0, 16.0)
|
||
.child(
|
||
status_dot(p.success())
|
||
.absolute(CHECK_X + CHECK_START[0], CHECK_START[1])
|
||
.size(0.0, 0.0)
|
||
.radius(0.0)
|
||
.opacity(0.0)
|
||
.motion(GATHER),
|
||
)
|
||
.child(
|
||
el().key("ink")
|
||
.absolute(CHECK_X + x, y)
|
||
.size(w, h)
|
||
.transition(wipe(DRAW, 3.0))
|
||
.sequence(Sequence::new(APPEAR))
|
||
.child(
|
||
rune::icon(p.k.glyph.check_small, 16.0)
|
||
.key("check")
|
||
.absolute(-x, -y)
|
||
.color(p.success()),
|
||
),
|
||
)
|
||
}
|
||
|
||
/// A left-to-right mask reveal with a soft edge.
|
||
fn wipe(spring: Spring, feather: f32) -> Transition {
|
||
let mut wipe = Transition::reveal(Edge::Leading).springs(SpringPair::new(spring, spring));
|
||
for reveal in [&mut wipe.insertion.reveal, &mut wipe.removal.reveal]
|
||
.into_iter()
|
||
.flatten()
|
||
{
|
||
reveal.feather = feather;
|
||
}
|
||
wipe
|
||
}
|
||
|
||
/// The Allow button with its chrome faded out: the same pill, fill, and
|
||
/// shadows at zero alpha, and the label in green. It keeps the button's
|
||
/// left padding so "Allow" stays put inside it and "ed" lands right after,
|
||
/// never over it.
|
||
fn allowed_pill(p: Paint, key: &str, kind: ButtonKind) -> El {
|
||
let k = p.k;
|
||
let (fill, shadows) = match kind {
|
||
ButtonKind::Primary => (k.c.bg_contrast, &k.elevation.button_contrast),
|
||
ButtonKind::Secondary | ButtonKind::Danger => {
|
||
(k.c.bg_button_neutral, &k.elevation.button_neutral)
|
||
}
|
||
};
|
||
let font = k.ty.ui_medium;
|
||
let ink = p.success();
|
||
let (allow, allowed) = (tr("Allow"), tr("Allowed"));
|
||
// Announced as the grant lands; the label says what its texts show.
|
||
let mut pill = row()
|
||
.key(key)
|
||
.role("status")
|
||
.label(allowed)
|
||
.h(28.0)
|
||
.pl(PILL_PADDING)
|
||
.center_y()
|
||
.radius(k.radius.md)
|
||
.fill(fill.alpha(0.0));
|
||
for shadow in k.shadow_layers(shadows) {
|
||
pill = pill.box_shadow(Shadow {
|
||
color: shadow.color.alpha(0.0),
|
||
..shadow
|
||
});
|
||
}
|
||
if kind == ButtonKind::Primary {
|
||
pill = pill.gradient(Color::TRANSPARENT, Color::TRANSPARENT);
|
||
}
|
||
match allowed
|
||
.strip_prefix(allow)
|
||
.filter(|suffix| !suffix.is_empty())
|
||
{
|
||
// "Allow" stays and "ed" wipes in after it.
|
||
Some(suffix) => pill
|
||
.child(
|
||
text(allow)
|
||
.key("label")
|
||
.font(font)
|
||
.color(ink)
|
||
.motion(INK)
|
||
.a11y_hidden(),
|
||
)
|
||
.child(
|
||
text(suffix)
|
||
.key("suffix")
|
||
.font(font)
|
||
.color(ink)
|
||
.transition(wipe(SUFFIX, 2.0))
|
||
.sequence(Sequence::new(APPEAR))
|
||
.a11y_hidden(),
|
||
),
|
||
// Languages whose word changes cross-fade it.
|
||
None => pill.child(
|
||
text(allowed)
|
||
.key("allowed")
|
||
.font(font)
|
||
.color(ink)
|
||
.a11y_hidden(),
|
||
),
|
||
}
|
||
}
|
||
|
||
/// A green check and label: a granted permission or a ready model.
|
||
pub(super) fn allowed(p: Paint, key: &str, label: &str) -> El {
|
||
row()
|
||
.key(key)
|
||
.gap(6.0)
|
||
.center_y()
|
||
.child(
|
||
rune::icon(p.k.glyph.check_small, 16.0)
|
||
.key("check")
|
||
.color(p.success())
|
||
.a11y_hidden(),
|
||
)
|
||
.child(
|
||
text(label)
|
||
.key("label")
|
||
.font(DESCRIPTION)
|
||
.color(p.success()),
|
||
)
|
||
}
|
||
|
||
/// A compact secondary button for actions inside a list row.
|
||
pub(super) fn small_button(
|
||
p: Paint,
|
||
key: &str,
|
||
label: &str,
|
||
press: impl Fn(&mut Ui, &mut rune::Tx) + 'static,
|
||
) -> El {
|
||
rune_kit::Button::new(label)
|
||
.variant(rune_kit::ButtonVariant::Neutral)
|
||
.on_press_tx(press)
|
||
.build_small_push(p.k)
|
||
.key(key)
|
||
}
|
||
|
||
/// The × that removes one item of an editable list.
|
||
pub(super) fn remove_button(
|
||
p: Paint,
|
||
size: rune_kit::ControlSize,
|
||
press: impl Fn(&mut Ui) + 'static,
|
||
) -> El {
|
||
rune_kit::IconButton::new(CLOSE)
|
||
.variant(rune_kit::IconButtonVariant::Ghost)
|
||
.control_size(size)
|
||
.label(tr("Remove"))
|
||
.on_press(press)
|
||
.build(p.k)
|
||
.key("remove")
|
||
}
|
||
|
||
/// A horizontal slider: the label and value over a track you press or drag.
|
||
/// `set` gets the position from zero through one and whether the gesture
|
||
/// ended (save then, not on every move). A cancelled drag (Escape, window
|
||
/// blur) puts the value from the press back and never saves.
|
||
pub(super) fn slider(
|
||
p: Paint,
|
||
key: &str,
|
||
label: &str,
|
||
value: f32,
|
||
display: String,
|
||
width: f32,
|
||
set: impl Fn(&mut Ui, f32, bool) + 'static,
|
||
) -> El {
|
||
slider_in(p, key, label, value, display, width, set)
|
||
}
|
||
|
||
/// A [`slider`] for a window whose state isn't [`Ui`].
|
||
pub(super) fn slider_in<S: 'static>(
|
||
p: Paint,
|
||
key: &str,
|
||
label: &str,
|
||
value: f32,
|
||
display: String,
|
||
width: f32,
|
||
set: impl Fn(&mut S, f32, bool) + 'static,
|
||
) -> El {
|
||
let c = &p.k.c;
|
||
let value = value.clamp(0.0, 1.0);
|
||
let knob = 14.0;
|
||
let track = row()
|
||
.key("track")
|
||
.role("slider")
|
||
.label(label)
|
||
.range_value(f64::from(value), 0.0, 1.0)
|
||
.a11y_value(display.clone())
|
||
.w(width)
|
||
.h(22.0)
|
||
.center_y()
|
||
.on_drag(move |ui: &mut S, drag: &mut rune::Drag, _: &mut rune::Tx| {
|
||
if drag.phase == rune::Phase::Down {
|
||
drag.data = value;
|
||
}
|
||
if drag.cancelled() {
|
||
set(ui, drag.data, false);
|
||
return;
|
||
}
|
||
let position = ((drag.x - knob / 2.0) / (drag.w - knob).max(1.0)).clamp(0.0, 1.0);
|
||
set(ui, position, drag.phase == rune::Phase::Up);
|
||
})
|
||
.child(
|
||
row()
|
||
.key("rail")
|
||
.w(width)
|
||
.h(4.0)
|
||
.radius(2.0)
|
||
.fill(c.layer_03)
|
||
.child(
|
||
el().key("fill")
|
||
.w((width - knob) * value + knob / 2.0)
|
||
.h(4.0)
|
||
.radius(2.0)
|
||
.fill(c.icon_accent),
|
||
)
|
||
.a11y_hidden(),
|
||
)
|
||
.child(
|
||
el().key("knob")
|
||
.absolute((width - knob) * value, 4.0)
|
||
.size(knob, knob)
|
||
.radius(knob / 2.0)
|
||
.fill(c.knob)
|
||
.border(p.hair.max(0.5), c.border_strong)
|
||
.a11y_hidden(),
|
||
);
|
||
col()
|
||
.key(key)
|
||
.w(width)
|
||
.gap(4.0)
|
||
.child(
|
||
row()
|
||
.key("heading")
|
||
.justify_between()
|
||
.child(text(label).key("label").font(DESCRIPTION).color(p.muted()))
|
||
.child(
|
||
text(display)
|
||
.key("value")
|
||
.font(p.k.ty.mono)
|
||
.color(p.faint()),
|
||
)
|
||
// The slider reads its name and value.
|
||
.a11y_hidden(),
|
||
)
|
||
.child(track)
|
||
}
|