further stripping
idk if this is still worth it, if the docs are really this bad
This commit is contained in:
@@ -6,6 +6,7 @@ use iced::widget::{
|
|||||||
};
|
};
|
||||||
use iced::window;
|
use iced::window;
|
||||||
use iced::{Command, Element, Font, Length, Subscription};
|
use iced::{Command, Element, Font, Length, Subscription};
|
||||||
|
use iced::futures::StreamExt;
|
||||||
|
|
||||||
use once_cell::sync::Lazy;
|
use once_cell::sync::Lazy;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
@@ -15,14 +16,7 @@ use realm_server::types::Message;
|
|||||||
static INPUT_ID: Lazy<text_input::Id> = Lazy::new(text_input::Id::unique);
|
static INPUT_ID: Lazy<text_input::Id> = Lazy::new(text_input::Id::unique);
|
||||||
|
|
||||||
#[derive(Default, Debug)]
|
#[derive(Default, Debug)]
|
||||||
pub enum RealmApp {
|
pub struct RealmApp {
|
||||||
#[default]
|
|
||||||
Loading,
|
|
||||||
Loaded(State),
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Default)]
|
|
||||||
pub struct State {
|
|
||||||
input_value: String,
|
input_value: String,
|
||||||
messages: Vec<Message>,
|
messages: Vec<Message>,
|
||||||
}
|
}
|
||||||
@@ -46,91 +40,48 @@ impl RealmApp {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn update(&mut self, event: Events) -> Command<Events> {
|
pub fn update(&mut self, event: Events) -> Command<Events> {
|
||||||
match self {
|
let command = match event {
|
||||||
RealmApp::Loading => {
|
Events::InputChanged(value) => {
|
||||||
text_input::focus(INPUT_ID.clone())
|
self.input_value = value;
|
||||||
|
|
||||||
|
Command::none()
|
||||||
}
|
}
|
||||||
RealmApp::Loaded(state) => {
|
Events::SendMessage => {
|
||||||
let command = match event {
|
//TODO
|
||||||
Events::InputChanged(value) => {
|
self.input_value.clear();
|
||||||
state.input_value = value;
|
Command::none()
|
||||||
|
|
||||||
Command::none()
|
|
||||||
}
|
|
||||||
Events::SendMessage => {
|
|
||||||
//TODO
|
|
||||||
|
|
||||||
Command::none()
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
Command::batch(vec![command])
|
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
|
Command::batch(vec![command])
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn view(&self) -> Element<Events> {
|
pub fn view(&self) -> Element<Events> {
|
||||||
match self {
|
let title = text("todos")
|
||||||
RealmApp::Loading => loading_message(),
|
.width(Length::Fill)
|
||||||
RealmApp::Loaded(State {
|
.size(100)
|
||||||
input_value,
|
.color([0.5, 0.5, 0.5])
|
||||||
messages: tasks,
|
.horizontal_alignment(alignment::Horizontal::Center);
|
||||||
..
|
|
||||||
}) => {
|
|
||||||
let title = text("todos")
|
|
||||||
.width(Length::Fill)
|
|
||||||
.size(100)
|
|
||||||
.color([0.5, 0.5, 0.5])
|
|
||||||
.horizontal_alignment(alignment::Horizontal::Center);
|
|
||||||
|
|
||||||
let input = text_input("What needs to be done?", input_value)
|
let input = text_input("New Message", &*self.input_value)
|
||||||
.id(INPUT_ID.clone())
|
.id(INPUT_ID.clone())
|
||||||
.on_input(Events::InputChanged)
|
.on_input(Events::InputChanged)
|
||||||
.on_submit(Events::SendMessage)
|
.on_submit(Events::SendMessage)
|
||||||
.padding(15)
|
//.padding(15)
|
||||||
.size(30);
|
.size(12);
|
||||||
|
|
||||||
// let controls = view_controls(tasks, *filter);
|
let messages: Vec<Text> = Vec::new();
|
||||||
// let filtered_tasks =
|
for message in &self.messages {
|
||||||
// tasks.iter().filter(|task| filter.matches(task));
|
|
||||||
//
|
|
||||||
// let tasks: Element<_> = if filtered_tasks.count() > 0 {
|
|
||||||
// keyed_column(
|
|
||||||
// tasks
|
|
||||||
// .iter()
|
|
||||||
// .enumerate()
|
|
||||||
// .filter(|(_, task)| filter.matches(task))
|
|
||||||
// .map(|(i, task)| {
|
|
||||||
// (
|
|
||||||
// task.id,
|
|
||||||
// task.view(i).map(move |message| {
|
|
||||||
// Events::TaskMessage(i, message)
|
|
||||||
// }),
|
|
||||||
// )
|
|
||||||
// }),
|
|
||||||
// )
|
|
||||||
// .spacing(10)
|
|
||||||
// .into()
|
|
||||||
// } else {
|
|
||||||
// empty_message(match filter {
|
|
||||||
// Filter::All => "You have not created a task yet...",
|
|
||||||
// Filter::Active => "All your tasks are done! :D",
|
|
||||||
// Filter::Completed => {
|
|
||||||
// "You have not completed a task yet..."
|
|
||||||
// }
|
|
||||||
// })
|
|
||||||
// };
|
|
||||||
|
|
||||||
let content = column![title, input]
|
|
||||||
.spacing(20)
|
|
||||||
.max_width(800);
|
|
||||||
|
|
||||||
scrollable(
|
|
||||||
container(content).center_x(Length::Fill).padding(40),
|
|
||||||
)
|
|
||||||
.into()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let content = column![title, input]
|
||||||
|
.spacing(20);
|
||||||
|
//.max_width(800);
|
||||||
|
|
||||||
|
scrollable(
|
||||||
|
container(content).center_x(Length::Fill).padding(40),
|
||||||
|
).into()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn subscription(&self) -> Subscription<Events> {
|
pub fn subscription(&self) -> Subscription<Events> {
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ use realm_client::RealmApp;
|
|||||||
|
|
||||||
pub fn main() -> iced::Result {
|
pub fn main() -> iced::Result {
|
||||||
tracing_subscriber::fmt::init();
|
tracing_subscriber::fmt::init();
|
||||||
|
|
||||||
iced::program(RealmApp::title, RealmApp::update, RealmApp::view)
|
iced::program(RealmApp::title, RealmApp::update, RealmApp::view)
|
||||||
.load(RealmApp::load)
|
.load(RealmApp::load)
|
||||||
.subscription(RealmApp::subscription)
|
.subscription(RealmApp::subscription)
|
||||||
|
|||||||
Reference in New Issue
Block a user