diff options
author | crupest <crupest@outlook.com> | 2021-10-15 20:35:17 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2021-10-15 20:35:17 +0800 |
commit | ed368423531b24e8735db0afe38c7486145caa56 (patch) | |
tree | 2a88be9ce9062ac3c7e5c4ceb496d687102815ec /include/cru | |
parent | d3e2a751353e6c5b0e4d7c0a2af1cdbc09d3ea95 (diff) | |
download | cru-ed368423531b24e8735db0afe38c7486145caa56.tar.gz cru-ed368423531b24e8735db0afe38c7486145caa56.tar.bz2 cru-ed368423531b24e8735db0afe38c7486145caa56.zip |
...
Diffstat (limited to 'include/cru')
-rw-r--r-- | include/cru/common/String.hpp | 144 | ||||
-rw-r--r-- | include/cru/osx/gui/Cursor.hpp | 43 | ||||
-rw-r--r-- | include/cru/osx/gui/Window.hpp | 2 | ||||
-rw-r--r-- | include/cru/platform/bootstrap/Bootstrap.hpp | 2 |
4 files changed, 117 insertions, 74 deletions
diff --git a/include/cru/common/String.hpp b/include/cru/common/String.hpp index 0530c208..13176fc6 100644 --- a/include/cru/common/String.hpp +++ b/include/cru/common/String.hpp @@ -71,7 +71,7 @@ class CRU_BASE_API String { template <Index size> String(const char16_t (&str)[size]) - : String(reinterpret_cast<const_pointer>(str), size) {} + : String(reinterpret_cast<const_pointer>(str), size - 1) {} template <typename Iter> String(Iter start, Iter end) { @@ -164,7 +164,7 @@ class CRU_BASE_API String { inline void append(StringView str); public: - String& operator+=(const String& other); + String& operator+=(StringView other); public: Utf16CodePointIterator CodePointIterator() const { @@ -199,6 +199,76 @@ class CRU_BASE_API String { Index capacity_ = 0; // always 1 smaller than real buffer size }; +class CRU_BASE_API StringView { + public: + using value_type = char16_t; + using size_type = Index; + using difference_type = Index; + using reference = value_type&; + using const_reference = const value_type&; + using pointer = value_type*; + using const_pointer = const value_type*; + using iterator = const value_type*; + using const_iterator = const value_type*; + using reverse_iterator = std::reverse_iterator<iterator>; + using const_reverse_iterator = std::reverse_iterator<const_iterator>; + + StringView() = default; + + constexpr StringView(const_pointer ptr, Index size) + : ptr_(ptr), size_(size) {} + + template <Index size> + constexpr StringView(const value_type (&array)[size]) + : StringView(array, size - 1) {} + + StringView(const String& str) : StringView(str.data(), str.size()) {} + + CRU_DEFAULT_COPY(StringView) + CRU_DEFAULT_MOVE(StringView) + + ~StringView() = default; + + Index size() const { return size_; } + const value_type* data() const { return ptr_; } + + public: + iterator begin() { return this->ptr_; } + const_iterator begin() const { return this->ptr_; } + const_iterator cbegin() const { return this->ptr_; } + + iterator end() { return this->ptr_ + this->size_; } + const_iterator end() const { return this->ptr_ + this->size_; } + const_iterator cend() const { return this->ptr_ + this->size_; } + + reverse_iterator rbegin() { return reverse_iterator{begin()}; } + const_reverse_iterator rbegin() const { + return const_reverse_iterator{begin()}; + } + const_reverse_iterator crbegin() const { + return const_reverse_iterator{cbegin()}; + } + + reverse_iterator rend() { return reverse_iterator{end()}; } + const_reverse_iterator rend() const { return const_reverse_iterator{end()}; } + const_reverse_iterator crend() const { + return const_reverse_iterator{cend()}; + } + + StringView substr(Index pos); + StringView substr(Index pos, Index size); + + int Compare(const StringView& other) const; + + String ToString() const { return String(ptr_, size_); } + + value_type operator[](Index index) const { return ptr_[index]; } + + private: + const char16_t* ptr_; + Index size_; +}; + CRU_DEFINE_COMPARE_OPERATORS(String) inline String operator+(const String& left, const String& right) { @@ -285,76 +355,6 @@ String String::Format(T&&... args) const { return cru::Format(*this, std::forward<T>(args)...); } -class CRU_BASE_API StringView { - public: - using value_type = char16_t; - using size_type = Index; - using difference_type = Index; - using reference = value_type&; - using const_reference = const value_type&; - using pointer = value_type*; - using const_pointer = const value_type*; - using iterator = const value_type*; - using const_iterator = const value_type*; - using reverse_iterator = std::reverse_iterator<iterator>; - using const_reverse_iterator = std::reverse_iterator<const_iterator>; - - StringView() = default; - - constexpr StringView(const_pointer ptr, Index size) - : ptr_(ptr), size_(size) {} - - template <Index size> - constexpr StringView(const value_type (&array)[size]) - : StringView(array, size) {} - - StringView(const String& str) : StringView(str.data(), str.size()) {} - - CRU_DEFAULT_COPY(StringView) - CRU_DEFAULT_MOVE(StringView) - - ~StringView() = default; - - Index size() const { return size_; } - const value_type* data() const { return ptr_; } - - public: - iterator begin() { return this->ptr_; } - const_iterator begin() const { return this->ptr_; } - const_iterator cbegin() const { return this->ptr_; } - - iterator end() { return this->ptr_ + this->size_; } - const_iterator end() const { return this->ptr_ + this->size_; } - const_iterator cend() const { return this->ptr_ + this->size_; } - - reverse_iterator rbegin() { return reverse_iterator{begin()}; } - const_reverse_iterator rbegin() const { - return const_reverse_iterator{begin()}; - } - const_reverse_iterator crbegin() const { - return const_reverse_iterator{cbegin()}; - } - - reverse_iterator rend() { return reverse_iterator{end()}; } - const_reverse_iterator rend() const { return const_reverse_iterator{end()}; } - const_reverse_iterator crend() const { - return const_reverse_iterator{cend()}; - } - - StringView substr(Index pos); - StringView substr(Index pos, Index size); - - int Compare(const StringView& other) const; - - String ToString() const { return String(ptr_, size_); } - - value_type operator[](Index index) const { return ptr_[index]; } - - private: - const char16_t* ptr_; - Index size_; -}; - CRU_DEFINE_COMPARE_OPERATORS(StringView) inline String::iterator String::insert(const_iterator pos, StringView str) { diff --git a/include/cru/osx/gui/Cursor.hpp b/include/cru/osx/gui/Cursor.hpp new file mode 100644 index 00000000..497f5853 --- /dev/null +++ b/include/cru/osx/gui/Cursor.hpp @@ -0,0 +1,43 @@ +#pragma once +#include "Resource.hpp" +#include "cru/platform/gui/Cursor.hpp" + +#include <memory> + +namespace cru::platform::gui::osx { +namespace details { +class OsxWindowPrivate; +class OsxCursorPrivate; +class OsxCursorManagerPrivate; +} // namespace details + +class OsxCursor : public OsxGuiResource, public virtual ICursor { + friend class OsxWindow; + friend class details::OsxWindowPrivate; + + public: + OsxCursor(IUiApplication* ui_application, SystemCursorType cursor_type); + CRU_DELETE_COPY(OsxCursor) + CRU_DELETE_MOVE(OsxCursor) + + ~OsxCursor() override; + + private: + std::unique_ptr<details::OsxCursorPrivate> p_; +}; + +class OsxCursorManager : public OsxGuiResource, public virtual ICursorManager { + public: + explicit OsxCursorManager(IUiApplication* ui_application); + + CRU_DELETE_COPY(OsxCursorManager) + CRU_DELETE_MOVE(OsxCursorManager) + + ~OsxCursorManager() override; + + std::shared_ptr<ICursor> GetSystemCursor(SystemCursorType type) override; + + private: + std::unique_ptr<details::OsxCursorManagerPrivate> p_; +}; +} // namespace cru::platform::gui::osx diff --git a/include/cru/osx/gui/Window.hpp b/include/cru/osx/gui/Window.hpp index 56ae83e6..710246bc 100644 --- a/include/cru/osx/gui/Window.hpp +++ b/include/cru/osx/gui/Window.hpp @@ -133,6 +133,6 @@ class OsxInputMethodContext : public OsxGuiResource, IEvent<StringView>* TextEvent() override; private: - details::OsxInputMethodContextPrivate* p_; + std::unique_ptr<details::OsxInputMethodContextPrivate> p_; }; } // namespace cru::platform::gui::osx diff --git a/include/cru/platform/bootstrap/Bootstrap.hpp b/include/cru/platform/bootstrap/Bootstrap.hpp index 730df28c..33fb5122 100644 --- a/include/cru/platform/bootstrap/Bootstrap.hpp +++ b/include/cru/platform/bootstrap/Bootstrap.hpp @@ -11,7 +11,7 @@ #define CRU_PLATFORM_BOOTSTRAP_API #endif -namespace cru::platform::boostrap { +namespace cru::platform::bootstrap { CRU_PLATFORM_BOOTSTRAP_API cru::platform::gui::IUiApplication* CreateUiApplication(); } |