#![allow(missing_docs, reason = "Names are self-explanatory.")]
use crate::core::{
DefaultProperties, PropertySet, PropertyStack, Selector, StyleProperty, StyleSet,
};
use crate::layout::{AsUnit, Length};
use crate::palette::css::DIM_GRAY;
use crate::parley::{GenericFamily, LineHeight};
use crate::peniko::Color;
use crate::properties::*;
use crate::widgets::*;
pub const BACKGROUND_COLOR: Color = Color::from_rgb8(0x1D, 0x1D, 0x1D);
pub const BORDER_WIDTH: Length = Length::const_px(1.);
pub const ZYNC_900: Color = Color::from_rgb8(0x18, 0x18, 0x1b);
pub const ZYNC_800: Color = Color::from_rgb8(0x27, 0x27, 0x2a);
pub const ZYNC_700: Color = Color::from_rgb8(0x3f, 0x3f, 0x46);
pub const ZYNC_600: Color = Color::from_rgb8(0x52, 0x52, 0x5b);
pub const ZYNC_500: Color = Color::from_rgb8(0x71, 0x71, 0x7a);
pub const ACCENT_COLOR: Color = Color::from_rgb8(0x3b, 0x7e, 0xe4);
pub const TEXT_COLOR: Color = Color::from_rgb8(0xf2, 0xf2, 0xf2);
pub const DISABLED_TEXT_COLOR: Color = Color::from_rgb8(0xa0, 0xa0, 0x9a);
pub const PLACEHOLDER_COLOR: Color = Color::from_rgba8(0xFF, 0xFF, 0xFF, 0x8F);
pub const TEXT_BACKGROUND_COLOR: Color = Color::from_rgb8(0x16, 0x16, 0x16);
pub const FOCUS_COLOR: Color = Color::from_rgb8(0xff, 0xff, 0xff);
pub const TEXT_SIZE_NORMAL: f32 = 15.0;
pub const BASIC_WIDGET_HEIGHT: Length = Length::const_px(18.0);
pub const BORDERED_WIDGET_HEIGHT: f64 = 24.0;
pub const SCROLLBAR_COLOR: Color = Color::from_rgb8(0xff, 0xff, 0xff);
pub const SCROLLBAR_BORDER_COLOR: Color = Color::from_rgb8(0x77, 0x77, 0x77);
pub const SCROLLBAR_WIDTH: f64 = 8.;
pub const SCROLLBAR_PAD: f64 = 2.;
pub const SCROLLBAR_MIN_SIZE: f64 = 45.;
pub const SCROLLBAR_RADIUS: f64 = 5.;
pub const SCROLLBAR_EDGE_WIDTH: f64 = 1.;
pub const DEFAULT_GAP: Length = Length::const_px(10.0);
pub const DEFAULT_SPACER_LEN: Length = Length::const_px(10.0);
pub const WIDGET_CONTROL_COMPONENT_PADDING: Length = Length::const_px(4.0);
pub const SELECTOR_MIN_WIDTH: f64 = 100.0;
pub fn default_property_set() -> DefaultProperties {
let mut properties = DefaultProperties::new();
properties.insert::<Badge, _>(Padding::from_vh(3.px(), 5.px()));
properties.insert::<Badge, _>(CornerRadius { radius: 999.px() });
properties.insert::<Badge, _>(BorderWidth { width: 0.px() });
properties.insert::<Badge, _>(Background::Color(ACCENT_COLOR));
properties.insert::<Badge, _>(BorderColor { color: ZYNC_700 });
{
let mut stack = PropertyStack::new();
stack.push_layer(
Selector::new().with_disabled(true),
Background::Color(ZYNC_800),
);
properties.insert_stack::<Badge>(stack);
}
properties.insert::<Button, _>(Padding::from_vh(6.px(), 16.px()));
properties.insert::<Button, _>(CornerRadius { radius: 6.px() });
properties.insert::<Button, _>(BorderWidth {
width: BORDER_WIDTH,
});
properties.insert::<Button, _>(Background::Color(ZYNC_800));
properties.insert::<Button, _>(BorderColor { color: ZYNC_700 });
{
let mut stack = PropertyStack::new();
stack.push_layer(
Selector::new().with_hovered(true),
BorderColor { color: ZYNC_500 },
);
stack.push_layer(
Selector::new().with_focused(true),
BorderColor { color: FOCUS_COLOR },
);
stack.push_layer(
Selector::new().with_active(true),
Background::Color(ZYNC_700),
);
stack.push_layer(
Selector::new().with_disabled(true),
Background::Color(Color::BLACK),
);
properties.insert_stack::<Button>(stack);
}
properties.insert::<Checkbox, _>(CornerRadius { radius: 4.px() });
properties.insert::<Checkbox, _>(BorderWidth {
width: BORDER_WIDTH,
});
properties.insert::<Checkbox, _>(Background::Color(ZYNC_800));
properties.insert::<Checkbox, _>(BorderColor { color: ZYNC_700 });
properties.insert::<Checkbox, _>(CheckmarkStrokeWidth { width: 2.0 });
properties.insert::<Checkbox, _>(CheckmarkColor { color: TEXT_COLOR });
{
let mut stack = PropertyStack::new();
stack.push_layer(
Selector::new().with_hovered(true),
BorderColor { color: ZYNC_500 },
);
stack.push_layer(
Selector::new().with_focused(true),
BorderColor { color: FOCUS_COLOR },
);
stack.push_layer(
Selector::new().with_active(true),
Background::Color(ZYNC_700),
);
stack.push_layer(
Selector::new().with_disabled(true),
PropertySet::new()
.with(Background::Color(Color::BLACK))
.with(CheckmarkColor {
color: DISABLED_TEXT_COLOR,
}),
);
properties.insert_stack::<Checkbox>(stack);
}
properties.insert::<DisclosureButton, _>(ContentColor::new(DIM_GRAY));
properties.insert::<DisclosureButton, _>(Dimensions::fixed(
Length::const_px(16.),
Length::const_px(16.),
));
properties.insert::<DisclosureButton, _>(Padding::all(4.px()));
properties.insert::<Divider, _>(ContentColor::new(ZYNC_500));
properties.insert::<Switch, _>(CornerRadius { radius: 10.px() }); properties.insert::<Switch, _>(BorderWidth {
width: BORDER_WIDTH,
});
properties.insert::<Switch, _>(Background::Color(ZYNC_700));
properties.insert::<Switch, _>(BorderColor { color: ZYNC_700 });
properties.insert::<Switch, _>(ThumbColor(Color::WHITE));
properties.insert::<Switch, _>(ThumbRadius(8.px()));
properties.insert::<Switch, _>(TrackThickness(20.px()));
{
let mut stack = PropertyStack::new();
stack.push_layer(
Selector::new().with_hovered(true),
BorderColor { color: ZYNC_500 },
);
stack.push_layer(
Selector::new().with_focused(true),
BorderColor { color: FOCUS_COLOR },
);
stack.push_layer(
Selector::classes(&["#toggled"]),
Background::Color(ACCENT_COLOR),
);
stack.push_layer(
Selector::new().with_active(true),
Background::Color(ZYNC_600),
);
stack.push_layer(
Selector::new().with_disabled(true),
Background::Color(Color::BLACK),
);
properties.insert_stack::<Switch>(stack);
}
use crate::widgets::Selector as SelectorButton;
properties.insert::<SelectorButton, _>(Padding::from_vh(6.px(), 16.px()));
properties.insert::<SelectorButton, _>(CornerRadius { radius: 2.px() });
properties.insert::<SelectorButton, _>(BorderWidth {
width: BORDER_WIDTH,
});
properties.insert::<SelectorButton, _>(Background::Color(ZYNC_800));
properties.insert::<SelectorButton, _>(BorderColor { color: ZYNC_700 });
{
let mut stack = PropertyStack::new();
stack.push_layer(
Selector::new().with_active(true),
Background::Color(ZYNC_700),
);
stack.push_layer(
Selector::new().with_disabled(true),
Background::Color(Color::BLACK),
);
stack.push_layer(
Selector::new().with_hovered(true),
BorderColor { color: ZYNC_500 },
);
stack.push_layer(
Selector::new().with_focused(true),
BorderColor { color: FOCUS_COLOR },
);
properties.insert_stack::<SelectorButton>(stack);
}
properties.insert::<SelectorItem, _>(Padding::from_vh(6.px(), 16.px()));
properties.insert::<SelectorItem, _>(Background::Color(ZYNC_900));
{
let mut stack = PropertyStack::new();
stack.push_layer(
Selector::new().with_hovered(true),
Background::Color(ZYNC_800),
);
stack.push_layer(
Selector::new().with_active(true),
Background::Color(ZYNC_700),
);
stack.push_layer(
Selector::new().with_disabled(true),
Background::Color(Color::BLACK),
);
properties.insert_stack::<SelectorItem>(stack);
}
properties.insert::<Flex, _>(Gap::new(DEFAULT_GAP));
properties.insert::<Grid, _>(Gap::ZERO);
properties.insert::<TextInput, _>(Padding::from_vh(6.px(), 12.px()));
properties.insert::<TextInput, _>(CornerRadius { radius: 4.px() });
properties.insert::<TextInput, _>(BorderWidth {
width: BORDER_WIDTH,
});
properties.insert::<TextInput, _>(BorderColor { color: ZYNC_600 });
properties.insert::<TextInput, _>(PlaceholderColor::new(PLACEHOLDER_COLOR));
properties.insert::<TextInput, _>(CaretColor { color: TEXT_COLOR });
properties.insert::<TextInput, _>(SelectionColor {
color: ACCENT_COLOR,
});
properties.insert::<TextInput, _>(Background::Color(TEXT_BACKGROUND_COLOR));
{
let mut stack = PropertyStack::new();
stack.push_layer(
Selector::classes(&["#unfocused"]),
SelectionColor {
color: DISABLED_TEXT_COLOR,
},
);
stack.push_layer(
Selector::new().with_focused(true),
BorderColor { color: FOCUS_COLOR },
);
stack.push_layer(
Selector::new().with_disabled(true),
Background::Color(TEXT_BACKGROUND_COLOR),
);
properties.insert_stack::<TextInput>(stack);
}
properties.insert::<TextArea<false>, _>(ContentColor::new(TEXT_COLOR));
properties.insert::<TextArea<false>, _>(CaretColor { color: TEXT_COLOR });
properties.insert::<TextArea<false>, _>(SelectionColor {
color: ACCENT_COLOR,
});
{
let mut stack = PropertyStack::new();
stack.push_layer(
Selector::new().with_disabled(true),
ContentColor::new(DISABLED_TEXT_COLOR),
);
properties.insert_stack::<TextArea<false>>(stack);
}
properties.insert::<TextArea<true>, _>(ContentColor::new(TEXT_COLOR));
properties.insert::<TextArea<true>, _>(CaretColor { color: TEXT_COLOR });
properties.insert::<TextArea<true>, _>(SelectionColor {
color: ACCENT_COLOR,
});
{
let mut stack = PropertyStack::new();
stack.push_layer(
Selector::new().with_disabled(true),
ContentColor::new(DISABLED_TEXT_COLOR),
);
properties.insert_stack::<TextArea<true>>(stack);
}
properties.insert::<Prose, _>(CaretColor { color: TEXT_COLOR });
properties.insert::<Prose, _>(ContentColor::new(TEXT_COLOR));
properties.insert::<Prose, _>(SelectionColor {
color: ACCENT_COLOR,
});
{
let mut stack = PropertyStack::new();
stack.push_layer(
Selector::classes(&["#unfocused"]),
SelectionColor {
color: DISABLED_TEXT_COLOR,
},
);
properties.insert_stack::<Prose>(stack);
}
properties.insert::<Label, _>(ContentColor::new(TEXT_COLOR));
{
let mut stack = PropertyStack::new();
stack.push_layer(
Selector::new().with_disabled(true),
ContentColor::new(DISABLED_TEXT_COLOR),
);
properties.insert_stack::<Label>(stack);
}
properties.insert::<ProgressBar, _>(CornerRadius { radius: 2.px() });
properties.insert::<ProgressBar, _>(BorderWidth {
width: BORDER_WIDTH,
});
properties.insert::<ProgressBar, _>(Background::Color(ZYNC_900));
properties.insert::<ProgressBar, _>(BorderColor { color: ZYNC_800 });
properties.insert::<ProgressBar, _>(BarColor(ACCENT_COLOR));
properties.insert::<RadioButton, _>(BorderWidth {
width: BORDER_WIDTH,
});
properties.insert::<RadioButton, _>(Background::Color(ZYNC_800));
properties.insert::<RadioButton, _>(BorderColor { color: ZYNC_700 });
properties.insert::<RadioButton, _>(CheckmarkColor { color: TEXT_COLOR });
{
let mut stack = PropertyStack::new();
stack.push_layer(
Selector::new().with_active(true),
Background::Color(ZYNC_700),
);
stack.push_layer(
Selector::new().with_hovered(true),
BorderColor { color: ZYNC_500 },
);
stack.push_layer(
Selector::new().with_focused(true),
BorderColor { color: FOCUS_COLOR },
);
stack.push_layer(
Selector::new().with_disabled(true),
(
CheckmarkColor::new(DISABLED_TEXT_COLOR),
Background::Color(Color::BLACK),
),
);
properties.insert_stack::<RadioButton>(stack);
}
properties.insert::<Slider, _>(TrackThickness(4.px()));
properties.insert::<Slider, _>(TrackColor {
active: ACCENT_COLOR,
inactive: ZYNC_800,
});
properties.insert::<Slider, _>(ThumbColor(TEXT_COLOR));
properties.insert::<Slider, _>(ThumbRadius(7.px()));
{
let mut stack = PropertyStack::new();
stack.push_layer(
Selector::new().with_hovered(true),
BorderColor { color: ZYNC_500 },
);
stack.push_layer(
Selector::new().with_focused(true),
BorderColor { color: FOCUS_COLOR },
);
properties.insert_stack::<Slider>(stack);
}
properties.insert::<Spinner, _>(TrackColor {
active: TEXT_COLOR,
inactive: Color::TRANSPARENT,
});
properties.insert::<Spinner, _>(TrackThickness(8.px()));
properties.insert::<Spinner, _>(AnimationDuration { seconds: 1.2 });
default_step_input_style::<u8>(&mut properties);
default_step_input_style::<i8>(&mut properties);
default_step_input_style::<u16>(&mut properties);
default_step_input_style::<i16>(&mut properties);
default_step_input_style::<u32>(&mut properties);
default_step_input_style::<i32>(&mut properties);
default_step_input_style::<u64>(&mut properties);
default_step_input_style::<i64>(&mut properties);
default_step_input_style::<usize>(&mut properties);
default_step_input_style::<isize>(&mut properties);
default_step_input_style::<f32>(&mut properties);
default_step_input_style::<f64>(&mut properties);
properties
}
pub fn default_text_styles(styles: &mut StyleSet) {
styles.insert(StyleProperty::LineHeight(LineHeight::FontSizeRelative(1.2)));
styles.insert(GenericFamily::SystemUi.into());
}
fn default_step_input_style<T: Steppable>(properties: &mut DefaultProperties) {
properties.insert::<StepInput<T>, _>(Padding::from_vh(6.px(), 0.px()));
properties.insert::<StepInput<T>, _>(CornerRadius { radius: 6.px() });
properties.insert::<StepInput<T>, _>(BorderWidth {
width: BORDER_WIDTH,
});
properties.insert::<StepInput<T>, _>(ContentColor::new(TEXT_COLOR));
properties.insert::<StepInput<T>, _>(Background::Color(ZYNC_800));
properties.insert::<StepInput<T>, _>(BorderColor { color: ZYNC_700 });
{
let mut stack = PropertyStack::new();
stack.push_layer(
Selector::new().with_disabled(true),
(
ContentColor::new(DISABLED_TEXT_COLOR),
Background::Color(Color::BLACK),
),
);
stack.push_layer(
Selector::new().with_hovered(true),
BorderColor { color: ZYNC_500 },
);
stack.push_layer(
Selector::new().with_focused(true),
BorderColor { color: FOCUS_COLOR },
);
properties.insert_stack::<StepInput<T>>(stack);
}
}
#[cfg(test)]
pub(crate) fn test_property_set() -> DefaultProperties {
#[allow(unused_mut, reason = "Sometimes we don't have anything to change")]
let mut properties = default_property_set();
properties
}