aboutsummaryrefslogtreecommitdiff
path: root/src/theme_builder/components/StyleRuleEditor.cpp
blob: aa2806b1a2c56d9208cbdbc1aa5e060d6873c32c (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
#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() {}

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());
  condition_editor_->ChangeEvent()->AddSpyOnlyHandler(
      [this] { change_event_.Raise(nullptr); });
  styler_editor_->ChangeEvent()->AddSpyOnlyHandler(
      [this] { change_event_.Raise(nullptr); });

  if (trigger_change) {
    change_event_.Raise(nullptr);
  }
}
}  // namespace cru::theme_builder