aboutsummaryrefslogtreecommitdiff
path: root/include/cru/ui/host/LayoutPaintCycler.h
blob: e95ed81deb1c45d01d3ed0eb741aed342ffc4217 (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
36
37
38
39
40
#pragma once
#include "../Base.h"

#include "cru/platform/gui/TimerHelper.h"
#include "cru/platform/gui/UiApplication.h"

#include <chrono>

namespace cru::ui::host {
class CRU_UI_API 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