This commit is contained in:
2026-08-31 21:12:05 +01:00
parent f77cd4d815
commit 81f242419e
7 changed files with 359 additions and 179 deletions
+66
View File
@@ -0,0 +1,66 @@
use iced::widget::{column, mouse_area, text, Row};
use iced::{window, Alignment, Element, Length, Task};
use crate::module::{downcast, ModuleDef, ModuleMsg, ModuleState};
use crate::Message;
pub struct Workspaces;
pub struct State {
workspaces: Vec<String>,
}
#[derive(Debug, Clone)]
pub enum Msg {
Select(String),
}
impl ModuleDef for Workspaces {
fn new_state(&self) -> Box<dyn ModuleState> {
Box::new(State {
workspaces: vec!["1".into(), "2".into(), "3".into(), "4".into()],
})
}
}
impl ModuleState for State {
fn label(&self) -> &'static str {
"workspaces"
}
fn handle(&mut self, msg: Box<dyn ModuleMsg>) -> Task<Message> {
let msg = *downcast::<Msg>(msg).expect("workspaces module received foreign message");
match msg {
Msg::Select(ws) => {
self.workspaces.sort_by_key(|w| w != &ws);
Task::none()
}
}
}
fn popup(&self, popup_id: window::Id) -> Element<'static, Message> {
let items: Vec<Element<'static, Message>> = self
.workspaces
.iter()
.map(|ws| {
mouse_area(text(ws.clone()).size(13))
.on_press(Message::Module(
"workspaces".into(),
Box::new(Msg::Select(ws.clone())),
))
.into()
})
.collect();
column![
text("workspaces menu")
.size(14)
.width(Length::Fill)
.align_x(Alignment::Center),
Row::from_vec(items).spacing(1),
mouse_area(text("close").size(12)).on_press(Message::ClosePopup(popup_id)),
]
.spacing(1)
.into()
}
}