Skip to content

Commit

Permalink
Slightly re-ordered UI
Browse files Browse the repository at this point in the history
  • Loading branch information
casperstorm committed Sep 8, 2024
1 parent 26ed734 commit ce8b2f0
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 58 deletions.
4 changes: 0 additions & 4 deletions src/icon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,6 @@ pub fn undo<'a>() -> Text<'a> {
to_text('\u{E80B}')
}

pub fn delete<'a>() -> Text<'a> {
to_text('\u{E80C}')
}

pub fn copy<'a>() -> Text<'a> {
to_text('\u{F0C5}')
}
Expand Down
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -817,7 +817,7 @@ impl Halloy {
}
} else if let Screen::Dashboard(dashboard) = &self.screen {
dashboard
.view_window(id, &self.theme, &self.config)
.view_window(id, &self.theme)
.map(Message::Dashboard)
} else {
column![].into()
Expand Down
9 changes: 2 additions & 7 deletions src/screen/dashboard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -650,15 +650,10 @@ impl Dashboard {
(Task::none(), None)
}

pub fn view_window<'a>(
&'a self,
id: window::Id,
theme: &'a Theme,
config: &'a Config,
) -> Element<'a, Message> {
pub fn view_window<'a>(&'a self, id: window::Id, theme: &'a Theme) -> Element<'a, Message> {
if let Some(editor) = self.theme_editor.as_ref() {
if editor.id == id {
return editor.view(theme, config).map(Message::ThemeEditor);
return editor.view(theme).map(Message::ThemeEditor);
}
}

Expand Down
72 changes: 28 additions & 44 deletions src/screen/dashboard/theme_editor.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
use std::path::PathBuf;
use std::time::Duration;

use data::{config, url, Config};
use data::{url, Config};
use futures::TryFutureExt;
use iced::alignment::Vertical;
use iced::widget::text::LineHeight;
use iced::widget::{button, center, column, container, row, text, text_input};
use iced::{alignment, clipboard, padding, Length::*};
use iced::widget::{button, center, column, container, row, text_input};
use iced::{alignment, clipboard, Length::*};
use iced::{Color, Length};
use iced::{Task, Vector};
use strum::IntoEnumIterator;
Expand Down Expand Up @@ -114,9 +115,17 @@ impl ThemeEditor {
}
Message::Save => {
let task = async move {
rfd::AsyncFileDialog::new()
.set_directory(Config::themes_dir())
.set_file_name("custom-theme.toml")
// TODO: rfd `set_directory` can't be used in combination with `set_file_name` on macOS.
// https://github.com/PolyMeilex/rfd/issues/214

let mut dialog =
rfd::AsyncFileDialog::new().set_directory(Config::themes_dir());

if !cfg!(target_os = "macos") {
dialog = dialog.set_file_name("custom-theme.toml");
}

dialog
.save_file()
.await
.map(|handle| handle.path().to_path_buf())
Expand Down Expand Up @@ -211,7 +220,7 @@ impl ThemeEditor {
(Task::none(), None)
}

pub fn view<'a>(&'a self, theme: &'a Theme, config: &'a Config) -> Element<'a, Message> {
pub fn view<'a>(&'a self, theme: &'a Theme) -> Element<'a, Message> {
let color = self
.component
.color(theme.colors())
Expand Down Expand Up @@ -245,40 +254,33 @@ impl ThemeEditor {
}
});

let undo = icon(icon::undo(), "Revert", Message::Revert);
let clear = icon(icon::delete(), "Clear", Message::Clear);
let undo = icon(icon::undo(), "Revert Color", Message::Revert);

let save = match self.save_result {
Some(is_success) => status_button(is_success),
None => secondary_button("Save", Message::Save),
None => secondary_button("Save to Disk", Message::Save),
};
let apply = secondary_button("Apply", Message::Apply);
let discard = secondary_button("Discard", Message::Discard);
let apply = secondary_button("Apply Colors", Message::Apply);

let share = text_input("", &url::theme(theme.colors()));
let copy = if self.copied {
success_icon()
} else {
icon(icon::copy(), "Copy", Message::Copy)
icon(icon::copy(), "Copy URL to theme", Message::Copy)
};

let color_picker = color_picker(color, Message::Color);

let content = column![
row![
subtitled("Component", container(component).width(Fill), &config.font),
subtitled("Hex", container(hex_input).width(80), &config.font),
subtitled("", undo, &config.font),
subtitled("", clear, &config.font),
]
.spacing(4),
row![
subtitled("Share", share, &config.font),
subtitled("", copy, &config.font)
container(component).width(Fill),
container(hex_input).width(80),
undo,
copy,
]
.align_y(Vertical::Center)
.spacing(4),
row![save, apply, discard].spacing(4),
color_picker
color_picker,
row![apply, save].spacing(4),
]
.spacing(8);

Expand All @@ -296,7 +298,7 @@ fn icon<'a>(icon: widget::Text<'a>, tip: &'a str, message: Message) -> Element<'
.width(22)
.height(22)
.padding(5)
.style(theme::button::bare)
.style(|theme, style| theme::button::primary(theme, style, false))
.on_press(message),
Some(tip),
tooltip::Position::Bottom,
Expand Down Expand Up @@ -343,24 +345,6 @@ fn status_button<'a>(is_success: bool) -> Element<'a, Message> {
.into()
}

fn subtitled<'a>(
subtitle: &'static str,
inner: impl Into<Element<'a, Message>>,
config: &config::Font,
) -> Element<'a, Message> {
column![
container(
text(subtitle)
.size(config.size.map(|u| u as f32).unwrap_or(theme::TEXT_SIZE) - 2.0)
.style(theme::text::secondary)
)
.padding(padding::left(2)),
inner.into()
]
.spacing(2)
.into()
}

fn components() -> impl Iterator<Item = Component> {
General::iter()
.map(Component::General)
Expand Down
4 changes: 2 additions & 2 deletions src/widget/color_picker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ use palette::{Hsva, RgbHue};
use super::{decorate, Container, Element, Renderer};
use crate::theme::Theme;

const HANDLE_RADIUS: f32 = 7.0;
const SLIDER_HEIGHT: f32 = 10.0;
const HANDLE_RADIUS: f32 = 10.0;
const SLIDER_HEIGHT: f32 = 20.0;

pub fn color_picker<'a, Message: 'a>(
color: Color,
Expand Down

0 comments on commit ce8b2f0

Please sign in to comment.