Utility: Add RichTextBuilder
This commit is contained in:
80
include/Nazara/Utility/RichTextBuilder.hpp
Normal file
80
include/Nazara/Utility/RichTextBuilder.hpp
Normal file
@@ -0,0 +1,80 @@
|
||||
// Copyright (C) 2023 Jérôme "Lynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - Utility module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_UTILITY_RICHTEXTBUILDER_HPP
|
||||
#define NAZARA_UTILITY_RICHTEXTBUILDER_HPP
|
||||
|
||||
#include <NazaraUtils/Prerequisites.hpp>
|
||||
#include <Nazara/Utility/Enums.hpp>
|
||||
#include <Nazara/Utility/Font.hpp>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class Font;
|
||||
|
||||
template<typename T>
|
||||
class RichTextBuilder
|
||||
{
|
||||
public:
|
||||
struct CharacterSizeWrapper;
|
||||
struct CharacterSpacingOffsetWrapper;
|
||||
struct LineSpacingOffsetWrapper;
|
||||
struct OutlineColorWrapper;
|
||||
struct OutlineThicknessWrapper;
|
||||
|
||||
RichTextBuilder(T& richText);
|
||||
RichTextBuilder(T* richText);
|
||||
RichTextBuilder(const RichTextBuilder&) = delete;
|
||||
RichTextBuilder(RichTextBuilder&&) = delete;
|
||||
~RichTextBuilder() = default;
|
||||
|
||||
inline RichTextBuilder& AppendText(std::string_view text);
|
||||
|
||||
inline RichTextBuilder& SetCharacterSize(unsigned int characterSize);
|
||||
inline RichTextBuilder& SetCharacterSpacingOffset(float offset);
|
||||
inline RichTextBuilder& SetLineSpacingOffset(float offset);
|
||||
inline RichTextBuilder& SetTextColor(const Color& color);
|
||||
inline RichTextBuilder& SetTextFont(const std::shared_ptr<Font>& font);
|
||||
inline RichTextBuilder& SetTextOutlineColor(const Color& color);
|
||||
inline RichTextBuilder& SetTextOutlineThickness(float thickness);
|
||||
inline RichTextBuilder& SetTextStyle(TextStyleFlags style);
|
||||
|
||||
RichTextBuilder& operator=(const RichTextBuilder&) = delete;
|
||||
RichTextBuilder& operator=(RichTextBuilder&&) = delete;
|
||||
|
||||
inline RichTextBuilder& operator<<(const Color& textColor);
|
||||
inline RichTextBuilder& operator<<(const std::shared_ptr<Font>& font);
|
||||
inline RichTextBuilder& operator<<(std::string_view str);
|
||||
inline RichTextBuilder& operator<<(CharacterSizeWrapper characterSize);
|
||||
inline RichTextBuilder& operator<<(CharacterSpacingOffsetWrapper characterSpacingOffset);
|
||||
inline RichTextBuilder& operator<<(LineSpacingOffsetWrapper lineSpacing);
|
||||
inline RichTextBuilder& operator<<(OutlineColorWrapper outlineColor);
|
||||
inline RichTextBuilder& operator<<(OutlineThicknessWrapper outlineThickness);
|
||||
inline RichTextBuilder& operator<<(TextStyleFlags textStyle);
|
||||
|
||||
static inline CharacterSizeWrapper CharacterSize(unsigned int characterSize);
|
||||
static inline CharacterSpacingOffsetWrapper CharacterSpacingOffset(unsigned int spacingOffset);
|
||||
static inline LineSpacingOffsetWrapper LineSpacingOffset(float spacingOffset);
|
||||
static inline OutlineColorWrapper OutlineColor(const Color& color);
|
||||
static inline OutlineThicknessWrapper OutlineThickness(float thickness);
|
||||
|
||||
struct CharacterSizeWrapper { unsigned int characterSize; };
|
||||
struct CharacterSpacingOffsetWrapper { float spacingOffset; };
|
||||
struct LineSpacingOffsetWrapper { float spacingOffset; };
|
||||
struct OutlineColorWrapper { const Color& color; };
|
||||
struct OutlineThicknessWrapper { float thickness; };
|
||||
|
||||
private:
|
||||
T& m_richText;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#include <Nazara/Utility/RichTextBuilder.inl>
|
||||
|
||||
#endif // NAZARA_UTILITY_RICHTEXTBUILDER_HPP
|
||||
169
include/Nazara/Utility/RichTextBuilder.inl
Normal file
169
include/Nazara/Utility/RichTextBuilder.inl
Normal file
@@ -0,0 +1,169 @@
|
||||
// Copyright (C) 2023 Jérôme "Lynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - Utility module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/Utility/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
template<typename T>
|
||||
RichTextBuilder<T>::RichTextBuilder(T& richText) :
|
||||
m_richText(richText)
|
||||
{
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
RichTextBuilder<T>::RichTextBuilder(T* richText) :
|
||||
m_richText(*richText)
|
||||
{
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
RichTextBuilder<T>& RichTextBuilder<T>::AppendText(std::string_view text)
|
||||
{
|
||||
m_richText.AppendText(text);
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
RichTextBuilder<T>& RichTextBuilder<T>::SetCharacterSize(unsigned int characterSize)
|
||||
{
|
||||
m_richText.SetCharacterSize(characterSize);
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
RichTextBuilder<T>& RichTextBuilder<T>::SetCharacterSpacingOffset(float offset)
|
||||
{
|
||||
m_richText.SetCharacterSpacingOffset(offset);
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
RichTextBuilder<T>& RichTextBuilder<T>::SetLineSpacingOffset(float offset)
|
||||
{
|
||||
m_richText.SetLineSpacingOffset(offset);
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
RichTextBuilder<T>& RichTextBuilder<T>::SetTextColor(const Color& color)
|
||||
{
|
||||
m_richText.SetTextColor(color);
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
RichTextBuilder<T>& RichTextBuilder<T>::SetTextFont(const std::shared_ptr<Font>& font)
|
||||
{
|
||||
m_richText.SetTextFont(font);
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
RichTextBuilder<T>& RichTextBuilder<T>::SetTextOutlineColor(const Color& color)
|
||||
{
|
||||
m_richText.SetTextOutlineColor(color);
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
RichTextBuilder<T>& RichTextBuilder<T>::SetTextOutlineThickness(float thickness)
|
||||
{
|
||||
m_richText.SetTextOutlineThickness(thickness);
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
RichTextBuilder<T>& RichTextBuilder<T>::SetTextStyle(TextStyleFlags style)
|
||||
{
|
||||
m_richText.SetTextStyle(style);
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
RichTextBuilder<T>& RichTextBuilder<T>::operator<<(const Color& textColor)
|
||||
{
|
||||
return SetTextColor(textColor);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
RichTextBuilder<T>& RichTextBuilder<T>::operator<<(const std::shared_ptr<Font>& font)
|
||||
{
|
||||
return SetTextFont(font);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
RichTextBuilder<T>& RichTextBuilder<T>::operator<<(std::string_view str)
|
||||
{
|
||||
return AppendText(str);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
RichTextBuilder<T>& RichTextBuilder<T>::operator<<(CharacterSizeWrapper characterSize)
|
||||
{
|
||||
return SetCharacterSize(characterSize.characterSize);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
RichTextBuilder<T>& RichTextBuilder<T>::operator<<(CharacterSpacingOffsetWrapper characterSpacingOffset)
|
||||
{
|
||||
return SetCharacterSpacingOffset(characterSpacingOffset.spacingOffset);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
RichTextBuilder<T>& RichTextBuilder<T>::operator<<(LineSpacingOffsetWrapper lineSpacing)
|
||||
{
|
||||
return SetLineSpacingOffset(lineSpacing.spacingOffset);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
RichTextBuilder<T>& RichTextBuilder<T>::operator<<(OutlineColorWrapper outlineColor)
|
||||
{
|
||||
return SetTextOutlineColor(outlineColor.color);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
RichTextBuilder<T>& RichTextBuilder<T>::operator<<(OutlineThicknessWrapper outlineThickness)
|
||||
{
|
||||
return SetTextOutlineThickness(outlineThickness.thickness);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
RichTextBuilder<T>& RichTextBuilder<T>::operator<<(TextStyleFlags textStyle)
|
||||
{
|
||||
return SetTextStyle(textStyle);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
auto RichTextBuilder<T>::CharacterSize(unsigned int characterSize) -> CharacterSizeWrapper
|
||||
{
|
||||
return { characterSize };
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
auto RichTextBuilder<T>::CharacterSpacingOffset(unsigned int spacingOffset) -> CharacterSpacingOffsetWrapper
|
||||
{
|
||||
return { spacingOffset };
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
auto RichTextBuilder<T>::LineSpacingOffset(float spacingOffset) -> LineSpacingOffsetWrapper
|
||||
{
|
||||
return { spacingOffset };
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
auto RichTextBuilder<T>::OutlineColor(const Color& color) -> OutlineColorWrapper
|
||||
{
|
||||
return { color };
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
auto RichTextBuilder<T>::OutlineThickness(float thickness) -> OutlineThicknessWrapper
|
||||
{
|
||||
return { thickness };
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/Utility/DebugOff.hpp>
|
||||
Reference in New Issue
Block a user