makepad_widget/
widgetstyle.rs

1use makepad_render::*;
2use crate::normalbutton::*;
3use crate::tab::*;
4use crate::desktopwindow::*;
5use crate::windowmenu::*;
6use crate::tabclose::*;
7use crate::texteditor::*;
8use crate::codeicon::*;
9use crate::textinput::*;
10use crate::scrollbar::*;
11use crate::scrollshadow::*;
12use crate::desktopbutton::*;
13use crate::splitter::*;
14use crate::tabcontrol::*;
15
16use serde::{Serialize, Deserialize};
17
18#[derive(Debug, Copy, Clone, Serialize, Deserialize, PartialEq)]
19pub struct StyleOptions {
20    pub scale: f32,
21    pub dark: bool
22}
23
24impl Default for StyleOptions{
25    fn default()->Self{
26        Self{
27            scale:1.0,
28            dark:true,
29        }
30    }
31}
32
33pub struct Theme {}
34impl Theme {
35    pub fn text_style_unscaled() -> TextStyleId {uid!()}
36    pub fn text_style_normal() -> TextStyleId {uid!()}
37    pub fn text_style_fixed() -> TextStyleId {uid!()}
38    
39    pub fn color_bg_splitter() -> ColorId {uid!()}
40    pub fn color_bg_splitter_over() -> ColorId {uid!()}
41    pub fn color_bg_splitter_peak() -> ColorId {uid!()}
42    pub fn color_bg_splitter_drag() -> ColorId {uid!()}
43    
44    pub fn color_scrollbar_base() -> ColorId {uid!()}
45    pub fn color_scrollbar_over() -> ColorId {uid!()}
46    pub fn color_scrollbar_down() -> ColorId {uid!()}
47    
48    pub fn color_bg_normal() -> ColorId {uid!()}
49    pub fn color_bg_selected() -> ColorId {uid!()}
50    pub fn color_bg_odd() -> ColorId {uid!()}
51    pub fn color_bg_selected_over() -> ColorId {uid!()}
52    pub fn color_bg_odd_over() -> ColorId {uid!()}
53    pub fn color_bg_marked() -> ColorId {uid!()}
54    pub fn color_bg_marked_over() -> ColorId {uid!()}
55    pub fn color_over_border() -> ColorId {uid!()}
56    pub fn color_icon() -> ColorId {uid!()}
57    pub fn color_drop_quad() -> ColorId {uid!()}
58    
59    pub fn color_text_focus() -> ColorId {uid!()}
60    pub fn color_text_defocus() -> ColorId {uid!()}
61    pub fn color_text_selected_focus() -> ColorId {uid!()}
62    pub fn color_text_deselected_focus() -> ColorId {uid!()}
63    pub fn color_text_selected_defocus() -> ColorId {uid!()}
64    pub fn color_text_deselected_defocus() -> ColorId {uid!()}
65}
66
67pub fn set_widget_style(cx: &mut Cx, opt: &StyleOptions) {
68    
69    //if opt.dark {
70        Theme::color_bg_splitter().set(cx, color256(25, 25, 25));
71        Theme::color_bg_splitter_over().set(cx, color("#5"));
72        Theme::color_bg_splitter_peak().set(cx, color("#f"));
73        Theme::color_bg_splitter_drag().set(cx, color("#6"));
74        Theme::color_scrollbar_base().set(cx, color("#5"));
75        Theme::color_scrollbar_over().set(cx, color("#7"));
76        Theme::color_scrollbar_down().set(cx, color("#9"));
77        Theme::color_bg_normal().set(cx, color256(52, 52, 52));
78        Theme::color_bg_selected().set(cx, color256(40, 40, 40));
79        Theme::color_bg_odd().set(cx, color256(37, 37, 37));
80        Theme::color_bg_selected_over().set(cx, color256(61, 61, 61));
81        Theme::color_bg_odd_over().set(cx, color256(56, 56, 56));
82        Theme::color_bg_marked().set(cx, color256(17, 70, 110));
83        Theme::color_bg_marked_over().set(cx, color256(17, 70, 110));
84        Theme::color_over_border().set(cx, color256(255, 255, 255));
85        Theme::color_drop_quad().set(cx, color("#a"));
86        Theme::color_text_defocus().set(cx, color("#9"));
87        Theme::color_text_focus().set(cx, color("#b"));
88        Theme::color_icon().set(cx, color256(127, 127, 127));
89        
90        Theme::color_text_selected_focus().set(cx, color256(255, 255, 255));
91        Theme::color_text_deselected_focus().set(cx, color256(157, 157, 157));
92        Theme::color_text_selected_defocus().set(cx, color256(157, 157, 157));
93        Theme::color_text_deselected_defocus().set(cx, color256(130, 130, 130));
94        
95        TextEditor::color_bg().set(cx, color256(30, 30, 30));
96        TextEditor::color_gutter_bg().set(cx, color256(30, 30, 30));
97        TextEditor::color_indent_line_unknown().set(cx, color("#5"));
98        TextEditor::color_indent_line_fn().set(cx, color256(220, 220, 174));
99        TextEditor::color_indent_line_typedef().set(cx, color256(91, 155, 211));
100        TextEditor::color_indent_line_looping().set(cx, color("darkorange"));
101        TextEditor::color_indent_line_flow().set(cx, color256(196, 133, 190));
102        TextEditor::color_selection().set(cx, color256(42, 78, 117));
103        TextEditor::color_selection_defocus().set(cx, color256(75, 75, 75));
104        TextEditor::color_highlight().set(cx, color256a(75, 75, 95, 128));
105        TextEditor::color_cursor().set(cx, color256(176, 176, 176));
106        TextEditor::color_cursor_row().set(cx, color256(45, 45, 45));
107        
108        TextEditor::color_paren_pair_match().set(cx, color256(255, 255, 255));
109        TextEditor::color_paren_pair_fail().set(cx, color256(255, 0, 0));
110        
111        TextEditor::color_marker_error().set(cx, color256(200, 0, 0));
112        TextEditor::color_marker_warning().set(cx, color256(0, 200, 0));
113        TextEditor::color_marker_log().set(cx, color256(200, 200, 200));
114        TextEditor::color_line_number_normal().set(cx, color256(136, 136, 136));
115        TextEditor::color_line_number_highlight().set(cx, color256(212, 212, 212));
116        
117        TextEditor::color_whitespace().set(cx, color256(110, 110, 110));
118        
119        TextEditor::color_keyword().set(cx, color256(91, 155, 211));
120        TextEditor::color_flow().set(cx, color256(196, 133, 190));
121        TextEditor::color_looping().set(cx, color("darkorange"));
122        TextEditor::color_identifier().set(cx, color256(212, 212, 212));
123        TextEditor::color_call().set(cx, color256(220, 220, 174));
124        TextEditor::color_type_name().set(cx, color256(86, 201, 177));
125        TextEditor::color_theme_name().set(cx, color256(204, 145, 123));
126        
127        TextEditor::color_string().set(cx, color256(204, 145, 123));
128        TextEditor::color_number().set(cx, color256(182, 206, 170));
129        
130        TextEditor::color_comment().set(cx, color256(99, 141, 84));
131        TextEditor::color_doc_comment().set(cx, color256(120, 171, 104));
132        TextEditor::color_paren_d1().set(cx, color256(212, 212, 212));
133        TextEditor::color_paren_d2().set(cx, color256(212, 212, 212));
134        TextEditor::color_operator().set(cx, color256(212, 212, 212));
135        TextEditor::color_delimiter().set(cx, color256(212, 212, 212));
136        TextEditor::color_unexpected().set(cx, color256(255, 0, 0));
137        
138        TextEditor::color_warning().set(cx, color256(225, 229, 112));
139        TextEditor::color_error().set(cx, color256(254, 0, 0));
140        TextEditor::color_defocus().set(cx, color256(128, 128, 128));
141    //}
142    
143    let font = cx.load_font("resources/Ubuntu-R.ttf");
144    Theme::text_style_unscaled().set(cx, TextStyle {
145        font: font,
146        font_size: 8.0,
147        brightness: 1.0,
148        curve: 0.6,
149        line_spacing: 1.4,
150        top_drop: 1.2,
151        height_factor: 1.3,
152    });
153    
154    Theme::text_style_normal().set(cx, TextStyle {
155        font_size: 8.0 * opt.scale,
156        ..Theme::text_style_unscaled().get(cx)
157    });
158    
159    let font = cx.load_font("resources/LiberationMono-Regular.ttf");
160    Theme::text_style_fixed().set(cx, TextStyle {
161        font: font,
162        brightness: 1.1,
163        font_size: 8.0 * opt.scale, 
164        line_spacing: 1.8,
165        top_drop: 1.3,
166        ..Theme::text_style_unscaled().get(cx)
167    });
168    
169    TabClose::style(cx, opt);
170    DesktopWindow::style(cx, opt);
171    NormalButton::style(cx, opt);
172    Tab::style(cx, opt);
173    MenuItemDraw::style(cx, opt);
174    TextEditor::style(cx, opt);
175    CodeIcon::style(cx, opt);
176    TextInput::style(cx, opt);
177    ScrollBar::style(cx, opt);
178    ScrollShadow::style(cx, opt);
179    DesktopButton::style(cx, opt);
180    Splitter::style(cx, opt);
181    TabControl::style(cx, opt);
182}