-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathArea.mpp
More file actions
82 lines (70 loc) · 2.16 KB
/
Area.mpp
File metadata and controls
82 lines (70 loc) · 2.16 KB
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
export module CppUtils.Terminal.Area;
import std;
import CppUtils.Container.Size;
export import CppUtils.Terminal.CharAttributes;
export import :DynamicAreaBuffer;
export import :Viewport;
export import :Widget;
export import :WidgetManager;
export import :WritableAreaView;
export namespace CppUtils::Terminal
{
class Area: public Widget, public DynamicAreaBuffer
{
public:
inline Area(const Container::Size2& size, const Viewport& viewport = {{0, 0}, {0, 0}}):
DynamicAreaBuffer{size},
m_viewport{(viewport.getSize().width() == 0 or viewport.getSize().height() == 0) ? Viewport{size} : viewport}
{}
template<std::derived_from<Widget> T>
inline auto addWidget(this auto&& self [[lifetimebound]], std::unique_ptr<T> widget) -> T&
{
widget->setWidgetManager(self.getWidgetManager());
self.m_widget = std::move(widget);
return dynamic_cast<T&>(*self.m_widget);
}
inline auto setViewport(const Viewport& viewport) noexcept -> void
{
m_viewport = viewport;
}
[[nodiscard]] inline auto getViewport(this auto&& self [[lifetimebound]]) noexcept -> decltype(auto)
{
return (self.m_viewport);
}
[[nodiscard]] inline auto getSize() const noexcept -> Container::Size2 final
{
return DynamicAreaBuffer::getSize();
}
[[nodiscard]] inline auto getWritableView(this auto&& self [[lifetimebound]], std::optional<Viewport> viewport = std::nullopt) -> WritableAreaView
{
return WritableAreaView{self, viewport.value_or(self.m_viewport)};
}
inline auto fill(const CharAttributes& c) noexcept -> void
{
auto view = getWritableView();
view.fill(c);
}
inline auto fill(char c) noexcept -> void
{
fill(CharAttributes{c});
}
inline auto clear() noexcept -> void
{
fill(' ');
}
inline auto draw([[maybe_unused]] WritableAreaView& view) noexcept -> void override
{
if (not m_widget)
return;
auto selfView = getWritableView();
m_widget->draw(selfView);
// Draw scrollbars
// Apply to view (applique la portion délimitée par viewport du buffer sur view)
// view.applyArea(m_widget->getBuffer(), m_viewport);
drawFinished();
}
protected:
Viewport m_viewport;
std::unique_ptr<Widget> m_widget;
};
}