122 lines
3.5 KiB
Rust
122 lines
3.5 KiB
Rust
use iced::Length::{self, Fill, FillPortion};
|
|
use iced::widget::container;
|
|
use iced::{
|
|
Background, Color, Element, Task, Theme,
|
|
widget::{Image, column, container::Style, row, text},
|
|
};
|
|
|
|
mod buttons;
|
|
mod channels;
|
|
mod servers;
|
|
|
|
use servers::{User, get_servers_buttons};
|
|
|
|
use crate::channels::get_channels_buttons;
|
|
|
|
fn main() -> Result<(), iced::Error> {
|
|
iced::application(Liscord::title, Liscord::update, Liscord::view)
|
|
.theme(Liscord::theme)
|
|
.run_with(Liscord::new)
|
|
}
|
|
|
|
struct Liscord {
|
|
user: Option<User>,
|
|
selected_server: Option<i32>,
|
|
selected_channel: Option<i32>,
|
|
}
|
|
|
|
#[derive(Debug, Clone)]
|
|
enum Event {
|
|
ServerPressed(i32),
|
|
ChannelPressed(i32),
|
|
}
|
|
|
|
impl Liscord {
|
|
fn new() -> (Self, Task<Event>) {
|
|
(
|
|
Self {
|
|
user: Some(User::default()),
|
|
selected_server: None,
|
|
selected_channel: None,
|
|
},
|
|
Task::none(),
|
|
)
|
|
}
|
|
|
|
fn title(&self) -> String {
|
|
"Liscord".to_string()
|
|
}
|
|
|
|
fn update(&mut self, event: Event) -> Task<Event> {
|
|
match event {
|
|
Event::ServerPressed(server_id) => {
|
|
println!("Server pressed: {server_id}");
|
|
self.selected_server = Some(server_id);
|
|
self.selected_channel = None;
|
|
// could kick off async load: return Task::perform(...)
|
|
}
|
|
Event::ChannelPressed(channel_id) => {
|
|
println!("Channel pressed: {channel_id}");
|
|
self.selected_channel = Some(channel_id);
|
|
// async tasks
|
|
}
|
|
}
|
|
Task::none()
|
|
}
|
|
|
|
fn view(&self) -> Element<'_, Event> {
|
|
let server_bar = {
|
|
let mut content = column![text("Servers")];
|
|
if let Some(user) = &self.user {
|
|
content = content.push(get_servers_buttons(user, self));
|
|
}
|
|
container(content)
|
|
.padding(10)
|
|
.width(iced::Length::Fixed(200.))
|
|
.height(Fill)
|
|
.style(|_| Style {
|
|
background: Some(Background::Color(Color::from_rgb(0.0, 0.0, 1.0))),
|
|
..Default::default()
|
|
})
|
|
};
|
|
|
|
let app_body = row![server_bar, self.inner_server_content()].height(FillPortion(19));
|
|
|
|
let app_header = {
|
|
let liscord_logo = Image::new("assets/liscord.png");
|
|
let liscord_text = text("Liscord");
|
|
let centered_text = container(liscord_text)
|
|
.width(Fill)
|
|
.center_x(Length::Fill)
|
|
.center_y(Length::Fill);
|
|
row![liscord_logo, centered_text].width(Fill).height(Fill)
|
|
}
|
|
.height(FillPortion(1));
|
|
|
|
column![app_header, app_body].into()
|
|
}
|
|
|
|
fn theme(&self) -> Theme {
|
|
Theme::Dark
|
|
}
|
|
|
|
fn inner_server_content(&self) -> Element<'_, Event> {
|
|
match self.selected_server {
|
|
Some(id) => {
|
|
let channels = get_channels_buttons(&self.user.clone().unwrap(), id, self)
|
|
.width(Length::Fixed(200.))
|
|
.padding(10)
|
|
.spacing(10);
|
|
container(channels)
|
|
.width(iced::Length::Fill)
|
|
.height(iced::Length::Fill)
|
|
.into()
|
|
}
|
|
None => container(text("Select a server"))
|
|
.width(iced::Length::Fill)
|
|
.height(iced::Length::Fill)
|
|
.into(),
|
|
}
|
|
}
|
|
}
|