1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
// Copyright 2019 The Druid Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

//! Theme keys and initial values.

#![allow(missing_docs)]

use crate::kurbo::RoundedRectRadii;

use crate::piet::Color;

use crate::{Env, FontDescriptor, FontFamily, FontStyle, FontWeight, Insets, Key};

pub const WINDOW_BACKGROUND_COLOR: Key<Color> =
    Key::new("org.linebender.druid.theme.window_background_color");

#[doc(hidden)]
#[deprecated(since = "0.8.0", note = "renamed to TEXT_COLOR")]
pub const LABEL_COLOR: Key<Color> = TEXT_COLOR;
pub const TEXT_COLOR: Key<Color> = Key::new("org.linebender.druid.theme.label_color");
pub const DISABLED_TEXT_COLOR: Key<Color> =
    Key::new("org.linebender.druid.theme.disabled_label_color");
pub const PLACEHOLDER_COLOR: Key<Color> = Key::new("org.linebender.druid.theme.placeholder_color");

pub const PRIMARY_LIGHT: Key<Color> = Key::new("org.linebender.druid.theme.primary_light");
pub const PRIMARY_DARK: Key<Color> = Key::new("org.linebender.druid.theme.primary_dark");
pub const PROGRESS_BAR_RADIUS: Key<RoundedRectRadii> =
    Key::new("org.linebender.druid.theme.progress_bar_radius");
pub const BACKGROUND_LIGHT: Key<Color> = Key::new("org.linebender.druid.theme.background_light");
pub const BACKGROUND_DARK: Key<Color> = Key::new("org.linebender.druid.theme.background_dark");
pub const FOREGROUND_LIGHT: Key<Color> = Key::new("org.linebender.druid.theme.foreground_light");
pub const FOREGROUND_DARK: Key<Color> = Key::new("org.linebender.druid.theme.foreground_dark");
pub const DISABLED_FOREGROUND_LIGHT: Key<Color> =
    Key::new("org.linebender.druid.theme.disabled_foreground_light");
pub const DISABLED_FOREGROUND_DARK: Key<Color> =
    Key::new("org.linebender.druid.theme.disabled_foreground_dark");
pub const BUTTON_DARK: Key<Color> = Key::new("org.linebender.druid.theme.button_dark");
pub const BUTTON_LIGHT: Key<Color> = Key::new("org.linebender.druid.theme.button_light");
pub const DISABLED_BUTTON_DARK: Key<Color> =
    Key::new("org.linebender.druid.theme.disabled_button_dark");
pub const DISABLED_BUTTON_LIGHT: Key<Color> =
    Key::new("org.linebender.druid.theme.disabled_button_light");
pub const BUTTON_BORDER_RADIUS: Key<RoundedRectRadii> =
    Key::new("org.linebender.druid.theme.button_radius");
pub const BUTTON_BORDER_WIDTH: Key<f64> =
    Key::new("org.linebender.druid.theme.button_border_width");
pub const BORDER_DARK: Key<Color> = Key::new("org.linebender.druid.theme.border_dark");
pub const BORDER_LIGHT: Key<Color> = Key::new("org.linebender.druid.theme.border_light");
#[doc(hidden)]
#[deprecated(since = "0.8.0", note = "use SELECTED_TEXT_BACKGROUND_COLOR instead")]
pub const SELECTION_COLOR: Key<Color> = SELECTED_TEXT_BACKGROUND_COLOR;
pub const SELECTED_TEXT_BACKGROUND_COLOR: Key<Color> =
    Key::new("org.linebender.druid.theme.selection_color");
pub const SELECTED_TEXT_INACTIVE_BACKGROUND_COLOR: Key<Color> =
    Key::new("org.linebender.druid.theme.selection_color_inactive");
pub const SELECTION_TEXT_COLOR: Key<Color> =
    Key::new("org.linebender.druid.theme.selection_text_color");
pub const CURSOR_COLOR: Key<Color> = Key::new("org.linebender.druid.theme.cursor_color");

