Widgets: Fix ScrollAreaWidget

This commit is contained in:
SirLynix
2022-07-20 13:37:45 +02:00
committed by Jérôme Leclercq
parent 0fcf24f336
commit e51695274c
9 changed files with 76 additions and 181 deletions

View File

@@ -82,12 +82,12 @@ namespace Nz
inline void Hide();
inline bool IsVisible() const;
std::unique_ptr<BaseWidget> ReleaseFromParent();
void Resize(const Vector2f& size);
void SetBackgroundColor(const Color& color);
void SetCursor(SystemCursor systemCursor);
void SetFocus();
void SetParent(BaseWidget* widget);
inline void SetFixedHeight(float fixedHeight);
inline void SetFixedSize(const Vector2f& fixedSize);

View File

@@ -13,6 +13,8 @@
namespace Nz
{
class ScrollbarWidget;
class NAZARA_WIDGETS_API ScrollAreaWidget : public BaseWidget
{
public:
@@ -23,8 +25,8 @@ namespace Nz
void EnableScrollbar(bool enable);
inline float GetScrollHeight() const;
inline float GetScrollRatio() const;
float GetScrollHeight() const;
float GetScrollRatio() const;
inline bool HasScrollbar() const;
inline bool IsScrollbarEnabled() const;
@@ -37,27 +39,15 @@ namespace Nz
ScrollAreaWidget& operator=(ScrollAreaWidget&&) = default;
private:
Nz::Rectf GetScrollbarRect() const;
void Layout() override;
void OnMouseButtonPress(int x, int y, Nz::Mouse::Button button) override;
void OnMouseButtonRelease(int x, int y, Nz::Mouse::Button button) override;
void OnMouseExit() override;
void OnMouseMoved(int x, int y, int deltaX, int deltaY) override;
void OnMouseWheelMoved(int x, int y, float delta) override;
bool OnMouseWheelMoved(int x, int y, float delta) override;
std::unique_ptr<ScrollAreaWidgetStyle> m_style;
BaseWidget* m_content;
EntityHandle m_scrollbarBackgroundEntity;
EntityHandle m_scrollbarEntity;
Nz::SpriteRef m_scrollbarBackgroundSprite;
Nz::SpriteRef m_scrollbarSprite;
Nz::Vector2i m_grabbedDelta;
bool m_isGrabbed;
ScrollbarWidget* m_horizontalScrollbar;
bool m_isScrollbarEnabled;
bool m_hasScrollbar;
float m_scrollRatio;
};
}

View File

@@ -3,21 +3,10 @@
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/Widgets/ScrollAreaWidget.hpp>
#include <NDK/Widgets/ScrollAreaWidget.hpp>
#include <Nazara/Widgets/Debug.hpp>
namespace Nz
{
inline float ScrollAreaWidget::GetScrollHeight() const
{
return m_scrollRatio * m_content->GetHeight();
}
inline float ScrollAreaWidget::GetScrollRatio() const
{
return m_scrollRatio;
}
inline bool ScrollAreaWidget::HasScrollbar() const
{
return m_hasScrollbar;

View File

@@ -32,6 +32,8 @@ namespace Nz
ScrollbarWidget& operator=(const ScrollbarWidget&) = delete;
ScrollbarWidget& operator=(ScrollbarWidget&&) = default;
NazaraSignal(OnScrollbarValueUpdate, ScrollbarWidget* /*emitter*/, float /*newValue*/);
private:
void Layout() override;

View File

@@ -36,6 +36,7 @@ namespace Nz
inline void ScrollbarWidget::SetValue(float newValue)
{
m_value = Clamp(newValue, m_minimumValue, m_maximumValue);
OnScrollbarValueUpdate(this, m_value);
Layout();
}