mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-17 05:14:24 +00:00
CommandPalette: the lead row is the command highlight
ListRow's command flag puts an option that runs a command in the menu row form: the lead row in accent.solid with text.on_accent, with no lead or chosen edge. The palette's rows take it; other option lists keep the option form.
This commit is contained in:
@@ -230,7 +230,7 @@ impl RowData {
|
||||
/// One line: the label, then the menu path, which drops out when the label would get too narrow, and the chord
|
||||
/// at the end.
|
||||
fn row(&self) -> ListRow<'static> {
|
||||
let row = ListRow::new(self.label.clone()).option().enabled(self.enabled);
|
||||
let row = ListRow::new(self.label.clone()).option().command().enabled(self.enabled);
|
||||
// The first trailing item is the outermost: the chord ends the row and the path sits before it.
|
||||
let row = match &self.chord {
|
||||
Some(chord) => row.trailing(chord.clone()),
|
||||
|
||||
@@ -247,6 +247,11 @@ pub struct ListRow<'a> {
|
||||
#[style_key]
|
||||
#[prop(flag)]
|
||||
pub(super) option: bool,
|
||||
/// On an option that runs a command (a command palette's row): the lead row is the command highlight, as a menu's,
|
||||
/// and no edge outlines the lead or the chosen row.
|
||||
#[style_key]
|
||||
#[prop(flag)]
|
||||
pub(super) command: bool,
|
||||
/// On an option of a list that picks a value: the row keeps a mark column, with the check mark when `true`.
|
||||
#[prop]
|
||||
pub(super) check: Option<bool>,
|
||||
@@ -314,6 +319,7 @@ impl<'a> ListRow<'a> {
|
||||
group: None,
|
||||
disclosure_by_host: false,
|
||||
option: false,
|
||||
command: false,
|
||||
check: None,
|
||||
event: None,
|
||||
open: None,
|
||||
|
||||
@@ -59,7 +59,11 @@ impl Component for ListRow<'_> {
|
||||
let text = &colors.text;
|
||||
let clear = Rgba::TRANSPARENT;
|
||||
let c = |rgba: Rgba| cx.color(rgba);
|
||||
let form = if key.option { RowForm::Option } else { RowForm::List };
|
||||
let form = match () {
|
||||
_ if key.option && key.command => RowForm::Command,
|
||||
_ if key.option => RowForm::Option,
|
||||
_ => RowForm::List,
|
||||
};
|
||||
let fill = fill_of(cx, FillKey { striped: key.striped, layer: key.layer, form });
|
||||
// An option sits inset in its popup with rounded corners whatever the theme's row form.
|
||||
let rounded = key.option || tokens.shape.rows == RowStyle::Rounded;
|
||||
@@ -68,7 +72,7 @@ impl Component for ListRow<'_> {
|
||||
if key.layer {
|
||||
surface = surface.border(Stateful::new(c(clear)).when(Flags::SELECTED, c(selected_outline(cx))), tokens.stroke.thin);
|
||||
}
|
||||
if key.option {
|
||||
if form == RowForm::Option {
|
||||
let edge = Stateful::new(c(clear)).when(Flags::SELECTED, c(colors.accent.text)).when(Flags::LEAD, c(colors.line.control_edge));
|
||||
surface = surface.border(edge, tokens.stroke.thin);
|
||||
}
|
||||
|
||||
@@ -46,7 +46,7 @@ pub struct ListRowStyle {
|
||||
pub(super) enum RowForm {
|
||||
/// An item of a list.
|
||||
List,
|
||||
/// A row of a menu: the lead row is the command highlight.
|
||||
/// A row of a menu, or an option that runs a command: the lead row is the command highlight.
|
||||
Command,
|
||||
/// An option of a listbox: the chosen row keeps the selected fill, the lead row the hover fill.
|
||||
Option,
|
||||
|
||||
Reference in New Issue
Block a user