logic for sending messages
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
use iced::{
|
||||
Border,
|
||||
Background, Border, Color,
|
||||
widget::{Button, container},
|
||||
};
|
||||
use iced::{Length, Shadow};
|
||||
@@ -46,29 +46,26 @@ where
|
||||
.on_press(press_variant(id))
|
||||
}
|
||||
|
||||
// Utility to round a button border while keeping other default styling.
|
||||
// Note: Applying a new .style(...) replaces any previous style closure.
|
||||
// Use this helper early (or integrate its logic) if you also need custom colors.
|
||||
pub fn round_button<'a, Message>(button: Button<'a, Message>, radius: f32) -> Button<'a, Message>
|
||||
pub fn round_button<'a, Message>(
|
||||
button: iced::widget::Button<'a, Message>,
|
||||
radius: f32,
|
||||
) -> iced::widget::Button<'a, Message>
|
||||
where
|
||||
Message: 'a,
|
||||
{
|
||||
button.style(move |_theme, status| {
|
||||
// Start from default style for this status
|
||||
let mut style = iced::widget::button::Style::default();
|
||||
|
||||
// Simple example tweak: lighter shadow when pressed
|
||||
match status {
|
||||
iced::widget::button::Status::Pressed => {
|
||||
style.shadow.offset = iced::Vector { x: 1.0, y: 1.0 };
|
||||
}
|
||||
_ => {}
|
||||
let green = Color::from_rgb8(0, 255, 128);
|
||||
if status == iced::widget::button::Status::Pressed {
|
||||
style.shadow.offset = iced::Vector { x: 1.0, y: 1.0 };
|
||||
}
|
||||
|
||||
// Override only the radius, keep other border attributes
|
||||
style.background = Some(Background::Color(green));
|
||||
|
||||
style.border = Border {
|
||||
radius: radius.into(),
|
||||
..style.border
|
||||
color: green,
|
||||
width: 4.,
|
||||
};
|
||||
|
||||
style
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
use iced::Length::{self, Fill, FillPortion};
|
||||
use iced::widget::text_editor;
|
||||
use iced::widget::{Container, container};
|
||||
use iced::widget::container;
|
||||
use iced::widget::text_editor::{self};
|
||||
use iced::widget::text_editor::{Action, Content, Edit};
|
||||
use iced::{
|
||||
Background, Color, Element, Task, Theme,
|
||||
widget::{Image, column, container::Style, row, text},
|
||||
};
|
||||
use iced::{Border, Font};
|
||||
use iced::{Border, Error, Font};
|
||||
|
||||
mod buttons;
|
||||
mod channels;
|
||||
@@ -13,7 +14,9 @@ mod servers;
|
||||
|
||||
use servers::{User, get_servers_buttons};
|
||||
|
||||
use crate::channels::get_channels_buttons;
|
||||
use channels::get_channels_buttons;
|
||||
|
||||
use buttons::round_button;
|
||||
|
||||
fn main() -> Result<(), iced::Error> {
|
||||
iced::application(Liscord::title, Liscord::update, Liscord::view)
|
||||
@@ -67,10 +70,14 @@ impl Liscord {
|
||||
self.selected_channel = Some(channel_id);
|
||||
// async tasks
|
||||
}
|
||||
Event::MessageInput(Action::Edit(Edit::Enter)) => {
|
||||
let _ = self.update(Event::SendMessage);
|
||||
}
|
||||
Event::MessageInput(action) => {
|
||||
// println!("{action:?}");
|
||||
self.message_editor.perform(action);
|
||||
}
|
||||
Event::SendMessage => println!("Message Sent !"),
|
||||
Event::SendMessage => self.send_message().expect("Message failed"),
|
||||
}
|
||||
Task::none()
|
||||
}
|
||||
@@ -182,6 +189,12 @@ impl Liscord {
|
||||
.center()
|
||||
.into()
|
||||
}
|
||||
|
||||
fn send_message(&mut self) -> Result<(), Error> {
|
||||
println!("Sending message: {}", self.message_editor.text());
|
||||
self.message_editor = Content::new();
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
fn icon<'a>(codepoint: char) -> Element<'a, Event> {
|
||||
@@ -193,29 +206,3 @@ fn icon<'a>(codepoint: char) -> Element<'a, Event> {
|
||||
fn send_icon<'a>() -> Element<'a, Event> {
|
||||
icon('\u{F1D8}')
|
||||
}
|
||||
|
||||
pub fn round_button<'a, Message>(
|
||||
button: iced::widget::Button<'a, Message>,
|
||||
radius: f32,
|
||||
) -> iced::widget::Button<'a, Message>
|
||||
where
|
||||
Message: 'a,
|
||||
{
|
||||
button.style(move |_theme, status| {
|
||||
let mut style = iced::widget::button::Style::default();
|
||||
let green = Color::from_rgb8(0, 255, 128);
|
||||
if status == iced::widget::button::Status::Pressed {
|
||||
style.shadow.offset = iced::Vector { x: 1.0, y: 1.0 };
|
||||
}
|
||||
|
||||
style.background = Some(Background::Color(green));
|
||||
|
||||
style.border = Border {
|
||||
radius: radius.into(),
|
||||
color: green,
|
||||
width: 4.,
|
||||
};
|
||||
|
||||
style
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user