pub const TEXT_SIZE_NORMAL: Key<f64> = Key::new("org.linebender.druid.theme.text_size_normal");
pub const TEXT_SIZE_LARGE: Key<f64> = Key::new("org.linebender.druid.theme.text_size_large");
pub const BASIC_WIDGET_HEIGHT: Key<f64> =
    Key::new("org.linebender.druid.theme.basic_widget_height");

/// The default font for labels, buttons, text boxes, and other UI elements.
pub const UI_FONT: Key<FontDescriptor> = Key::new("org.linebender.druid.theme.ui-font");

/// A bold version of the default UI font.
pub const UI_FONT_BOLD: Key<FontDescriptor> = Key::new("org.linebender.druid.theme.ui-font-bold");

/// An Italic version of the default UI font.
pub const UI_FONT_ITALIC: Key<FontDescriptor> =
    Key::new("org.linebender.druid.theme.ui-font-italic");

/// The default minimum width for a 'wide' widget; a textbox, slider, progress bar, etc.
pub const WIDE_WIDGET_WIDTH: Key<f64> = Key::new("org.linebender.druid.theme.long-widget-width");
pub const BORDERED_WIDGET_HEIGHT: Key<f64> =
    Key::new("org.linebender.druid.theme.bordered_widget_height");

pub const TEXTBOX_BORDER_RADIUS: Key<RoundedRectRadii> =
    Key::new("org.linebender.druid.theme.textbox_border_radius");
pub const TEXTBOX_BORDER_WIDTH: Key<f64> =
    Key::new("org.linebender.druid.theme.textbox_border_width");
pub const TEXTBOX_INSETS: Key<Insets> = Key::new("org.linebender.druid.theme.textbox_insets");

/// The default horizontal spacing between widgets.
pub const WIDGET_PADDING_HORIZONTAL: Key<f64> =
    Key::new("org.linebender.druid.theme.widget-padding-h");
/// The default vertical spacing between widgets.
pub const WIDGET_PADDING_VERTICAL: Key<f64> =
    Key::new("org.linebender.druid.theme.widget-padding-v");
/// The default internal (horizontal) padding for visually distinct components
/// of a widget; for instance between a checkbox and its label.
pub const WIDGET_CONTROL_COMPONENT_PADDING: Key<f64> =
    Key::new("org.linebender.druid.theme.widget-padding-control-label");

pub const SCROLLBAR_COLOR: Key<Color> = Key::new("org.linebender.druid.theme.scrollbar_color");
pub const SCROLLBAR_BORDER_COLOR: Key<Color> =
    Key::new("org.linebender.druid.theme.scrollbar_border_color");
pub const SCROLLBAR_MAX_OPACITY: Key<f64> =
    Key::new("org.linebender.druid.theme.scrollbar_max_opacity");
pub const SCROLLBAR_FADE_DELAY: Key<u64> =
    Key::new("org.linebender.druid.theme.scrollbar_fade_time");
pub const SCROLLBAR_WIDTH: Key<f64> = Key::new("org.linebender.druid.theme.scrollbar_width");
pub const SCROLLBAR_PAD: Key<f64> = Key::new("org.linebender.druid.theme.scrollbar_pad");
pub const SCROLLBAR_RADIUS: Key<RoundedRectRadii> =
    Key::new("org.linebender.druid.theme.scrollbar_radius");
pub const SCROLLBAR_EDGE_WIDTH: Key<f64> =
    Key::new("org.linebender.druid.theme.scrollbar_edge_width");
/// Minimum length for any scrollbar to be when measured on that
/// scrollbar's primary axis.
pub const SCROLLBAR_MIN_SIZE: Key<f64> = Key::new("org.linebender.theme.scrollbar_min_size");

