aboutsummaryrefslogtreecommitdiff
path: root/src/ui/render
diff options
context:
space:
mode:
Diffstat (limited to 'src/ui/render')
-rw-r--r--src/ui/render/border_render_object.cpp41
-rw-r--r--src/ui/render/flex_layout_render_object.cpp4
-rw-r--r--src/ui/render/render_object.cpp16
-rw-r--r--src/ui/render/text_render_object.cpp29
-rw-r--r--src/ui/render/window_render_object.cpp32
5 files changed, 63 insertions, 59 deletions
diff --git a/src/ui/render/border_render_object.cpp b/src/ui/render/border_render_object.cpp
index 5b203391..16f2828a 100644
--- a/src/ui/render/border_render_object.cpp
+++ b/src/ui/render/border_render_object.cpp
@@ -1,9 +1,10 @@
#include "cru/ui/render/border_render_object.hpp"
+#include "../helper.hpp"
#include "cru/common/logger.hpp"
+#include "cru/platform/graph/factory.hpp"
#include "cru/platform/graph/geometry.hpp"
-#include "cru/platform/graph/graph_factory.hpp"
-#include "cru/platform/graph/util/painter_util.hpp"
+#include "cru/platform/graph/util/painter.hpp"
#include <algorithm>
#include <cassert>
@@ -16,13 +17,13 @@ BorderRenderObject::BorderRenderObject() {
BorderRenderObject::~BorderRenderObject() {}
-void BorderRenderObject::Draw(platform::graph::Painter* painter) {
+void BorderRenderObject::Draw(platform::graph::IPainter* painter) {
if (background_brush_ != nullptr)
painter->FillGeometry(border_inner_geometry_.get(),
background_brush_.get());
if (is_border_enabled_) {
if (border_brush_ == nullptr) {
- log::Warn(L"Border is enabled but brush is null");
+ log::Warn("Border is enabled but brush is null");
} else {
painter->FillGeometry(geometry_.get(), border_brush_.get());
}
@@ -79,14 +80,14 @@ void BorderRenderObject::OnMeasureCore(const Size& available_size) {
auto coerced_margin_border_padding_size = margin_border_padding_size;
if (coerced_margin_border_padding_size.width > available_size.width) {
log::Warn(
- L"Measure: horizontal length of padding, border and margin is bigger "
- L"than available length.");
+ "Measure: horizontal length of padding, border and margin is bigger "
+ "than available length.");
coerced_margin_border_padding_size.width = available_size.width;
}
if (coerced_margin_border_padding_size.height > available_size.height) {
log::Warn(
- L"Measure: vertical length of padding, border and margin is bigger "
- L"than available length.");
+ "Measure: vertical length of padding, border and margin is bigger "
+ "than available length.");
coerced_margin_border_padding_size.height = available_size.height;
}
@@ -117,14 +118,14 @@ void BorderRenderObject::OnLayoutCore(const Rect& rect) {
if (coerced_content_available_size.width < 0) {
log::Warn(
- L"Layout: horizontal length of padding, border and margin is bigger "
- L"than available length.");
+ "Layout: horizontal length of padding, border and margin is bigger "
+ "than available length.");
coerced_content_available_size.width = 0;
}
if (coerced_content_available_size.height < 0) {
log::Warn(
- L"Layout: vertical length of padding, border and margin is bigger "
- L"than available length.");
+ "Layout: vertical length of padding, border and margin is bigger "
+ "than available length.");
coerced_content_available_size.height = 0;
}
@@ -177,7 +178,7 @@ void BorderRenderObject::RecreateGeometry() {
r.left_bottom - Point{t.left, t.bottom},
r.right_bottom - Point{t.right, t.bottom});
- auto f = [](platform::graph::GeometryBuilder* builder, const Rect& rect,
+ auto f = [](platform::graph::IGeometryBuilder* builder, const Rect& rect,
const CornerRadius& corner) {
builder->BeginFigure(Point(rect.left + corner.left_top.x, rect.top));
builder->LineTo(Point(rect.GetRight() - corner.right_top.x, rect.top));
@@ -204,24 +205,24 @@ void BorderRenderObject::RecreateGeometry() {
const Rect outer_rect{margin.left, margin.top,
size.width - margin.GetHorizontalTotal(),
size.height - margin.GetVerticalTotal()};
- const auto graph_factory = platform::graph::GraphFactory::GetInstance();
- std::unique_ptr<platform::graph::GeometryBuilder> builder{
+ const auto graph_factory = GetGraphFactory();
+ std::unique_ptr<platform::graph::IGeometryBuilder> builder{
graph_factory->CreateGeometryBuilder()};
f(builder.get(), outer_rect, outer_radius);
- border_outer_geometry_.reset(builder->Build());
+ border_outer_geometry_ = builder->Build();
builder.reset();
const Rect inner_rect = outer_rect.Shrink(border_thickness_);
- builder.reset(graph_factory->CreateGeometryBuilder());
+ builder = graph_factory->CreateGeometryBuilder();
f(builder.get(), inner_rect, inner_radius);
- border_inner_geometry_.reset(builder->Build());
+ border_inner_geometry_ = builder->Build();
builder.reset();
- builder.reset(graph_factory->CreateGeometryBuilder());
+ builder = graph_factory->CreateGeometryBuilder();
f(builder.get(), outer_rect, outer_radius);
f(builder.get(), inner_rect, inner_radius);
- geometry_.reset(builder->Build());
+ geometry_ = builder->Build();
builder.reset();
}
} // namespace cru::ui::render
diff --git a/src/ui/render/flex_layout_render_object.cpp b/src/ui/render/flex_layout_render_object.cpp
index a16aec69..3370ffc1 100644
--- a/src/ui/render/flex_layout_render_object.cpp
+++ b/src/ui/render/flex_layout_render_object.cpp
@@ -1,6 +1,6 @@
#include "cru/ui/render/flex_layout_render_object.hpp"
-#include "cru/platform/graph/util/painter_util.hpp"
+#include "cru/platform/graph/util/painter.hpp"
#include <algorithm>
#include <cassert>
@@ -11,7 +11,7 @@ FlexLayoutRenderObject::FlexLayoutRenderObject() {
SetChildMode(ChildMode::Multiple);
}
-void FlexLayoutRenderObject::Draw(platform::graph::Painter* painter) {
+void FlexLayoutRenderObject::Draw(platform::graph::IPainter* painter) {
for (const auto child : GetChildren()) {
auto offset = child->GetOffset();
platform::graph::util::WithTransform(
diff --git a/src/ui/render/render_object.cpp b/src/ui/render/render_object.cpp
index a28b4f03..8e65dad0 100644
--- a/src/ui/render/render_object.cpp
+++ b/src/ui/render/render_object.cpp
@@ -62,14 +62,14 @@ void RenderObject::OnMeasureCore(const Size& available_size) {
auto coerced_margin_padding_size = margin_padding_size;
if (coerced_margin_padding_size.width > available_size.width) {
log::Warn(
- L"Measure: horizontal length of padding and margin is bigger than "
- L"available length.");
+ "Measure: horizontal length of padding and margin is bigger than "
+ "available length.");
coerced_margin_padding_size.width = available_size.width;
}
if (coerced_margin_padding_size.height > available_size.height) {
log::Warn(
- L"Measure: vertical length of padding and margin is bigger than "
- L"available length.");
+ "Measure: vertical length of padding and margin is bigger than "
+ "available length.");
coerced_margin_padding_size.height = available_size.height;
}
@@ -90,14 +90,14 @@ void RenderObject::OnLayoutCore(const Rect& rect) {
if (coerced_content_available_size.width < 0) {
log::Warn(
- L"Layout: horizontal length of padding and margin is bigger than "
- L"available length.");
+ "Layout: horizontal length of padding and margin is bigger than "
+ "available length.");
coerced_content_available_size.width = 0;
}
if (coerced_content_available_size.height < 0) {
log::Warn(
- L"Layout: vertical length of padding and margin is bigger than "
- L"available length.");
+ "Layout: vertical length of padding and margin is bigger than "
+ "available length.");
coerced_content_available_size.height = 0;
}
diff --git a/src/ui/render/text_render_object.cpp b/src/ui/render/text_render_object.cpp
index a21dc028..9afb9f6e 100644
--- a/src/ui/render/text_render_object.cpp
+++ b/src/ui/render/text_render_object.cpp
@@ -1,17 +1,20 @@
#include "cru/ui/render/text_render_object.hpp"
-#include "cru/platform/graph/graph_factory.hpp"
+#include "../helper.hpp"
+#include "cru/platform/graph/factory.hpp"
#include "cru/platform/graph/text_layout.hpp"
-#include "cru/platform/graph/util/painter_util.hpp"
+#include "cru/platform/graph/util/painter.hpp"
#include <algorithm>
#include <cassert>
+//TODO: Null Check!!!
+
namespace cru::ui::render {
TextRenderObject::TextRenderObject(
- std::shared_ptr<platform::graph::Brush> brush,
- std::shared_ptr<platform::graph::Font> font,
- std::shared_ptr<platform::graph::Brush> selection_brush) {
+ std::shared_ptr<platform::graph::IBrush> brush,
+ std::shared_ptr<platform::graph::IFont> font,
+ std::shared_ptr<platform::graph::IBrush> selection_brush) {
assert(brush);
assert(font);
assert(selection_brush);
@@ -22,32 +25,32 @@ TextRenderObject::TextRenderObject(
font.swap(font_);
selection_brush.swap(selection_brush_);
- const auto graph_factory = platform::graph::GraphFactory::GetInstance();
- text_layout_.reset(graph_factory->CreateTextLayout(font_, L""));
+ const auto graph_factory = GetGraphFactory();
+ text_layout_ = graph_factory->CreateTextLayout(font_, "");
}
-std::wstring TextRenderObject::GetText() const {
+std::string TextRenderObject::GetText() const {
return text_layout_->GetText();
}
-void TextRenderObject::SetText(std::wstring new_text) {
+void TextRenderObject::SetText(std::string new_text) {
text_layout_->SetText(std::move(new_text));
}
-std::shared_ptr<platform::graph::Font> TextRenderObject::GetFont() const {
+std::shared_ptr<platform::graph::IFont> TextRenderObject::GetFont() const {
return text_layout_->GetFont();
}
-void TextRenderObject::SetFont(std::shared_ptr<platform::graph::Font> font) {
+void TextRenderObject::SetFont(std::shared_ptr<platform::graph::IFont> font) {
text_layout_->SetFont(std::move(font));
}
-void TextRenderObject::Draw(platform::graph::Painter* painter) {
+void TextRenderObject::Draw(platform::graph::IPainter* painter) {
platform::graph::util::WithTransform(
painter,
platform::Matrix::Translation(GetMargin().left + GetPadding().left,
GetMargin().top + GetPadding().top),
- [this](platform::graph::Painter* p) {
+ [this](platform::graph::IPainter* p) {
if (this->selection_range_.has_value()) {
const auto&& rects =
text_layout_->TextRangeRect(this->selection_range_.value());
diff --git a/src/ui/render/window_render_object.cpp b/src/ui/render/window_render_object.cpp
index 64bec1e7..8e48b7c9 100644
--- a/src/ui/render/window_render_object.cpp
+++ b/src/ui/render/window_render_object.cpp
@@ -1,9 +1,10 @@
#include "cru/ui/render/window_render_object.hpp"
+#include "../helper.hpp"
#include "cru/common/logger.hpp"
-#include "cru/platform/graph/util/painter_util.hpp"
-#include "cru/platform/native/native_window.hpp"
+#include "cru/platform/graph/util/painter.hpp"
#include "cru/platform/native/ui_application.hpp"
+#include "cru/platform/native/window.hpp"
#include "cru/ui/window.hpp"
#include <cassert>
@@ -20,7 +21,7 @@ class WindowRenderHost : public IRenderHost,
void InvalidateLayout() override;
void InvalidatePaint() override {
- render_object_->GetWindow()->GetNativeWindow()->Repaint();
+ render_object_->GetWindow()->GetNativeWindow()->RequestRepaint();
}
IEvent<AfterLayoutEventArgs>* AfterLayoutEvent() override {
@@ -37,17 +38,16 @@ class WindowRenderHost : public IRenderHost,
void WindowRenderHost::InvalidateLayout() {
if (!need_layout_) {
- log::Debug(L"A relayout is required.");
- platform::native::UiApplication::GetInstance()->InvokeLater(
- [resolver = this->CreateResolver()] {
- if (const auto host = resolver.Resolve()) {
- host->render_object_->Relayout();
- host->need_layout_ = false;
- host->after_layout_event_.Raise(AfterLayoutEventArgs{});
- log::Debug(L"A relayout finished.");
- host->InvalidatePaint();
- }
- });
+ log::Debug("A relayout is required.");
+ GetUiApplication()->InvokeLater([resolver = this->CreateResolver()] {
+ if (const auto host = resolver.Resolve()) {
+ host->render_object_->Relayout();
+ host->need_layout_ = false;
+ host->after_layout_event_.Raise(AfterLayoutEventArgs{});
+ log::Debug("A relayout finished.");
+ host->InvalidatePaint();
+ }
+ });
need_layout_ = true;
}
}
@@ -66,13 +66,13 @@ void WindowRenderObject::Relayout() {
Layout(Rect{Point{}, client_size});
}
-void WindowRenderObject::Draw(platform::graph::Painter* painter) {
+void WindowRenderObject::Draw(platform::graph::IPainter* painter) {
painter->Clear(colors::white);
if (const auto child = GetChild()) {
auto offset = child->GetOffset();
platform::graph::util::WithTransform(
painter, platform::Matrix::Translation(offset.x, offset.y),
- [child](platform::graph::Painter* p) { child->Draw(p); });
+ [child](platform::graph::IPainter* p) { child->Draw(p); });
}
}