added channels front-end

This commit is contained in:
2025-08-27 19:19:49 +02:00
parent 0bef2b69c2
commit c4f471179c
4 changed files with 159 additions and 70 deletions

View File

@@ -5,11 +5,14 @@ use iced::{
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)
@@ -19,19 +22,22 @@ fn main() -> Result<(), iced::Error> {
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>) {
(
Liscord {
Self {
user: Some(User::default()),
selected_server: None,
selected_channel: None,
},
Task::none(),
)
@@ -44,38 +50,37 @@ impl Liscord {
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);
// println!("Server Pressed ! Id: {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 app_body = {
let server_bar = {
let mut content = column![text("Servers")];
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()
})
};
if let Some(user) = &self.user {
content = content.push(get_servers_buttons(user, self))
}
container(content)
.padding(10)
.width(iced::Length::Fixed(300.))
.height(Fill)
.style(|_theme| Style {
background: Some(Background::Color(Color::from_rgb(0.0, 0.0, 1.0))),
..Default::default()
})
};
let message_content = container(text("Messages"))
.width(iced::Length::Fill)
.height(Fill);
row![server_bar, message_content]
}
.height(FillPortion(19));
let app_body = row![server_bar, self.inner_server_content()].height(FillPortion(19));
let app_header = {
let liscord_logo = Image::new("assets/liscord.png");
@@ -84,7 +89,6 @@ impl Liscord {
.width(Fill)
.center_x(Length::Fill)
.center_y(Length::Fill);
row![liscord_logo, centered_text].width(Fill).height(Fill)
}
.height(FillPortion(1));
@@ -95,4 +99,23 @@ impl Liscord {
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(),
}
}
}