1
0

add more category colors

This commit is contained in:
Rokas Puzonas 2023-01-30 00:16:45 +02:00
parent 640a0a8835
commit 510b28bde5
2 changed files with 24 additions and 11 deletions

View File

@ -22,6 +22,9 @@ fn get_category_bg(category: EventCategory) -> Color32 {
match category { match category {
EventCategory::Default => Color32::GRAY, EventCategory::Default => Color32::GRAY,
EventCategory::Yellow => Color32::from_rgb(251, 184, 41), EventCategory::Yellow => Color32::from_rgb(251, 184, 41),
EventCategory::Green => Color32::from_rgb(152, 188, 55),
EventCategory::Red => Color32::from_rgb(247, 83, 65),
EventCategory::Blue => Color32::from_rgb(10, 174, 179),
} }
} }
@ -289,9 +292,9 @@ impl<'a> EventsTable<'a> {
// now line // now line
let painter = ui.painter(); let painter = ui.painter();
let current_time = now.minute() + now.hour() * 60 - timestamps_mins[0]; let current_time = now.minute() + now.hour() * 60;
if current_time > 0 && current_time < *timestamps_mins.last().unwrap_or(&0) && !is_weekend(now.date()) { if current_time > timestamps_mins[0] && current_time < *timestamps_mins.last().unwrap_or(&0) && !is_weekend(now.date()) {
let offset = current_time as f32 * minute_to_pixel_scale; let offset = (current_time - timestamps_mins[0]) as f32 * minute_to_pixel_scale;
let points = [ let points = [
rect.left_top() + vec2(0.0, offset), rect.left_top() + vec2(0.0, offset),
rect.right_top() + vec2(0.0, offset) rect.right_top() + vec2(0.0, offset)

View File

@ -7,7 +7,10 @@ use lazy_regex::{regex_captures};
#[derive(Debug, Clone, Copy)] #[derive(Debug, Clone, Copy)]
pub enum EventCategory { pub enum EventCategory {
Default, Default,
Yellow Yellow,
Green,
Red,
Blue
} }
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
@ -30,7 +33,8 @@ pub struct Timetable {
#[derive(Debug)] #[derive(Debug)]
pub enum GetTimetableError { pub enum GetTimetableError {
NotFound NotFound,
EmptyTimetable
} }
impl Timetable { impl Timetable {
@ -51,8 +55,10 @@ impl Error for GetTimetableError {}
impl fmt::Display for GetTimetableError { impl fmt::Display for GetTimetableError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
use GetTimetableError::*;
match self { match self {
GetTimetableError::NotFound => write!(f, "Timetable not found"), NotFound => write!(f, "Timetable not found"),
EmptyTimetable => write!(f, "Timetable is empty")
} }
} }
} }
@ -93,7 +99,7 @@ impl TimetableGetter for BlockingTimetableGetter {
} }
let cal = cal.unwrap().unwrap(); let cal = cal.unwrap().unwrap();
if cal.events.is_empty() { if cal.events.is_empty() {
return Err(GetTimetableError::NotFound); return Err(GetTimetableError::EmptyTimetable);
} }
let mut timetable = Timetable { events: vec![] }; let mut timetable = Timetable { events: vec![] };
@ -106,10 +112,14 @@ impl TimetableGetter for BlockingTimetableGetter {
let location_prop = find_property(&event.properties, "LOCATION")?; let location_prop = find_property(&event.properties, "LOCATION")?;
let mut category = EventCategory::Default; let mut category = EventCategory::Default;
if let Some(category_value) = &category_prop.value { if let Some(category_str) = &category_prop.value {
if category_value == "Yellow Category" { category = match category_str.as_str() {
category = EventCategory::Yellow; "Yellow Category" => EventCategory::Yellow,
} "Green Category" => EventCategory::Green,
"Red Category" => EventCategory::Red,
"Blue Category" => EventCategory::Blue,
_ => EventCategory::Default
};
} }
let start_str = start_prop.value.clone().unwrap(); let start_str = start_prop.value.clone().unwrap();
let end_str = end_prop.value.clone().unwrap(); let end_str = end_prop.value.clone().unwrap();