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

Correct transparency for colored nicks #241

Merged
merged 1 commit into from
Mar 1, 2024
Merged
Show file tree
Hide file tree
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
4 changes: 4 additions & 0 deletions data/src/theme.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ impl Colors {
success: Subpalette::from_color(palette.success, palette),
}
}

pub fn is_dark_theme(&self) -> bool {
self.background.is_dark()
}
}

#[derive(Debug, Clone)]
Expand Down
16 changes: 7 additions & 9 deletions src/buffer/channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ pub fn view<'a>(
selectable_text(config.buffer.nickname.brackets.format(user)).style(
theme::Text::Nickname(
user.color_seed(&config.buffer.nickname.color),
false,
),
),
user.clone(),
Expand Down Expand Up @@ -218,7 +219,7 @@ impl Channel {
}

mod nick_list {
use data::{User, Config};
use data::{Config, User};
use iced::widget::{column, container, scrollable, text};
use iced::Length;
use user_context::Message;
Expand All @@ -227,20 +228,17 @@ mod nick_list {
use crate::theme;
use crate::widget::Element;

pub fn view<'a>(users: &[User], config: &'a Config) -> Element<'a,Message> {
pub fn view<'a>(users: &[User], config: &'a Config) -> Element<'a, Message> {
let column = column(users.iter().map(|user| {
let content = text(format!(
"{}{}",
user.highest_access_level(),
user.nickname()
))
.style(if user.is_away() {
theme::Text::Transparent
} else {
theme::Text::Nickname(
user.color_seed(&config.buffer.channel.users.color)
)
});
.style(theme::Text::Nickname(
user.color_seed(&config.buffer.channel.users.color),
user.is_away(),
));

user_context::view(content, user.clone())
}))
Expand Down
1 change: 1 addition & 0 deletions src/buffer/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ pub fn view<'a>(
selectable_text(config.buffer.nickname.brackets.format(user)).style(
theme::Text::Nickname(
user.color_seed(&config.buffer.nickname.color),
false,
),
),
user.clone(),
Expand Down
23 changes: 15 additions & 8 deletions src/theme.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use data::message;
use data::theme::{randomize_color, Colors};
use data::theme::{alpha, randomize_color, Colors};
use iced::widget::{button, container, pane_grid, rule, scrollable, text, text_input};
use iced::{application, overlay, Background, Border, Color};

Expand Down Expand Up @@ -108,7 +108,7 @@ pub enum Text {
Error,
Transparent,
Status(message::source::Status),
Nickname(Option<String>),
Nickname(Option<String>, bool),
}

impl text::StyleSheet for Theme {
Expand All @@ -132,12 +132,19 @@ impl text::StyleSheet for Theme {
Text::Error => text::Appearance {
color: Some(self.colors().error.base),
},
Text::Nickname(seed) => {
Text::Nickname(seed, transparent) => {
let original_color = self.colors().action.base;
let color = seed
let randomized_color = seed
.map(|seed| randomize_color(original_color, seed.as_str()))
.unwrap_or_else(|| original_color);

let color = if transparent {
let dark_theme = self.colors().is_dark_theme();
alpha(randomized_color, if dark_theme { 0.2 } else { 0.4 })
} else {
randomized_color
};

text::Appearance { color: Some(color) }
}
Text::Server => text::Appearance {
Expand Down Expand Up @@ -226,7 +233,7 @@ impl container::StyleSheet for Theme {
border: Border {
radius: 4.0.into(),
width: 1.0,
color: if self.colors().background.is_dark() {
color: if self.colors().is_dark_theme() {
self.colors().background.lighter
} else {
self.colors().background.darker
Expand Down Expand Up @@ -322,7 +329,7 @@ impl button::StyleSheet for Theme {
Button::Pane { .. } => button::Appearance {
background: Some(Background::Color(self.colors().background.dark)),
border: Border {
color: if self.colors().background.is_dark() {
color: if self.colors().is_dark_theme() {
self.colors().background.lightest
} else {
self.colors().background.darkest
Expand Down Expand Up @@ -394,7 +401,7 @@ impl button::StyleSheet for Theme {
..active
},
Button::Pane { .. } => button::Appearance {
background: Some(Background::Color(if self.colors().background.is_dark() {
background: Some(Background::Color(if self.colors().is_dark_theme() {
self.colors().background.light
} else {
self.colors().background.darker
Expand Down Expand Up @@ -654,7 +661,7 @@ impl overlay::menu::StyleSheet for Theme {
border: Border {
width: 1.0,
radius: 4.0.into(),
color: if self.colors().background.is_dark() {
color: if self.colors().is_dark_theme() {
self.colors().background.lighter
} else {
self.colors().background.darker
Expand Down
Loading