From 0813c05fd233aa1b14806b04b1557267d94b3ce0 Mon Sep 17 00:00:00 2001 From: Pinchuk Aleksei Date: Wed, 17 Jul 2019 20:10:26 +0300 Subject: [PATCH] added standart functions to label --- headers/enduro2d/high/components/label.hpp | 16 ++++++ sources/enduro2d/high/components/label.cpp | 67 ++++++++++++++++++++++ 2 files changed, 83 insertions(+) diff --git a/headers/enduro2d/high/components/label.hpp b/headers/enduro2d/high/components/label.hpp index 404ddd23..46966450 100644 --- a/headers/enduro2d/high/components/label.hpp +++ b/headers/enduro2d/high/components/label.hpp @@ -18,6 +18,22 @@ namespace e2d label() = default; label(str32_view text); + label(label&& other) noexcept; + label& operator=(label&& other) noexcept; + + label(const label& other); + label& operator=(const label& other); + + label(str32_view text, font_asset::ptr font, color32 tint); + + label& assign(label&& other) noexcept; + label& assign(const label& other); + label& assign(str32_view text, font_asset::ptr font, color32 tint); + + void swap(label& other) noexcept; + void clear() noexcept; + bool empty() const noexcept; + label& text(str32_view text); const str32& text() const noexcept; diff --git a/sources/enduro2d/high/components/label.cpp b/sources/enduro2d/high/components/label.cpp index 18e01e1c..0a4b74d1 100644 --- a/sources/enduro2d/high/components/label.cpp +++ b/sources/enduro2d/high/components/label.cpp @@ -50,3 +50,70 @@ namespace e2d return true; } } + +namespace e2d +{ + label::label(label&& other) noexcept { + assign(std::move(other)); + } + + label& label::operator=(label&& other) noexcept { + return assign(std::move(other)); + } + + label::label(const label& other) { + assign(other); + } + + label& label::operator=(const label& other) { + return assign(other); + } + + label::label(str32_view text, font_asset::ptr font, color32 tint) { + assign(text, font, tint); + } + + label& label::assign(label&& other) noexcept { + if ( this != &other ) { + swap(other); + other.clear(); + } + return *this; + } + + label& label::assign(const label& other) { + if ( this != &other ) { + dirty_ = true; + text_ = other.text_; + font_ = other.font_; + tint_ = other.tint_; + } + return *this; + } + + label& label::assign(str32_view text, font_asset::ptr font, color32 tint) { + dirty_ = false; + text_ = text; + font_ = font; + tint_ = tint; + } + + void label::swap(label& other) noexcept { + using std::swap; + swap(dirty_, other.dirty_); + swap(text_, other.text_); + swap(font_, other.font_); + swap(tint_, other.tint_); + } + + void label::clear() noexcept { + dirty_ = true; + text_.clear(); + font_ = nullptr; + tint_ = color32::white(); + } + + bool label::empty() const noexcept { + return text_.empty(); + } +}