Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Calendar Widget to lala-bar #31

Merged
merged 5 commits into from
Nov 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
111 changes: 111 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions lala_bar/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,4 @@ iced_zbus_notification.workspace = true
chrono = "0.4.38"
async-trait.workspace = true
tracing-journald = "0.3.0"
iced_aw = "0.11.0"
5 changes: 5 additions & 0 deletions lala_bar/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use launcher::{LaunchMessage, Launcher};
use zbus_mpirs::ServiceInfo;

use futures::channel::mpsc::Sender;
use iced_aw::date_picker::Date;
use iced_layershell::reexport::{Anchor, Layer};
use iced_layershell::settings::{LayerShellSettings, Settings, StartMode};
use iced_layershell::to_layer_message;
Expand Down Expand Up @@ -54,6 +55,7 @@ pub enum LaLaInfo {
HiddenInfo,
RightPanel,
ErrorHappened(iced::window::Id),
Calendar,
}

#[to_layer_message(multi, info_name = "LaLaInfo")]
Expand Down Expand Up @@ -87,6 +89,9 @@ pub enum Message {
Ready(Sender<NotifyCommand>),
#[allow(unused)]
LinkClicked(markdown::Url),
ToggleCalendar,
Cancel,
Submit(Date),
}

impl From<NotifyMessage> for Message {
Expand Down
57 changes: 54 additions & 3 deletions lala_bar/src/music_bar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use iced::widget::{
text_input, Space,
};
use iced::{executor, Alignment, Element, Font, Length, Task as Command, Theme};
use iced_aw::{date_picker::Date, helpers::date_picker};
use iced_layershell::reexport::{Anchor, KeyboardInteractivity, Layer, NewLayerShellSettings};
use iced_layershell::MultiApplication;
use iced_runtime::window::Action as WindowAction;
Expand Down Expand Up @@ -48,8 +49,11 @@ pub struct LalaMusicBar {
cached_hidden_notifications: Vec<NotifyUnitWidgetInfo>,
sender: Option<Sender<NotifyCommand>>,
quite_mode: bool,

datetime: DateTime<Local>,
calendar_id: Option<iced::window::Id>,
show_picker: bool,
date: Date,
is_calendar_open: bool,
}

impl LalaMusicBar {
Expand All @@ -59,9 +63,9 @@ impl LalaMusicBar {
let week = date.format("%A").to_string();
let time = self.datetime.time();
let time_info = time.format("%H:%M").to_string();

let week_btn = button(text(week.clone())).on_press(Message::ToggleCalendar);
container(row![
text(week),
week_btn,
Space::with_width(5.),
text(time_info),
Space::with_width(5.),
Expand Down Expand Up @@ -500,6 +504,10 @@ impl MultiApplication for LalaMusicBar {
sender: None,
quite_mode: false,
datetime: Local::now(),
calendar_id: None,
show_picker: false,
date: Date::today(),
is_calendar_open: false,
},
Command::batch(vec![
Command::done(Message::UpdateBalance),
Expand All @@ -519,6 +527,8 @@ impl MultiApplication for LalaMusicBar {
Some(LaLaInfo::HiddenInfo)
} else if self.right_panel.is_some_and(|tid| tid == id) {
Some(LaLaInfo::RightPanel)
} else if self.calendar_id.is_some_and(|tid| tid == id) {
Some(LaLaInfo::Calendar)
} else {
if let Some(info) = self.cached_notifications.get(&id) {
return Some(LaLaInfo::Notify(Box::new(info.clone())));
Expand Down Expand Up @@ -547,6 +557,7 @@ impl MultiApplication for LalaMusicBar {
self.hiddenid = Some(id);
}
LaLaInfo::RightPanel => self.right_panel = Some(id),
LaLaInfo::Calendar => self.calendar_id = Some(id),
_ => unreachable!(),
}
}
Expand Down Expand Up @@ -585,6 +596,36 @@ impl MultiApplication for LalaMusicBar {
Message::RequestDBusInfoUpdate => {
return Command::perform(get_metadata(), Message::DBusInfoUpdate)
}
Message::ToggleCalendar => {
if self.is_calendar_open && self.calendar_id.is_some() {
Decodetalkers marked this conversation as resolved.
Show resolved Hide resolved
self.is_calendar_open = false;
return iced_runtime::task::effect(Action::Window(WindowAction::Close(
self.calendar_id.unwrap(),
)));
} else {
self.is_calendar_open = true;
return Command::done(Message::NewLayerShell {
settings: NewLayerShellSettings {
size: Some((400, 350)),
exclusive_zone: None,
anchor: Anchor::Right | Anchor::Bottom,
layer: Layer::Top,
margin: Some((10, 10, 10, 10)),
keyboard_interactivity: KeyboardInteractivity::Exclusive,
use_last_output: false,
},
info: LaLaInfo::Calendar,
});
}
}

Message::Submit(date) => {
self.date = date;
self.show_picker = false;
}
Message::Cancel => {
self.show_picker = false;
}
Message::RequestPlay => {
if let Some(ref data) = self.service_data {
if !data.can_play {
Expand Down Expand Up @@ -1000,6 +1041,16 @@ impl MultiApplication for LalaMusicBar {
return launcher.view();
}
}
LaLaInfo::Calendar => {
let datepicker = date_picker(
true,
self.date,
button(text("Pick date")),
Message::Cancel,
Message::Submit,
);
return column![datepicker].into();
}
LaLaInfo::Notify(unitwidgetinfo) => {
let btnwidgets: Element<Message> = unitwidgetinfo.notify_button(self);

Expand Down