diff options
author | crupest <crupest@outlook.com> | 2020-10-30 13:14:34 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2020-10-30 13:14:34 +0800 |
commit | 93265251d56c91b05f160423077ce95339786f87 (patch) | |
tree | 96627217a4a3ed3bca6a21e35ca6310ef6217936 /src/ui/host/LayoutPaintCycler.cpp | |
parent | a176c40ba0f913f98e966f11bad557833ae6dc57 (diff) | |
download | cru-93265251d56c91b05f160423077ce95339786f87.tar.gz cru-93265251d56c91b05f160423077ce95339786f87.tar.bz2 cru-93265251d56c91b05f160423077ce95339786f87.zip |
...
Diffstat (limited to 'src/ui/host/LayoutPaintCycler.cpp')
-rw-r--r-- | src/ui/host/LayoutPaintCycler.cpp | 35 |
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..9b319da4 --- /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_ = true; + paint_dirty_ = true; +} +} // namespace cru::ui::host |