app: add applications from a dialog, with icons and a running state
The add row under the sources offered a type selector for device sources, which the daemon cannot capture reliably, and nothing told a right process name from a wrong one. A plus in the card header now opens a dialog asking for a name and a process, and Add stays grey until both are filled. Every source shows its executable's icon, read from the running process or found on disk when the program is closed, and a chip saying whether that process is running. The process table is read off the UI thread every couple of seconds while the audio tab is open, and the disk search remembers its misses so a name costs one walk per run. Settings drops Refresh and Settings from the title bar, where both only repeated what the screen already shows.
This commit is contained in:
1 parent
3dfef1961d
commit
c7fee5beeb
8 files changed
+805
-203
No files matched your search
+173
-10
@@ -51,6 +51,11 @@ pub fn body(size: f32) -> TextStyle {
|
||||
|
||||
/// A titled card of rows with hairlines between them.
|
||||
pub fn card(p: Paint, title: Option<&str>, rows: Vec<El>) -> El {
|
||||
card_action(p, title, None, rows)
|
||||
}
|
||||
|
||||
/// [`card`] with a control in its header, such as the button that adds to the list below.
|
||||
pub fn card_action(p: Paint, title: Option<&str>, action: Option<El>, rows: Vec<El>) -> El {
|
||||
let count = rows.len();
|
||||
let mut inner = col()
|
||||
.key("card")
|
||||
@@ -75,13 +80,22 @@ pub fn card(p: Paint, title: Option<&str>, rows: Vec<El>) -> El {
|
||||
}
|
||||
let mut section = col().gap(space::S2);
|
||||
if let Some(title) = title {
|
||||
section = section.child(
|
||||
text(title)
|
||||
.key("header")
|
||||
.font(type_::SECTION)
|
||||
.color(p.t.text_secondary)
|
||||
.ml(space::S3),
|
||||
);
|
||||
let mut header = row()
|
||||
.key("header")
|
||||
.w_full()
|
||||
.center_y()
|
||||
.justify_between()
|
||||
.child(
|
||||
text(title)
|
||||
.key("header-label")
|
||||
.font(type_::SECTION)
|
||||
.color(p.t.text_secondary)
|
||||
.ml(space::S3),
|
||||
);
|
||||
if let Some(action) = action {
|
||||
header = header.child(action);
|
||||
}
|
||||
section = section.child(header);
|
||||
}
|
||||
section.child(inner)
|
||||
}
|
||||
@@ -283,12 +297,30 @@ pub fn text_field(
|
||||
label: &str,
|
||||
edit: &rune::TextEdit,
|
||||
to: fn(&mut App) -> &mut rune::TextEdit,
|
||||
) -> El {
|
||||
text_field_width(p, key, label, 220.0, rune::Align::End, edit, to, |app| {
|
||||
app.form.dirty = true;
|
||||
})
|
||||
}
|
||||
|
||||
/// [`text_field`] at a given width and text alignment; a dialog field is wide and starts at its
|
||||
/// left edge, where typing begins.
|
||||
#[allow(clippy::too_many_arguments)] // the columns of a field: size, alignment and what typing does
|
||||
pub fn text_field_width(
|
||||
p: Paint,
|
||||
key: &'static str,
|
||||
label: &str,
|
||||
width: f32,
|
||||
align: rune::Align,
|
||||
edit: &rune::TextEdit,
|
||||
to: fn(&mut App) -> &mut rune::TextEdit,
|
||||
on_input: fn(&mut App),
|
||||
) -> El {
|
||||
let focused = edit.focused;
|
||||
row()
|
||||
.key(key)
|
||||
.h(28.0)
|
||||
.w(220.0)
|
||||
.w(width)
|
||||
.px(8.0)
|
||||
.center_y()
|
||||
.radius(radius::MD)
|
||||
@@ -308,10 +340,10 @@ pub fn text_field(
|
||||
.w_full()
|
||||
.label(label)
|
||||
.color(p.t.text)
|
||||
.align(rune::Align::End)
|
||||
.align(align)
|
||||
.caret(p.t.text, p.accent.alpha(0.3))
|
||||
.on_edit(to)
|
||||
.on_input_change(|app: &mut App, _| app.form.dirty = true),
|
||||
.on_input_change(move |app: &mut App, _| on_input(app)),
|
||||
)
|
||||
}
|
||||
|
||||
@@ -390,6 +422,137 @@ pub fn button(
|
||||
)
|
||||
}
|
||||
|
||||
/// A small square button holding one glyph, for the corner of a card or a dialog.
|
||||
pub fn icon_button(
|
||||
p: Paint,
|
||||
key: &str,
|
||||
glyph: &str,
|
||||
label: &str,
|
||||
primary: bool,
|
||||
on_press: impl Fn(&mut App) + Send + Sync + 'static,
|
||||
) -> El {
|
||||
el().key(key)
|
||||
.role("button")
|
||||
.label(label)
|
||||
.focusable(true)
|
||||
.size(24.0, 24.0)
|
||||
.center()
|
||||
.radius(radius::MD)
|
||||
.fill(if primary {
|
||||
p.accent.alpha(0.14)
|
||||
} else {
|
||||
Color::TRANSPARENT
|
||||
})
|
||||
.border(
|
||||
p.hair,
|
||||
if primary {
|
||||
p.accent.alpha(0.32)
|
||||
} else {
|
||||
Color::TRANSPARENT
|
||||
},
|
||||
)
|
||||
.hover(p.t.hover)
|
||||
.press(p.t.press)
|
||||
.on_press(on_press)
|
||||
.child(
|
||||
text(glyph)
|
||||
.key("glyph")
|
||||
.font(body(if primary { 16.0 } else { 15.0 }))
|
||||
.color(if primary { p.accent } else { p.muted() })
|
||||
.a11y_hidden(),
|
||||
)
|
||||
}
|
||||
|
||||
/// A primary button with nothing to do yet, for a dialog whose fields are still empty.
|
||||
pub fn button_muted(p: Paint, key: &str, label: &str) -> El {
|
||||
el().key(key)
|
||||
.role("button")
|
||||
.label(label)
|
||||
.disabled(true)
|
||||
.h(28.0)
|
||||
.px(14.0)
|
||||
.center()
|
||||
.radius(radius::MD)
|
||||
.fill(p.accent.alpha(0.28))
|
||||
.child(
|
||||
text(label)
|
||||
.key("label")
|
||||
.font(type_::LABEL)
|
||||
.color(p.accent_ink.alpha(0.55))
|
||||
.a11y_hidden(),
|
||||
)
|
||||
}
|
||||
|
||||
/// A process's icon as Windows draws it for the executable, with its initial until the icon is
|
||||
/// decoded and for processes whose executable has none.
|
||||
pub fn process_icon(app: &App, p: Paint, process: &str, size: f32) -> El {
|
||||
let radius = (size * 0.22).max(2.0);
|
||||
let initial = process
|
||||
.trim()
|
||||
.chars()
|
||||
.next()
|
||||
.map(|c| c.to_ascii_uppercase().to_string())
|
||||
.unwrap_or_else(|| "?".to_string());
|
||||
let image = app
|
||||
.processes
|
||||
.get(&crate::process::normalize(process))
|
||||
.and_then(|found| found.path.as_deref())
|
||||
.and_then(|path| {
|
||||
app.icons
|
||||
.as_ref()
|
||||
.map(|icons| icons.app_icon_scaled(path, size, p.scale))
|
||||
});
|
||||
let tile = el()
|
||||
.key("process-icon")
|
||||
.size(size, size)
|
||||
.radius(radius)
|
||||
.fill(p.t.control_off)
|
||||
.a11y_hidden();
|
||||
match image {
|
||||
Some(image) => tile.child(
|
||||
el().key("process-image")
|
||||
.w_full()
|
||||
.h_full()
|
||||
.radius(radius)
|
||||
.pixels(image.pixels()),
|
||||
),
|
||||
None => tile.child(
|
||||
text(initial)
|
||||
.key("initial")
|
||||
.font(body(size * 0.52))
|
||||
.color(p.muted())
|
||||
.center(),
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
/// Whether a process is up: a chip beside its name in the list.
|
||||
pub fn process_state(p: Paint, running: bool, width: f32) -> El {
|
||||
let color = if running { p.success } else { p.muted() };
|
||||
row()
|
||||
.key("process-state")
|
||||
.w(width)
|
||||
.h(20.0)
|
||||
.px(8.0)
|
||||
.gap(6.0)
|
||||
.center_y()
|
||||
.radius(radius::MD)
|
||||
.fill(color.alpha(0.12))
|
||||
.child(
|
||||
el().key("state-dot")
|
||||
.size(6.0, 6.0)
|
||||
.radius(3.0)
|
||||
.fill(color)
|
||||
.a11y_hidden(),
|
||||
)
|
||||
.child(
|
||||
text(if running { "Running" } else { "Not found" })
|
||||
.key("state-label")
|
||||
.font(body(10.5))
|
||||
.color(color),
|
||||
)
|
||||
}
|
||||
|
||||
/// A coloured dot used for status.
|
||||
pub fn dot(color: Color) -> El {
|
||||
el().key("dot")
|
||||
|
||||
Reference in new issue
Block a user