config: clean up and document theming
This commit is contained in:
parent
4780315f50
commit
6916f03e94
17 changed files with 745 additions and 285 deletions
175
src/theme.rs
175
src/theme.rs
|
|
@ -8,22 +8,6 @@ pub struct Color {
|
|||
pub a: f32,
|
||||
}
|
||||
|
||||
impl Color {
|
||||
pub const GREY: Self = Self {
|
||||
r: 0.8,
|
||||
g: 0.8,
|
||||
b: 0.8,
|
||||
a: 1.0,
|
||||
};
|
||||
|
||||
pub const BLACK: Self = Self {
|
||||
r: 0.0,
|
||||
g: 0.0,
|
||||
b: 0.0,
|
||||
a: 1.0,
|
||||
};
|
||||
}
|
||||
|
||||
fn to_f32(c: u8) -> f32 {
|
||||
c as f32 / 255f32
|
||||
}
|
||||
|
|
@ -33,6 +17,15 @@ fn to_u8(c: f32) -> u8 {
|
|||
}
|
||||
|
||||
impl Color {
|
||||
pub fn from_rgb(r: u8, g: u8, b: u8) -> Self {
|
||||
Self {
|
||||
r: to_f32(r),
|
||||
g: to_f32(g),
|
||||
b: to_f32(b),
|
||||
a: 1.0,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn from_rgba_straight(r: u8, g: u8, b: u8, a: u8) -> Self {
|
||||
let alpha = to_f32(a);
|
||||
Self {
|
||||
|
|
@ -51,39 +44,145 @@ impl Color {
|
|||
|
||||
impl From<jay_config::theme::Color> for Color {
|
||||
fn from(f: jay_config::theme::Color) -> Self {
|
||||
Self {
|
||||
r: to_f32(f.r),
|
||||
g: to_f32(f.g),
|
||||
b: to_f32(f.b),
|
||||
a: to_f32(f.a),
|
||||
let [r, g, b, a] = f.to_f32_premultiplied();
|
||||
Self { r, g, b, a }
|
||||
}
|
||||
}
|
||||
|
||||
macro_rules! colors {
|
||||
($($name:ident = ($r:expr, $g:expr, $b:expr),)*) => {
|
||||
pub struct ThemeColors {
|
||||
$(
|
||||
pub $name: Cell<Color>,
|
||||
)*
|
||||
}
|
||||
|
||||
impl ThemeColors {
|
||||
pub fn reset(&self) {
|
||||
let default = Self::default();
|
||||
$(
|
||||
self.$name.set(default.$name.get());
|
||||
)*
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for ThemeColors {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
$(
|
||||
$name: Cell::new(Color::from_rgb($r, $g, $b)),
|
||||
)*
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
colors! {
|
||||
background = (0x00, 0x10, 0x19),
|
||||
unfocused_title_background = (0x22, 0x22, 0x22),
|
||||
focused_title_background = (0x28, 0x55, 0x77),
|
||||
focused_inactive_title_background = (0x5f, 0x67, 0x6a),
|
||||
unfocused_title_text = (0x88, 0x88, 0x88),
|
||||
focused_title_text = (0xff, 0xff, 0xff),
|
||||
focused_inactive_title_text = (0xff, 0xff, 0xff),
|
||||
separator = (0x33, 0x33, 0x33),
|
||||
border = (0x3f, 0x47, 0x4a),
|
||||
bar_background = (0x00, 0x00, 0x00),
|
||||
bar_text = (0xff, 0xff, 0xff),
|
||||
}
|
||||
|
||||
macro_rules! sizes {
|
||||
($($name:ident = ($min:expr, $max:expr, $def:expr),)*) => {
|
||||
pub struct ThemeSizes {
|
||||
$(
|
||||
pub $name: Cell<i32>,
|
||||
)*
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug)]
|
||||
#[allow(non_camel_case_types)]
|
||||
pub enum ThemeSized {
|
||||
$(
|
||||
$name,
|
||||
)*
|
||||
}
|
||||
|
||||
impl ThemeSized {
|
||||
pub fn min(self) -> i32 {
|
||||
match self {
|
||||
$(
|
||||
Self::$name => $min,
|
||||
)*
|
||||
}
|
||||
}
|
||||
|
||||
pub fn max(self) -> i32 {
|
||||
match self {
|
||||
$(
|
||||
Self::$name => $max,
|
||||
)*
|
||||
}
|
||||
}
|
||||
|
||||
pub fn field(self, theme: &Theme) -> &Cell<i32> {
|
||||
let sizes = &theme.sizes;
|
||||
match self {
|
||||
$(
|
||||
Self::$name => &sizes.$name,
|
||||
)*
|
||||
}
|
||||
}
|
||||
|
||||
pub fn name(self) -> &'static str {
|
||||
match self {
|
||||
$(
|
||||
Self::$name => stringify!($name),
|
||||
)*
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl ThemeSizes {
|
||||
pub fn reset(&self) {
|
||||
let default = Self::default();
|
||||
$(
|
||||
self.$name.set(default.$name.get());
|
||||
)*
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for ThemeSizes {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
$(
|
||||
$name: Cell::new($def),
|
||||
)*
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
sizes! {
|
||||
title_height = (1, 1000, 17),
|
||||
border_width = (1, 1000, 4),
|
||||
}
|
||||
|
||||
pub const DEFAULT_FONT: &str = "monospace 8";
|
||||
|
||||
pub struct Theme {
|
||||
pub background_color: Cell<Color>,
|
||||
pub title_color: Cell<Color>,
|
||||
pub active_title_color: Cell<Color>,
|
||||
pub underline_color: Cell<Color>,
|
||||
pub border_color: Cell<Color>,
|
||||
pub last_active_color: Cell<Color>,
|
||||
pub title_height: Cell<i32>,
|
||||
pub border_width: Cell<i32>,
|
||||
pub colors: ThemeColors,
|
||||
pub sizes: ThemeSizes,
|
||||
pub font: RefCell<String>,
|
||||
}
|
||||
|
||||
impl Default for Theme {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
background_color: Cell::new(Color::from_rgba_straight(0x00, 0x10, 0x19, 255)),
|
||||
last_active_color: Cell::new(Color::from_rgba_straight(0x5f, 0x67, 0x6a, 255)),
|
||||
title_color: Cell::new(Color::from_rgba_straight(0x22, 0x22, 0x22, 255)),
|
||||
active_title_color: Cell::new(Color::from_rgba_straight(0x28, 0x55, 0x77, 255)),
|
||||
underline_color: Cell::new(Color::from_rgba_straight(0x33, 0x33, 0x33, 255)),
|
||||
border_color: Cell::new(Color::from_rgba_straight(0x3f, 0x47, 0x4a, 255)),
|
||||
title_height: Cell::new(17),
|
||||
border_width: Cell::new(4),
|
||||
font: RefCell::new("monospace 8".to_string()),
|
||||
colors: Default::default(),
|
||||
sizes: Default::default(),
|
||||
font: RefCell::new(DEFAULT_FONT.to_string()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue