#include "ScrollContainer.hpp" #include "Styles.hpp" #include #include namespace Raven { void ScrollContainer::on_layout() { if (!m_target) return; m_target->rect().set_x(-m_scroll.x()); m_target->rect().set_y(-m_scroll.y()); // todo: doesn't work with horizontal scrolling m_target->rect().set_min_width(rect().width()); m_target->rect().set_max_width(rect().width()); } std::shared_ptr ScrollContainer::make_target() { m_target = add(); m_target->set_style(style()); m_target->rect().update(); return m_target; } void ScrollContainer::on_mouse_button(MouseButtonEvent &event) { if (event.did_scroll_down()) { set_scroll(Point(m_scroll.x(), m_scroll.y() + m_scroll_step)); } else if (event.did_scroll_up()) { set_scroll(Point(m_scroll.x(), m_scroll.y() - m_scroll_step)); } } }