aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2022-02-10 19:26:19 +0800
committercrupest <crupest@outlook.com>2022-02-10 19:26:19 +0800
commitb2622f654598f82a220a98daaa84fed9ce3b92b2 (patch)
tree544d5a9a52d7530bf54e888d3fabd79ff85bfdb7 /src
parentb8863c403a44c1c7ac35f1a1da92bbf3c8858552 (diff)
downloadcru-b2622f654598f82a220a98daaa84fed9ce3b92b2.tar.gz
cru-b2622f654598f82a220a98daaa84fed9ce3b92b2.tar.bz2
cru-b2622f654598f82a220a98daaa84fed9ce3b92b2.zip
...
Diffstat (limited to 'src')
-rw-r--r--src/theme_builder/components/MainWindow.cpp6
-rw-r--r--src/ui/CMakeLists.txt1
-rw-r--r--src/ui/components/Menu.cpp6
-rw-r--r--src/ui/controls/Control.cpp10
-rw-r--r--src/ui/controls/NoChildControl.cpp2
-rw-r--r--src/ui/render/TextRenderObject.cpp5
6 files changed, 15 insertions, 15 deletions
diff --git a/src/theme_builder/components/MainWindow.cpp b/src/theme_builder/components/MainWindow.cpp
index 31530491..4c605756 100644
--- a/src/theme_builder/components/MainWindow.cpp
+++ b/src/theme_builder/components/MainWindow.cpp
@@ -14,14 +14,14 @@ MainWindow::MainWindow() {
main_layout_ = FlexLayout::Create();
main_layout_->SetFlexDirection(FlexDirection::Horizontal);
- window_->AddChild(main_layout_, 0);
+ window_->AddChild(main_layout_);
preview_layout_ = StackLayout::Create();
- main_layout_->AddChild(preview_layout_, 0);
+ main_layout_->AddChild(preview_layout_);
preview_button_ = Button::Create();
preview_button_->SetChild(TextBlock::Create(u"Preview"));
- preview_layout_->AddChild(preview_button_, 0);
+ preview_layout_->AddChild(preview_button_);
preview_layout_->SetChildLayoutData(
0, StackChildLayoutData{Alignment::Center, Alignment::Center});
}
diff --git a/src/ui/CMakeLists.txt b/src/ui/CMakeLists.txt
index 98d21c9e..6ed06bc2 100644
--- a/src/ui/CMakeLists.txt
+++ b/src/ui/CMakeLists.txt
@@ -50,6 +50,7 @@ add_library(cru_ui SHARED
render/RenderObject.cpp
render/ScrollBar.cpp
render/ScrollRenderObject.cpp
+ render/SingleChildRenderObject.cpp
render/StackLayoutRenderObject.cpp
render/TextRenderObject.cpp
render/TreeRenderObject.cpp
diff --git a/src/ui/components/Menu.cpp b/src/ui/components/Menu.cpp
index 3134bbb6..af2043a9 100644
--- a/src/ui/components/Menu.cpp
+++ b/src/ui/components/Menu.cpp
@@ -49,7 +49,7 @@ void Menu::AddItem(Component* item, gsl::index index) {
Expects(index >= 0 && index <= GetItemCount());
items_.insert(items_.cbegin() + index, item);
- container_->AddChild(item->GetRootControl(), index);
+ container_->AddChildAt(item->GetRootControl(), index);
}
Component* Menu::RemoveItem(gsl::index index) {
@@ -58,7 +58,7 @@ Component* Menu::RemoveItem(gsl::index index) {
Component* item = items_[index];
items_.erase(items_.cbegin() + index);
- container_->RemoveChild(index);
+ container_->RemoveChildAt(index);
return item;
}
@@ -91,7 +91,7 @@ PopupMenu::PopupMenu(controls::Control* attached_control)
menu_->SetOnItemClick([this](Index) { this->Close(); });
- popup_->AddChild(menu_->GetRootControl(), 0);
+ popup_->AddChildAt(menu_->GetRootControl(), 0);
}
PopupMenu::~PopupMenu() {
diff --git a/src/ui/controls/Control.cpp b/src/ui/controls/Control.cpp
index df71f660..ba43b2b8 100644
--- a/src/ui/controls/Control.cpp
+++ b/src/ui/controls/Control.cpp
@@ -1,15 +1,11 @@
#include "cru/ui/controls/Control.h"
-#include "cru/common/Base.h"
#include "cru/platform/gui/Cursor.h"
#include "cru/platform/gui/UiApplication.h"
-#include "cru/ui/Base.h"
#include "cru/ui/host/WindowHost.h"
#include "cru/ui/render/RenderObject.h"
#include "cru/ui/style/StyleRuleSet.h"
-#include <memory>
-
namespace cru::ui::controls {
using platform::gui::ICursor;
using platform::gui::IUiApplication;
@@ -48,6 +44,12 @@ void Control::SetParent(Control* parent) {
OnParentChanged(old_parent, parent);
}
+void Control::RemoveFromParent() {
+ if (parent_) {
+ parent_->RemoveChild(this);
+ }
+}
+
bool Control::HasFocus() {
auto host = GetWindowHost();
if (host == nullptr) return false;
diff --git a/src/ui/controls/NoChildControl.cpp b/src/ui/controls/NoChildControl.cpp
index 4a9002ed..382a5d18 100644
--- a/src/ui/controls/NoChildControl.cpp
+++ b/src/ui/controls/NoChildControl.cpp
@@ -5,4 +5,6 @@ void NoChildControl::ForEachChild(
const std::function<void(Control*)>& callback) {
CRU_UNUSED(callback);
}
+
+void NoChildControl::RemoveChild(Control* child) { CRU_UNUSED(child); }
} // namespace cru::ui::controls
diff --git a/src/ui/render/TextRenderObject.cpp b/src/ui/render/TextRenderObject.cpp
index 6f4a8320..a64c96d2 100644
--- a/src/ui/render/TextRenderObject.cpp
+++ b/src/ui/render/TextRenderObject.cpp
@@ -184,9 +184,6 @@ void TextRenderObject::Draw(platform::graphics::IPainter* painter) {
this->brush_->GetDebugString());
}
- painter->PushState();
- painter->ConcatTransform(Matrix::Translation(GetOffset()));
-
if (this->selection_range_.has_value()) {
const auto&& rects =
text_layout_->TextRangeRect(this->selection_range_.value());
@@ -199,8 +196,6 @@ void TextRenderObject::Draw(platform::graphics::IPainter* painter) {
if (this->draw_caret_ && this->caret_width_ != 0.0f) {
painter->FillRectangle(GetCaretRectInContent(), this->caret_brush_.get());
}
-
- painter->PopState();
}
Size TextRenderObject::OnMeasureContent(const MeasureRequirement& requirement,