added message box

This commit is contained in:
2025-08-27 22:29:07 +02:00
parent c4f471179c
commit 3c47de3dc3

View File

@@ -1,5 +1,6 @@
use iced::Length::{self, Fill, FillPortion}; use iced::Length::{self, Fill, FillPortion};
use iced::widget::container; use iced::widget::container;
use iced::widget::text_editor;
use iced::{ use iced::{
Background, Color, Element, Task, Theme, Background, Color, Element, Task, Theme,
widget::{Image, column, container::Style, row, text}, widget::{Image, column, container::Style, row, text},
@@ -23,12 +24,14 @@ struct Liscord {
user: Option<User>, user: Option<User>,
selected_server: Option<i32>, selected_server: Option<i32>,
selected_channel: Option<i32>, selected_channel: Option<i32>,
message_editor: text_editor::Content,
} }
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
enum Event { enum Event {
ServerPressed(i32), ServerPressed(i32),
ChannelPressed(i32), ChannelPressed(i32),
MessageInput(text_editor::Action),
} }
impl Liscord { impl Liscord {
@@ -38,6 +41,7 @@ impl Liscord {
user: Some(User::default()), user: Some(User::default()),
selected_server: None, selected_server: None,
selected_channel: None, selected_channel: None,
message_editor: text_editor::Content::new(),
}, },
Task::none(), Task::none(),
) )
@@ -60,16 +64,19 @@ impl Liscord {
self.selected_channel = Some(channel_id); self.selected_channel = Some(channel_id);
// async tasks // async tasks
} }
Event::MessageInput(action) => {
self.message_editor.perform(action);
}
} }
Task::none() Task::none()
} }
fn view(&self) -> Element<'_, Event> { fn view(&self) -> Element<'_, Event> {
let server_bar = { let server_bar = {
let mut content = column![text("Servers")]; let content = match &self.user {
if let Some(user) = &self.user { Some(user) => get_servers_buttons(user, self).spacing(10),
content = content.push(get_servers_buttons(user, self)); None => column![],
} };
container(content) container(content)
.padding(10) .padding(10)
.width(iced::Length::Fixed(200.)) .width(iced::Length::Fixed(200.))
@@ -107,7 +114,17 @@ impl Liscord {
.width(Length::Fixed(200.)) .width(Length::Fixed(200.))
.padding(10) .padding(10)
.spacing(10); .spacing(10);
container(channels)
let message_box = if let Some(channel) = self.selected_channel {
self.messages(channel)
} else {
text("Select a server to show messages")
.width(Length::Fill)
.height(Length::Fill)
.center()
.into()
};
container(row![channels, message_box])
.width(iced::Length::Fill) .width(iced::Length::Fill)
.height(iced::Length::Fill) .height(iced::Length::Fill)
.into() .into()
@@ -118,4 +135,42 @@ impl Liscord {
.into(), .into(),
} }
} }
fn messages<'a>(&'a self, _channel: i32) -> Element<'a, Event> {
let messages_container = self.messages_container();
let text_box = iced::widget::text_editor(&self.message_editor)
.height(Length::Fixed(38.0))
.padding(6)
.size(16.0)
.placeholder("Type a message...")
.on_action(Event::MessageInput)
.style(|_theme, status| {
let focused = matches!(status, text_editor::Status::Focused);
text_editor::Style {
value: Color::from_rgb8(0, 255, 128),
placeholder: Color::from_rgb8(140, 140, 140),
selection: Color::from_rgba8(0, 120, 255, 0.35),
icon: Color::WHITE,
background: Background::Color(Color::from_rgb8(30, 30, 30)),
border: iced::Border {
color: if focused {
Color::from_rgb8(0, 180, 120)
} else {
Color::from_rgb8(70, 70, 70)
},
width: 1.0,
radius: 4.0.into(),
},
}
});
column![messages_container, text_box].into()
}
fn messages_container<'a>(&self) -> Element<'a, Event> {
text("Messages will be there")
.width(Length::Fill)
.height(Length::Fill)
.center()
.into()
}
} }