blob: 1329a08a7221a7d176464930992c7f98fb1a3a1b (
plain)
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
|
#include "BorderStylerEditor.h"
#include "cru/base/ClonablePtr.h"
#include "cru/platform/graphics/Brush.h"
#include "cru/platform/graphics/Factory.h"
#include "cru/platform/gui/UiApplication.h"
#include "cru/ui/style/ApplyBorderStyleInfo.h"
#include "cru/ui/style/Styler.h"
namespace cru::theme_builder::components::stylers {
BorderStylerEditor::BorderStylerEditor() {
SetLabel(u"Border Styler");
GetContainer()->AddChild(corner_radius_editor_.GetRootControl());
GetContainer()->AddChild(thickness_editor_.GetRootControl());
GetContainer()->AddChild(brush_editor_.GetRootControl());
GetContainer()->AddChild(foreground_brush_editor_.GetRootControl());
GetContainer()->AddChild(background_brush_editor_.GetRootControl());
thickness_editor_.GetEditor()->SetLabel(u"Thickness");
brush_editor_.GetEditor()->SetLabel(u"Border");
foreground_brush_editor_.GetEditor()->SetLabel(u"Foreground");
background_brush_editor_.GetEditor()->SetLabel(u"Background");
ConnectChangeEvent(corner_radius_editor_);
ConnectChangeEvent(thickness_editor_);
ConnectChangeEvent(brush_editor_);
ConnectChangeEvent(foreground_brush_editor_);
ConnectChangeEvent(background_brush_editor_);
}
BorderStylerEditor::~BorderStylerEditor() {}
ClonablePtr<ui::style::BorderStyler> BorderStylerEditor::GetValue() {
auto graphics_factory =
platform::gui::IUiApplication::GetInstance()->GetGraphicsFactory();
ui::style::ApplyBorderStyleInfo border_style;
border_style.border_radius = corner_radius_editor_.GetValue();
border_style.border_thickness = thickness_editor_.GetValue();
if (brush_editor_.IsEnabled()) {
border_style.border_brush = graphics_factory->CreateSolidColorBrush(
brush_editor_.GetEditor()->GetValue());
}
if (foreground_brush_editor_.IsEnabled()) {
border_style.foreground_brush = graphics_factory->CreateSolidColorBrush(
foreground_brush_editor_.GetEditor()->GetValue());
}
if (background_brush_editor_.IsEnabled()) {
border_style.background_brush = graphics_factory->CreateSolidColorBrush(
background_brush_editor_.GetEditor()->GetValue());
}
return ui::style::BorderStyler::Create(border_style);
}
void BorderStylerEditor::SetValue(ui::style::BorderStyler* styler,
bool trigger_change) {
Expects(styler);
auto border_style = styler->GetBorderStyle();
corner_radius_editor_.SetValue(border_style.border_radius, false);
thickness_editor_.SetValue(border_style.border_thickness, false);
brush_editor_.SetEnabled(border_style.border_brush.has_value(), false);
if (border_style.border_brush.has_value()) {
brush_editor_.GetEditor()->SetValue(
std::dynamic_pointer_cast<platform::graphics::ISolidColorBrush>(
border_style.border_brush.value())
->GetColor(),
false);
}
foreground_brush_editor_.SetEnabled(border_style.foreground_brush.has_value(),
false);
if (border_style.foreground_brush.has_value()) {
foreground_brush_editor_.GetEditor()->SetValue(
std::dynamic_pointer_cast<platform::graphics::ISolidColorBrush>(
border_style.foreground_brush.value())
->GetColor(),
false);
}
background_brush_editor_.SetEnabled(border_style.background_brush.has_value(),
false);
if (border_style.background_brush.has_value()) {
background_brush_editor_.GetEditor()->SetValue(
std::dynamic_pointer_cast<platform::graphics::ISolidColorBrush>(
border_style.background_brush.value())
->GetColor(),
false);
}
if (trigger_change) {
RaiseChangeEvent();
}
}
} // namespace cru::theme_builder::components::stylers
|