Widgets: Add SimpleLabelWidget
A simpler alternative to LabelWidget
This commit is contained in:
parent
f0b4674039
commit
23645fc398
|
|
@ -0,0 +1,40 @@
|
|||
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - Widgets module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_WIDGETS_ABSTRACTLABELWIDGET_HPP
|
||||
#define NAZARA_WIDGETS_ABSTRACTLABELWIDGET_HPP
|
||||
|
||||
#include <Nazara/Widgets/BaseWidget.hpp>
|
||||
#include <Nazara/Widgets/WidgetTheme.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class AbstractTextDrawer;
|
||||
|
||||
class NAZARA_WIDGETS_API AbstractLabelWidget : public BaseWidget
|
||||
{
|
||||
public:
|
||||
AbstractLabelWidget(BaseWidget* parent);
|
||||
AbstractLabelWidget(const AbstractLabelWidget&) = delete;
|
||||
AbstractLabelWidget(AbstractLabelWidget&&) = delete;
|
||||
~AbstractLabelWidget() = default;
|
||||
|
||||
AbstractLabelWidget& operator=(const AbstractLabelWidget&) = delete;
|
||||
AbstractLabelWidget& operator=(AbstractLabelWidget&&) = delete;
|
||||
|
||||
protected:
|
||||
std::unique_ptr<LabelWidgetStyle> m_style;
|
||||
|
||||
private:
|
||||
void OnMouseEnter() override;
|
||||
void OnMouseExit() override;
|
||||
void OnRenderLayerUpdated(int baseRenderLayer) override;
|
||||
};
|
||||
}
|
||||
|
||||
#include <Nazara/Widgets/AbstractLabelWidget.inl>
|
||||
|
||||
#endif // NAZARA_WIDGETS_ABSTRACTLABELWIDGET_HPP
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - Widgets module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/Widgets/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
}
|
||||
|
||||
#include <Nazara/Widgets/DebugOff.hpp>
|
||||
|
|
@ -25,7 +25,7 @@ namespace Nz
|
|||
std::unique_ptr<ButtonWidgetStyle> CreateStyle(ButtonWidget* buttonWidget) const override;
|
||||
std::unique_ptr<CheckboxWidgetStyle> CreateStyle(CheckboxWidget* checkboxWidget) const override;
|
||||
std::unique_ptr<ImageButtonWidgetStyle> CreateStyle(ImageButtonWidget* imageButtonWidget) const override;
|
||||
std::unique_ptr<LabelWidgetStyle> CreateStyle(LabelWidget* labelWidget) const override;
|
||||
std::unique_ptr<LabelWidgetStyle> CreateStyle(AbstractLabelWidget* labelWidget) const override;
|
||||
std::unique_ptr<ProgressBarWidgetStyle> CreateStyle(ProgressBarWidget* progressBarWidget) const override;
|
||||
std::unique_ptr<ScrollAreaWidgetStyle> CreateStyle(ScrollAreaWidget* scrollAreaWidget) const override;
|
||||
std::unique_ptr<ScrollbarWidgetStyle> CreateStyle(ScrollbarWidget* scrollbarWidget) const override;
|
||||
|
|
|
|||
|
|
@ -7,19 +7,16 @@
|
|||
#ifndef NAZARA_WIDGETS_LABELWIDGET_HPP
|
||||
#define NAZARA_WIDGETS_LABELWIDGET_HPP
|
||||
|
||||
#include <Nazara/Graphics/TextSprite.hpp>
|
||||
#include <Nazara/Widgets/BaseWidget.hpp>
|
||||
#include <Nazara/Widgets/WidgetTheme.hpp>
|
||||
#include <Nazara/Widgets/AbstractLabelWidget.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class AbstractTextDrawer;
|
||||
class TextSprite;
|
||||
|
||||
class NAZARA_WIDGETS_API LabelWidget : public BaseWidget
|
||||
class NAZARA_WIDGETS_API LabelWidget final : public AbstractLabelWidget
|
||||
{
|
||||
public:
|
||||
LabelWidget(BaseWidget* parent);
|
||||
using AbstractLabelWidget::AbstractLabelWidget;
|
||||
LabelWidget(const LabelWidget&) = delete;
|
||||
LabelWidget(LabelWidget&&) = delete;
|
||||
~LabelWidget() = default;
|
||||
|
|
@ -28,14 +25,6 @@ namespace Nz
|
|||
|
||||
LabelWidget& operator=(const LabelWidget&) = delete;
|
||||
LabelWidget& operator=(LabelWidget&&) = delete;
|
||||
|
||||
private:
|
||||
void OnMouseEnter() override;
|
||||
void OnMouseExit() override;
|
||||
|
||||
void OnRenderLayerUpdated(int baseRenderLayer) override;
|
||||
|
||||
std::unique_ptr<LabelWidgetStyle> m_style;
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,50 @@
|
|||
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - Widgets module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_WIDGETS_SIMPLELABELWIDGET_HPP
|
||||
#define NAZARA_WIDGETS_SIMPLELABELWIDGET_HPP
|
||||
|
||||
#include <Nazara/Utility/SimpleTextDrawer.hpp>
|
||||
#include <Nazara/Widgets/AbstractLabelWidget.hpp>
|
||||
#include <NazaraUtils/FunctionRef.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class NAZARA_WIDGETS_API SimpleLabelWidget final : public AbstractLabelWidget
|
||||
{
|
||||
public:
|
||||
using AbstractLabelWidget::AbstractLabelWidget;
|
||||
SimpleLabelWidget(const SimpleLabelWidget&) = delete;
|
||||
SimpleLabelWidget(SimpleLabelWidget&&) = delete;
|
||||
~SimpleLabelWidget() = default;
|
||||
|
||||
inline void AppendText(std::string_view str);
|
||||
|
||||
inline unsigned int GetCharacterSize() const;
|
||||
inline const SimpleTextDrawer& GetDrawer() const;
|
||||
inline const std::string& GetText() const;
|
||||
inline const Color& GetTextColor() const;
|
||||
|
||||
inline void SetCharacterSize(unsigned int characterSize);
|
||||
inline void SetText(std::string text);
|
||||
inline void SetTextColor(const Color& color);
|
||||
|
||||
template<typename F> void UpdateDrawer(F&& callback);
|
||||
|
||||
SimpleLabelWidget& operator=(const SimpleLabelWidget&) = delete;
|
||||
SimpleLabelWidget& operator=(SimpleLabelWidget&&) = delete;
|
||||
|
||||
private:
|
||||
void UpdateText();
|
||||
void UpdateTextAndSize();
|
||||
|
||||
SimpleTextDrawer m_drawer;
|
||||
};
|
||||
}
|
||||
|
||||
#include <Nazara/Widgets/SimpleLabelWidget.inl>
|
||||
|
||||
#endif // NAZARA_WIDGETS_SIMPLELABELWIDGET_HPP
|
||||
|
|
@ -0,0 +1,70 @@
|
|||
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - Widgets module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/Widgets/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
inline void SimpleLabelWidget::AppendText(std::string_view str)
|
||||
{
|
||||
m_drawer.AppendText(str);
|
||||
UpdateTextAndSize();
|
||||
}
|
||||
|
||||
inline unsigned int SimpleLabelWidget::GetCharacterSize() const
|
||||
{
|
||||
return m_drawer.GetCharacterSize();
|
||||
}
|
||||
|
||||
inline const SimpleTextDrawer& SimpleLabelWidget::GetDrawer() const
|
||||
{
|
||||
return m_drawer;
|
||||
}
|
||||
|
||||
inline const std::string& SimpleLabelWidget::GetText() const
|
||||
{
|
||||
return m_drawer.GetText();
|
||||
}
|
||||
|
||||
inline const Color& SimpleLabelWidget::GetTextColor() const
|
||||
{
|
||||
return m_drawer.GetTextColor();
|
||||
}
|
||||
|
||||
inline void SimpleLabelWidget::SetCharacterSize(unsigned int characterSize)
|
||||
{
|
||||
m_drawer.SetCharacterSize(characterSize);
|
||||
UpdateTextAndSize();
|
||||
}
|
||||
|
||||
inline void SimpleLabelWidget::SetText(std::string text)
|
||||
{
|
||||
m_drawer.SetText(std::move(text));
|
||||
UpdateTextAndSize();
|
||||
}
|
||||
|
||||
inline void SimpleLabelWidget::SetTextColor(const Color& color)
|
||||
{
|
||||
m_drawer.SetTextColor(color);
|
||||
UpdateTextAndSize();
|
||||
}
|
||||
|
||||
template<typename F>
|
||||
void SimpleLabelWidget::UpdateDrawer(F&& callback)
|
||||
{
|
||||
using Ret = decltype(callback(m_drawer));
|
||||
if constexpr (std::is_void_v<Ret>)
|
||||
callback(m_drawer);
|
||||
else
|
||||
{
|
||||
static_assert(std::is_same_v<Ret, bool>, "callback must either return a boolean or nothing");
|
||||
if (!callback(m_drawer))
|
||||
return;
|
||||
}
|
||||
|
||||
UpdateTextAndSize();
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/Widgets/DebugOff.hpp>
|
||||
|
|
@ -154,7 +154,7 @@ namespace Nz
|
|||
class NAZARA_WIDGETS_API SimpleLabelWidgetStyle : public LabelWidgetStyle
|
||||
{
|
||||
public:
|
||||
SimpleLabelWidgetStyle(LabelWidget* labelWidget, std::shared_ptr<MaterialInstance> material, std::shared_ptr<MaterialInstance> hoveredMaterial = {});
|
||||
SimpleLabelWidgetStyle(AbstractLabelWidget* labelWidget, std::shared_ptr<MaterialInstance> material, std::shared_ptr<MaterialInstance> hoveredMaterial = {});
|
||||
SimpleLabelWidgetStyle(const SimpleLabelWidgetStyle&) = delete;
|
||||
SimpleLabelWidgetStyle(SimpleLabelWidgetStyle&&) = default;
|
||||
~SimpleLabelWidgetStyle() = default;
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@
|
|||
|
||||
namespace Nz
|
||||
{
|
||||
class AbstractLabelWidget;
|
||||
class AbstractTextDrawer;
|
||||
class ButtonWidget;
|
||||
class ButtonWidgetStyle;
|
||||
|
|
@ -22,7 +23,6 @@ namespace Nz
|
|||
class CheckboxWidgetStyle;
|
||||
class ImageButtonWidget;
|
||||
class ImageButtonWidgetStyle;
|
||||
class LabelWidget;
|
||||
class LabelWidgetStyle;
|
||||
class ProgressBarWidget;
|
||||
class ProgressBarWidgetStyle;
|
||||
|
|
@ -46,7 +46,7 @@ namespace Nz
|
|||
virtual std::unique_ptr<ButtonWidgetStyle> CreateStyle(ButtonWidget* buttonWidget) const = 0;
|
||||
virtual std::unique_ptr<CheckboxWidgetStyle> CreateStyle(CheckboxWidget* checkboxWidget) const = 0;
|
||||
virtual std::unique_ptr<ImageButtonWidgetStyle> CreateStyle(ImageButtonWidget* imageButtonWidget) const = 0;
|
||||
virtual std::unique_ptr<LabelWidgetStyle> CreateStyle(LabelWidget* labelWidget) const = 0;
|
||||
virtual std::unique_ptr<LabelWidgetStyle> CreateStyle(AbstractLabelWidget* labelWidget) const = 0;
|
||||
virtual std::unique_ptr<ProgressBarWidgetStyle> CreateStyle(ProgressBarWidget* labelWidget) const = 0;
|
||||
virtual std::unique_ptr<ScrollAreaWidgetStyle> CreateStyle(ScrollAreaWidget* scrollareaWidget) const = 0;
|
||||
virtual std::unique_ptr<ScrollbarWidgetStyle> CreateStyle(ScrollbarWidget* scrollbarWidget) const = 0;
|
||||
|
|
|
|||
|
|
@ -0,0 +1,34 @@
|
|||
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - Widgets module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/Widgets/AbstractLabelWidget.hpp>
|
||||
#include <Nazara/Utility/AbstractTextDrawer.hpp>
|
||||
#include <Nazara/Widgets/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
AbstractLabelWidget::AbstractLabelWidget(BaseWidget* parent) :
|
||||
BaseWidget(parent)
|
||||
{
|
||||
m_style = GetTheme()->CreateStyle(this);
|
||||
SetRenderLayerCount(m_style->GetRenderLayerCount());
|
||||
|
||||
Layout();
|
||||
}
|
||||
|
||||
void AbstractLabelWidget::OnMouseEnter()
|
||||
{
|
||||
m_style->OnHoverBegin();
|
||||
}
|
||||
|
||||
void AbstractLabelWidget::OnMouseExit()
|
||||
{
|
||||
m_style->OnHoverEnd();
|
||||
}
|
||||
|
||||
void AbstractLabelWidget::OnRenderLayerUpdated(int baseRenderLayer)
|
||||
{
|
||||
m_style->UpdateRenderLayer(baseRenderLayer);
|
||||
}
|
||||
}
|
||||
|
|
@ -218,7 +218,7 @@ namespace Nz
|
|||
return std::make_unique<SimpleImageButtonWidgetStyle>(imageButtonWidget, styleConfig);
|
||||
}
|
||||
|
||||
std::unique_ptr<LabelWidgetStyle> DefaultWidgetTheme::CreateStyle(LabelWidget* labelWidget) const
|
||||
std::unique_ptr<LabelWidgetStyle> DefaultWidgetTheme::CreateStyle(AbstractLabelWidget* labelWidget) const
|
||||
{
|
||||
return std::make_unique<SimpleLabelWidgetStyle>(labelWidget, Widgets::Instance()->GetTransparentMaterial());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,15 +8,6 @@
|
|||
|
||||
namespace Nz
|
||||
{
|
||||
LabelWidget::LabelWidget(BaseWidget* parent) :
|
||||
BaseWidget(parent)
|
||||
{
|
||||
m_style = GetTheme()->CreateStyle(this);
|
||||
SetRenderLayerCount(m_style->GetRenderLayerCount());
|
||||
|
||||
Layout();
|
||||
}
|
||||
|
||||
void LabelWidget::UpdateText(const AbstractTextDrawer& drawer)
|
||||
{
|
||||
m_style->UpdateText(drawer);
|
||||
|
|
@ -27,19 +18,4 @@ namespace Nz
|
|||
|
||||
Layout();
|
||||
}
|
||||
|
||||
void LabelWidget::OnMouseEnter()
|
||||
{
|
||||
m_style->OnHoverBegin();
|
||||
}
|
||||
|
||||
void LabelWidget::OnMouseExit()
|
||||
{
|
||||
m_style->OnHoverEnd();
|
||||
}
|
||||
|
||||
void LabelWidget::OnRenderLayerUpdated(int baseRenderLayer)
|
||||
{
|
||||
m_style->UpdateRenderLayer(baseRenderLayer);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,26 @@
|
|||
// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - Widgets module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/Widgets/SimpleLabelWidget.hpp>
|
||||
#include <Nazara/Utility/AbstractTextDrawer.hpp>
|
||||
#include <Nazara/Widgets/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
void SimpleLabelWidget::UpdateText()
|
||||
{
|
||||
m_style->UpdateText(m_drawer);
|
||||
}
|
||||
|
||||
void SimpleLabelWidget::UpdateTextAndSize()
|
||||
{
|
||||
m_style->UpdateText(m_drawer);
|
||||
|
||||
Vector2f size(m_drawer.GetBounds().GetLengths());
|
||||
SetMinimumSize(size);
|
||||
SetPreferredSize(size);
|
||||
|
||||
Layout();
|
||||
}
|
||||
}
|
||||
|
|
@ -5,11 +5,11 @@
|
|||
#include <Nazara/Widgets/SimpleWidgetStyles.hpp>
|
||||
#include <Nazara/Graphics/Components/GraphicsComponent.hpp>
|
||||
#include <Nazara/Utility/Components/NodeComponent.hpp>
|
||||
#include <Nazara/Widgets/AbstractLabelWidget.hpp>
|
||||
#include <Nazara/Widgets/ButtonWidget.hpp>
|
||||
#include <Nazara/Widgets/Canvas.hpp>
|
||||
#include <Nazara/Widgets/CheckboxWidget.hpp>
|
||||
#include <Nazara/Widgets/ImageButtonWidget.hpp>
|
||||
#include <Nazara/Widgets/LabelWidget.hpp>
|
||||
#include <Nazara/Widgets/ProgressBarWidget.hpp>
|
||||
#include <Nazara/Widgets/ScrollAreaWidget.hpp>
|
||||
#include <Nazara/Widgets/ScrollbarButtonWidget.hpp>
|
||||
|
|
@ -342,7 +342,7 @@ namespace Nz
|
|||
|
||||
/************************************************************************/
|
||||
|
||||
SimpleLabelWidgetStyle::SimpleLabelWidgetStyle(LabelWidget* labelWidget, std::shared_ptr<MaterialInstance> material, std::shared_ptr<MaterialInstance> hoveredMaterial) :
|
||||
SimpleLabelWidgetStyle::SimpleLabelWidgetStyle(AbstractLabelWidget* labelWidget, std::shared_ptr<MaterialInstance> material, std::shared_ptr<MaterialInstance> hoveredMaterial) :
|
||||
LabelWidgetStyle(labelWidget, 1),
|
||||
m_hoveredMaterial(std::move(hoveredMaterial)),
|
||||
m_material(std::move(material))
|
||||
|
|
|
|||
Loading…
Reference in New Issue