input: mark move up/down disabled for first/last keyboard laout disabled
Signed-off-by: nicole mikołajczyk <git@mkljczk.pl>
This commit is contained in:
parent
c7481ba336
commit
72f366d8db
1 changed files with 43 additions and 9 deletions
|
|
@ -211,6 +211,7 @@ fn popover_menu_row(
|
||||||
id: DefaultKey,
|
id: DefaultKey,
|
||||||
label: String,
|
label: String,
|
||||||
message: impl Fn(DefaultKey) -> SourceContext + 'static,
|
message: impl Fn(DefaultKey) -> SourceContext + 'static,
|
||||||
|
disabled: bool,
|
||||||
) -> cosmic::Element<'static, Message> {
|
) -> cosmic::Element<'static, Message> {
|
||||||
let spacing = theme::spacing();
|
let spacing = theme::spacing();
|
||||||
widget::text::body(label)
|
widget::text::body(label)
|
||||||
|
|
@ -219,21 +220,31 @@ fn popover_menu_row(
|
||||||
.padding([spacing.space_xxxs, spacing.space_xs])
|
.padding([spacing.space_xxxs, spacing.space_xs])
|
||||||
.width(Length::Fill)
|
.width(Length::Fill)
|
||||||
.class(theme::Button::MenuItem)
|
.class(theme::Button::MenuItem)
|
||||||
.on_press(Message::SourceContext(message(id)))
|
.on_press_maybe(if disabled {
|
||||||
|
None
|
||||||
|
} else {
|
||||||
|
Some(Message::SourceContext(message(id)))
|
||||||
|
})
|
||||||
.apply(Element::from)
|
.apply(Element::from)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn popover_menu(id: DefaultKey) -> cosmic::Element<'static, Message> {
|
fn popover_menu(
|
||||||
|
id: DefaultKey,
|
||||||
|
is_first: bool,
|
||||||
|
is_last: bool,
|
||||||
|
) -> cosmic::Element<'static, Message> {
|
||||||
widget::column::with_children([
|
widget::column::with_children([
|
||||||
popover_menu_row(
|
popover_menu_row(
|
||||||
id,
|
id,
|
||||||
fl!("keyboard-sources", "move-up"),
|
fl!("keyboard-sources", "move-up"),
|
||||||
SourceContext::MoveUp,
|
SourceContext::MoveUp,
|
||||||
|
is_first,
|
||||||
),
|
),
|
||||||
popover_menu_row(
|
popover_menu_row(
|
||||||
id,
|
id,
|
||||||
fl!("keyboard-sources", "move-down"),
|
fl!("keyboard-sources", "move-down"),
|
||||||
SourceContext::MoveDown,
|
SourceContext::MoveDown,
|
||||||
|
is_last,
|
||||||
),
|
),
|
||||||
widget::divider::horizontal::default()
|
widget::divider::horizontal::default()
|
||||||
.apply(widget::container)
|
.apply(widget::container)
|
||||||
|
|
@ -243,13 +254,20 @@ fn popover_menu(id: DefaultKey) -> cosmic::Element<'static, Message> {
|
||||||
id,
|
id,
|
||||||
fl!("keyboard-sources", "settings"),
|
fl!("keyboard-sources", "settings"),
|
||||||
SourceContext::Settings,
|
SourceContext::Settings,
|
||||||
|
false,
|
||||||
),
|
),
|
||||||
popover_menu_row(
|
popover_menu_row(
|
||||||
id,
|
id,
|
||||||
fl!("keyboard-sources", "view-layout"),
|
fl!("keyboard-sources", "view-layout"),
|
||||||
SourceContext::ViewLayout,
|
SourceContext::ViewLayout,
|
||||||
|
false,
|
||||||
|
),
|
||||||
|
popover_menu_row(
|
||||||
|
id,
|
||||||
|
fl!("keyboard-sources", "remove"),
|
||||||
|
SourceContext::Remove,
|
||||||
|
false,
|
||||||
),
|
),
|
||||||
popover_menu_row(id, fl!("keyboard-sources", "remove"), SourceContext::Remove),
|
|
||||||
])
|
])
|
||||||
.width(Length::Fixed(200.0))
|
.width(Length::Fixed(200.0))
|
||||||
.apply(widget::container)
|
.apply(widget::container)
|
||||||
|
|
@ -258,7 +276,12 @@ fn popover_menu(id: DefaultKey) -> cosmic::Element<'static, Message> {
|
||||||
.into()
|
.into()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn popover_button(id: DefaultKey, expanded: bool) -> cosmic::Element<'static, Message> {
|
fn popover_button(
|
||||||
|
id: DefaultKey,
|
||||||
|
expanded: bool,
|
||||||
|
is_first: bool,
|
||||||
|
is_last: bool,
|
||||||
|
) -> cosmic::Element<'static, Message> {
|
||||||
let on_press = Message::ExpandInputSourcePopover(if expanded { None } else { Some(id) });
|
let on_press = Message::ExpandInputSourcePopover(if expanded { None } else { Some(id) });
|
||||||
|
|
||||||
let button = button::icon(icon::from_name("view-more-symbolic"))
|
let button = button::icon(icon::from_name("view-more-symbolic"))
|
||||||
|
|
@ -268,7 +291,7 @@ fn popover_button(id: DefaultKey, expanded: bool) -> cosmic::Element<'static, Me
|
||||||
if expanded {
|
if expanded {
|
||||||
widget::popover(button)
|
widget::popover(button)
|
||||||
.position(widget::popover::Position::Bottom)
|
.position(widget::popover::Position::Bottom)
|
||||||
.popup(popover_menu(id))
|
.popup(popover_menu(id, is_first, is_last))
|
||||||
.on_close(Message::ExpandInputSourcePopover(None))
|
.on_close(Message::ExpandInputSourcePopover(None))
|
||||||
.into()
|
.into()
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -280,10 +303,16 @@ fn input_source(
|
||||||
id: DefaultKey,
|
id: DefaultKey,
|
||||||
description: &str,
|
description: &str,
|
||||||
expanded_source_popover: Option<DefaultKey>,
|
expanded_source_popover: Option<DefaultKey>,
|
||||||
|
is_first: bool,
|
||||||
|
is_last: bool,
|
||||||
) -> cosmic::Element<'_, Message> {
|
) -> cosmic::Element<'_, Message> {
|
||||||
let expanded = expanded_source_popover.is_some_and(|expanded_id| expanded_id == id);
|
let expanded = expanded_source_popover.is_some_and(|expanded_id| expanded_id == id);
|
||||||
|
|
||||||
settings::item(description, popover_button(id, expanded)).into()
|
settings::item(
|
||||||
|
description,
|
||||||
|
popover_button(id, expanded, is_first, is_last),
|
||||||
|
)
|
||||||
|
.into()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn special_char_radio_row<'a>(
|
fn special_char_radio_row<'a>(
|
||||||
|
|
@ -747,12 +776,17 @@ fn input_sources() -> Section<crate::pages::Message> {
|
||||||
// TODO Need something more custom, with drag and drop
|
// TODO Need something more custom, with drag and drop
|
||||||
let mut section = settings::section().title(§ion.title);
|
let mut section = settings::section().title(§ion.title);
|
||||||
|
|
||||||
for id in &page.active_layouts {
|
for (position, id) in page.active_layouts.iter().enumerate() {
|
||||||
if let Some((_locale, _variant, description, _source)) =
|
if let Some((_locale, _variant, description, _source)) =
|
||||||
page.keyboard_layouts.get(*id)
|
page.keyboard_layouts.get(*id)
|
||||||
{
|
{
|
||||||
section =
|
section = section.add(input_source(
|
||||||
section.add(input_source(*id, description, page.expanded_source_popover));
|
*id,
|
||||||
|
description,
|
||||||
|
page.expanded_source_popover,
|
||||||
|
position == 0,
|
||||||
|
position + 1 == page.active_layouts.len(),
|
||||||
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue