aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/cru/common/event.hpp11
-rw-r--r--include/cru/common/format.hpp4
-rw-r--r--include/cru/platform/basic_types.hpp1
-rw-r--r--include/cru/platform/matrix.hpp7
-rw-r--r--include/cru/platform/painter.hpp2
-rw-r--r--include/cru/platform/win/win_text_layout.hpp2
-rw-r--r--include/cru/ui/controls/button.hpp (renamed from src/ui/controls/button.hpp)8
-rw-r--r--include/cru/ui/controls/flex_layout.hpp (renamed from src/ui/controls/flex_layout.hpp)8
-rw-r--r--include/cru/ui/controls/text_block.hpp (renamed from src/ui/controls/text_block.hpp)12
-rw-r--r--include/cru/ui/render/text_render_object.hpp2
-rw-r--r--include/cru/ui/window.hpp2
-rw-r--r--src/CMakeLists.txt3
-rw-r--r--src/main.cpp29
-rw-r--r--src/platform_win/win_application.cpp2
-rw-r--r--src/platform_win/win_native_window.cpp6
-rw-r--r--src/platform_win/win_painter.cpp1
-rw-r--r--src/platform_win/win_text_layout.cpp15
-rw-r--r--src/platform_win/window_manager.cpp9
-rw-r--r--src/ui/content_control.cpp2
-rw-r--r--src/ui/control.cpp2
-rw-r--r--src/ui/controls/button.cpp10
-rw-r--r--src/ui/controls/flex_layout.cpp4
-rw-r--r--src/ui/controls/text_block.cpp14
-rw-r--r--src/ui/layout_control.cpp2
-rw-r--r--src/ui/render/border_render_object.cpp2
-rw-r--r--src/ui/render/flex_layout_render_object.cpp4
-rw-r--r--src/ui/render/window_render_object.cpp11
-rw-r--r--src/ui/ui_manager.cpp15
-rw-r--r--src/ui/window.cpp23
29 files changed, 122 insertions, 91 deletions
diff --git a/include/cru/common/event.hpp b/include/cru/common/event.hpp
index 763f8378..6228d867 100644
--- a/include/cru/common/event.hpp
+++ b/include/cru/common/event.hpp
@@ -22,7 +22,7 @@ class Event {
: resolver_(resolver), token_(token) {}
EventHandlerRevokerImpl(const EventHandlerRevokerImpl& other) = default;
EventHandlerRevokerImpl(EventHandlerRevokerImpl&& other) = default;
- EventHandlerRevokerImpl& operator=(EventHandlerRevokerImpl&& other) =
+ EventHandlerRevokerImpl& operator=(const EventHandlerRevokerImpl& other) =
default;
EventHandlerRevokerImpl& operator=(EventHandlerRevokerImpl&& other) =
default;
@@ -31,7 +31,7 @@ class Event {
void operator()() {
const auto true_resolver = resolver_.lock();
if (true_resolver) {
- true_resolver()->RemoveHandler(token_);
+ (*true_resolver)()->RemoveHandler(token_);
}
}
@@ -63,10 +63,11 @@ class Event {
return EventHandlerRevoker(EventHandlerRevokerImpl(event_resolver_, token));
}
- template <typename... Args>
- EventHandlerRevoker AddHandler(Args&& args...) {
+ template <typename Arg>
+ EventHandlerRevoker AddHandler(Arg&& handler) {
+ static_assert(std::is_invocable_v<Arg, TArgs...>, "Handler not invocable.");
const auto token = current_token_++;
- handlers_.emplace(token, EventHandler(std::forward<Args>(args)...));
+ handlers_.emplace(token, EventHandler(std::forward<Arg>(handler)));
return EventHandlerRevoker(EventHandlerRevokerImpl(event_resolver_, token));
}
diff --git a/include/cru/common/format.hpp b/include/cru/common/format.hpp
index 1fb6863a..f085635a 100644
--- a/include/cru/common/format.hpp
+++ b/include/cru/common/format.hpp
@@ -83,7 +83,7 @@ inline std::string_view FormatToString(const std::string& string,
}
inline std::wstring_view FormatToString(const std::wstring_view& string,
- details::TypeTag<String>) {
+ details::TypeTag<std::wstring>) {
return string;
}
@@ -93,7 +93,7 @@ inline std::string_view FormatToString(const std::string_view& string,
}
inline std::wstring_view FormatToString(const wchar_t* string,
- details::TypeTag<String>) {
+ details::TypeTag<std::wstring>) {
return std::wstring_view(string);
}
diff --git a/include/cru/platform/basic_types.hpp b/include/cru/platform/basic_types.hpp
index 81ee3e34..e6ab4b59 100644
--- a/include/cru/platform/basic_types.hpp
+++ b/include/cru/platform/basic_types.hpp
@@ -1,3 +1,4 @@
+#pragma once
#include "cru/common/pre_config.hpp"
namespace cru::platform {
diff --git a/include/cru/platform/matrix.hpp b/include/cru/platform/matrix.hpp
index e5e5cf42..37e4725e 100644
--- a/include/cru/platform/matrix.hpp
+++ b/include/cru/platform/matrix.hpp
@@ -1,3 +1,4 @@
+#pragma once
#include "cru/common/pre_config.hpp"
#include "cru/common/ui_base.hpp"
@@ -29,12 +30,14 @@ struct Matrix {
m31 == 0.0f && m32 == 0.0f;
}
- Matrix& operator*=(const Matrix& matrix) const {
+ Matrix& operator*=(const Matrix& matrix) {
*this = Product(*this, matrix);
return *this;
}
- Matrix operator*(const Matrix& matrix) const { return Product(this, matrix); }
+ Matrix operator*(const Matrix& matrix) const {
+ return Product(*this, matrix);
+ }
ui::Point TransformPoint(const ui::Point& point) const {
return ui::Point{point.x * m11 + point.y * m21 + m31,
diff --git a/include/cru/platform/painter.hpp b/include/cru/platform/painter.hpp
index eaaf61f9..b7b89fc9 100644
--- a/include/cru/platform/painter.hpp
+++ b/include/cru/platform/painter.hpp
@@ -19,7 +19,7 @@ struct Painter : virtual Interface {
virtual void StrokeGeometry(Geometry* geometry, Brush* brush,
float width) = 0;
virtual void FillGeometry(Geometry* geometry, Brush* brush) = 0;
- virtual void DrawText(const ui::Point& offset, TextLayout* text_layout, Brush* brush);
+ virtual void DrawText(const ui::Point& offset, TextLayout* text_layout, Brush* brush) = 0;
virtual void EndDraw() = 0;
virtual bool IsDisposed() = 0;
};
diff --git a/include/cru/platform/win/win_text_layout.hpp b/include/cru/platform/win/win_text_layout.hpp
index 9c93aa8c..dfb54264 100644
--- a/include/cru/platform/win/win_text_layout.hpp
+++ b/include/cru/platform/win/win_text_layout.hpp
@@ -17,7 +17,7 @@ class WinTextLayout : public Object, public virtual TextLayout {
WinTextLayout(WinTextLayout&& other) = delete;
WinTextLayout& operator=(const WinTextLayout& other) = delete;
WinTextLayout& operator=(WinTextLayout&& other) = delete;
- ~WinTextLayout() override;
+ ~WinTextLayout() override = default;
std::wstring GetText() override;
void SetText(std::wstring new_text) override;
diff --git a/src/ui/controls/button.hpp b/include/cru/ui/controls/button.hpp
index 3f313dfc..348416c5 100644
--- a/src/ui/controls/button.hpp
+++ b/include/cru/ui/controls/button.hpp
@@ -1,10 +1,8 @@
#pragma once
-#include "pre.hpp"
+#include "../content_control.hpp"
#include <memory>
-#include "ui/content_control.hpp"
-
namespace cru::ui::render {
class BorderRenderObject;
}
@@ -26,7 +24,9 @@ class Button : public ContentControl {
Button& operator=(Button&& other) = delete;
~Button() override = default;
- StringView GetControlType() const override final { return control_type; }
+ std::wstring_view GetControlType() const override final {
+ return control_type;
+ }
render::RenderObject* GetRenderObject() const override;
diff --git a/src/ui/controls/flex_layout.hpp b/include/cru/ui/controls/flex_layout.hpp
index 9ceef1f6..7422bc05 100644
--- a/src/ui/controls/flex_layout.hpp
+++ b/include/cru/ui/controls/flex_layout.hpp
@@ -1,10 +1,8 @@
#pragma once
-#include "pre.hpp"
+#include "../layout_control.hpp"
#include <memory>
-#include "ui/layout_control.hpp"
-
namespace cru::ui::render {
class FlexLayoutRenderObject;
}
@@ -27,7 +25,9 @@ class FlexLayout : public LayoutControl {
FlexLayout& operator=(FlexLayout&& other) = delete;
~FlexLayout() override = default;
- StringView GetControlType() const override final { return control_type; }
+ std::wstring_view GetControlType() const override final {
+ return control_type;
+ }
render::RenderObject* GetRenderObject() const override;
diff --git a/src/ui/controls/text_block.hpp b/include/cru/ui/controls/text_block.hpp
index 0d65dd67..45cd12b9 100644
--- a/src/ui/controls/text_block.hpp
+++ b/include/cru/ui/controls/text_block.hpp
@@ -1,10 +1,8 @@
#pragma once
-#include "pre.hpp"
+#include "../no_child_control.hpp"
#include <memory>
-#include "ui/no_child_control.hpp"
-
namespace cru::ui::render {
class TextRenderObject;
}
@@ -26,12 +24,14 @@ class TextBlock : public NoChildControl {
TextBlock& operator=(TextBlock&& other) = delete;
~TextBlock() override = default;
- StringView GetControlType() const override final { return control_type; }
+ std::wstring_view GetControlType() const override final {
+ return control_type;
+ }
render::RenderObject* GetRenderObject() const override;
- String GetText() const;
- void SetText(const String& text);
+ std::wstring GetText() const;
+ void SetText(std::wstring text);
private:
std::shared_ptr<render::TextRenderObject> render_object_;
diff --git a/include/cru/ui/render/text_render_object.hpp b/include/cru/ui/render/text_render_object.hpp
index 329af18a..527fcd71 100644
--- a/include/cru/ui/render/text_render_object.hpp
+++ b/include/cru/ui/render/text_render_object.hpp
@@ -21,7 +21,7 @@ class TextRenderObject : public RenderObject {
TextRenderObject(TextRenderObject&& other) = delete;
TextRenderObject& operator=(const TextRenderObject& other) = delete;
TextRenderObject& operator=(TextRenderObject&& other) = delete;
- ~TextRenderObject() override;
+ ~TextRenderObject() override = default;
std::wstring GetText() const;
void SetText(std::wstring new_text);
diff --git a/include/cru/ui/window.hpp b/include/cru/ui/window.hpp
index 94deb4c5..991ebf70 100644
--- a/include/cru/ui/window.hpp
+++ b/include/cru/ui/window.hpp
@@ -38,7 +38,7 @@ class Window final : public ContentControl {
render::RenderObject* GetRenderObject() const override;
- platform::NativeWindow* GetNativeWindow() const;
+ platform::NativeWindow* GetNativeWindow() const { return native_window_; }
Control* GetMouseHoverControl() const { return mouse_hover_control_; }
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 4155e800..8f29ddc9 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -22,7 +22,6 @@ target_link_libraries(cru_ui PUBLIC cru_platform_win)
endif()
-
-add_executable(demo WIN32 main.cpp)
+add_executable(demo main.cpp)
target_link_libraries(demo PRIVATE cru_ui)
diff --git a/src/main.cpp b/src/main.cpp
index c35213f7..c0c90002 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -1,28 +1,27 @@
-#include "pre.hpp"
-
-#include "application.hpp"
-#include "ui/controls/button.hpp"
-#include "ui/controls/flex_layout.hpp"
-#include "ui/controls/text_block.hpp"
-#include "ui/window.hpp"
-
-using cru::Application;
-using cru::String;
-using cru::StringView;
+#include "cru/platform/native_window.hpp"
+#include "cru/platform/ui_applicaition.hpp"
+#include "cru/ui/controls/button.hpp"
+#include "cru/ui/controls/flex_layout.hpp"
+#include "cru/ui/controls/text_block.hpp"
+#include "cru/ui/window.hpp"
+
+using cru::platform::UiApplication;
using cru::ui::Rect;
using cru::ui::Thickness;
using cru::ui::Window;
using cru::ui::controls::Button;
using cru::ui::controls::FlexLayout;
using cru::ui::controls::TextBlock;
-
+/*
int APIENTRY wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPWSTR lpCmdLine, int nCmdShow) {
#ifdef CRU_DEBUG
_CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
#endif
+*/
- Application application(hInstance);
+int main() {
+ auto application = UiApplication::GetInstance();
const auto window = Window::CreateOverlapped();
@@ -40,7 +39,7 @@ int APIENTRY wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
text_block2->SetText(L"Hello World!");
flex_layout->AddChild(text_block2, 1);
- window->Show();
+ window->GetNativeWindow()->SetVisible(true);
- return application.Run();
+ return application->Run();
}
diff --git a/src/platform_win/win_application.cpp b/src/platform_win/win_application.cpp
index 31d8c990..ce187136 100644
--- a/src/platform_win/win_application.cpp
+++ b/src/platform_win/win_application.cpp
@@ -40,7 +40,7 @@ WinApplication::WinApplication(HINSTANCE h_instance) : h_instance_(h_instance) {
timer_manager_ = std::make_shared<TimerManager>(god_window_.get());
window_manager_ = std::make_shared<WindowManager>(this);
graph_manager_ = std::make_shared<GraphManager>();
- graph_factory_ = std::make_shared<GraphFactory>(graph_manager_.get());
+ graph_factory_ = std::make_shared<WinGraphFactory>(graph_manager_.get());
}
WinApplication::~WinApplication() { instance_ = nullptr; }
diff --git a/src/platform_win/win_native_window.cpp b/src/platform_win/win_native_window.cpp
index 12c25674..3f34717f 100644
--- a/src/platform_win/win_native_window.cpp
+++ b/src/platform_win/win_native_window.cpp
@@ -34,6 +34,9 @@ WinNativeWindow::WinNativeWindow(WinApplication* application,
throw Win32Error(::GetLastError(), "Failed to create window.");
window_manager->RegisterWindow(hwnd_, this);
+
+ window_render_target_.reset(
+ new WindowRenderTarget(application->GetGraphManager(), hwnd_));
}
WinNativeWindow::~WinNativeWindow() {
@@ -113,7 +116,8 @@ void WinNativeWindow::SetWindowRect(const ui::Rect& rect) {
}
}
-Painter* WinNativeWindow::BeginPaint() { return new WinPainter(this); }
+Painter* WinNativeWindow::BeginPaint() {
+ return new WinPainter(this); }
bool WinNativeWindow::HandleNativeWindowMessage(HWND hwnd, UINT msg,
WPARAM w_param, LPARAM l_param,
diff --git a/src/platform_win/win_painter.cpp b/src/platform_win/win_painter.cpp
index 6ce5f4de..7c99146a 100644
--- a/src/platform_win/win_painter.cpp
+++ b/src/platform_win/win_painter.cpp
@@ -97,6 +97,7 @@ void WinPainter::EndDraw() {
if (!IsDisposed()) {
ThrowIfFailed(render_target_->EndDraw());
render_target_ = nullptr;
+ window_->GetWindowRenderTarget()->Present();
is_disposed = true;
}
}
diff --git a/src/platform_win/win_text_layout.cpp b/src/platform_win/win_text_layout.cpp
index 7ae87a80..04b5e928 100644
--- a/src/platform_win/win_text_layout.cpp
+++ b/src/platform_win/win_text_layout.cpp
@@ -17,8 +17,9 @@ WinTextLayout::WinTextLayout(GraphManager* graph_manager,
font_descriptor_.swap(font);
ThrowIfFailed(graph_manager_->GetDWriteFactory()->CreateTextLayout(
- text_.c_str(), text_.size(), font_descriptor_->GetDWriteTextFormat(),
- max_width_, max_height_, &text_layout_));
+ text_.c_str(), static_cast<UINT32>(text_.size()),
+ font_descriptor_->GetDWriteTextFormat(), max_width_, max_height_,
+ &text_layout_));
}
std::wstring WinTextLayout::GetText() { return text_; }
@@ -26,8 +27,9 @@ std::wstring WinTextLayout::GetText() { return text_; }
void WinTextLayout::SetText(std::wstring new_text) {
text_.swap(new_text);
ThrowIfFailed(graph_manager_->GetDWriteFactory()->CreateTextLayout(
- text_.c_str(), text_.size(), font_descriptor_->GetDWriteTextFormat(),
- max_width_, max_height_, &text_layout_));
+ text_.c_str(), static_cast<UINT32>(text_.size()),
+ font_descriptor_->GetDWriteTextFormat(), max_width_, max_height_,
+ &text_layout_));
}
std::shared_ptr<FontDescriptor> WinTextLayout::GetFont() {
@@ -39,8 +41,9 @@ void WinTextLayout::SetFont(std::shared_ptr<FontDescriptor> font) {
assert(f);
f.swap(font_descriptor_);
ThrowIfFailed(graph_manager_->GetDWriteFactory()->CreateTextLayout(
- text_.c_str(), text_.size(), font_descriptor_->GetDWriteTextFormat(),
- max_width_, max_height_, &text_layout_));
+ text_.c_str(), static_cast<UINT32>(text_.size()),
+ font_descriptor_->GetDWriteTextFormat(), max_width_, max_height_,
+ &text_layout_));
}
void WinTextLayout::SetMaxWidth(float max_width) {
diff --git a/src/platform_win/window_manager.cpp b/src/platform_win/window_manager.cpp
index 62a73499..e6c255c3 100644
--- a/src/platform_win/window_manager.cpp
+++ b/src/platform_win/window_manager.cpp
@@ -2,13 +2,15 @@
#include "cru/platform/win/win_application.hpp"
#include "cru/platform/win/win_native_window.hpp"
+#include "cru/platform/win/window_class.hpp"
#include <assert.h>
namespace cru::platform::win {
LRESULT __stdcall GeneralWndProc(HWND hWnd, UINT Msg, WPARAM wParam,
LPARAM lParam) {
- auto window = WinApplication::GetInstance()->GetWindowManager()->FromHandle(hWnd);
+ auto window =
+ WinApplication::GetInstance()->GetWindowManager()->FromHandle(hWnd);
LRESULT result;
if (window != nullptr &&
@@ -21,8 +23,7 @@ LRESULT __stdcall GeneralWndProc(HWND hWnd, UINT Msg, WPARAM wParam,
WindowManager::WindowManager(WinApplication* application) {
application_ = application;
general_window_class_ = std::make_shared<WindowClass>(
- L"CruUIWindowClass", GeneralWndProc,
- application->GetInstanceHandle());
+ L"CruUIWindowClass", GeneralWndProc, application->GetInstanceHandle());
}
void WindowManager::RegisterWindow(HWND hwnd, WinNativeWindow* window) {
@@ -50,4 +51,4 @@ std::vector<WinNativeWindow*> WindowManager::GetAllWindows() const {
for (auto [key, value] : window_map_) windows.push_back(value);
return windows;
}
-}
+} // namespace cru::platform::win
diff --git a/src/ui/content_control.cpp b/src/ui/content_control.cpp
index 3a23164c..6383a10e 100644
--- a/src/ui/content_control.cpp
+++ b/src/ui/content_control.cpp
@@ -1,6 +1,6 @@
#include "cru/ui/content_control.hpp"
-#include "window.hpp"
+#include "cru/ui/window.hpp"
#include <cassert>
diff --git a/src/ui/control.cpp b/src/ui/control.cpp
index c5d02d40..f915af07 100644
--- a/src/ui/control.cpp
+++ b/src/ui/control.cpp
@@ -1,6 +1,6 @@
#include "cru/ui/control.hpp"
-#include "window.hpp"
+#include "cru/ui/window.hpp"
#include <cassert>
diff --git a/src/ui/controls/button.cpp b/src/ui/controls/button.cpp
index a6578251..0ac65d26 100644
--- a/src/ui/controls/button.cpp
+++ b/src/ui/controls/button.cpp
@@ -1,7 +1,7 @@
-#include "button.hpp"
+#include "cru/ui/controls/button.hpp"
-#include "ui/render/border_render_object.hpp"
-#include "ui/ui_manager.hpp"
+#include "cru/ui/render/border_render_object.hpp"
+#include "cru/ui/ui_manager.hpp"
namespace cru::ui::controls {
Button::Button() {
@@ -14,7 +14,9 @@ Button::Button() {
render_object_->SetCornerRadius(render::CornerRadius{Point{10, 5}});
}
-render::RenderObject* Button::GetRenderObject() const { return render_object_.get(); }
+render::RenderObject* Button::GetRenderObject() const {
+ return render_object_.get();
+}
void Button::OnChildChanged(Control* old_child, Control* new_child) {
if (old_child != nullptr) render_object_->RemoveChild(0);
diff --git a/src/ui/controls/flex_layout.cpp b/src/ui/controls/flex_layout.cpp
index bdbe2d73..3b70c98c 100644
--- a/src/ui/controls/flex_layout.cpp
+++ b/src/ui/controls/flex_layout.cpp
@@ -1,6 +1,6 @@
-#include "flex_layout.hpp"
+#include "cru/ui/controls/flex_layout.hpp"
-#include "ui/render/flex_layout_render_object.hpp"
+#include "cru/ui/render/flex_layout_render_object.hpp"
namespace cru::ui::controls {
using render::FlexLayoutRenderObject;
diff --git a/src/ui/controls/text_block.cpp b/src/ui/controls/text_block.cpp
index c2f8cd8e..55d83acc 100644
--- a/src/ui/controls/text_block.cpp
+++ b/src/ui/controls/text_block.cpp
@@ -1,7 +1,7 @@
-#include "text_block.hpp"
+#include "cru/ui/controls/text_block.hpp"
-#include "ui/render/text_render_object.hpp"
-#include "ui/ui_manager.hpp"
+#include "cru/ui/render/text_render_object.hpp"
+#include "cru/ui/ui_manager.hpp"
namespace cru::ui::controls {
using render::TextRenderObject;
@@ -11,7 +11,7 @@ TextBlock::TextBlock() {
UiManager::GetInstance()->GetPredefineResources();
render_object_.reset(
new TextRenderObject(predefined_resources->text_block_text_brush,
- predefined_resources->text_block_text_format,
+ predefined_resources->text_block_font,
predefined_resources->text_block_selection_brush));
}
@@ -19,7 +19,9 @@ render::RenderObject* TextBlock::GetRenderObject() const {
return render_object_.get();
}
-String TextBlock::GetText() const { return render_object_->GetText(); }
+std::wstring TextBlock::GetText() const { return render_object_->GetText(); }
-void TextBlock::SetText(const String& text) { render_object_->SetText(text); }
+void TextBlock::SetText(std::wstring text) {
+ render_object_->SetText(std::move(text));
+}
} // namespace cru::ui::controls
diff --git a/src/ui/layout_control.cpp b/src/ui/layout_control.cpp
index 9d789670..00215a8e 100644
--- a/src/ui/layout_control.cpp
+++ b/src/ui/layout_control.cpp
@@ -1,6 +1,6 @@
#include "cru/ui/layout_control.hpp"
-#include "window.hpp"
+#include "cru/ui/window.hpp"
#include <cassert>
diff --git a/src/ui/render/border_render_object.cpp b/src/ui/render/border_render_object.cpp
index 93e87c90..97e386dd 100644
--- a/src/ui/render/border_render_object.cpp
+++ b/src/ui/render/border_render_object.cpp
@@ -192,7 +192,7 @@ void BorderRenderObject::RecreateGeometry() {
builder.reset(graph_factory->CreateGeometryBuilder());
f(builder.get(), outer_rect, corner_radius_);
f(builder.get(), inner_rect, corner_radius_);
- border_outer_geometry_.reset(builder->Build());
+ geometry_.reset(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 99368c23..e7840b7e 100644
--- a/src/ui/render/flex_layout_render_object.cpp
+++ b/src/ui/render/flex_layout_render_object.cpp
@@ -188,7 +188,7 @@ void FlexLayoutRenderObject::OnLayoutContent(const Rect& content_rect) {
const float content_anchor_x = calculate_anchor(
content_main_align_, 0, content_rect.width, actual_content_width);
- auto anchor_x = 0;
+ float anchor_x = 0;
for (int i = 0; i < children.size(); i++) {
const auto child = children[i];
const auto size = child->GetPreferredSize();
@@ -215,7 +215,7 @@ void FlexLayoutRenderObject::OnLayoutContent(const Rect& content_rect) {
const float content_anchor_y = calculate_anchor(
content_main_align_, 0, content_rect.height, actual_content_height);
- auto anchor_y = 0;
+ float anchor_y = 0;
for (int i = 0; i < children.size(); i++) {
const auto child = children[i];
const auto size = child->GetPreferredSize();
diff --git a/src/ui/render/window_render_object.cpp b/src/ui/render/window_render_object.cpp
index ca1ab707..781087aa 100644
--- a/src/ui/render/window_render_object.cpp
+++ b/src/ui/render/window_render_object.cpp
@@ -1,22 +1,25 @@
#include "cru/ui/render/window_render_object.hpp"
+#include "cru/platform/native_window.hpp"
#include "cru/platform/painter_util.hpp"
+#include "cru/ui/window.hpp"
#include <cassert>
namespace cru::ui::render {
void WindowRenderObject::MeasureAndLayout() {
- const auto client_size = window_->GetClientSize();
+ const auto client_size = window_->GetNativeWindow()->GetClientSize();
Measure(client_size);
Layout(Rect{Point{}, client_size});
}
void WindowRenderObject::Draw(platform::Painter* painter) {
+ painter->Clear(colors::white);
if (const auto child = GetChild()) {
auto offset = child->GetOffset();
- platform::util::WithTransform(painter,
- platform::Matrix::Translation(offset.x, offset.y),
- [child](auto rt) { child->Draw(rt); });
+ platform::util::WithTransform(
+ painter, platform::Matrix::Translation(offset.x, offset.y),
+ [child](auto rt) { child->Draw(rt); });
}
}
diff --git a/src/ui/ui_manager.cpp b/src/ui/ui_manager.cpp
index 9c3c00d2..b1132ea8 100644
--- a/src/ui/ui_manager.cpp
+++ b/src/ui/ui_manager.cpp
@@ -1,5 +1,7 @@
#include "cru/ui/ui_manager.hpp"
+#include "cru/platform/brush.hpp"
+#include "cru/platform/font.hpp"
#include "cru/platform/graph_factory.hpp"
#include "cru/platform/ui_applicaition.hpp"
@@ -8,13 +10,12 @@ PredefineResources::PredefineResources() {
const auto graph_factory =
platform::UiApplication::GetInstance()->GetGraphFactory();
- button_normal_border_brush.reset(
- graph_factory->CreateSolidColorBrush(colors::black));
-
- text_block_selection_brush.reset(
- graph_factory->CreateSolidColorBrush(colors::skyblue));
- text_block_text_brush.reset(
- graph_factory->CreateSolidColorBrush(colors::black));
+ button_normal_border_brush.reset(static_cast<platform::Brush*>(
+ graph_factory->CreateSolidColorBrush(colors::black)));
+ text_block_selection_brush.reset(static_cast<platform::Brush*>(
+ graph_factory->CreateSolidColorBrush(colors::skyblue)));
+ text_block_text_brush.reset(static_cast<platform::Brush*>(
+ graph_factory->CreateSolidColorBrush(colors::black)));
text_block_font.reset(graph_factory->CreateFontDescriptor(L"等线", 24.0f));
}
diff --git a/src/ui/window.cpp b/src/ui/window.cpp
index c0ee1a83..23bda285 100644
--- a/src/ui/window.cpp
+++ b/src/ui/window.cpp
@@ -99,6 +99,8 @@ Window* Window::CreateOverlapped() {
}
Window::Window(tag_overlapped_constructor) {
+ using namespace std::placeholders;
+
native_window_ =
platform::UiApplication::GetInstance()->CreateWindow(nullptr);
render_object_.reset(new render::WindowRenderObject(this));
@@ -108,12 +110,21 @@ Window::Window(tag_overlapped_constructor) {
event_revokers_.push_back(native_window_->PaintEvent()->AddHandler(
std::bind(&Window::OnNativePaint, this)));
event_revokers_.push_back(native_window_->ResizeEvent()->AddHandler(
- std::bind(&Window::OnNativeResize, this)));
- event_revokers_.push_back(native_window_->FocusEvent()->AddHandler(
- std::bind(&Window::OnNativeFocus, this)));
+ std::bind(&Window::OnNativeResize, this, _1)));
event_revokers_.push_back(native_window_->FocusEvent()->AddHandler(
- std::bind(&Window::OnNativeFocus, this)));
- //TODO!
+ std::bind(&Window::OnNativeFocus, this, _1)));
+ event_revokers_.push_back(native_window_->MouseEnterLeaveEvent()->AddHandler(
+ std::bind(&Window::OnNativeMouseEnterLeave, this, _1)));
+ event_revokers_.push_back(native_window_->MouseMoveEvent()->AddHandler(
+ std::bind(&Window::OnNativeMouseMove, this, _1)));
+ event_revokers_.push_back(native_window_->MouseDownEvent()->AddHandler(
+ std::bind(&Window::OnNativeMouseDown, this, _1, _2)));
+ event_revokers_.push_back(native_window_->MouseUpEvent()->AddHandler(
+ std::bind(&Window::OnNativeMouseUp, this, _1, _2)));
+ event_revokers_.push_back(native_window_->KeyDownEvent()->AddHandler(
+ std::bind(&Window::OnNativeKeyDown, this, _1)));
+ event_revokers_.push_back(native_window_->KeyUpEvent()->AddHandler(
+ std::bind(&Window::OnNativeKeyUp, this, _1)));
}
Window::~Window() {
@@ -157,7 +168,7 @@ void Window::OnNativeDestroy() { delete this; }
void Window::OnNativePaint() {
const auto painter =
- std::make_unique<platform::Painter>(native_window_->BeginPaint());
+ std::unique_ptr<platform::Painter>(native_window_->BeginPaint());
render_object_->Draw(painter.get());
painter->EndDraw();
}