blob: 9b319da4f7e4d968101a42ed32b0a3673cbb923b (
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.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_ = true;
paint_dirty_ = true;
}
} // namespace cru::ui::host
|