blob: 7f8523d4284dddbb2ce1dbe2b930c56fd1b2191c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
#include "cru/ui/host/LayoutPaintCycler.h"
#include <chrono>
#include "../Helper.h"
#include "cru/ui/Base.h"
#include "cru/ui/host/WindowHost.h"
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
|