first commit
This commit is contained in:
1
front/.gitignore
vendored
Normal file
1
front/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
/target
|
||||
4259
front/Cargo.lock
generated
Normal file
4259
front/Cargo.lock
generated
Normal file
File diff suppressed because it is too large
Load Diff
11
front/Cargo.toml
Normal file
11
front/Cargo.toml
Normal file
@@ -0,0 +1,11 @@
|
||||
[package]
|
||||
name = "front"
|
||||
version = "0.1.0"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
iced = { version = "0.13.1", features = ["debug", "image"] }
|
||||
|
||||
[[bin]]
|
||||
name = "liscord"
|
||||
path = "src/main.rs"
|
||||
BIN
front/assets/liscord.png
Normal file
BIN
front/assets/liscord.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 248 KiB |
15
front/src/channels.rs
Normal file
15
front/src/channels.rs
Normal file
@@ -0,0 +1,15 @@
|
||||
#[allow(dead_code)]
|
||||
#[derive(Clone, Default)]
|
||||
pub struct Channel {
|
||||
pub server_id: i32,
|
||||
pub channel_name: String,
|
||||
}
|
||||
|
||||
impl Channel {
|
||||
fn new(server_id: i32, channel_name: &str) -> Self {
|
||||
Channel {
|
||||
server_id,
|
||||
channel_name: channel_name.to_string(),
|
||||
}
|
||||
}
|
||||
}
|
||||
98
front/src/main.rs
Normal file
98
front/src/main.rs
Normal file
@@ -0,0 +1,98 @@
|
||||
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 channels;
|
||||
mod servers;
|
||||
|
||||
use servers::{User, get_servers_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>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
enum Event {
|
||||
ServerPressed(i32),
|
||||
}
|
||||
|
||||
impl Liscord {
|
||||
fn new() -> (Self, Task<Event>) {
|
||||
(
|
||||
Liscord {
|
||||
user: Some(User::default()),
|
||||
selected_server: None,
|
||||
},
|
||||
Task::none(),
|
||||
)
|
||||
}
|
||||
|
||||
fn title(&self) -> String {
|
||||
"Liscord".to_string()
|
||||
}
|
||||
|
||||
fn update(&mut self, event: Event) -> Task<Event> {
|
||||
match event {
|
||||
Event::ServerPressed(server_id) => {
|
||||
self.selected_server = Some(server_id);
|
||||
// println!("Server Pressed ! Id: {server_id}")
|
||||
}
|
||||
}
|
||||
Task::none()
|
||||
}
|
||||
|
||||
fn view(&self) -> Element<'_, Event> {
|
||||
let app_body = {
|
||||
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(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_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
|
||||
}
|
||||
}
|
||||
93
front/src/servers.rs
Normal file
93
front/src/servers.rs
Normal file
@@ -0,0 +1,93 @@
|
||||
use iced::{
|
||||
Border,
|
||||
widget::{Button, Column, container},
|
||||
};
|
||||
use iced::{Length, Shadow};
|
||||
|
||||
use crate::{Event, Liscord};
|
||||
|
||||
mod colors {
|
||||
use iced::Color;
|
||||
|
||||
pub const BUTTON_COLOR: Color = Color::from_rgb(0.2, 0.2, 0.2);
|
||||
pub const SELECTED_BUTTON_COLOR: Color = Color::from_rgb(0.2, 0.2, 1.);
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
#[derive(Default, Clone)]
|
||||
pub struct Server {
|
||||
pub server_id: i32,
|
||||
pub server_name: String,
|
||||
is_hovered: bool,
|
||||
}
|
||||
|
||||
impl Server {
|
||||
fn new(id: i32, name: &str) -> Self {
|
||||
Server {
|
||||
server_id: id,
|
||||
server_name: name.to_string(),
|
||||
..Default::default()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl PartialEq for Server {
|
||||
fn eq(&self, other: &Self) -> bool {
|
||||
self.server_id == other.server_id
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
#[derive(Default)]
|
||||
pub struct User {
|
||||
pub user_id: i32,
|
||||
pub username: String,
|
||||
pub password_hash: String,
|
||||
pub email: String,
|
||||
}
|
||||
|
||||
pub fn get_servers(_user: &User) -> Vec<Server> {
|
||||
let friend_serv0 = Server::new(0, "Friends0");
|
||||
let friend_serv1 = Server::new(1, "Friends1");
|
||||
let friend_serv2 = Server::new(2, "Friends2");
|
||||
vec![friend_serv0, friend_serv1, friend_serv2]
|
||||
}
|
||||
|
||||
pub fn get_servers_buttons<'a>(user: &User, instance: &'a Liscord) -> Column<'a, Event> {
|
||||
let servers = get_servers(user);
|
||||
|
||||
let mut col = Column::new();
|
||||
|
||||
for server in servers {
|
||||
col = col.push(server_button(server, instance));
|
||||
}
|
||||
|
||||
col
|
||||
}
|
||||
|
||||
fn server_button<'a>(server: Server, instance: &'a Liscord) -> Button<'a, Event> {
|
||||
Button::new(
|
||||
container(iced::widget::text(server.server_name).size(20))
|
||||
.center_x(Length::Fill)
|
||||
.center_y(Length::Fill),
|
||||
)
|
||||
.padding(10)
|
||||
.width(iced::Length::Fill)
|
||||
.height(Length::Fixed(100.0))
|
||||
.style(move |_theme, _status| iced::widget::button::Style {
|
||||
background: Some(iced::Background::Color(
|
||||
if Some(server.server_id) == instance.selected_server {
|
||||
colors::SELECTED_BUTTON_COLOR
|
||||
} else {
|
||||
colors::BUTTON_COLOR
|
||||
},
|
||||
)),
|
||||
border: Border::default().rounded(10),
|
||||
shadow: Shadow {
|
||||
offset: iced::Vector { x: 3., y: 3. },
|
||||
..Default::default()
|
||||
},
|
||||
..Default::default()
|
||||
})
|
||||
.on_press(Event::ServerPressed(server.server_id))
|
||||
}
|
||||
Reference in New Issue
Block a user