refactor: popups for nav bar / segmented buttons
This commit is contained in:
parent
f5fc392ba4
commit
cde1989e78
13 changed files with 544 additions and 57 deletions
|
|
@ -7,7 +7,7 @@ use cosmic::app::Settings;
|
|||
use cosmic::iced::{Alignment, Length, Size};
|
||||
use cosmic::prelude::*;
|
||||
use cosmic::widget::menu::{self, KeyBind};
|
||||
use cosmic::widget::nav_bar;
|
||||
use cosmic::widget::{nav_bar, RcElementWrapper};
|
||||
use cosmic::{executor, iced, widget, Core};
|
||||
use std::collections::HashMap;
|
||||
use std::sync::LazyLock;
|
||||
|
|
@ -43,7 +43,7 @@ pub enum Action {
|
|||
impl widget::menu::Action for Action {
|
||||
type Message = Message;
|
||||
|
||||
fn message(&self) -> Message {
|
||||
fn message(&self) -> Self::Message {
|
||||
match self {
|
||||
Action::Hi => Message::Hi,
|
||||
Action::Hi2 => Message::Hi2,
|
||||
|
|
@ -52,6 +52,25 @@ impl widget::menu::Action for Action {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
|
||||
pub enum Action2 {
|
||||
Hi,
|
||||
Hi2,
|
||||
Hi3,
|
||||
}
|
||||
|
||||
impl widget::menu::Action for Action2 {
|
||||
type Message = cosmic::Action<Message>;
|
||||
|
||||
fn message(&self) -> Self::Message {
|
||||
cosmic::Action::App(match self {
|
||||
Action2::Hi => Message::Hi,
|
||||
Action2::Hi2 => Message::Hi2,
|
||||
Action2::Hi3 => Message::Hi3,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
/// Runs application with these settings
|
||||
#[rustfmt::skip]
|
||||
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
|
|
@ -158,6 +177,70 @@ impl cosmic::Application for App {
|
|||
self.update_title()
|
||||
}
|
||||
|
||||
fn nav_context_menu(&self) -> Option<Vec<menu::Tree<cosmic::Action<Self::Message>>>> {
|
||||
Some(menu::nav_context(
|
||||
&HashMap::new(),
|
||||
vec![
|
||||
vec![cosmic::widget::menu::Item::Button(
|
||||
"Hi",
|
||||
Some(cosmic::widget::icon::from_name("screenshot-window-symbolic").into()),
|
||||
Action2::Hi,
|
||||
)],
|
||||
vec![
|
||||
cosmic::widget::menu::Item::Button(
|
||||
"Hi 2",
|
||||
Some(cosmic::widget::icon::from_name("screenshot-window-symbolic").into()),
|
||||
Action2::Hi,
|
||||
),
|
||||
cosmic::widget::menu::Item::Button(
|
||||
"Hi 22",
|
||||
Some(cosmic::widget::icon::from_name("screenshot-window-symbolic").into()),
|
||||
Action2::Hi,
|
||||
),
|
||||
],
|
||||
vec![
|
||||
cosmic::widget::menu::Item::Button(
|
||||
"Hi 3",
|
||||
Some(cosmic::widget::icon::from_name("screenshot-window-symbolic").into()),
|
||||
Action2::Hi,
|
||||
),
|
||||
cosmic::widget::menu::Item::Button(
|
||||
"Hi 33",
|
||||
Some(cosmic::widget::icon::from_name("screenshot-window-symbolic").into()),
|
||||
Action2::Hi,
|
||||
),
|
||||
cosmic::widget::menu::Item::Button(
|
||||
"Hi 333",
|
||||
Some(cosmic::widget::icon::from_name("screenshot-window-symbolic").into()),
|
||||
Action2::Hi,
|
||||
),
|
||||
],
|
||||
vec![
|
||||
cosmic::widget::menu::Item::Button(
|
||||
"Hi 44",
|
||||
Some(cosmic::widget::icon::from_name("screenshot-window-symbolic").into()),
|
||||
Action2::Hi,
|
||||
),
|
||||
cosmic::widget::menu::Item::Button(
|
||||
"Hi 4444",
|
||||
Some(cosmic::widget::icon::from_name("screenshot-window-symbolic").into()),
|
||||
Action2::Hi,
|
||||
),
|
||||
cosmic::widget::menu::Item::Button(
|
||||
"Hi 444444",
|
||||
Some(cosmic::widget::icon::from_name("screenshot-window-symbolic").into()),
|
||||
Action2::Hi,
|
||||
),
|
||||
cosmic::widget::menu::Item::Button(
|
||||
"Hi 444444444444",
|
||||
Some(cosmic::widget::icon::from_name("screenshot-window-symbolic").into()),
|
||||
Action2::Hi,
|
||||
),
|
||||
],
|
||||
],
|
||||
))
|
||||
}
|
||||
|
||||
/// Handle application events here.
|
||||
fn update(&mut self, message: Self::Message) -> cosmic::app::Task<Self::Message> {
|
||||
match message {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue