sunset theme.xml in favor of globals
This commit is contained in:
@@ -125,6 +125,25 @@ impl Color {
|
|||||||
pub fn debug_ansi_block(&self) -> String {
|
pub fn debug_ansi_block(&self) -> String {
|
||||||
format!("{}███{}", self.debug_ansi_format(), ANSI_RESET_CODE)
|
format!("{}███{}", self.debug_ansi_format(), ANSI_RESET_CODE)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[must_use]
|
||||||
|
pub fn with_alpha(&self, n: f32) -> Self {
|
||||||
|
Self {
|
||||||
|
r: self.r,
|
||||||
|
g: self.g,
|
||||||
|
b: self.b,
|
||||||
|
a: n,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[must_use]
|
||||||
|
pub fn to_hex(&self) -> String {
|
||||||
|
let r = (self.r.clamp(0.0, 1.0) * 255.0).round() as u8;
|
||||||
|
let g = (self.g.clamp(0.0, 1.0) * 255.0).round() as u8;
|
||||||
|
let b = (self.b.clamp(0.0, 1.0) * 255.0).round() as u8;
|
||||||
|
let a = (self.a.clamp(0.0, 1.0) * 255.0).round() as u8;
|
||||||
|
format!("#{r:02X}{g:02X}{b:02X}{a:02X}")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for Color {
|
impl Default for Color {
|
||||||
|
|||||||
@@ -21,6 +21,8 @@ pub struct Defaults {
|
|||||||
pub button_color: drawing::Color,
|
pub button_color: drawing::Color,
|
||||||
pub accent_color: drawing::Color,
|
pub accent_color: drawing::Color,
|
||||||
pub danger_color: drawing::Color,
|
pub danger_color: drawing::Color,
|
||||||
|
pub faded_color: drawing::Color,
|
||||||
|
pub translucent_alpha: f32,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for Defaults {
|
impl Default for Defaults {
|
||||||
@@ -31,6 +33,8 @@ impl Default for Defaults {
|
|||||||
button_color: drawing::Color::new(1.0, 1.0, 1.0, 0.05),
|
button_color: drawing::Color::new(1.0, 1.0, 1.0, 0.05),
|
||||||
accent_color: drawing::Color::new(0.0, 0.54, 1.0, 1.0),
|
accent_color: drawing::Color::new(0.0, 0.54, 1.0, 1.0),
|
||||||
danger_color: drawing::Color::new(0.8, 0.0, 0.0, 1.0),
|
danger_color: drawing::Color::new(0.8, 0.0, 0.0, 1.0),
|
||||||
|
faded_color: drawing::Color::new(0.4, 0.5, 0.6, 1.0),
|
||||||
|
translucent_alpha: 0.25,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -377,6 +377,30 @@ impl ParserContext<'_> {
|
|||||||
log::warn!("duplicate widget ID \"{id}\" in the same layout file!");
|
log::warn!("duplicate widget ID \"{id}\" in the same layout file!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn populate_theme_variables(&mut self) {
|
||||||
|
let def = self.doc_params.globals.defaults();
|
||||||
|
|
||||||
|
macro_rules! insert_color_vars {
|
||||||
|
($self:expr, $name:literal, $field:expr, $alpha:expr) => {
|
||||||
|
$self.insert_var(concat!("color_", $name), &$field.to_hex());
|
||||||
|
$self.insert_var(
|
||||||
|
concat!("color_", $name, "_translucent"),
|
||||||
|
&$field.with_alpha($alpha).to_hex(),
|
||||||
|
);
|
||||||
|
$self.insert_var(concat!("color_", $name, "_50"), &$field.mult_rgb(0.50).to_hex());
|
||||||
|
$self.insert_var(concat!("color_", $name, "_20"), &$field.mult_rgb(0.20).to_hex());
|
||||||
|
$self.insert_var(concat!("color_", $name, "_10"), &$field.mult_rgb(0.10).to_hex());
|
||||||
|
$self.insert_var(concat!("color_", $name, "_5"), &$field.mult_rgb(0.05).to_hex());
|
||||||
|
$self.insert_var(concat!("color_", $name, "_1"), &$field.mult_rgb(0.01).to_hex());
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
insert_color_vars!(self, "text", def.text_color, def.translucent_alpha);
|
||||||
|
insert_color_vars!(self, "accent", def.accent_color, def.translucent_alpha);
|
||||||
|
insert_color_vars!(self, "danger", def.danger_color, def.translucent_alpha);
|
||||||
|
insert_color_vars!(self, "faded", def.faded_color, def.translucent_alpha);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Parses a color from a HTML hex string
|
// Parses a color from a HTML hex string
|
||||||
@@ -1030,6 +1054,8 @@ pub fn parse_from_assets(
|
|||||||
) -> anyhow::Result<ParserState> {
|
) -> anyhow::Result<ParserState> {
|
||||||
let parser_data = ParserData::default();
|
let parser_data = ParserData::default();
|
||||||
let mut ctx = create_default_context(doc_params, layout, &parser_data);
|
let mut ctx = create_default_context(doc_params, layout, &parser_data);
|
||||||
|
ctx.populate_theme_variables();
|
||||||
|
|
||||||
let (file, node_layout) = get_doc_from_asset_path(&ctx, doc_params.path)?;
|
let (file, node_layout) = get_doc_from_asset_path(&ctx, doc_params.path)?;
|
||||||
parse_document_root(&file, &mut ctx, parent_id, node_layout)?;
|
parse_document_root(&file, &mut ctx, parent_id, node_layout)?;
|
||||||
|
|
||||||
|
|||||||
@@ -6,8 +6,8 @@ use taffy::{
|
|||||||
use crate::{
|
use crate::{
|
||||||
drawing,
|
drawing,
|
||||||
parser::{
|
parser::{
|
||||||
is_percent, parse_color_hex, parse_f32, parse_percent, parse_size_unit, parse_val, print_invalid_attrib,
|
AttribPair, is_percent, parse_color_hex, parse_f32, parse_percent, parse_size_unit, parse_val,
|
||||||
print_invalid_value, AttribPair,
|
print_invalid_attrib, print_invalid_value,
|
||||||
},
|
},
|
||||||
renderer_vk::text::{FontWeight, HorizontalAlign, TextStyle},
|
renderer_vk::text::{FontWeight, HorizontalAlign, TextStyle},
|
||||||
widget::util::WLength,
|
widget::util::WLength,
|
||||||
|
|||||||
@@ -129,6 +129,10 @@ pub struct GeneralConfig {
|
|||||||
#[serde(default = "def_theme_path")]
|
#[serde(default = "def_theme_path")]
|
||||||
pub theme_path: Arc<str>,
|
pub theme_path: Arc<str>,
|
||||||
|
|
||||||
|
pub color_accent: Option<String>,
|
||||||
|
pub color_danger: Option<String>,
|
||||||
|
pub color_faded: Option<String>,
|
||||||
|
|
||||||
#[serde(default = "def_click_freeze_time_ms")]
|
#[serde(default = "def_click_freeze_time_ms")]
|
||||||
pub click_freeze_time_ms: u32,
|
pub click_freeze_time_ms: u32,
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,4 @@
|
|||||||
<layout>
|
<layout>
|
||||||
<include src="theme.xml" />
|
|
||||||
|
|
||||||
<macro name="button_style"
|
<macro name="button_style"
|
||||||
margin="2" overflow="hidden" box_sizing="border_box"
|
margin="2" overflow="hidden" box_sizing="border_box"
|
||||||
border_color="~color_accent_translucent" border="2" round="8" color="~color_accent_5" color2="~color_accent_1" gradient="vertical"
|
border_color="~color_accent_translucent" border="2" round="8" color="~color_accent_5" color2="~color_accent_1" gradient="vertical"
|
||||||
|
|||||||
@@ -1,6 +1,4 @@
|
|||||||
<layout>
|
<layout>
|
||||||
<include src="theme.xml" />
|
|
||||||
|
|
||||||
<macro name="keycap_rect"
|
<macro name="keycap_rect"
|
||||||
margin="2" width="100%" overflow="hidden" box_sizing="border_box"
|
margin="2" width="100%" overflow="hidden" box_sizing="border_box"
|
||||||
border_color="~color_accent_translucent" border="2" round="8" color="~color_accent_5" color2="~color_accent_1" gradient="vertical"
|
border_color="~color_accent_translucent" border="2" round="8" color="~color_accent_5" color2="~color_accent_1" gradient="vertical"
|
||||||
@@ -73,4 +71,4 @@
|
|||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
</layout>
|
</layout>
|
||||||
|
|||||||
@@ -1,25 +0,0 @@
|
|||||||
<layout>
|
|
||||||
<theme>
|
|
||||||
<var key="color_text" value="#FFFFFF" />
|
|
||||||
<var key="color_text_translucent" value="#FFFFFF40" />
|
|
||||||
|
|
||||||
<var key="color_accent" value="#008cff" />
|
|
||||||
<var key="color_accent_translucent" value="#008cff40" />
|
|
||||||
<var key="color_accent_20" value="#001c33" /> <!-- 20% brightness -->
|
|
||||||
<var key="color_accent_5" value="#00070d" /> <!-- 5% brightness -->
|
|
||||||
<var key="color_accent_1" value="#000103" /> <!-- 1% brightness -->
|
|
||||||
|
|
||||||
|
|
||||||
<var key="color_danger" value="#ff3300" />
|
|
||||||
<var key="color_danger_translucent" value="#ff330040" />
|
|
||||||
<var key="color_danger_20" value="#330a00" /> <!-- 20% brightness -->
|
|
||||||
<var key="color_danger_5" value="#0d0200" /> <!-- 5% brightness -->
|
|
||||||
<var key="color_danger_1" value="#030000" /> <!-- 1% brightness -->
|
|
||||||
|
|
||||||
<var key="color_faded" value="#668299" />
|
|
||||||
<var key="color_faded_translucent" value="#66829940" />
|
|
||||||
<var key="color_faded_20" value="#141a1f" /> <!-- 20% brightness -->
|
|
||||||
<var key="color_faded_5" value="#050708" /> <!-- 5% brightness -->
|
|
||||||
<var key="color_faded_1" value="#010102" /> <!-- 1% brightness -->
|
|
||||||
</theme>
|
|
||||||
</layout>
|
|
||||||
@@ -1,6 +1,4 @@
|
|||||||
<layout>
|
<layout>
|
||||||
<include src="theme.xml" />
|
|
||||||
|
|
||||||
<elements>
|
<elements>
|
||||||
<div interactable="0" >
|
<div interactable="0" >
|
||||||
<rectangle max_width="500" max_height="400" padding="4" box_sizing="content_box" flex_wrap="wrap" flex_direction="row" gap="4" color="#000000c0" border_color="~color_accent" border="2" round="8" justify_content="space_between">
|
<rectangle max_width="500" max_height="400" padding="4" box_sizing="content_box" flex_wrap="wrap" flex_direction="row" gap="4" color="#000000c0" border_color="~color_accent" border="2" round="8" justify_content="space_between">
|
||||||
|
|||||||
@@ -1,9 +1,5 @@
|
|||||||
<layout>
|
<layout>
|
||||||
<include src="theme.xml" />
|
|
||||||
|
|
||||||
<theme>
|
<theme>
|
||||||
<var key="border" value="2" />
|
|
||||||
<var key="kbd_color" value="#a6da95" />
|
|
||||||
<var key="set_color" value="#cad3f5" />
|
<var key="set_color" value="#cad3f5" />
|
||||||
|
|
||||||
<var key="clock0_color" value="#cad3f5" />
|
<var key="clock0_color" value="#cad3f5" />
|
||||||
|
|||||||
@@ -1,9 +1,10 @@
|
|||||||
use glam::Affine3A;
|
use glam::Affine3A;
|
||||||
use idmap::IdMap;
|
use idmap::IdMap;
|
||||||
use smallvec::{SmallVec, smallvec};
|
use smallvec::{SmallVec, smallvec};
|
||||||
use std::sync::Arc;
|
use smithay::backend::renderer::Texture;
|
||||||
|
use std::{ops::Not, sync::Arc};
|
||||||
use wgui::{
|
use wgui::{
|
||||||
font_config::WguiFontConfig, gfx::WGfx, globals::WguiGlobals,
|
font_config::WguiFontConfig, gfx::WGfx, globals::WguiGlobals, parser::parse_color_hex,
|
||||||
renderer_vk::context::SharedContext as WSharedContext,
|
renderer_vk::context::SharedContext as WSharedContext,
|
||||||
};
|
};
|
||||||
use wlx_common::{
|
use wlx_common::{
|
||||||
@@ -87,6 +88,28 @@ impl AppState {
|
|||||||
let wgui_shared = WSharedContext::new(gfx.clone())?;
|
let wgui_shared = WSharedContext::new(gfx.clone())?;
|
||||||
let theme = session.config.theme_path.clone();
|
let theme = session.config.theme_path.clone();
|
||||||
|
|
||||||
|
let mut defaults = wgui::globals::Defaults::default();
|
||||||
|
defaults.accent_color = session
|
||||||
|
.config
|
||||||
|
.color_accent
|
||||||
|
.as_ref()
|
||||||
|
.and_then(|c| parse_color_hex(&c))
|
||||||
|
.unwrap_or(defaults.accent_color);
|
||||||
|
|
||||||
|
defaults.danger_color = session
|
||||||
|
.config
|
||||||
|
.color_danger
|
||||||
|
.as_ref()
|
||||||
|
.and_then(|c| parse_color_hex(&c))
|
||||||
|
.unwrap_or(defaults.danger_color);
|
||||||
|
|
||||||
|
defaults.faded_color = session
|
||||||
|
.config
|
||||||
|
.color_faded
|
||||||
|
.as_ref()
|
||||||
|
.and_then(|c| parse_color_hex(&c))
|
||||||
|
.unwrap_or(defaults.faded_color);
|
||||||
|
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
session,
|
session,
|
||||||
tasks,
|
tasks,
|
||||||
@@ -102,7 +125,7 @@ impl AppState {
|
|||||||
toast_sound: toast_sound_wav,
|
toast_sound: toast_sound_wav,
|
||||||
wgui_globals: WguiGlobals::new(
|
wgui_globals: WguiGlobals::new(
|
||||||
Box::new(gui::asset::GuiAsset {}),
|
Box::new(gui::asset::GuiAsset {}),
|
||||||
wgui::globals::Defaults::default(),
|
defaults,
|
||||||
&WguiFontConfig::default(),
|
&WguiFontConfig::default(),
|
||||||
get_config_file_path(&theme),
|
get_config_file_path(&theme),
|
||||||
)?,
|
)?,
|
||||||
|
|||||||
Reference in New Issue
Block a user