Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Indicate that messages cannot be longer than 450 characters #69

Merged
merged 1 commit into from
Jan 20, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions src/gui/chat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ use crate::core::chat::{Chat, ChatLike, Message, MessageChunk, MessageType};
use crate::gui::state::UIState;
use crate::gui::DecoratedText;

const MAX_MESSAGE_LENGTH: usize = 450;

trait WithInnerShadow {
fn inner_shadow_bottom(&self, pixels: usize);
}
Expand Down Expand Up @@ -71,13 +73,25 @@ impl ChatWindow {
if interactive {
egui::TopBottomPanel::bottom("input").show(ctx, |ui| {
ui.vertical_centered_justified(|ui| {
let message_length_exceeded = self.chat_input.len() >= 450;

// Special tabs (server messages and highlights) are 1) fake and 2) read-only
let text_field = egui::TextEdit::singleline(&mut self.chat_input)
let mut text_field = egui::TextEdit::singleline(&mut self.chat_input)
.char_limit(MAX_MESSAGE_LENGTH)
.id_source("chat-input")
.hint_text("new message");
if message_length_exceeded {
text_field = text_field.text_color(egui::Color32::RED);
}

ui.add_space(8.);
let response = ui.add(text_field);
let mut response = ui.add(text_field);
if message_length_exceeded {
response = response.on_hover_text_at_pointer(format!(
"messages longer than {} characters are truncated",
MAX_MESSAGE_LENGTH
));
}
self.response_widget_id = Some(response.id);
ui.add_space(2.);

Expand Down
Loading