From ce8b2f040b32e471b3ee7aa37d1f8ea33e4c20b2 Mon Sep 17 00:00:00 2001 From: Casper Rogild Storm Date: Sun, 8 Sep 2024 20:38:57 +0200 Subject: [PATCH] Slightly re-ordered UI --- src/icon.rs | 4 -- src/main.rs | 2 +- src/screen/dashboard.rs | 9 +--- src/screen/dashboard/theme_editor.rs | 72 +++++++++++----------------- src/widget/color_picker.rs | 4 +- 5 files changed, 33 insertions(+), 58 deletions(-) diff --git a/src/icon.rs b/src/icon.rs index 084607d0c..954c70e1e 100644 --- a/src/icon.rs +++ b/src/icon.rs @@ -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}') } diff --git a/src/main.rs b/src/main.rs index 7b9b5d3ac..4b087d9ff 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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() diff --git a/src/screen/dashboard.rs b/src/screen/dashboard.rs index 2b6481256..c4d43afd6 100644 --- a/src/screen/dashboard.rs +++ b/src/screen/dashboard.rs @@ -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); } } diff --git a/src/screen/dashboard/theme_editor.rs b/src/screen/dashboard/theme_editor.rs index f17a844f4..bfc0ccf9e 100644 --- a/src/screen/dashboard/theme_editor.rs +++ b/src/screen/dashboard/theme_editor.rs @@ -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; @@ -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()) @@ -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()) @@ -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); @@ -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, @@ -343,24 +345,6 @@ fn status_button<'a>(is_success: bool) -> Element<'a, Message> { .into() } -fn subtitled<'a>( - subtitle: &'static str, - inner: impl Into>, - 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 { General::iter() .map(Component::General) diff --git a/src/widget/color_picker.rs b/src/widget/color_picker.rs index 3292f50c1..221aab302 100644 --- a/src/widget/color_picker.rs +++ b/src/widget/color_picker.rs @@ -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,