diff options
author | crupest <crupest@outlook.com> | 2021-02-24 23:01:15 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2021-02-24 23:01:15 +0800 |
commit | 9c2f860ea80310f87b62a2947b4ddea5e7d85587 (patch) | |
tree | e912a13eb2e82b6874340fe2833989d62525c761 /src/ui/render/ScrollRenderObject.cpp | |
parent | 1e1170a89330881c5fad60988bc27c824dfcf454 (diff) | |
download | cru-9c2f860ea80310f87b62a2947b4ddea5e7d85587.tar.gz cru-9c2f860ea80310f87b62a2947b4ddea5e7d85587.tar.bz2 cru-9c2f860ea80310f87b62a2947b4ddea5e7d85587.zip |
feat: Scroll bar. Only collapse state.
Diffstat (limited to 'src/ui/render/ScrollRenderObject.cpp')
-rw-r--r-- | src/ui/render/ScrollRenderObject.cpp | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/src/ui/render/ScrollRenderObject.cpp b/src/ui/render/ScrollRenderObject.cpp index 5b9cb627..18b0adbf 100644 --- a/src/ui/render/ScrollRenderObject.cpp +++ b/src/ui/render/ScrollRenderObject.cpp @@ -2,8 +2,11 @@ #include "cru/platform/graphics/Painter.hpp" #include "cru/platform/graphics/util/Painter.hpp" +#include "cru/ui/controls/Control.hpp" +#include "cru/ui/render/ScrollBarDelegate.hpp" #include <algorithm> +#include <memory> namespace cru::ui::render { namespace { @@ -31,6 +34,10 @@ Point CoerceScroll(const Point& scroll_offset, const Size& content_size, } } // namespace +ScrollRenderObject::ScrollRenderObject() : RenderObject(ChildMode::Single) { + scroll_bar_delegate_ = std::make_unique<ScrollBarDelegate>(this); +} + RenderObject* ScrollRenderObject::HitTest(const Point& point) { if (const auto child = GetSingleChild()) { const auto offset = child->GetOffset(); @@ -52,6 +59,7 @@ void ScrollRenderObject::OnDrawCore(platform::graphics::IPainter* painter) { [child](platform::graphics::IPainter* p) { child->Draw(p); }); painter->PopLayer(); } + scroll_bar_delegate_->DrawScrollBar(painter); } Point ScrollRenderObject::GetScrollOffset() { @@ -141,4 +149,12 @@ void ScrollRenderObject::OnLayoutContent(const Rect& content_rect) { child->Layout(content_rect.GetLeftTop() - GetScrollOffset()); } } + +void ScrollRenderObject::OnAttachedControlChanged(controls::Control* control) { + if (control) { + scroll_bar_delegate_->InstallHandlers(control); + } else { + scroll_bar_delegate_->UninstallHandlers(); + } +} } // namespace cru::ui::render |