Added custom border color
This commit is contained in:
1 parent
758486084e
commit
a73668c4be
2 files changed
+70
-51
No files matched your search
+44
-41
@@ -1522,8 +1522,8 @@ struct Moorly {
|
||||
command_palette_enabled: bool,
|
||||
command_palette_enabled_draft: bool,
|
||||
advanced_open: bool,
|
||||
colors: [Color; 5],
|
||||
saved_colors: [Color; 5],
|
||||
colors: [Color; 6],
|
||||
saved_colors: [Color; 6],
|
||||
custom_toasts: bool,
|
||||
toast_colors: [Color; 9],
|
||||
builtin_custom_toasts: bool,
|
||||
@@ -1578,15 +1578,17 @@ enum ColorOption {
|
||||
MainBackground,
|
||||
SidebarBackground,
|
||||
Text,
|
||||
Border,
|
||||
}
|
||||
|
||||
impl ColorOption {
|
||||
const ALL: [Self; 5] = [
|
||||
const ALL: [Self; 6] = [
|
||||
Self::Accent,
|
||||
Self::ActiveTabOutline,
|
||||
Self::MainBackground,
|
||||
Self::SidebarBackground,
|
||||
Self::Text,
|
||||
Self::Border,
|
||||
];
|
||||
|
||||
fn label(self) -> &'static str {
|
||||
@@ -1596,6 +1598,7 @@ impl ColorOption {
|
||||
Self::MainBackground => "Main background",
|
||||
Self::SidebarBackground => "Sidebar background",
|
||||
Self::Text => "Text color",
|
||||
Self::Border => "Border color",
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1606,16 +1609,18 @@ impl ColorOption {
|
||||
Self::MainBackground => 2,
|
||||
Self::SidebarBackground => 3,
|
||||
Self::Text => 4,
|
||||
Self::Border => 5,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const DEFAULT_COLORS: [Color; 5] = [
|
||||
const DEFAULT_COLORS: [Color; 6] = [
|
||||
theme::SETTINGS_ACTIVE,
|
||||
theme::ACTIVE_TAB,
|
||||
theme::TAB_ACTIVE_BG,
|
||||
theme::TAB_INACTIVE_BG,
|
||||
theme::TAB_TEXT,
|
||||
Color::WHITE,
|
||||
];
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
@@ -1714,7 +1719,7 @@ struct CustomTheme {
|
||||
id: String,
|
||||
name: String,
|
||||
based_on: theme::Preference,
|
||||
colors: [Color; 5],
|
||||
colors: [Color; 6],
|
||||
custom_toasts: bool,
|
||||
toast_colors: [Color; 9],
|
||||
typography: Typography,
|
||||
@@ -1734,6 +1739,8 @@ struct ThemeFile {
|
||||
sidebar_background: Option<String>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
text: Option<String>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
border: Option<String>,
|
||||
#[serde(default)]
|
||||
typography: TypographyConfig,
|
||||
#[serde(default)]
|
||||
@@ -1768,8 +1775,8 @@ impl ThemeFile {
|
||||
fn from_colors(
|
||||
name: String,
|
||||
based_on: theme::Preference,
|
||||
colors: &[Color; 5],
|
||||
base: &[Color; 5],
|
||||
colors: &[Color; 6],
|
||||
base: &[Color; 6],
|
||||
custom_toasts: bool,
|
||||
toast_colors: &[Color; 9],
|
||||
typography: &Typography,
|
||||
@@ -1788,12 +1795,13 @@ impl ThemeFile {
|
||||
main_background: changed(ColorOption::MainBackground),
|
||||
sidebar_background: changed(ColorOption::SidebarBackground),
|
||||
text: changed(ColorOption::Text),
|
||||
border: changed(ColorOption::Border),
|
||||
typography: TypographyConfig::from_typography(typography),
|
||||
toast: ToastFile::from_colors(custom_toasts, toast_colors),
|
||||
}
|
||||
}
|
||||
|
||||
fn colors(&self, based_on: theme::Preference) -> [Color; 5] {
|
||||
fn colors(&self, based_on: theme::Preference) -> [Color; 6] {
|
||||
let mut colors = builtin_colors(based_on);
|
||||
|
||||
let mut apply = |option: ColorOption, value: &Option<String>| {
|
||||
@@ -1807,6 +1815,7 @@ impl ThemeFile {
|
||||
apply(ColorOption::MainBackground, &self.main_background);
|
||||
apply(ColorOption::SidebarBackground, &self.sidebar_background);
|
||||
apply(ColorOption::Text, &self.text);
|
||||
apply(ColorOption::Border, &self.border);
|
||||
|
||||
colors
|
||||
}
|
||||
@@ -1851,7 +1860,7 @@ impl ToastFile {
|
||||
}
|
||||
}
|
||||
|
||||
fn builtin_colors(_preference: theme::Preference) -> [Color; 5] {
|
||||
fn builtin_colors(_preference: theme::Preference) -> [Color; 6] {
|
||||
DEFAULT_COLORS
|
||||
}
|
||||
|
||||
@@ -2609,7 +2618,7 @@ fn write_custom_theme(
|
||||
id: &str,
|
||||
name: &str,
|
||||
based_on: theme::Preference,
|
||||
colors: &[Color; 5],
|
||||
colors: &[Color; 6],
|
||||
custom_toasts: bool,
|
||||
toast_colors: &[Color; 9],
|
||||
typography: &Typography,
|
||||
@@ -3999,7 +4008,7 @@ fn resolve_theme(
|
||||
) -> (
|
||||
ThemeChoice,
|
||||
theme::Preference,
|
||||
[Color; 5],
|
||||
[Color; 6],
|
||||
bool,
|
||||
[Color; 9],
|
||||
Typography,
|
||||
@@ -6371,7 +6380,7 @@ fn tab_view(
|
||||
hide_close: bool,
|
||||
close_opacity: f32,
|
||||
width: f32,
|
||||
colors: [Color; 5],
|
||||
colors: [Color; 6],
|
||||
) -> Element<'static, Message> {
|
||||
let title = tab.title();
|
||||
let padding = Padding::new(10.0);
|
||||
@@ -6485,7 +6494,7 @@ fn tab_view(
|
||||
fn drag_ghost(
|
||||
state: &Moorly,
|
||||
window: window::Id,
|
||||
colors: [Color; 5],
|
||||
colors: [Color; 6],
|
||||
) -> Option<Element<'static, Message>> {
|
||||
let drag = state
|
||||
.drag
|
||||
@@ -6548,7 +6557,7 @@ fn drag_ghost(
|
||||
fn tab_drop_bar(
|
||||
state: &Moorly,
|
||||
window: window::Id,
|
||||
colors: [Color; 5],
|
||||
colors: [Color; 6],
|
||||
) -> Option<Element<'static, Message>> {
|
||||
let drag = state
|
||||
.drag
|
||||
@@ -6618,7 +6627,7 @@ fn tab_drop_bar(
|
||||
fn drop_panel(
|
||||
state: &Moorly,
|
||||
window: window::Id,
|
||||
colors: [Color; 5],
|
||||
colors: [Color; 6],
|
||||
) -> Option<Element<'static, Message>> {
|
||||
let drag = state.drag.as_ref().filter(|drag| drag.window == window)?;
|
||||
let window_state = state.windows.get(&window)?;
|
||||
@@ -6870,10 +6879,9 @@ fn font_family_picker(state: &Moorly, level: TypographyLevel) -> Element<'_, Mes
|
||||
.width(Length::Fill)
|
||||
.padding([6, 10])
|
||||
.style(|theme: &iced::Theme, status| {
|
||||
let palette = theme.extended_palette();
|
||||
let mut button = button::text(theme, status);
|
||||
button.border = Border {
|
||||
color: palette.background.strong.color,
|
||||
color: theme::border_color(),
|
||||
width: 1.0,
|
||||
radius: 4.0.into(),
|
||||
};
|
||||
@@ -6907,17 +6915,13 @@ fn font_family_picker(state: &Moorly, level: TypographyLevel) -> Element<'_, Mes
|
||||
)
|
||||
.width(Length::Fill)
|
||||
.padding(2)
|
||||
.style(|theme: &iced::Theme| {
|
||||
let palette = theme.extended_palette();
|
||||
|
||||
container::Style {
|
||||
border: Border {
|
||||
color: palette.background.strong.color,
|
||||
width: 1.0,
|
||||
radius: 4.0.into(),
|
||||
},
|
||||
..container::Style::default()
|
||||
}
|
||||
.style(|_theme: &iced::Theme| container::Style {
|
||||
border: Border {
|
||||
color: theme::border_color(),
|
||||
width: 1.0,
|
||||
radius: 4.0.into(),
|
||||
},
|
||||
..container::Style::default()
|
||||
});
|
||||
|
||||
column = column.push(list);
|
||||
@@ -7139,7 +7143,7 @@ fn color_swatch_row<'a>(
|
||||
.style(move |_| container::Style {
|
||||
background: Some(color.into()),
|
||||
border: Border {
|
||||
color: theme::ADVANCED_BORDER,
|
||||
color: theme::border_color(),
|
||||
width: 1.0,
|
||||
radius: 3.0.into(),
|
||||
},
|
||||
@@ -7990,7 +7994,7 @@ fn profile_dialog_view<'a>(
|
||||
.style(move |_| container::Style {
|
||||
background: Some(draft.glyph_color.into()),
|
||||
border: Border {
|
||||
color: theme::ADVANCED_BORDER,
|
||||
color: theme::border_color(),
|
||||
width: 1.0,
|
||||
radius: 3.0.into(),
|
||||
},
|
||||
@@ -9322,17 +9326,13 @@ fn command_palette_item(
|
||||
container(text("Enter").size(11))
|
||||
.align_y(Alignment::Center)
|
||||
.padding([0, 8])
|
||||
.style(|theme: &iced::Theme| {
|
||||
let palette = theme.extended_palette();
|
||||
|
||||
container::Style {
|
||||
border: Border {
|
||||
color: palette.background.strong.color,
|
||||
width: 1.0,
|
||||
radius: 4.0.into(),
|
||||
},
|
||||
..container::Style::default()
|
||||
}
|
||||
.style(|_theme: &iced::Theme| container::Style {
|
||||
border: Border {
|
||||
color: theme::border_color(),
|
||||
width: 1.0,
|
||||
radius: 4.0.into(),
|
||||
},
|
||||
..container::Style::default()
|
||||
}),
|
||||
);
|
||||
}
|
||||
@@ -9417,6 +9417,7 @@ fn command_palette_layer(state: &Moorly, window: window::Id) -> Option<Element<'
|
||||
|
||||
/// The application content with the notification stack rendered above it.
|
||||
fn view(state: &Moorly, window: window::Id) -> Element<'_, Message> {
|
||||
theme::set_border_color(state.colors[ColorOption::Border.index()]);
|
||||
let content = main_view(state, window);
|
||||
let palette = command_palette_layer(state, window);
|
||||
|
||||
@@ -9961,6 +9962,7 @@ mod tests {
|
||||
fn theme_file_only_stores_changed_colors() {
|
||||
let mut colors = super::DEFAULT_COLORS;
|
||||
colors[super::ColorOption::Accent.index()] = iced::Color::from_rgb8(1, 2, 3);
|
||||
colors[super::ColorOption::Border.index()] = iced::Color::from_rgb8(4, 5, 6);
|
||||
|
||||
let file = super::ThemeFile::from_colors(
|
||||
"Test theme".to_owned(),
|
||||
@@ -9976,6 +9978,7 @@ mod tests {
|
||||
assert!(text.contains("name = \"Test theme\""));
|
||||
assert!(text.contains("based_on = \"dark\""));
|
||||
assert!(text.contains("accent = \"#010203\""));
|
||||
assert!(text.contains("border = \"#040506\""));
|
||||
assert!(!text.contains("active_tab_outline"));
|
||||
assert!(text.contains("[typography.h1]"));
|
||||
assert!(text.contains(&format!("font = \"{}\"", super::default_ui_font())));
|
||||
|
||||
Reference in new issue
Block a user