[MIRROR] https://codeberg.org/naomi/nanel
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Calendar menu

+91 -7
+3 -1
src/panel.rs
··· 289 289 NanelWindowType::Notification => { 290 290 notification_menu::view(id).style(rounded_background) 291 291 } 292 - NanelWindowType::Calendar => calendar_menu::view(id).style(rounded_background), 292 + NanelWindowType::Calendar => { 293 + calendar_menu::view(id, self.datetime).style(rounded_background) 294 + } 293 295 NanelWindowType::SystemTray => systray_menu::view(id).style(rounded_background), 294 296 NanelWindowType::QuickSettings => { 295 297 quick_settings_menu::view(id).style(rounded_background)
+88 -6
src/windows/calendar_menu.rs
··· 1 + use chrono::{DateTime, Datelike, Local}; 1 2 use iced::{ 2 - widget::{Container, button, container}, 3 + Alignment::Center, 4 + Length, 5 + widget::{Container, button, column, container, row, text}, 3 6 window, 4 7 }; 8 + use iced_fonts::Bootstrap; 5 9 use once_cell::sync::Lazy; 6 10 7 - use crate::{config::GAP, msg::Message}; 11 + use crate::{ 12 + config::{BUTTON_SIZE, GAP}, 13 + msg::Message, 14 + styles, 15 + widgets::small_icon, 16 + }; 8 17 9 18 pub static CALENDAR_MENU: Lazy<container::Id> = Lazy::new(|| container::Id::new("cal_menu")); 10 19 11 - pub fn view<'a>(window_id: window::Id) -> Container<'a, Message> { 12 - container(button("Close Calendar").on_press(Message::UserClosedWindow(window_id))) 13 - .padding(GAP) 14 - .id(CALENDAR_MENU.clone()) 20 + pub fn view<'a>(_window_id: window::Id, datetime: DateTime<Local>) -> Container<'a, Message> { 21 + let weekdays = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"]; 22 + 23 + let header = row(weekdays.iter().map(|day| { 24 + container(text(*day)) 25 + .width(Length::Fixed(BUTTON_SIZE)) 26 + .align_x(Center) 27 + .align_y(Center) 28 + .into() 29 + })); 30 + 31 + // first day of month and total days 32 + let first_day = datetime 33 + .with_day(1) 34 + .unwrap() 35 + .weekday() 36 + .num_days_from_sunday() as usize; 37 + 38 + let days_in_month = (datetime 39 + .with_day(1) 40 + .unwrap() 41 + .with_month(datetime.month() + 1) 42 + .unwrap_or(datetime.with_month(1).unwrap()) 43 + .signed_duration_since(datetime.with_day(1).unwrap()) 44 + .num_days() 45 + + 1) as usize; 46 + 47 + let grid = column((0..6).map(|r| { 48 + row((0..7).map(|col| { 49 + let day_num = r * 7 + col; 50 + let (content, style): ( 51 + String, 52 + for<'b> fn( 53 + &'b iced::Theme, 54 + iced::widget::button::Status, 55 + ) -> iced::widget::button::Style, 56 + ) = if day_num >= first_day && day_num < first_day + days_in_month { 57 + let day = day_num - first_day + 1; 58 + ( 59 + day.to_string(), 60 + match day == datetime.day() as usize { 61 + true => styles::solid, 62 + false => styles::transparent, 63 + }, 64 + ) 65 + } else { 66 + (String::new(), styles::transparent) 67 + }; 68 + 69 + button(text(content).align_x(Center).align_y(Center)) 70 + .width(Length::Fixed(BUTTON_SIZE)) 71 + .height(Length::Fixed(BUTTON_SIZE)) 72 + .style(style) 73 + .into() 74 + })) 75 + .spacing(1) 76 + .into() 77 + })) 78 + .spacing(1); 79 + 80 + container(column![ 81 + row![ 82 + text(datetime.format("%a %-e %B %Y").to_string()).size(24), 83 + button(small_icon(Bootstrap::ChevronLeft)) 84 + .style(styles::transparent) 85 + .width(Length::Shrink), 86 + button(small_icon(Bootstrap::ChevronRight)) 87 + .style(styles::transparent) 88 + .width(Length::Shrink), 89 + ], 90 + header, 91 + grid 92 + ]) 93 + .width(Length::Shrink) 94 + .width(Length::Shrink) 95 + .padding(GAP) 96 + .id(CALENDAR_MENU.clone()) 15 97 }