aboutsummaryrefslogtreecommitdiff
path: root/src/ThemeBuilder/components/properties/CornerRadiusPropertyEditor.cpp
blob: fc86b0ed8c4099ae7af47b0562f377bf805fc56e (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
#include "CornerRadiusPropertyEditor.h"
#include "cru/ui/Base.h"
#include "cru/ui/controls/FlexLayout.h"

namespace cru::theme_builder::components::properties {
CornerRadiusPropertyEditor::CornerRadiusPropertyEditor() {
  container_.SetItemCrossAlign(ui::controls::FlexCrossAlignment::Start);

  left_top_editor_.SetLabel(u"⌜");
  right_top_editor_.SetLabel(u"⌝");
  left_bottom_editor_.SetLabel(u"⌞");
  right_bottom_editor_.SetLabel(u"⌟");

  container_.SetFlexDirection(ui::controls::FlexDirection::Vertical);
  container_.AddChild(left_top_editor_.GetRootControl());
  container_.AddChild(right_top_editor_.GetRootControl());
  container_.AddChild(left_bottom_editor_.GetRootControl());
  container_.AddChild(right_bottom_editor_.GetRootControl());

  ConnectChangeEvent(left_top_editor_);
  ConnectChangeEvent(right_top_editor_);
  ConnectChangeEvent(left_bottom_editor_);
  ConnectChangeEvent(right_bottom_editor_);
}

CornerRadiusPropertyEditor::~CornerRadiusPropertyEditor() {}

ui::CornerRadius CornerRadiusPropertyEditor::GetValue() const {
  return ui::CornerRadius(
      left_top_editor_.GetValue(), right_top_editor_.GetValue(),
      left_bottom_editor_.GetValue(), right_bottom_editor_.GetValue());
}

void CornerRadiusPropertyEditor::SetValue(const ui::CornerRadius& corner_radius,
                                          bool trigger_change) {
  left_top_editor_.SetValue(corner_radius.left_top, false);
  right_top_editor_.SetValue(corner_radius.right_top, false);
  left_bottom_editor_.SetValue(corner_radius.left_bottom, false);
  right_bottom_editor_.SetValue(corner_radius.right_bottom, false);
  if (trigger_change) RaiseChangeEvent();
}
}  // namespace cru::theme_builder::components::properties