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

usable dark mode #414

Draft
wants to merge 1 commit into
base: settings-tab
Choose a base branch
from
Draft
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
20 changes: 13 additions & 7 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,9 @@ impl Application for ESLauncher {
}
}
}
Message::SettingsMessage(msg) => self.settings.update(msg),
Message::SettingsMessage(msg) => {
self.settings.update(msg)
},
Message::AddInstance(instance) => {
let is_ready = instance.state.is_ready();
self.instances_frame
Expand Down Expand Up @@ -262,7 +264,7 @@ impl Application for ESLauncher {
self.settings.view(),
)
.set_active_tab(&self.active_tab)
.tab_bar_style(tab_bar());
.tab_bar_style(tab_bar(self.settings.dark_theme));

let logbox = self.log_buffer.iter().fold(
Column::new()
Expand Down Expand Up @@ -338,11 +340,15 @@ impl Application for ESLauncher {
}

fn theme(&self) -> Self::Theme {
iced::Theme::custom("LightModified".into(), {
let mut palette = iced::theme::Palette::LIGHT;
palette.primary = iced::Color::from_rgb(0.2, 0.2, 0.2);
palette
})
if self.settings.dark_theme {
Theme::Dark
} else {
iced::Theme::custom("LightModified".into(), {
let mut palette = iced::theme::Palette::LIGHT;
palette.primary = iced::Color::from_rgb(0.2, 0.2, 0.2);
palette
})
}
}
}

Expand Down
123 changes: 115 additions & 8 deletions src/style.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,27 +40,31 @@ pub fn folder_icon() -> Text<'static> {
}

pub fn icon_button() -> iced::theme::Button {
iced::theme::Button::Custom(Box::new(ButtonStyle::Icon))
iced::theme::Button::Custom(Box::new(LightButtonStyle::Icon))
}
pub fn text_button() -> iced::theme::Button {
iced::theme::Button::Custom(Box::new(ButtonStyle::Text))
iced::theme::Button::Custom(Box::new(LightButtonStyle::Text))
}

pub fn tab_bar() -> iced_aw::style::tab_bar::TabBarStyles {
iced_aw::style::tab_bar::TabBarStyles::Custom(Rc::new(CustomTabBar))
pub fn tab_bar(dark_theme: bool ) -> iced_aw::style::tab_bar::TabBarStyles {
if dark_theme {
iced_aw::style::tab_bar::TabBarStyles::Custom(Rc::new(DarkTabBar))
} else {
iced_aw::style::tab_bar::TabBarStyles::Custom(Rc::new(LightTabBar))
}
}

pub fn log_container(log: &str) -> iced::theme::Container {
iced::theme::Container::Custom(Box::new(LogContainer::from(log)))
}

/// graphic design is my passion
pub enum ButtonStyle {
pub enum LightButtonStyle {
Icon,
Text,
}

impl button::StyleSheet for ButtonStyle {
impl button::StyleSheet for LightButtonStyle {
type Style = Theme;

fn active(&self, _: &Self::Style) -> button::Appearance {
Expand Down Expand Up @@ -114,6 +118,65 @@ impl button::StyleSheet for ButtonStyle {
}
}

pub enum DarkButtonStyle {
Icon,
Text,
}

impl button::StyleSheet for DarkButtonStyle {
type Style = Theme;

fn active(&self, _: &Self::Style) -> button::Appearance {
match self {
Self::Icon => button::Appearance {
text_color: Color::from_rgb(0.5, 0.5, 0.5).inverse(),
..Default::default()
},
Self::Text => button::Appearance {
background: Some(Background::Color(Color::WHITE.inverse())),
border: Border {
color: Color::from_rgb(0.8, 0.8, 0.8).inverse(),
width: 0.3,
radius: Radius::from(2.0),
},
shadow_offset: Vector::new(0.3, 0.3),
..Default::default()
},
}
}

fn hovered(&self, style: &Self::Style) -> button::Appearance {
let active = self.active(style);

match self {
Self::Icon => button::Appearance {
text_color: Color::from_rgb(0.3, 0.3, 0.3).inverse(),
shadow_offset: active.shadow_offset + Vector::new(0.0, 1.0),
..active
},
Self::Text => button::Appearance {
border: Border {
color: Color::from_rgb(0.4, 0.4, 0.4).inverse(),
..Default::default()
},
shadow_offset: active.shadow_offset + Vector::new(0.1, 0.3),
..active
},
}
}

fn disabled(&self, style: &Self::Style) -> button::Appearance {
let active = self.active(style);
match self {
Self::Text => button::Appearance {
text_color: Color::from_rgb(0.5, 0.5, 0.5).inverse(),
..active
},
_ => active,
}
}
}

pub struct LogContainer {
background: Option<Color>,
}
Expand Down Expand Up @@ -144,9 +207,9 @@ impl container::StyleSheet for LogContainer {
}
}

pub struct CustomTabBar;
pub struct LightTabBar;

impl iced_aw::style::tab_bar::StyleSheet for CustomTabBar {
impl iced_aw::style::tab_bar::StyleSheet for LightTabBar {
type Style = Theme;

fn active(&self, _: &Self::Style, is_active: bool) -> iced_aw::style::tab_bar::Appearance {
Expand Down Expand Up @@ -175,3 +238,47 @@ impl iced_aw::style::tab_bar::StyleSheet for CustomTabBar {
}
}
}

pub struct DarkTabBar;

impl iced_aw::style::tab_bar::StyleSheet for DarkTabBar {
type Style = Theme;

fn active(&self, _: &Self::Style, is_active: bool) -> iced_aw::style::tab_bar::Appearance {
let tab_label_background = Background::Color(if is_active {
Color::WHITE.inverse()
} else {
Color::from_rgb(0.87, 0.87, 0.87).inverse()
});
let text_color = if is_active {
Color::WHITE
} else {
Color::from_rgb(0.87, 0.87, 0.87)
};
iced_aw::style::tab_bar::Appearance {
tab_label_background,
tab_label_border_width: 0.,
text_color,
..Default::default()
}
}

fn hovered(&self, _: &Self::Style, is_active: bool) -> iced_aw::style::tab_bar::Appearance {
let tab_label_background = Background::Color(if is_active {
Color::WHITE.inverse()
} else {
Color::from_rgb(0.94, 0.94, 0.94).inverse()
});
let text_color = if is_active {
Color::WHITE
} else {
Color::from_rgb(0.94, 0.94, 0.94)
};
iced_aw::style::tab_bar::Appearance {
tab_label_background,
tab_label_border_width: 0.,
text_color,
..Default::default()
}
}
}