aboutsummaryrefslogtreecommitdiff
path: root/src/ui/host/LayoutPaintCycler.cpp
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2021-03-24 19:14:19 +0800
committercrupest <crupest@outlook.com>2021-03-24 19:14:19 +0800
commit7f15a1ff9a2007e119798053083a0a87d042990a (patch)
treecb35c01a7eaee867376d959b96c9bbd15df939e5 /src/ui/host/LayoutPaintCycler.cpp
parent74956951ee663012df0c3fe4ebe29799cb2f7732 (diff)
parent7703063a5816b089483e78ccd74bb9902ccfbea8 (diff)
downloadcru-7f15a1ff9a2007e119798053083a0a87d042990a.tar.gz
cru-7f15a1ff9a2007e119798053083a0a87d042990a.tar.bz2
cru-7f15a1ff9a2007e119798053083a0a87d042990a.zip
Merge branch 'master' of https://github.com/crupest/CruUI
Diffstat (limited to 'src/ui/host/LayoutPaintCycler.cpp')
-rw-r--r--src/ui/host/LayoutPaintCycler.cpp35
1 files changed, 35 insertions, 0 deletions
diff --git a/src/ui/host/LayoutPaintCycler.cpp b/src/ui/host/LayoutPaintCycler.cpp
new file mode 100644
index 00000000..fd581e00
--- /dev/null
+++ b/src/ui/host/LayoutPaintCycler.cpp
@@ -0,0 +1,35 @@
+#include "cru/ui/host/LayoutPaintCycler.hpp"
+#include <chrono>
+
+#include "../Helper.hpp"
+#include "cru/ui/Base.hpp"
+#include "cru/ui/host/WindowHost.hpp"
+
+namespace cru::ui::host {
+LayoutPaintCycler::LayoutPaintCycler(WindowHost* host) : host_(host) {
+ timer_canceler_ = GetUiApplication()->SetInterval(
+ std::chrono::duration_cast<std::chrono::milliseconds>(
+ this->cycle_threshold_),
+ [this] { OnCycle(); });
+}
+
+LayoutPaintCycler::~LayoutPaintCycler() = default;
+
+void LayoutPaintCycler::InvalidateLayout() { layout_dirty_ = true; }
+
+void LayoutPaintCycler::InvalidatePaint() { paint_dirty_ = true; }
+
+void LayoutPaintCycler::OnCycle() {
+ last_cycle_time_ = std::chrono::steady_clock::now();
+ if (layout_dirty_) {
+ host_->Relayout();
+ host_->Repaint();
+ } else {
+ if (paint_dirty_) {
+ host_->Repaint();
+ }
+ }
+ layout_dirty_ = false;
+ paint_dirty_ = false;
+}
+} // namespace cru::ui::host