/// An initial theme.
pub(crate) fn add_to_env(env: Env) -> Env {
    env.adding(WINDOW_BACKGROUND_COLOR, Color::rgb8(0x29, 0x29, 0x29))
        .adding(TEXT_COLOR, Color::rgb8(0xf0, 0xf0, 0xea))
        .adding(DISABLED_TEXT_COLOR, Color::rgb8(0xa0, 0xa0, 0x9a))
        .adding(PLACEHOLDER_COLOR, Color::rgb8(0x80, 0x80, 0x80))
        .adding(PRIMARY_LIGHT, Color::rgb8(0x5c, 0xc4, 0xff))
        .adding(PRIMARY_DARK, Color::rgb8(0x00, 0x8d, 0xdd))
        .adding(PROGRESS_BAR_RADIUS, 4.)
        .adding(BACKGROUND_LIGHT, Color::rgb8(0x3a, 0x3a, 0x3a))
        .adding(BACKGROUND_DARK, Color::rgb8(0x31, 0x31, 0x31))
        .adding(FOREGROUND_LIGHT, Color::rgb8(0xf9, 0xf9, 0xf9))
        .adding(FOREGROUND_DARK, Color::rgb8(0xbf, 0xbf, 0xbf))
        .adding(DISABLED_FOREGROUND_LIGHT, Color::rgb8(0x89, 0x89, 0x89))
        .adding(DISABLED_FOREGROUND_DARK, Color::rgb8(0x6f, 0x6f, 0x6f))
        .adding(BUTTON_DARK, Color::BLACK)
        .adding(BUTTON_LIGHT, Color::rgb8(0x21, 0x21, 0x21))
        .adding(DISABLED_BUTTON_DARK, Color::grey8(0x28))
        .adding(DISABLED_BUTTON_LIGHT, Color::grey8(0x38))
        .adding(BUTTON_BORDER_RADIUS, 4.)
        .adding(BUTTON_BORDER_WIDTH, 2.)
        .adding(BORDER_DARK, Color::rgb8(0x3a, 0x3a, 0x3a))
        .adding(BORDER_LIGHT, Color::rgb8(0xa1, 0xa1, 0xa1))
        .adding(
            SELECTED_TEXT_BACKGROUND_COLOR,
            Color::rgb8(0x43, 0x70, 0xA8),
        )
        .adding(SELECTED_TEXT_INACTIVE_BACKGROUND_COLOR, Color::grey8(0x74))
        .adding(SELECTION_TEXT_COLOR, Color::rgb8(0x00, 0x00, 0x00))
        .adding(CURSOR_COLOR, Color::WHITE)
        .adding(TEXT_SIZE_NORMAL, 15.0)
        .adding(TEXT_SIZE_LARGE, 24.0)
        .adding(BASIC_WIDGET_HEIGHT, 18.0)
        .adding(WIDE_WIDGET_WIDTH, 100.)
        .adding(BORDERED_WIDGET_HEIGHT, 24.0)
        .adding(TEXTBOX_BORDER_RADIUS, 2.)
        .adding(TEXTBOX_BORDER_WIDTH, 1.)
        .adding(TEXTBOX_INSETS, Insets::new(4.0, 4.0, 4.0, 4.0))
        .adding(SCROLLBAR_COLOR, Color::rgb8(0xff, 0xff, 0xff))
        .adding(SCROLLBAR_BORDER_COLOR, Color::rgb8(0x77, 0x77, 0x77))
        .adding(SCROLLBAR_MAX_OPACITY, 0.7)
        .adding(SCROLLBAR_FADE_DELAY, 1500u64)
        .adding(SCROLLBAR_WIDTH, 8.)
        .adding(SCROLLBAR_PAD, 2.)
        .adding(SCROLLBAR_MIN_SIZE, 45.)
        .adding(SCROLLBAR_RADIUS, 5.)
        .adding(SCROLLBAR_EDGE_WIDTH, 1.)
        .adding(WIDGET_PADDING_VERTICAL, 10.0)
        .adding(WIDGET_PADDING_HORIZONTAL, 8.0)
        .adding(WIDGET_CONTROL_COMPONENT_PADDING, 4.0)
        .adding(
            UI_FONT,
            FontDescriptor::new(FontFamily::SYSTEM_UI).with_size(15.0),
        )
        .adding(
            UI_FONT_BOLD,
            FontDescriptor::new(FontFamily::SYSTEM_UI)
                .with_weight(FontWeight::BOLD)
                .with_size(15.0),
        )
        .adding(
            UI_FONT_ITALIC,
            FontDescriptor::new(FontFamily::SYSTEM_UI)
                .with_style(FontStyle::Italic)
                .with_size(15.0),
        )
}