aboutsummaryrefslogtreecommitdiff
path: root/src/theme_builder/components/StyleRuleEditor.cpp
blob: 7a99900bf2625e39c5f1e2c991aad91d30e411a7 (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
#include "StyleRuleEditor.h"
#include "conditions/ConditionEditor.h"
#include "cru/ui/style/StyleRule.h"

namespace cru::theme_builder {
StyleRuleEditor::StyleRuleEditor() {
  main_layout_.SetFlexDirection(ui::controls::FlexDirection::Horizontal);
  main_layout_.AddChild(&remove_button_);

  remove_button_.SetChild(&remove_button_text_);
  remove_button_text_.SetText(u"X");

  main_layout_.AddChild(&right_layout_);
  right_layout_.SetFlexDirection(ui::controls::FlexDirection::Vertical);

  remove_button_.ClickEvent()->AddSpyOnlyHandler(
      [this] { remove_event_.Raise(nullptr); });
}

StyleRuleEditor::~StyleRuleEditor() { main_layout_.RemoveFromParent(); }

ui::style::StyleRule StyleRuleEditor::GetValue() const {
  return ui::style::StyleRule(condition_editor_->GetCondition(),
                              styler_editor_->GetStyler());
}

void StyleRuleEditor::SetValue(const ui::style::StyleRule& style_rule,
                               bool trigger_change) {
  right_layout_.ClearChildren();
  condition_editor_ =
      components::conditions::CreateConditionEditor(style_rule.GetCondition());
  styler_editor_ =
      components::stylers::CreateStylerEditor(style_rule.GetStyler());
  right_layout_.AddChild(condition_editor_->GetRootControl());
  right_layout_.AddChild(styler_editor_->GetRootControl());
}
}  // namespace cru::theme_builder