Skip to content
This repository has been archived by the owner on Apr 19, 2024. It is now read-only.

Commit

Permalink
Page titles
Browse files Browse the repository at this point in the history
  • Loading branch information
edfloreshz committed May 17, 2023
1 parent 58a400f commit 5352c21
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 17 deletions.
4 changes: 4 additions & 0 deletions src/widgets/content/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,10 @@ pub async fn select_task_list(
let local = LocalStorage::new();
let mut guard = model.task_factory.guard();
guard.clear();
model.icon = list.icon().map(|s| s.to_owned());
model.title = list.name();
model.description = list.description();
model.smart = list.smart();
match list {
SidebarList::All => {
model.parent_list = Some(SidebarList::All);
Expand Down
4 changes: 4 additions & 0 deletions src/widgets/content/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ pub struct ContentModel {
pub task_entry: Controller<TaskEntryModel>,
pub parent_list: Option<SidebarList>,
pub compact: bool,
pub icon: Option<String>,
pub title: String,
pub description: String,
pub smart: bool,
pub selected_task: Option<Task>,
pub show_task_details: bool,
}
41 changes: 41 additions & 0 deletions src/widgets/content/widget.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,42 @@ impl AsyncComponent for ContentModel {
set_width_request: 300,
set_margin_all: 10,
set_orientation: gtk::Orientation::Vertical,
gtk::Box {
set_orientation: gtk::Orientation::Horizontal,
gtk::Image {
#[watch]
set_visible: model.smart,
#[watch]
set_icon_name: model.icon.as_deref(),
set_margin_start: 10,
},
gtk::Label {
#[watch]
set_visible: !model.smart,
#[watch]
set_text: model.icon.as_deref().unwrap_or_default(),
set_margin_start: 10,
},
gtk::Label {
set_css_classes: &["title-3"],
set_halign: gtk::Align::Start,
set_margin_start: 10,
set_margin_end: 10,
#[watch]
set_text: model.title.as_str()
},
},
gtk::Label {
#[watch]
set_visible: !model.description.is_empty(),
set_css_classes: &["title-5"],
set_halign: gtk::Align::Start,
set_margin_bottom: 10,
set_margin_start: 10,
set_margin_end: 10,
#[watch]
set_text: model.description.as_str()
},
#[name(task_container)]
gtk::Stack {
set_transition_duration: 250,
Expand All @@ -58,6 +94,7 @@ impl AsyncComponent for ContentModel {
set_visible: !model.task_factory.is_empty(),
set_vexpand: true,
set_hexpand: true,

#[local_ref]
list_box -> gtk::ListBox {
set_show_separators: true,
Expand Down Expand Up @@ -141,6 +178,10 @@ impl AsyncComponent for ContentModel {
),
parent_list: None,
compact,
icon: None,
title: String::new(),
smart: false,
description: String::new(),
selected_task: None,
show_task_details: false,
};
Expand Down
7 changes: 7 additions & 0 deletions src/widgets/sidebar/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,11 @@ impl SidebarList {
SidebarList::Custom(list) => list.icon.as_deref(),
}
}

pub fn smart(&self) -> bool {
match self {
SidebarList::Custom(_) => false,
_ => true,
}
}
}
6 changes: 4 additions & 2 deletions src/widgets/task_entry/model.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
use done_local_storage::models::{List, Task};
use done_local_storage::models::Task;
use relm4::gtk;

use crate::widgets::sidebar::model::SidebarList;

#[derive(Debug)]
pub struct TaskEntryModel {
pub task: Task,
pub parent_list: Option<List>,
pub parent_list: Option<SidebarList>,
pub buffer: gtk::EntryBuffer,
}
31 changes: 16 additions & 15 deletions src/widgets/task_entry/widget.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::{fl, widgets::sidebar::model::SidebarList};
use adw::traits::{EntryRowExt, PreferencesRowExt};
use done_local_storage::models::{List, Task};
use done_local_storage::models::Task;
use gtk::traits::{EditableExt, ListBoxRowExt};
use relm4::{
adw, gtk,
Expand All @@ -18,13 +18,16 @@ impl Component for TaskEntryModel {
type CommandOutput = ();
type Input = TaskEntryInput;
type Output = TaskEntryOutput;
type Init = Option<List>;
type Init = Option<SidebarList>;

view! {
#[root]
adw::EntryRow {
#[watch]
set_visible: model.parent_list.is_some(),
set_visible: match model.parent_list.as_ref() {
Some(SidebarList::Custom(_)) => true,
_ => false,
},
set_hexpand: true,
add_css_class: "card",
set_title: fl!("new-task"),
Expand Down Expand Up @@ -89,21 +92,19 @@ impl Component for TaskEntryModel {
},
TaskEntryInput::AddTask => {
if !self.task.title.is_empty() && self.parent_list.is_some() {
self.task.parent = self.parent_list.as_ref().unwrap().id.clone();
sender
.output(TaskEntryOutput::AddTask(self.task.clone()))
.unwrap_or_default();
self.task = Task::new(
String::new(),
self.parent_list.as_ref().unwrap().id.clone(),
);
sender.input(TaskEntryInput::CleanTaskEntry);
if let SidebarList::Custom(list) = self.parent_list.as_ref().unwrap()
{
self.task.parent = list.id.clone();
sender
.output(TaskEntryOutput::AddTask(self.task.clone()))
.unwrap_or_default();
self.task = Task::new(String::new(), list.id.clone());
sender.input(TaskEntryInput::CleanTaskEntry);
}
}
},
TaskEntryInput::SetParentList(list) => {
if let Some(SidebarList::Custom(list)) = list {
self.parent_list = Some(list);
}
self.parent_list = list;
},
}
}
Expand Down

0 comments on commit 5352c21

Please sign in to comment.