aboutsummaryrefslogtreecommitdiff
path: root/include/cru
diff options
context:
space:
mode:
Diffstat (limited to 'include/cru')
-rw-r--r--include/cru/common/String.hpp8
-rw-r--r--include/cru/ui/components/Menu.hpp8
-rw-r--r--include/cru/ui/controls/TextBlock.hpp6
-rw-r--r--include/cru/ui/controls/TextHostControlService.hpp6
4 files changed, 18 insertions, 10 deletions
diff --git a/include/cru/common/String.hpp b/include/cru/common/String.hpp
index 13176fc6..5d09d380 100644
--- a/include/cru/common/String.hpp
+++ b/include/cru/common/String.hpp
@@ -166,6 +166,10 @@ class CRU_BASE_API String {
public:
String& operator+=(StringView other);
+ operator std::u16string_view() const {
+ return std::u16string_view(data(), size());
+ }
+
public:
Utf16CodePointIterator CodePointIterator() const {
return Utf16CodePointIterator(
@@ -264,6 +268,10 @@ class CRU_BASE_API StringView {
value_type operator[](Index index) const { return ptr_[index]; }
+ operator std::u16string_view() const {
+ return std::u16string_view(data(), size());
+ }
+
private:
const char16_t* ptr_;
Index size_;
diff --git a/include/cru/ui/components/Menu.hpp b/include/cru/ui/components/Menu.hpp
index dedf2bd5..d60d38eb 100644
--- a/include/cru/ui/components/Menu.hpp
+++ b/include/cru/ui/components/Menu.hpp
@@ -13,7 +13,7 @@ namespace cru::ui::components {
class MenuItem : public Component {
public:
MenuItem();
- explicit MenuItem(std::u16string text);
+ explicit MenuItem(String text);
CRU_DELETE_COPY(MenuItem)
CRU_DELETE_MOVE(MenuItem)
@@ -23,7 +23,7 @@ class MenuItem : public Component {
public:
controls::Control* GetRootControl() override { return container_; }
- void SetText(std::u16string text);
+ void SetText(String text);
private:
controls::Button* container_;
@@ -48,10 +48,10 @@ class Menu : public Component {
void AddItem(Component* component, gsl::index index);
Component* RemoveItem(gsl::index index);
- void AddTextItem(std::u16string text) {
+ void AddTextItem(String text) {
AddTextItem(std::move(text), GetItemCount());
}
- void AddTextItem(std::u16string text, gsl::index index);
+ void AddTextItem(String text, gsl::index index);
private:
controls::FlexLayout* container_;
diff --git a/include/cru/ui/controls/TextBlock.hpp b/include/cru/ui/controls/TextBlock.hpp
index be31816c..b3ce21c5 100644
--- a/include/cru/ui/controls/TextBlock.hpp
+++ b/include/cru/ui/controls/TextBlock.hpp
@@ -9,7 +9,7 @@ class TextBlock : public NoChildControl, public virtual ITextHostControl {
static constexpr std::u16string_view control_type = u"TextBlock";
static TextBlock* Create();
- static TextBlock* Create(std::u16string text, bool selectable = false);
+ static TextBlock* Create(String text, bool selectable = false);
protected:
TextBlock();
@@ -25,8 +25,8 @@ class TextBlock : public NoChildControl, public virtual ITextHostControl {
render::RenderObject* GetRenderObject() const override;
- std::u16string GetText() const;
- void SetText(std::u16string text);
+ String GetText() const;
+ void SetText(String text);
bool IsSelectable() const;
void SetSelectable(bool value);
diff --git a/include/cru/ui/controls/TextHostControlService.hpp b/include/cru/ui/controls/TextHostControlService.hpp
index 84c226ca..b56374dc 100644
--- a/include/cru/ui/controls/TextHostControlService.hpp
+++ b/include/cru/ui/controls/TextHostControlService.hpp
@@ -8,7 +8,6 @@
#include "cru/ui/helper/ShortcutHub.hpp"
#include <functional>
-#include <string>
namespace cru::ui::render {
class TextRenderObject;
@@ -43,9 +42,10 @@ class TextHostControlService : public Object {
void SetEditable(bool editable);
String GetText() { return this->text_; }
+ StringView GetTextView() { return this->text_; }
void SetText(String text, bool stop_composition = false);
- void InsertText(gsl::index position, std::u16string_view text,
+ void InsertText(gsl::index position, StringView text,
bool stop_composition = false);
void DeleteChar(gsl::index position, bool stop_composition = false);
@@ -76,7 +76,7 @@ class TextHostControlService : public Object {
void DeleteSelectedText();
// If some text is selected, then they are deleted first. Then insert text
// into caret position.
- void ReplaceSelectedText(std::u16string_view text);
+ void ReplaceSelectedText(StringView text);
void ScrollToCaret();