106 lines
2.8 KiB
Rust
106 lines
2.8 KiB
Rust
use iced::widget::{column, container, scrollable, text, text_input};
|
|
use iced::Alignment::Center;
|
|
use iced::{Element, Fill, Task, Theme};
|
|
|
|
// use uuid::Uuid;
|
|
|
|
pub fn main() -> iced::Result {
|
|
iced::application("Zieltakt", App::update, App::view)
|
|
.theme(theme)
|
|
.run_with(App::new)
|
|
}
|
|
|
|
fn theme(_state: &App) -> Theme {
|
|
Theme::Nightfly
|
|
}
|
|
|
|
#[derive(Debug, Default, Clone)]
|
|
enum App {
|
|
#[default]
|
|
Loading,
|
|
Loaded(State),
|
|
}
|
|
|
|
#[derive(Debug, Clone, Default)]
|
|
struct State {
|
|
input_value: String,
|
|
habits: Vec<Habit>,
|
|
dirty: bool,
|
|
saving: bool,
|
|
}
|
|
|
|
#[derive(Debug, Clone)]
|
|
struct Habit {
|
|
// #[serde(default = "Uuid::new_v4")]
|
|
// id: Uuid,
|
|
description: String,
|
|
completed: bool,
|
|
// #[serde(skip)]
|
|
// state: TaskState,
|
|
}
|
|
|
|
#[derive(Debug, Clone)]
|
|
enum Message {
|
|
InputChanged(String),
|
|
CreateTask,
|
|
}
|
|
|
|
impl App {
|
|
fn new() -> (Self, Task<Message>) {
|
|
// TODO: Imlepment loading using serde
|
|
(App::Loaded(State::default()), Task::none())
|
|
}
|
|
|
|
fn update(app: &mut App, message: Message) -> Task<Message> {
|
|
match app {
|
|
App::Loading => {
|
|
// TODO: Imlepment loading using serde
|
|
Task::none()
|
|
}
|
|
App::Loaded(state) => {
|
|
let command = match message {
|
|
Message::InputChanged(value) => {
|
|
state.input_value = value;
|
|
Task::none()
|
|
}
|
|
Message::CreateTask => {
|
|
state.habits.push(Habit {
|
|
description: state.input_value.clone(),
|
|
completed: false,
|
|
});
|
|
state.input_value = String::new();
|
|
println!("{:?}", state.habits);
|
|
Task::none()
|
|
}
|
|
|
|
};
|
|
return command;
|
|
}
|
|
}
|
|
}
|
|
|
|
fn view(app: &App) -> Element<Message> {
|
|
match &app {
|
|
App::Loading => text("Loading...").into(),
|
|
App::Loaded(State { input_value, .. }) => {
|
|
let title = text("todos")
|
|
.width(Fill)
|
|
.size(100)
|
|
.color([0.5, 0.5, 0.5])
|
|
.align_x(Center);
|
|
|
|
let input = text_input("What needs to be done?", input_value)
|
|
.id("new-task")
|
|
.on_input(Message::InputChanged)
|
|
.on_submit(Message::CreateTask)
|
|
.padding(15)
|
|
.size(30)
|
|
.align_x(Center);
|
|
|
|
let content = column![title, input].spacing(20).max_width(800);
|
|
|
|
scrollable(container(content).center_x(Fill).padding(40)).into()
|
|
}
|
|
}
|
|
}
|
|
}
|