Widgets: Add SimpleLabelWidget
A simpler alternative to LabelWidget
This commit is contained in:
40
include/Nazara/Widgets/AbstractLabelWidget.hpp
Normal file
40
include/Nazara/Widgets/AbstractLabelWidget.hpp
Normal file
@@ -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
|
||||
11
include/Nazara/Widgets/AbstractLabelWidget.inl
Normal file
11
include/Nazara/Widgets/AbstractLabelWidget.inl
Normal file
@@ -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;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
50
include/Nazara/Widgets/SimpleLabelWidget.hpp
Normal file
50
include/Nazara/Widgets/SimpleLabelWidget.hpp
Normal file
@@ -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
|
||||
70
include/Nazara/Widgets/SimpleLabelWidget.inl
Normal file
70
include/Nazara/Widgets/SimpleLabelWidget.inl
Normal file
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user