aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2021-10-26 16:32:13 +0800
committercrupest <crupest@outlook.com>2021-10-26 16:32:13 +0800
commit9dec93315173999c4fb9ab5a0e57909eb5e7fd8b (patch)
tree042fff007fc3d0959146f131f425b9626448718e
parent397843cda9e4161d3e92d8797f8012f478ce64f0 (diff)
downloadcru-9dec93315173999c4fb9ab5a0e57909eb5e7fd8b.tar.gz
cru-9dec93315173999c4fb9ab5a0e57909eb5e7fd8b.tar.bz2
cru-9dec93315173999c4fb9ab5a0e57909eb5e7fd8b.zip
...
-rw-r--r--demos/CMakeLists.txt3
-rw-r--r--demos/input_method/CMakeLists.txt4
-rw-r--r--demos/main/CMakeLists.txt12
-rw-r--r--demos/main/main.cpp6
-rw-r--r--demos/scroll_view/CMakeLists.txt12
-rw-r--r--demos/scroll_view/main.cpp2
-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
-rw-r--r--src/ui/Helper.cpp2
-rw-r--r--src/ui/Helper.hpp6
-rw-r--r--src/ui/UiManager.cpp2
-rw-r--r--src/ui/components/Menu.cpp6
-rw-r--r--src/ui/controls/TextBlock.cpp8
-rw-r--r--src/ui/controls/TextHostControlService.cpp11
-rw-r--r--src/ui/render/BorderRenderObject.cpp2
-rw-r--r--src/ui/render/ScrollBar.cpp2
-rw-r--r--src/ui/render/TextRenderObject.cpp2
19 files changed, 64 insertions, 44 deletions
diff --git a/demos/CMakeLists.txt b/demos/CMakeLists.txt
index 1a86c69f..3edabd0a 100644
--- a/demos/CMakeLists.txt
+++ b/demos/CMakeLists.txt
@@ -8,6 +8,9 @@ if(WIN32) # Currently only enable tests on Windows.
add_subdirectory(input_method)
elseif(APPLE)
+ add_subdirectory(main)
+ add_subdirectory(scroll_view)
+
add_subdirectory(input_method)
elseif(UNIX)
add_subdirectory(xcb)
diff --git a/demos/input_method/CMakeLists.txt b/demos/input_method/CMakeLists.txt
index 4c94bcbd..7f8be37a 100644
--- a/demos/input_method/CMakeLists.txt
+++ b/demos/input_method/CMakeLists.txt
@@ -5,8 +5,8 @@ else()
add_executable(demo_input_method MACOSX_BUNDLE main.cpp)
set_target_properties(demo_input_method PROPERTIES
BUNDLE TRUE
- MACOSX_BUNDLE_GUI_IDENTIFIER life.crupest.cru.demo_input_method
- MACOSX_BUNDLE_BUNDLE_NAME demo_input_method
+ MACOSX_BUNDLE_GUI_IDENTIFIER life.crupest.cru.demo-input-method
+ MACOSX_BUNDLE_BUNDLE_NAME demo-input-method
)
endif()
diff --git a/demos/main/CMakeLists.txt b/demos/main/CMakeLists.txt
index 9974671d..2f8ef9cb 100644
--- a/demos/main/CMakeLists.txt
+++ b/demos/main/CMakeLists.txt
@@ -1,2 +1,12 @@
-add_executable(demo_main main.cpp)
+if(NOT APPLE)
+ add_executable(demo_main main.cpp)
+else()
+ add_executable(demo_main MACOSX_BUNDLE main.cpp)
+ set_target_properties(demo_main PROPERTIES
+ BUNDLE TRUE
+ MACOSX_BUNDLE_GUI_IDENTIFIER life.crupest.cru.demo-main
+ MACOSX_BUNDLE_BUNDLE_NAME demo-main
+ )
+endif()
+
target_link_libraries(demo_main PRIVATE cru_demo_base cru_ui)
diff --git a/demos/main/main.cpp b/demos/main/main.cpp
index af2625a9..9a28ade8 100644
--- a/demos/main/main.cpp
+++ b/demos/main/main.cpp
@@ -18,11 +18,7 @@ using cru::ui::controls::TextBox;
using cru::ui::controls::Window;
int main() {
-#ifdef CRU_DEBUG
- cru::platform::SetupHeapDebug();
-#endif
-
- IUiApplication* application = cru::platform::boostrap::CreateUiApplication();
+ IUiApplication* application = cru::platform::bootstrap::CreateUiApplication();
const auto window = Window::Create();
diff --git a/demos/scroll_view/CMakeLists.txt b/demos/scroll_view/CMakeLists.txt
index e9efe7d2..b84bcea2 100644
--- a/demos/scroll_view/CMakeLists.txt
+++ b/demos/scroll_view/CMakeLists.txt
@@ -1,2 +1,12 @@
-add_executable(demo_scroll_view main.cpp)
+if(NOT APPLE)
+ add_executable(demo_scroll_view main.cpp)
+else()
+ add_executable(demo_scroll_view MACOSX_BUNDLE main.cpp)
+ set_target_properties(demo_scroll_view PROPERTIES
+ BUNDLE TRUE
+ MACOSX_BUNDLE_GUI_IDENTIFIER life.crupest.cru.demo-scroll-view
+ MACOSX_BUNDLE_BUNDLE_NAME demo-scroll-view
+ )
+endif()
+
target_link_libraries(demo_scroll_view PRIVATE cru_demo_base cru_ui)
diff --git a/demos/scroll_view/main.cpp b/demos/scroll_view/main.cpp
index 2d65f68f..be8bd228 100644
--- a/demos/scroll_view/main.cpp
+++ b/demos/scroll_view/main.cpp
@@ -10,7 +10,7 @@ using cru::ui::controls::TextBlock;
using cru::ui::controls::Window;
int main() {
- IUiApplication* application = cru::platform::boostrap::CreateUiApplication();
+ IUiApplication* application = cru::platform::bootstrap::CreateUiApplication();
auto window = Window::Create();
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();
diff --git a/src/ui/Helper.cpp b/src/ui/Helper.cpp
index fd54c05b..a5ab3a72 100644
--- a/src/ui/Helper.cpp
+++ b/src/ui/Helper.cpp
@@ -7,7 +7,7 @@ namespace cru::ui {
using cru::platform::graphics::IGraphicsFactory;
using cru::platform::gui::IUiApplication;
-IGraphicsFactory* GetGraphFactory() {
+IGraphicsFactory* GetGraphicsFactory() {
return IUiApplication::GetInstance()->GetGraphicsFactory();
}
diff --git a/src/ui/Helper.hpp b/src/ui/Helper.hpp
index cf1140dc..27f1d7e6 100644
--- a/src/ui/Helper.hpp
+++ b/src/ui/Helper.hpp
@@ -2,8 +2,8 @@
#include "cru/ui/Base.hpp"
namespace cru::platform {
-namespace graph {
-struct IGraphFactory;
+namespace graphics {
+struct IGraphicsFactory;
}
namespace native {
struct ICursor;
@@ -12,6 +12,6 @@ struct IUiApplication;
} // namespace cru::platform
namespace cru::ui {
-cru::platform::graphics::IGraphicsFactory* GetGraphFactory();
+cru::platform::graphics::IGraphicsFactory* GetGraphicsFactory();
cru::platform::gui::IUiApplication* GetUiApplication();
} // namespace cru::ui
diff --git a/src/ui/UiManager.cpp b/src/ui/UiManager.cpp
index ed40e70f..fde82eed 100644
--- a/src/ui/UiManager.cpp
+++ b/src/ui/UiManager.cpp
@@ -38,7 +38,7 @@ UiManager* UiManager::GetInstance() {
}
UiManager::UiManager() {
- const auto factory = GetGraphFactory();
+ const auto factory = GetGraphicsFactory();
theme_resource_.default_font_family = u"等线";
diff --git a/src/ui/components/Menu.cpp b/src/ui/components/Menu.cpp
index d45bc44f..afd1ab71 100644
--- a/src/ui/components/Menu.cpp
+++ b/src/ui/components/Menu.cpp
@@ -16,9 +16,7 @@ MenuItem::MenuItem() {
&UiManager::GetInstance()->GetThemeResources()->menu_item_style);
}
-MenuItem::MenuItem(std::u16string text) : MenuItem() {
- SetText(std::move(text));
-}
+MenuItem::MenuItem(String text) : MenuItem() { SetText(std::move(text)); }
MenuItem::~MenuItem() {
if (!container_->GetWindowHost()) {
@@ -27,7 +25,7 @@ MenuItem::~MenuItem() {
}
}
-void MenuItem::SetText(std::u16string text) { text_->SetText(std::move(text)); }
+void MenuItem::SetText(String text) { text_->SetText(std::move(text)); }
Menu::Menu() { container_ = controls::FlexLayout::Create(); }
diff --git a/src/ui/controls/TextBlock.cpp b/src/ui/controls/TextBlock.cpp
index 0724edcf..16fd5df6 100644
--- a/src/ui/controls/TextBlock.cpp
+++ b/src/ui/controls/TextBlock.cpp
@@ -10,7 +10,7 @@ using render::TextRenderObject;
TextBlock* TextBlock::Create() { return new TextBlock(); }
-TextBlock* TextBlock::Create(std::u16string text, bool selectable) {
+TextBlock* TextBlock::Create(String text, bool selectable) {
auto c = new TextBlock();
c->SetText(text);
c->SetSelectable(selectable);
@@ -38,11 +38,9 @@ render::RenderObject* TextBlock::GetRenderObject() const {
return text_render_object_.get();
}
-std::u16string TextBlock::GetText() const { return service_->GetText(); }
+String TextBlock::GetText() const { return service_->GetText(); }
-void TextBlock::SetText(std::u16string text) {
- service_->SetText(std::move(text));
-}
+void TextBlock::SetText(String text) { service_->SetText(std::move(text)); }
bool TextBlock::IsSelectable() const { return service_->IsEnabled(); }
diff --git a/src/ui/controls/TextHostControlService.cpp b/src/ui/controls/TextHostControlService.cpp
index 2f096126..2233d1e6 100644
--- a/src/ui/controls/TextHostControlService.cpp
+++ b/src/ui/controls/TextHostControlService.cpp
@@ -68,14 +68,13 @@ void TextHostControlService::SetText(String text, bool stop_composition) {
SyncTextRenderObject();
}
-void TextHostControlService::InsertText(gsl::index position,
- std::u16string_view text,
+void TextHostControlService::InsertText(gsl::index position, StringView text,
bool stop_composition) {
if (!Utf16IsValidInsertPosition(this->text_, position)) {
log::TagError(log_tag, u"Invalid text insert position.");
return;
}
- this->text_.insert(this->text_.cbegin() + position, text.begin(), text.end());
+ this->text_.insert(this->text_.cbegin() + position, text);
if (stop_composition) {
CancelComposition();
}
@@ -224,7 +223,7 @@ void TextHostControlService::AbortSelection() {
SetSelection(GetCaretPosition());
}
-void TextHostControlService::ReplaceSelectedText(std::u16string_view text) {
+void TextHostControlService::ReplaceSelectedText(StringView text) {
DeleteSelectedText();
InsertText(GetSelection().GetStart(), text);
SetSelection(GetSelection().GetStart() + text.size());
@@ -344,9 +343,7 @@ void TextHostControlService::GainFocusHandler(
input_method_context->CompositionEndEvent()->AddHandler(sync);
input_method_context_event_guard_ +=
input_method_context->TextEvent()->AddHandler(
- [this](const std::u16string_view& text) {
- this->ReplaceSelectedText(text);
- });
+ [this](StringView text) { this->ReplaceSelectedText(text); });
host::WindowHost* window_host = control_->GetWindowHost();
if (window_host)
diff --git a/src/ui/render/BorderRenderObject.cpp b/src/ui/render/BorderRenderObject.cpp
index 6b2404db..9e081828 100644
--- a/src/ui/render/BorderRenderObject.cpp
+++ b/src/ui/render/BorderRenderObject.cpp
@@ -175,7 +175,7 @@ void BorderRenderObject::RecreateGeometry() {
const Rect outer_rect{margin.left, margin.top,
size.width - margin.GetHorizontalTotal(),
size.height - margin.GetVerticalTotal()};
- const auto graph_factory = GetGraphFactory();
+ const auto graph_factory = GetGraphicsFactory();
std::unique_ptr<platform::graphics::IGeometryBuilder> builder{
graph_factory->CreateGeometryBuilder()};
f(builder.get(), outer_rect, outer_radius);
diff --git a/src/ui/render/ScrollBar.cpp b/src/ui/render/ScrollBar.cpp
index 1dfe67bf..0d644a1f 100644
--- a/src/ui/render/ScrollBar.cpp
+++ b/src/ui/render/ScrollBar.cpp
@@ -77,7 +77,7 @@ std::u16string GenerateScrollBarThemeColorKey(ScrollBarBrushUsageKind usage,
namespace {
std::unique_ptr<platform::graphics::IGeometry> CreateScrollBarArrowGeometry() {
- auto geometry_builder = GetGraphFactory()->CreateGeometryBuilder();
+ auto geometry_builder = GetGraphicsFactory()->CreateGeometryBuilder();
geometry_builder->BeginFigure({-kScrollBarArrowHeight / 2, 0});
geometry_builder->LineTo({kScrollBarArrowHeight / 2, kScrollBarArrowHeight});
geometry_builder->LineTo({kScrollBarArrowHeight / 2, -kScrollBarArrowHeight});
diff --git a/src/ui/render/TextRenderObject.cpp b/src/ui/render/TextRenderObject.cpp
index dc6b2d43..ff9ebc58 100644
--- a/src/ui/render/TextRenderObject.cpp
+++ b/src/ui/render/TextRenderObject.cpp
@@ -27,7 +27,7 @@ TextRenderObject::TextRenderObject(
selection_brush.swap(selection_brush_);
caret_brush.swap(caret_brush_);
- const auto graph_factory = GetGraphFactory();
+ const auto graph_factory = GetGraphicsFactory();
text_layout_ = graph_factory->CreateTextLayout(font_, u"");
}