Skip to content

Commit

Permalink
clock
Browse files Browse the repository at this point in the history
Signed-off-by: Ryan Brue <ryanbrue.dev@gmail.com>
  • Loading branch information
ryanabx committed Aug 22, 2024
1 parent 2b9cfdf commit 634cc6f
Show file tree
Hide file tree
Showing 4 changed files with 106 additions and 5 deletions.
44 changes: 44 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 Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ cosmic-protocols = { git = "https://github.com/pop-os/cosmic-protocols", default
"client",
], rev = "c8d3a1c" }
once_cell = "1.19.0"
chrono = "0.4.38"
23 changes: 19 additions & 4 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ use iced::{
application::{
actions::layer_surface::SctkLayerSurfaceSettings, layer_surface::Anchor, InitialSurface,
},
widget::{column, container::Style},
Application, Background, Color, Command, Radius, Settings, Theme,
widget::{column, container::Style, row},
Application, Background, Color, Command, Radius, Settings, Subscription, Theme,
};
use settings_tray::{SettingsTray, SettingsTrayMessage};

mod app_tray;
mod config;
Expand All @@ -30,13 +31,15 @@ fn main() -> Result<(), iced::Error> {
struct Panel<'a> {
_panel_config: PanelConfig,
app_tray: AppTray<'a>,
settings_tray: SettingsTray,
}

impl<'a> Default for Panel<'a> {
fn default() -> Self {
Self {
_panel_config: PanelConfig::default(),
app_tray: AppTray::new(AppTrayConfig::default()),
settings_tray: SettingsTray::new(),
}
}
}
Expand All @@ -45,6 +48,7 @@ impl<'a> Default for Panel<'a> {
pub enum Message {
Panic,
AppTray(AppTrayMessage),
SettingsTray(SettingsTrayMessage),
}

impl<'a> Application for Panel<'a> {
Expand All @@ -63,6 +67,7 @@ impl<'a> Application for Panel<'a> {
}

fn update(&mut self, message: Self::Message) -> iced::Command<Self::Message> {
println!("Received message: {:?}", message);
match message {
Message::Panic => {
panic!("Panic button pressed hehe");
Expand All @@ -71,14 +76,21 @@ impl<'a> Application for Panel<'a> {
.app_tray
.handle_message(app_tray_msg)
.map(Message::AppTray),
Message::SettingsTray(settings_tray_msg) => self
.settings_tray
.handle_message(settings_tray_msg)
.map(Message::SettingsTray),
}
}

fn view(
&self,
_id: iced::window::Id,
) -> iced::Element<'_, Self::Message, Self::Theme, Self::Renderer> {
let panel_items = self.app_tray.view().map(Message::AppTray);
let panel_items = row![
self.app_tray.view().map(Message::AppTray),
self.settings_tray.view().map(Message::SettingsTray)
];
iced::widget::container(column![
iced::widget::horizontal_rule(1).style(|_| iced::widget::rule::Style {
color: Color::WHITE,
Expand All @@ -94,7 +106,10 @@ impl<'a> Application for Panel<'a> {
}

fn subscription(&self) -> iced::Subscription<Self::Message> {
self.app_tray.subscription().map(Message::AppTray)
Subscription::batch(vec![
self.settings_tray.subscription().map(Message::SettingsTray),
self.app_tray.subscription().map(Message::AppTray),
])
}
}

Expand Down
43 changes: 42 additions & 1 deletion src/settings_tray/mod.rs
Original file line number Diff line number Diff line change
@@ -1 +1,42 @@
pub fn get_tray_widget() {}
use clock_subscription::{Clock, ClockMessage};
use iced::widget::{row, text};

mod clock_subscription;

#[derive(Clone, Debug)]
pub struct SettingsTray {
clock: Clock,
}

#[derive(Clone, Debug)]
pub enum SettingsTrayMessage {
Clock(ClockMessage),
}

impl SettingsTray {
pub fn new() -> Self {
Self {
clock: Clock::new(),
}
}

pub fn handle_message(
&mut self,
message: SettingsTrayMessage,
) -> iced::Command<SettingsTrayMessage> {
match message {
SettingsTrayMessage::Clock(clock_msg) => self
.clock
.handle_message(clock_msg)
.map(SettingsTrayMessage::Clock),
}
}

pub fn view(&self) -> iced::Element<SettingsTrayMessage> {
iced::widget::container(row![self.clock.view().map(SettingsTrayMessage::Clock)]).into()
}

pub fn subscription(&self) -> iced::Subscription<SettingsTrayMessage> {
self.clock.subscription().map(SettingsTrayMessage::Clock)
}
}

0 comments on commit 634cc6f

Please sign in to comment.