aboutsummaryrefslogtreecommitdiff
path: root/include/cru/ui/host
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2020-10-30 13:14:34 +0800
committercrupest <crupest@outlook.com>2020-10-30 13:14:34 +0800
commit93265251d56c91b05f160423077ce95339786f87 (patch)
tree96627217a4a3ed3bca6a21e35ca6310ef6217936 /include/cru/ui/host
parenta176c40ba0f913f98e966f11bad557833ae6dc57 (diff)
downloadcru-93265251d56c91b05f160423077ce95339786f87.tar.gz
cru-93265251d56c91b05f160423077ce95339786f87.tar.bz2
cru-93265251d56c91b05f160423077ce95339786f87.zip
...
Diffstat (limited to 'include/cru/ui/host')
-rw-r--r--include/cru/ui/host/LayoutPaintCycler.hpp39
-rw-r--r--include/cru/ui/host/WindowHost.hpp8
2 files changed, 46 insertions, 1 deletions
diff --git a/include/cru/ui/host/LayoutPaintCycler.hpp b/include/cru/ui/host/LayoutPaintCycler.hpp
new file mode 100644
index 00000000..ed543afa
--- /dev/null
+++ b/include/cru/ui/host/LayoutPaintCycler.hpp
@@ -0,0 +1,39 @@
+#pragma once
+#include "../Base.hpp"
+
+#include "cru/platform/gui/UiApplication.hpp"
+
+#include <chrono>
+
+namespace cru::ui::host {
+class LayoutPaintCycler {
+ public:
+ explicit LayoutPaintCycler(WindowHost* host);
+
+ CRU_DELETE_COPY(LayoutPaintCycler)
+ CRU_DELETE_MOVE(LayoutPaintCycler)
+
+ ~LayoutPaintCycler();
+
+ public:
+ void InvalidateLayout();
+ void InvalidatePaint();
+
+ bool IsLayoutDirty() { return layout_dirty_; }
+
+ private:
+ void OnCycle();
+
+ private:
+ WindowHost* host_;
+
+ platform::gui::TimerAutoCanceler timer_canceler_;
+
+ bool layout_dirty_ = true;
+ bool paint_dirty_ = true;
+
+ std::chrono::steady_clock::time_point last_cycle_time_;
+ std::chrono::steady_clock::duration cycle_threshold_ =
+ std::chrono::milliseconds(1000) / 144;
+};
+} // namespace cru::ui::host
diff --git a/include/cru/ui/host/WindowHost.hpp b/include/cru/ui/host/WindowHost.hpp
index 77ed937f..81eabb52 100644
--- a/include/cru/ui/host/WindowHost.hpp
+++ b/include/cru/ui/host/WindowHost.hpp
@@ -7,8 +7,11 @@
#include "../render/Base.hpp"
#include <functional>
+#include <memory>
namespace cru::ui::host {
+class LayoutPaintCycler;
+
struct AfterLayoutEventArgs {};
// The bridge between control tree and native window.
@@ -43,6 +46,8 @@ class WindowHost : public Object {
void Relayout();
void Relayout(const Size& available_size);
+ void Repaint();
+
// Is layout is invalid, wait for relayout and then run the action. Otherwist
// run it right now.
void RunAfterLayoutStable(std::function<void()> action);
@@ -125,7 +130,8 @@ class WindowHost : public Object {
platform::gui::INativeWindow* native_window_ = nullptr;
- bool need_layout_ = false;
+ std::unique_ptr<LayoutPaintCycler> layout_paint_cycler_;
+
Event<AfterLayoutEventArgs> after_layout_event_;
std::vector<std::function<void()> > after_layout_stable_action_;