Move colors to constants in util.rs
This commit is contained in:
parent
3c05b23b90
commit
f15b092c26
3 changed files with 76 additions and 30 deletions
33
src/cri.rs
33
src/cri.rs
|
@ -5,7 +5,7 @@ use iced::{
|
|||
alignment::{Horizontal, Vertical},
|
||||
executor,
|
||||
widget::{column, container, mouse_area, row, text, text_input},
|
||||
Application, Background, Color, Element, Length, Theme,
|
||||
Application, Background, Element, Length, Theme,
|
||||
};
|
||||
use irc::proto::{message::Tag, CapSubCommand, Capability, Command as IrcCommand, Response};
|
||||
use once_cell::sync::Lazy;
|
||||
|
@ -16,6 +16,7 @@ use crate::{
|
|||
irc_message::MessageDetail,
|
||||
message_log::MessageLog,
|
||||
ui_message::{self, UiMessage},
|
||||
util,
|
||||
};
|
||||
|
||||
static INPUT_ID: Lazy<text_input::Id> = Lazy::new(text_input::Id::unique);
|
||||
|
@ -327,10 +328,6 @@ impl Application for Cri {
|
|||
}
|
||||
|
||||
fn view(&self) -> iced::Element<'_, Self::Message, iced::Renderer<Self::Theme>> {
|
||||
let dark_grey = Color::new(0.58, 0.65, 0.65, 1.0);
|
||||
let light_blue = Color::new(0.26, 0.62, 0.85, 1.0);
|
||||
let light_red = Color::new(0.99, 0.36, 0.40, 1.0);
|
||||
|
||||
let log = self.message_log.view(&self.nickname);
|
||||
|
||||
let message_box = text_input("your magnum opus", &self.input_value)
|
||||
|
@ -349,9 +346,17 @@ impl Application for Cri {
|
|||
Some(channel_name) => channel_name,
|
||||
};
|
||||
|
||||
let text_color = if is_active { Some(Color::WHITE) } else { None };
|
||||
let nickname_color = if is_active { Color::WHITE } else { light_blue };
|
||||
let no_message_color = if is_active { Color::WHITE } else { dark_grey };
|
||||
let text_color = if is_active { Some(util::WHITE) } else { None };
|
||||
let nickname_color = if is_active {
|
||||
util::WHITE
|
||||
} else {
|
||||
util::LIGHT_BLUE
|
||||
};
|
||||
let no_message_color = if is_active {
|
||||
util::WHITE
|
||||
} else {
|
||||
util::DARK_GREY
|
||||
};
|
||||
|
||||
let text_size = 14.0;
|
||||
let last_message = container(
|
||||
|
@ -405,7 +410,7 @@ impl Application for Cri {
|
|||
} else {
|
||||
String::new()
|
||||
})
|
||||
.style(Color::WHITE)
|
||||
.style(util::WHITE)
|
||||
.size(12),
|
||||
)
|
||||
.width(20)
|
||||
|
@ -414,13 +419,13 @@ impl Application for Cri {
|
|||
.align_y(Vertical::Center)
|
||||
.style(move |_: &_| container::Appearance {
|
||||
background: Some(Background::Color(if unread_highlights > 0 {
|
||||
light_red
|
||||
util::LIGHT_RED
|
||||
} else if unread_messages > 0 {
|
||||
light_blue
|
||||
util::LIGHT_BLUE
|
||||
} else if unread_events > 0 {
|
||||
dark_grey
|
||||
util::DARK_GREY
|
||||
} else {
|
||||
Color::TRANSPARENT
|
||||
util::TRANSPARENT
|
||||
})),
|
||||
border_radius: 12.0.into(),
|
||||
..Default::default()
|
||||
|
@ -436,7 +441,7 @@ impl Application for Cri {
|
|||
])
|
||||
.style(move |_: &_| container::Appearance {
|
||||
background: match is_active {
|
||||
true => Some(Background::Color(light_blue)),
|
||||
true => Some(Background::Color(util::LIGHT_BLUE)),
|
||||
false => None,
|
||||
},
|
||||
text_color,
|
||||
|
|
|
@ -372,8 +372,6 @@ impl<'a> MessageLog {
|
|||
}
|
||||
|
||||
pub fn view(&self, current_nickname: &str) -> Container<'_, crate::ui_message::UiMessage> {
|
||||
let lighter_grey = Color::new(0.93, 0.94, 0.95, 1.0);
|
||||
|
||||
let channel = self.get(&self.active_channel).unwrap();
|
||||
|
||||
let header = container(column![
|
||||
|
@ -404,7 +402,7 @@ impl<'a> MessageLog {
|
|||
)
|
||||
.height(Length::Fill)
|
||||
.width(Length::Fill)
|
||||
.style(move |_: &_| Self::container_appearance(lighter_grey, 0.0)),
|
||||
.style(move |_: &_| Self::container_appearance(util::LIGHTER_GREY, 0.0)),
|
||||
])
|
||||
.height(Length::Fill)
|
||||
.width(Length::Fill)
|
||||
|
@ -422,10 +420,6 @@ impl<'a> MessageLog {
|
|||
current_nickname: &str,
|
||||
irc_message: &IrcMessage,
|
||||
) -> Option<iced::Element<'a, crate::ui_message::UiMessage>> {
|
||||
let dark_grey = Color::new(0.58, 0.65, 0.65, 1.0);
|
||||
let dark_red = Color::new(0.75, 0.22, 0.17, 1.0);
|
||||
let lighter_green = Color::new(0.94, 0.99, 0.87, 1.0);
|
||||
|
||||
let timestamp = irc_message.timestamp.format("%H:%M:%S");
|
||||
|
||||
match &irc_message.detail {
|
||||
|
@ -455,19 +449,19 @@ impl<'a> MessageLog {
|
|||
}
|
||||
MessageDetail::Privmsg { nickname, message } => {
|
||||
let is_self = nickname == current_nickname;
|
||||
let text_color = if is_self { dark_red } else { Color::BLACK };
|
||||
let message_appearance = Self::container_appearance(Color::WHITE, 8.0);
|
||||
let own_message_appearance = Self::container_appearance(lighter_green, 8.0);
|
||||
let text_color = if is_self { util::DARK_RED } else { util::BLACK };
|
||||
let message_appearance = Self::container_appearance(util::WHITE, 8.0);
|
||||
let own_message_appearance = Self::container_appearance(util::LIGHTER_GREEN, 8.0);
|
||||
let mut elements: Vec<Element<'_, _, _>> =
|
||||
vec![text(message).style(text_color).into()];
|
||||
|
||||
if !is_self {
|
||||
elements.insert(0, text(nickname).style(dark_red).into());
|
||||
elements.insert(0, text(nickname).style(util::DARK_RED).into());
|
||||
}
|
||||
|
||||
elements.push(
|
||||
text(timestamp)
|
||||
.style(dark_grey)
|
||||
.style(util::DARK_GREY)
|
||||
.horizontal_alignment(Horizontal::Right)
|
||||
.into(),
|
||||
);
|
||||
|
@ -501,11 +495,14 @@ impl<'a> MessageLog {
|
|||
}
|
||||
|
||||
fn event_container(content: String) -> iced::Element<'a, crate::ui_message::UiMessage> {
|
||||
let dark_grey = Color::new(0.58, 0.65, 0.65, 1.0);
|
||||
container(
|
||||
container(text(content).style(Color::WHITE).horizontal_alignment(Horizontal::Center))
|
||||
.style(move |_: &_| Self::container_appearance(dark_grey, 8.0))
|
||||
.padding([3, 10]),
|
||||
container(
|
||||
text(content)
|
||||
.style(util::WHITE)
|
||||
.horizontal_alignment(Horizontal::Center),
|
||||
)
|
||||
.style(move |_: &_| Self::container_appearance(util::DARK_GREY, 8.0))
|
||||
.padding([3, 10]),
|
||||
)
|
||||
.width(Length::Fill)
|
||||
.center_x()
|
||||
|
|
44
src/util.rs
44
src/util.rs
|
@ -1,5 +1,49 @@
|
|||
use iced::Color;
|
||||
use regex::Regex;
|
||||
|
||||
pub const WHITE: Color = Color::WHITE;
|
||||
pub const BLACK: Color = Color::BLACK;
|
||||
pub const TRANSPARENT: Color = Color::TRANSPARENT;
|
||||
|
||||
pub const LIGHTER_GREEN: Color = Color {
|
||||
r: 0.94,
|
||||
g: 0.99,
|
||||
b: 0.87,
|
||||
a: 1.0,
|
||||
};
|
||||
pub const LIGHTER_GREY: Color = Color {
|
||||
r: 0.93,
|
||||
g: 0.94,
|
||||
b: 0.95,
|
||||
a: 1.0,
|
||||
};
|
||||
|
||||
pub const LIGHT_BLUE: Color = Color {
|
||||
r: 0.26,
|
||||
g: 0.62,
|
||||
b: 0.85,
|
||||
a: 1.0,
|
||||
};
|
||||
pub const LIGHT_RED: Color = Color {
|
||||
r: 0.99,
|
||||
g: 0.36,
|
||||
b: 0.40,
|
||||
a: 1.0,
|
||||
};
|
||||
|
||||
pub const DARK_GREY: Color = Color {
|
||||
r: 0.58,
|
||||
g: 0.65,
|
||||
b: 0.65,
|
||||
a: 1.0,
|
||||
};
|
||||
pub const DARK_RED: Color = Color {
|
||||
r: 0.75,
|
||||
g: 0.22,
|
||||
b: 0.17,
|
||||
a: 1.0,
|
||||
};
|
||||
|
||||
pub fn contains_word(needle: &str, haystack: &str) -> bool {
|
||||
let pattern = format!(r"\b{}\b", regex::escape(needle));
|
||||
let regex = Regex::new(&pattern).unwrap();
|
||||
|
|
Loading…
Reference in a new issue