Layouts (#189)
* Layout WIP * Widgets/BoxLayout: Fix layout algorithm * Widgets/BoxLayout: Fix box layout algorithm for good * SDK/Widgets: Remove padding * Sdk/Widgets: Make use of minimum/preferred size * Sdk/TextAreaWidget: Add Minimum/PreferredSize to TextArea * Sdk/Widgets: Add height/width variants of get/set fixed, maximum, minimum and preferred size methods * Sdk/BoxLayout: Remove useless code * Sdk/TextAreaWidget: Fix compilation * Widgets/TextAreaWidget: Fix cursor position
This commit is contained in:
48
SDK/include/NDK/Widgets/BoxLayout.hpp
Normal file
48
SDK/include/NDK/Widgets/BoxLayout.hpp
Normal file
@@ -0,0 +1,48 @@
|
||||
// Copyright (C) 2017 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Development Kit"
|
||||
// For conditions of distribution and use, see copyright notice in Prerequisites.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NDK_WIDGETS_BOXLAYOUT_HPP
|
||||
#define NDK_WIDGETS_BOXLAYOUT_HPP
|
||||
|
||||
#include <NDK/Prerequisites.hpp>
|
||||
#include <NDK/BaseWidget.hpp>
|
||||
#include <NDK/Widgets/Enums.hpp>
|
||||
#include <vector>
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
class NDK_API BoxLayout : public BaseWidget
|
||||
{
|
||||
public:
|
||||
inline BoxLayout(BaseWidget* parent, BoxLayoutOrientation orientation);
|
||||
BoxLayout(const BoxLayout&) = delete;
|
||||
BoxLayout(BoxLayout&&) = default;
|
||||
~BoxLayout() = default;
|
||||
|
||||
void Layout() override;
|
||||
|
||||
BoxLayout& operator=(const BoxLayout&) = delete;
|
||||
BoxLayout& operator=(BoxLayout&&) = default;
|
||||
|
||||
private:
|
||||
struct ChildInfo
|
||||
{
|
||||
BaseWidget* widget;
|
||||
bool isConstrained;
|
||||
float maximumSize;
|
||||
float minimumSize;
|
||||
float size;
|
||||
};
|
||||
|
||||
std::vector<ChildInfo> m_childInfos;
|
||||
BoxLayoutOrientation m_orientation;
|
||||
float m_spacing;
|
||||
};
|
||||
}
|
||||
|
||||
#include <NDK/Widgets/BoxLayout.inl>
|
||||
|
||||
#endif // NDK_WIDGETS_BOXLAYOUT_HPP
|
||||
15
SDK/include/NDK/Widgets/BoxLayout.inl
Normal file
15
SDK/include/NDK/Widgets/BoxLayout.inl
Normal file
@@ -0,0 +1,15 @@
|
||||
// Copyright (C) 2017 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Development Kit"
|
||||
// For conditions of distribution and use, see copyright notice in Prerequisites.hpp
|
||||
|
||||
#include <NDK/Widgets/BoxLayout.hpp>
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
BoxLayout::BoxLayout(BaseWidget* parent, BoxLayoutOrientation orientation) :
|
||||
BaseWidget(parent),
|
||||
m_orientation(orientation),
|
||||
m_spacing(5.f)
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -28,10 +28,6 @@ namespace Ndk
|
||||
ButtonWidget(ButtonWidget&&) = default;
|
||||
~ButtonWidget() = default;
|
||||
|
||||
//virtual ButtonWidget* Clone() const = 0;
|
||||
|
||||
void ResizeToContent() override;
|
||||
|
||||
inline const Nz::Color& GetColor() const;
|
||||
inline const Nz::Color& GetCornerColor() const;
|
||||
inline const Nz::Color& GetHoverColor() const;
|
||||
|
||||
@@ -93,6 +93,10 @@ namespace Ndk
|
||||
{
|
||||
m_textSprite->Update(drawer);
|
||||
|
||||
Nz::Vector2f textSize = Nz::Vector2f(m_textSprite->GetBoundingVolume().obb.localBox.GetLengths());
|
||||
SetMinimumSize(textSize);
|
||||
SetPreferredSize(textSize + Nz::Vector2f(20.f, 10.f));
|
||||
|
||||
Layout();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,7 +53,6 @@ namespace Ndk
|
||||
void SetState(CheckboxState state);
|
||||
inline void SetTextMargin(float margin);
|
||||
|
||||
void ResizeToContent() override;
|
||||
inline void UpdateText(const Nz::AbstractTextDrawer& drawer);
|
||||
|
||||
|
||||
@@ -68,6 +67,7 @@ namespace Ndk
|
||||
|
||||
void Layout() override;
|
||||
void UpdateCheckbox();
|
||||
void UpdateSize();
|
||||
|
||||
void OnMouseButtonRelease(int x, int y, Nz::Mouse::Button button) override;
|
||||
inline bool ContainsCheckbox(int x, int y) const;
|
||||
|
||||
@@ -65,6 +65,7 @@ namespace Ndk
|
||||
m_checkboxBackgroundSprite->SetSize(size - GetCheckboxBorderSize() * 2.f);
|
||||
m_checkboxContentSprite->SetSize(GetCheckboxSize() - GetCheckboxBorderSize() * 2.f - Nz::Vector2f { 4.f, 4.f });
|
||||
|
||||
UpdateSize();
|
||||
Layout();
|
||||
}
|
||||
|
||||
@@ -77,6 +78,8 @@ namespace Ndk
|
||||
inline void CheckboxWidget::UpdateText(const Nz::AbstractTextDrawer& drawer)
|
||||
{
|
||||
m_textSprite->Update(drawer);
|
||||
|
||||
UpdateSize();
|
||||
Layout();
|
||||
}
|
||||
|
||||
|
||||
@@ -9,6 +9,12 @@
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
enum BoxLayoutOrientation
|
||||
{
|
||||
BoxLayoutOrientation_Horizontal,
|
||||
BoxLayoutOrientation_Vertical
|
||||
};
|
||||
|
||||
enum CheckboxState
|
||||
{
|
||||
CheckboxState_Checked,
|
||||
|
||||
@@ -26,14 +26,14 @@ namespace Ndk
|
||||
|
||||
//virtual ImageWidget* Clone() const = 0;
|
||||
|
||||
void ResizeToContent() override;
|
||||
void ResizeToContent();
|
||||
|
||||
inline const Nz::Color& GetColor() const;
|
||||
inline const Nz::TextureRef& GetTexture() const;
|
||||
inline const Nz::Rectf& GetTextureCoords() const;
|
||||
|
||||
inline void SetColor(const Nz::Color& color);
|
||||
inline void SetTexture(const Nz::TextureRef& texture, bool resizeToContent = true);
|
||||
inline void SetTexture(const Nz::TextureRef& texture);
|
||||
inline void SetTextureCoords(const Nz::Rectf& coords);
|
||||
inline void SetTextureRect(const Nz::Rectui& rect);
|
||||
|
||||
|
||||
@@ -26,12 +26,13 @@ namespace Ndk
|
||||
m_sprite->SetColor(color);
|
||||
}
|
||||
|
||||
inline void ImageWidget::SetTexture(const Nz::TextureRef& texture, bool resizeToContent)
|
||||
inline void ImageWidget::SetTexture(const Nz::TextureRef& texture)
|
||||
{
|
||||
m_sprite->SetTexture(texture, false);
|
||||
|
||||
if (resizeToContent)
|
||||
ResizeToContent();
|
||||
Nz::Vector2f textureSize = Nz::Vector2f(Nz::Vector2ui(m_sprite->GetMaterial()->GetDiffuseMap()->GetSize()));
|
||||
SetMinimumSize(textureSize);
|
||||
SetPreferredSize(textureSize);
|
||||
}
|
||||
|
||||
inline void ImageWidget::SetTextureCoords(const Nz::Rectf& coords)
|
||||
|
||||
@@ -26,10 +26,6 @@ namespace Ndk
|
||||
LabelWidget(LabelWidget&&) = default;
|
||||
~LabelWidget() = default;
|
||||
|
||||
//virtual LabelWidget* Clone() const = 0;
|
||||
|
||||
void ResizeToContent() override;
|
||||
|
||||
inline void UpdateText(const Nz::AbstractTextDrawer& drawer);
|
||||
|
||||
LabelWidget& operator=(const LabelWidget&) = delete;
|
||||
|
||||
@@ -9,5 +9,8 @@ namespace Ndk
|
||||
inline void LabelWidget::UpdateText(const Nz::AbstractTextDrawer& drawer)
|
||||
{
|
||||
m_textSprite->Update(drawer);
|
||||
|
||||
SetMinimumSize(Nz::Vector2f(m_textSprite->GetBoundingVolume().obb.localBox.GetLengths()));
|
||||
SetPreferredSize(Nz::Vector2f(m_textSprite->GetBoundingVolume().obb.localBox.GetLengths()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -67,8 +67,6 @@ namespace Ndk
|
||||
inline void SetTextMargin(float margin);
|
||||
inline void SetTextColor(const Nz::Color& color);
|
||||
|
||||
inline void ResizeToContent() override {}
|
||||
|
||||
NazaraSignal(OnValueChanged, const ProgressBarWidget* /*progressBar*/);
|
||||
|
||||
private:
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright (C) 2017 Samy Bensaid
|
||||
// Copyright (C) 2017 Samy Bensaid
|
||||
// This file is part of the "Nazara Development Kit"
|
||||
// For conditions of distribution and use, see copyright notice in Prerequisites.hpp
|
||||
|
||||
@@ -148,9 +148,8 @@ namespace Ndk
|
||||
{
|
||||
if (IsTextEnabled())
|
||||
{
|
||||
Nz::Vector2f size = GetContentSize();
|
||||
m_textSprite->Update(Nz::SimpleTextDrawer::Draw(Nz::String::Number(m_value).Append('%'),
|
||||
static_cast<unsigned>(std::min(size.x, size.y) / 2.f), 0u, m_textColor));
|
||||
Nz::Vector2f size = GetSize();
|
||||
m_textSprite->Update(Nz::SimpleTextDrawer::Draw(Nz::String::Number(m_value).Append('%'), static_cast<unsigned int>(std::min(size.x, size.y) / 2.f), 0u, m_textColor));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,8 +11,8 @@
|
||||
#include <Nazara/Utility/SimpleTextDrawer.hpp>
|
||||
#include <NDK/BaseWidget.hpp>
|
||||
#include <NDK/Widgets/Enums.hpp>
|
||||
#include <vector>
|
||||
#include <functional>
|
||||
#include <vector>
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
@@ -40,7 +40,7 @@ namespace Ndk
|
||||
void Erase(std::size_t firstGlyph, std::size_t lastGlyph);
|
||||
void EraseSelection();
|
||||
|
||||
inline CharacterFilter GetCharacterFilter() const;
|
||||
inline const CharacterFilter& GetCharacterFilter() const;
|
||||
inline unsigned int GetCharacterSize() const;
|
||||
inline const Nz::Vector2ui& GetCursorPosition() const;
|
||||
inline Nz::Vector2ui GetCursorPosition(std::size_t glyphIndex) const;
|
||||
@@ -61,10 +61,8 @@ namespace Ndk
|
||||
inline void MoveCursor(int offset);
|
||||
inline void MoveCursor(const Nz::Vector2i& offset);
|
||||
|
||||
void ResizeToContent() override;
|
||||
|
||||
inline void SetCharacterFilter(CharacterFilter filter);
|
||||
inline void SetCharacterSize(unsigned int characterSize);
|
||||
void SetCharacterSize(unsigned int characterSize);
|
||||
inline void SetCursorPosition(std::size_t glyphIndex);
|
||||
inline void SetCursorPosition(Nz::Vector2ui cursorPosition);
|
||||
inline void SetEchoMode(EchoMode echoMode);
|
||||
@@ -108,7 +106,7 @@ namespace Ndk
|
||||
void RefreshCursor();
|
||||
void UpdateDisplayText();
|
||||
|
||||
std::function<bool(char32_t)> m_characterFilter;
|
||||
CharacterFilter m_characterFilter;
|
||||
EchoMode m_echoMode;
|
||||
EntityHandle m_cursorEntity;
|
||||
EntityHandle m_textEntity;
|
||||
|
||||
@@ -33,7 +33,7 @@ namespace Ndk
|
||||
Erase(glyphPosition, glyphPosition + 1U);
|
||||
}
|
||||
|
||||
inline TextAreaWidget::CharacterFilter TextAreaWidget::GetCharacterFilter() const
|
||||
inline const TextAreaWidget::CharacterFilter& TextAreaWidget::GetCharacterFilter() const
|
||||
{
|
||||
return m_characterFilter;
|
||||
}
|
||||
@@ -162,12 +162,7 @@ namespace Ndk
|
||||
|
||||
inline void TextAreaWidget::SetCharacterFilter(CharacterFilter filter)
|
||||
{
|
||||
m_characterFilter = filter;
|
||||
}
|
||||
|
||||
inline void TextAreaWidget::SetCharacterSize(unsigned int characterSize)
|
||||
{
|
||||
m_drawer.SetCharacterSize(characterSize);
|
||||
m_characterFilter = std::move(filter);
|
||||
}
|
||||
|
||||
inline void TextAreaWidget::SetCursorPosition(std::size_t glyphIndex)
|
||||
|
||||
Reference in New Issue
Block a user