aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--demos/InputMethod/main.cpp20
-rw-r--r--demos/ScrollView/main.cpp2
-rw-r--r--demos/main/main.cpp14
-rw-r--r--demos/platform/graphics/DrawText.cpp4
-rw-r--r--demos/platform/graphics/SvgPath.cpp2
-rw-r--r--include/cru/base/StringUtil.h24
-rw-r--r--include/cru/platform/Check.h4
-rw-r--r--include/cru/platform/Resource.h14
-rw-r--r--include/cru/platform/graphics/Base.h8
-rw-r--r--include/cru/platform/graphics/Factory.h7
-rw-r--r--include/cru/platform/graphics/Font.h4
-rw-r--r--include/cru/platform/graphics/Geometry.h5
-rw-r--r--include/cru/platform/graphics/NullPainter.h4
-rw-r--r--include/cru/platform/graphics/Resource.h2
-rw-r--r--include/cru/platform/graphics/SvgGeometryBuilderMixin.h15
-rw-r--r--include/cru/platform/graphics/TextLayout.h4
-rw-r--r--include/cru/platform/graphics/cairo/CairoGraphicsFactory.h4
-rw-r--r--include/cru/platform/graphics/cairo/CairoResource.h2
-rw-r--r--include/cru/platform/graphics/cairo/PangoFont.h6
-rw-r--r--include/cru/platform/graphics/cairo/PangoTextLayout.h11
-rw-r--r--include/cru/platform/gui/Base.h34
-rw-r--r--include/cru/platform/gui/Clipboard.h4
-rw-r--r--include/cru/platform/gui/Input.h (renamed from include/cru/platform/gui/Keyboard.h)34
-rw-r--r--include/cru/platform/gui/InputMethod.h8
-rw-r--r--include/cru/platform/gui/Menu.h7
-rw-r--r--include/cru/platform/gui/SaveOpenDialogOptions.h21
-rw-r--r--include/cru/platform/gui/UiApplication.h17
-rw-r--r--include/cru/platform/gui/Window.h13
-rw-r--r--include/cru/platform/gui/osx/Keyboard.h2
-rw-r--r--include/cru/platform/gui/sdl/Base.h4
-rw-r--r--include/cru/platform/gui/sdl/Window.h4
-rw-r--r--include/cru/platform/gui/win/Keyboard.h2
-rw-r--r--include/cru/platform/gui/xcb/Base.h8
-rw-r--r--include/cru/platform/gui/xcb/Clipboard.h4
-rw-r--r--include/cru/platform/gui/xcb/Cursor.h5
-rw-r--r--include/cru/platform/gui/xcb/Input.h (renamed from include/cru/platform/gui/xcb/Keyboard.h)2
-rw-r--r--include/cru/platform/gui/xcb/InputMethod.h9
-rw-r--r--include/cru/platform/gui/xcb/UiApplication.h2
-rw-r--r--include/cru/platform/gui/xcb/Window.h11
-rw-r--r--include/cru/ui/Base.h11
-rw-r--r--include/cru/ui/ThemeManager.h13
-rw-r--r--include/cru/ui/ThemeResourceDictionary.h10
-rw-r--r--include/cru/ui/components/Input.h14
-rw-r--r--include/cru/ui/components/Menu.h8
-rw-r--r--include/cru/ui/components/PopupButton.h8
-rw-r--r--include/cru/ui/components/Select.h6
-rw-r--r--include/cru/ui/controls/IconButton.h6
-rw-r--r--include/cru/ui/controls/TextBlock.h8
-rw-r--r--include/cru/ui/controls/TextBox.h6
-rw-r--r--include/cru/ui/controls/TextHostControlService.h26
-rw-r--r--include/cru/ui/events/KeyEventArgs.h4
-rw-r--r--include/cru/ui/events/MouseButtonEventArgs.h13
-rw-r--r--include/cru/ui/events/MouseWheelEventArgs.h4
-rw-r--r--include/cru/ui/helper/ClickDetector.h2
-rw-r--r--include/cru/ui/helper/ShortcutHub.h18
-rw-r--r--include/cru/ui/mapper/Mapper.h4
-rw-r--r--include/cru/ui/mapper/StringMapper.h2
-rw-r--r--include/cru/ui/render/RenderObject.h2
-rw-r--r--include/cru/ui/render/ScrollBar.h2
-rw-r--r--include/cru/ui/render/TextRenderObject.h4
-rw-r--r--include/cru/ui/style/ApplyBorderStyleInfo.h2
-rw-r--r--src/ThemeBuilder/components/HeadBodyEditor.cpp4
-rw-r--r--src/ThemeBuilder/components/HeadBodyEditor.h4
-rw-r--r--src/ThemeBuilder/components/MainWindow.cpp4
-rw-r--r--src/ThemeBuilder/components/StyleRuleEditor.cpp6
-rw-r--r--src/ThemeBuilder/components/StyleRuleSetEditor.cpp4
-rw-r--r--src/ThemeBuilder/components/conditions/CheckedConditionEditor.cpp4
-rw-r--r--src/ThemeBuilder/components/conditions/ClickStateConditionEditor.cpp14
-rw-r--r--src/ThemeBuilder/components/conditions/CompoundConditionEditor.cpp12
-rw-r--r--src/ThemeBuilder/components/conditions/FocusConditionEditor.cpp4
-rw-r--r--src/ThemeBuilder/components/conditions/NoConditionEditor.cpp2
-rw-r--r--src/ThemeBuilder/components/properties/CheckBoxPropertyEditor.h4
-rw-r--r--src/ThemeBuilder/components/properties/ColorPropertyEditor.cpp8
-rw-r--r--src/ThemeBuilder/components/properties/ColorPropertyEditor.h4
-rw-r--r--src/ThemeBuilder/components/properties/CornerRadiusPropertyEditor.cpp8
-rw-r--r--src/ThemeBuilder/components/properties/FontPropertyEditor.cpp4
-rw-r--r--src/ThemeBuilder/components/properties/FontPropertyEditor.h4
-rw-r--r--src/ThemeBuilder/components/properties/MeasureLengthPropertyEditor.cpp9
-rw-r--r--src/ThemeBuilder/components/properties/MeasureLengthPropertyEditor.h4
-rw-r--r--src/ThemeBuilder/components/properties/OptionalPropertyEditor.h4
-rw-r--r--src/ThemeBuilder/components/properties/PointPropertyEditor.cpp8
-rw-r--r--src/ThemeBuilder/components/properties/PointPropertyEditor.h6
-rw-r--r--src/ThemeBuilder/components/properties/SelectPropertyEditor.h8
-rw-r--r--src/ThemeBuilder/components/properties/TextPropertyEditor.cpp7
-rw-r--r--src/ThemeBuilder/components/properties/TextPropertyEditor.h14
-rw-r--r--src/ThemeBuilder/components/properties/ThicknessPropertyEditor.cpp7
-rw-r--r--src/ThemeBuilder/components/properties/ThicknessPropertyEditor.h4
-rw-r--r--src/ThemeBuilder/components/stylers/BorderStylerEditor.cpp10
-rw-r--r--src/ThemeBuilder/components/stylers/CompoundStylerEditor.cpp14
-rw-r--r--src/ThemeBuilder/components/stylers/CursorStylerEditor.cpp6
-rw-r--r--src/ThemeBuilder/components/stylers/MarginStylerEditor.cpp4
-rw-r--r--src/ThemeBuilder/components/stylers/PaddingStylerEditor.cpp4
-rw-r--r--src/ThemeBuilder/components/stylers/PreferredSizeStylerEditor.cpp6
-rw-r--r--src/base/StringUtil.cpp38
-rw-r--r--src/platform/CMakeLists.txt1
-rw-r--r--src/platform/Resource.cpp7
-rw-r--r--src/platform/graphics/CMakeLists.txt2
-rw-r--r--src/platform/graphics/Geometry.cpp14
-rw-r--r--src/platform/graphics/SvgGeometryBuilderMixin.cpp37
-rw-r--r--src/platform/graphics/cairo/CairoGraphicsFactory.cpp4
-rw-r--r--src/platform/graphics/cairo/CairoImageFactory.cpp2
-rw-r--r--src/platform/graphics/cairo/CairoPainter.cpp24
-rw-r--r--src/platform/graphics/cairo/CairoResource.cpp6
-rw-r--r--src/platform/graphics/cairo/PangoFont.cpp9
-rw-r--r--src/platform/graphics/cairo/PangoTextLayout.cpp56
-rw-r--r--src/platform/graphics/direct2d/ImageFactory.cpp2
-rw-r--r--src/platform/graphics/direct2d/Painter.cpp24
-rw-r--r--src/platform/graphics/direct2d/TextLayout.cpp4
-rw-r--r--src/platform/graphics/quartz/Factory.cpp2
-rw-r--r--src/platform/graphics/quartz/ImageFactory.cpp2
-rw-r--r--src/platform/graphics/quartz/Painter.cpp22
-rw-r--r--src/platform/graphics/quartz/TextLayout.cpp2
-rw-r--r--src/platform/graphics/web_canvas/Painter.cpp2
-rw-r--r--src/platform/gui/CMakeLists.txt2
-rw-r--r--src/platform/gui/Input.cpp140
-rw-r--r--src/platform/gui/Keyboard.cpp140
-rw-r--r--src/platform/gui/UiApplication.cpp9
-rw-r--r--src/platform/gui/osx/Window.mm8
-rw-r--r--src/platform/gui/sdl/Window.cpp6
-rw-r--r--src/platform/gui/win/Window.cpp4
-rw-r--r--src/platform/gui/xcb/CMakeLists.txt2
-rw-r--r--src/platform/gui/xcb/Clipboard.cpp4
-rw-r--r--src/platform/gui/xcb/Cursor.cpp1
-rw-r--r--src/platform/gui/xcb/Input.cpp (renamed from src/platform/gui/xcb/Keyboard.cpp)13
-rw-r--r--src/platform/gui/xcb/InputMethod.cpp11
-rw-r--r--src/platform/gui/xcb/UiApplication.cpp3
-rw-r--r--src/platform/gui/xcb/Window.cpp15
-rw-r--r--src/ui/Helper.h11
-rw-r--r--src/ui/ThemeManager.cpp15
-rw-r--r--src/ui/ThemeResourceDictionary.cpp2
-rw-r--r--src/ui/components/Input.cpp30
-rw-r--r--src/ui/components/Menu.cpp8
-rw-r--r--src/ui/components/PopupButton.cpp4
-rw-r--r--src/ui/components/Select.cpp2
-rw-r--r--src/ui/controls/Button.cpp6
-rw-r--r--src/ui/controls/CheckBox.cpp2
-rw-r--r--src/ui/controls/IconButton.cpp16
-rw-r--r--src/ui/controls/TextBlock.cpp14
-rw-r--r--src/ui/controls/TextBox.cpp10
-rw-r--r--src/ui/controls/TextHostControlService.cpp154
-rw-r--r--src/ui/helper/ShortcutHub.cpp14
-rw-r--r--src/ui/mapper/ColorMapper.cpp2
-rw-r--r--src/ui/mapper/FontMapper.cpp4
-rw-r--r--src/ui/mapper/Mapper.cpp3
-rw-r--r--src/ui/mapper/PointMapper.cpp2
-rw-r--r--src/ui/mapper/SizeMapper.cpp2
-rw-r--r--src/ui/mapper/StringMapper.cpp3
-rw-r--r--src/ui/mapper/ThicknessMapper.cpp1
-rw-r--r--src/ui/mapper/style/ContentBrushStylerMapper.cpp2
-rw-r--r--src/ui/mapper/style/FontStylerMapper.cpp2
-rw-r--r--src/ui/mapper/style/MarginStylerMapper.cpp2
-rw-r--r--src/ui/mapper/style/PaddingStylerMapper.cpp2
-rw-r--r--src/ui/render/BorderRenderObject.cpp10
-rw-r--r--src/ui/render/ScrollBar.cpp31
-rw-r--r--src/ui/render/TextRenderObject.cpp11
155 files changed, 860 insertions, 848 deletions
diff --git a/demos/InputMethod/main.cpp b/demos/InputMethod/main.cpp
index 4ea5ab72..3598626d 100644
--- a/demos/InputMethod/main.cpp
+++ b/demos/InputMethod/main.cpp
@@ -11,6 +11,8 @@
#include "cru/platform/gui/UiApplication.h"
#include "cru/platform/gui/Window.h"
+#include <string>
+
using namespace cru;
using namespace cru::platform;
using namespace cru::platform::graphics;
@@ -33,7 +35,7 @@ class DemoWindow {
std::unique_ptr<INativeWindow> window_;
std::unique_ptr<ITextLayout> prompt_text_layout_;
std::unique_ptr<ITextLayout> committed_text_layout_;
- String committed_text_;
+ std::string committed_text_;
CompositionText composition_text_;
};
@@ -47,11 +49,11 @@ DemoWindow::DemoWindow(IUiApplication* application, DemoBrushes* brushes,
prompt_text_layout_ =
graphics_factory->CreateTextLayout(font,
- u"Ctrl+1: Enable IME\n"
- u"Ctrl+2: Disable IME\n"
- u"Ctrl+3: Complete composition.\n"
- u"Ctrl+4: Cancel composition.");
- committed_text_layout_ = graphics_factory->CreateTextLayout(font, u"");
+ "Ctrl+1: Enable IME\n"
+ "Ctrl+2: Disable IME\n"
+ "Ctrl+3: Complete composition.\n"
+ "Ctrl+4: Cancel composition.");
+ committed_text_layout_ = graphics_factory->CreateTextLayout(font, "");
auto update_text_layout_width = [this](const Size& size) {
prompt_text_layout_->SetMaxWidth(size.width);
@@ -102,7 +104,7 @@ DemoWindow::DemoWindow(IUiApplication* application, DemoBrushes* brushes,
window_->KeyDownEvent()->AddHandler([this](const NativeKeyEventArgs& args) {
auto input_method_context = window_->GetInputMethodContext();
- if (args.modifier & KeyModifiers::ctrl) {
+ if (args.modifier & KeyModifiers::Ctrl) {
switch (args.key) {
case KeyCode::N1:
input_method_context->EnableIME();
@@ -136,7 +138,7 @@ DemoWindow::DemoWindow(IUiApplication* application, DemoBrushes* brushes,
};
input_method_context->TextEvent()->AddHandler(
- [this, update_state](const StringView& c) {
+ [this, update_state](const std::string& c) {
committed_text_ += c;
update_state();
});
@@ -168,7 +170,7 @@ int main() {
graphics_factory->CreateSolidColorBrush(colors::green),
graphics_factory->CreateSolidColorBrush(colors::blue)};
- std::shared_ptr<IFont> font = graphics_factory->CreateFont(String{}, 30);
+ std::shared_ptr<IFont> font = graphics_factory->CreateFont({}, 30);
DemoWindow window1(application, &brushes, font);
DemoWindow window2(application, &brushes, font);
diff --git a/demos/ScrollView/main.cpp b/demos/ScrollView/main.cpp
index c7b4d0d6..f8e2adda 100644
--- a/demos/ScrollView/main.cpp
+++ b/demos/ScrollView/main.cpp
@@ -19,7 +19,7 @@ int main() {
window.AddChild(&scroll_view);
auto text_block = TextBlock::Create(
- uR"([Verse 1]
+ R"([Verse 1]
The snow glows white on the mountain tonight
Not a footprint to be seen
A kingdom of isolation
diff --git a/demos/main/main.cpp b/demos/main/main.cpp
index d574670d..91c9e85f 100644
--- a/demos/main/main.cpp
+++ b/demos/main/main.cpp
@@ -29,9 +29,9 @@ int main() {
->GetItemAt(0)
->GetSubmenu()
->CreateItemAt(0);
- mi->SetTitle(u"Quit");
+ mi->SetTitle("Quit");
mi->SetKeyboardShortcut(cru::platform::gui::KeyCode::Q,
- cru::platform::gui::KeyModifiers::command);
+ cru::platform::gui::KeyModifiers::Command);
mi->SetEnabled(true);
mi->SetOnClickHandler([&]() { application->RequestQuit(0); });
}
@@ -45,10 +45,10 @@ int main() {
window.AddChild(&flex_layout);
- auto text_block = TextBlock::Create(u"Hello World from CruUI!", true);
+ auto text_block = TextBlock::Create("Hello World from CruUI!", true);
flex_layout.AddChild(text_block.get());
- auto button_text_block = TextBlock::Create(u"OK");
+ auto button_text_block = TextBlock::Create("OK");
Button button;
button.SetChild(button_text_block.get());
flex_layout.AddChild(&button);
@@ -58,12 +58,12 @@ int main() {
flex_layout.AddChild(&text_box);
PopupMenuTextButton popup_menu_text_button;
- popup_menu_text_button.SetButtonText(u"Popup Menu Button");
- popup_menu_text_button.SetMenuItems({u"Item 1", u"Item 2", u"Item 3"});
+ popup_menu_text_button.SetButtonText("Popup Menu Button");
+ popup_menu_text_button.SetMenuItems({"Item 1", "Item 2", "Item 3"});
flex_layout.AddChild(popup_menu_text_button.GetRootControl());
Select select;
- select.SetItems({u"Item 1", u"Item 2", u"Item 3"});
+ select.SetItems({"Item 1", "Item 2", "Item 3"});
flex_layout.AddChild(select.GetRootControl());
window.GetWindowHost()->GetNativeWindow()->SetVisibility(
diff --git a/demos/platform/graphics/DrawText.cpp b/demos/platform/graphics/DrawText.cpp
index dfea18cd..275e141a 100644
--- a/demos/platform/graphics/DrawText.cpp
+++ b/demos/platform/graphics/DrawText.cpp
@@ -14,8 +14,8 @@ int main() {
demo.GetFactory()->CreateSolidColorBrush(cru::platform::colors::skyblue);
std::shared_ptr<cru::platform::graphics::IFont> font(
- demo.GetFactory()->CreateFont(u"", 24));
- auto text_layout = demo.GetFactory()->CreateTextLayout(font, u"Hello world!");
+ demo.GetFactory()->CreateFont("", 24));
+ auto text_layout = demo.GetFactory()->CreateTextLayout(font, "Hello world!");
demo.GetPainter()->DrawText({0, 0}, text_layout.get(), brush.get());
auto bounds = text_layout->GetTextBounds();
diff --git a/demos/platform/graphics/SvgPath.cpp b/demos/platform/graphics/SvgPath.cpp
index d0827878..d944cc5f 100644
--- a/demos/platform/graphics/SvgPath.cpp
+++ b/demos/platform/graphics/SvgPath.cpp
@@ -15,7 +15,7 @@ int main() {
auto geometry_builder = demo.GetFactory()->CreateGeometryBuilder();
geometry_builder->ParseAndApplySvgPathData(
- uR"(
+ R"(
M8.5 5.5a.5.5 0 0 0-1 0v3.362l-1.429 2.38a.5.5 0 1 0 .858.515l1.5-2.5A.5.5 0 0 0 8.5 9V5.5z
M6.5 0a.5.5 0 0 0 0 1H7v1.07a7.001 7.001 0 0 0-3.273 12.474l-.602.602a.5.5 0 0 0 .707.708l.746-.746A6.97 6.97 0 0 0 8 16a6.97 6.97 0 0 0 3.422-.892l.746.746a.5.5 0 0 0 .707-.708l-.601-.602A7.001 7.001 0 0 0 9 2.07V1h.5a.5.5 0 0 0 0-1h-3zm1.038 3.018a6.093 6.093 0 0 1 .924 0 6 6 0 1 1-.924 0zM0 3.5c0 .753.333 1.429.86 1.887A8.035 8.035 0 0 1 4.387 1.86 2.5 2.5 0 0 0 0 3.5zM13.5 1c-.753 0-1.429.333-1.887.86a8.035 8.035 0 0 1 3.527 3.527A2.5 2.5 0 0 0 13.5 1z
)");
diff --git a/include/cru/base/StringUtil.h b/include/cru/base/StringUtil.h
index 0ce3802f..2b1b5914 100644
--- a/include/cru/base/StringUtil.h
+++ b/include/cru/base/StringUtil.h
@@ -269,4 +269,28 @@ Utf8CodePointIterator CRU_BASE_API CreateUtf8Iterator(const std::byte* buffer,
Utf8CodePointIterator CRU_BASE_API
CreateUtf8Iterator(const std::vector<std::byte>& buffer);
+CodePoint CRU_BASE_API Utf8NextCodePoint(std::string_view str, Index current,
+ Index* next_position);
+CodePoint CRU_BASE_API Utf8PreviousCodePoint(std::string_view str,
+ Index current,
+ Index* next_position);
+// Return position after the character making predicate returns true or 0 if no
+// character doing so.
+Index CRU_BASE_API
+Utf8BackwardUntil(std::string_view str, Index position,
+ const std::function<bool(CodePoint)>& predicate);
+// Return position before the character making predicate returns true or
+// str.size() if no character doing so.
+Index CRU_BASE_API
+Utf8ForwardUntil(std::string_view str, Index position,
+ const std::function<bool(CodePoint)>& predicate);
+
+bool CRU_BASE_API Utf8IsValidInsertPosition(std::string_view str,
+ Index position);
+
+Index CRU_BASE_API Utf8PreviousWord(std::string_view str, Index position,
+ bool* is_space = nullptr);
+Index CRU_BASE_API Utf8NextWord(std::string_view str, Index position,
+ bool* is_space = nullptr);
+
} // namespace cru
diff --git a/include/cru/platform/Check.h b/include/cru/platform/Check.h
index b36b7fc1..6b002c0c 100644
--- a/include/cru/platform/Check.h
+++ b/include/cru/platform/Check.h
@@ -13,7 +13,7 @@ TTarget* CheckPlatform(IPlatformResource* resource,
const auto result = dynamic_cast<TTarget*>(resource);
if (result == nullptr) {
throw PlatformNotMatchException(
- resource->GetPlatformIdUtf8(), target_platform,
+ resource->GetPlatformId(), target_platform,
"Try to convert resource to target platform failed.");
}
return result;
@@ -28,7 +28,7 @@ std::shared_ptr<TTarget> CheckPlatform(const std::shared_ptr<TSource>& resource,
const auto result = std::dynamic_pointer_cast<TTarget>(resource);
if (result == nullptr) {
throw PlatformNotMatchException(
- resource->GetPlatformIdUtf8(), target_platform,
+ resource->GetPlatformId(), target_platform,
"Try to convert resource to target platform failed.");
}
return result;
diff --git a/include/cru/platform/Resource.h b/include/cru/platform/Resource.h
index a16a9dbd..35a401be 100644
--- a/include/cru/platform/Resource.h
+++ b/include/cru/platform/Resource.h
@@ -1,17 +1,13 @@
#pragma once
#include "Base.h"
-#include "cru/base/Base.h"
-#include "cru/base/String.h"
+#include <cru/base/Base.h>
+
+#include <string>
namespace cru::platform {
struct CRU_PLATFORM_API IPlatformResource : virtual Interface {
- CRU_DEFAULT_CONSTRUCTOR_DESTRUCTOR(IPlatformResource)
-
- virtual String GetPlatformId() const = 0;
-
- virtual String GetDebugString() { return String(); }
-
- virtual std::string GetPlatformIdUtf8() const;
+ virtual std::string GetPlatformId() const = 0;
+ virtual std::string GetDebugString() { return {}; }
};
} // namespace cru::platform
diff --git a/include/cru/platform/graphics/Base.h b/include/cru/platform/graphics/Base.h
index a61eb2a7..c3381394 100644
--- a/include/cru/platform/graphics/Base.h
+++ b/include/cru/platform/graphics/Base.h
@@ -1,8 +1,8 @@
#pragma once
-#include "../Color.h"
-#include "../GraphicsBase.h"
-#include "../Matrix.h"
-#include "../Resource.h"
+#include <cru/platform/Base.h> // IWYU pragma: export
+#include <cru/platform/Color.h> // IWYU pragma: export
+#include <cru/platform/GraphicsBase.h> // IWYU pragma: export
+#include <cru/platform/Matrix.h> // IWYU pragma: export
#ifdef CRU_IS_DLL
#ifdef CRU_PLATFORM_GRAPHICS_EXPORT_API
diff --git a/include/cru/platform/graphics/Factory.h b/include/cru/platform/graphics/Factory.h
index d197d821..fa9a3a95 100644
--- a/include/cru/platform/graphics/Factory.h
+++ b/include/cru/platform/graphics/Factory.h
@@ -1,10 +1,9 @@
#pragma once
-#include "Resource.h"
+#include "Base.h"
#include "Brush.h"
#include "Font.h"
#include "Geometry.h"
-#include "Image.h"
#include "ImageFactory.h"
#include "TextLayout.h"
@@ -15,11 +14,11 @@ struct CRU_PLATFORM_GRAPHICS_API IGraphicsFactory : virtual IPlatformResource {
virtual std::unique_ptr<IGeometryBuilder> CreateGeometryBuilder() = 0;
- virtual std::unique_ptr<IFont> CreateFont(String font_family,
+ virtual std::unique_ptr<IFont> CreateFont(std::string font_family,
float font_size) = 0;
virtual std::unique_ptr<ITextLayout> CreateTextLayout(
- std::shared_ptr<IFont> font, String text) = 0;
+ std::shared_ptr<IFont> font, std::string text) = 0;
std::unique_ptr<ISolidColorBrush> CreateSolidColorBrush(const Color& color) {
std::unique_ptr<ISolidColorBrush> brush = CreateSolidColorBrush();
diff --git a/include/cru/platform/graphics/Font.h b/include/cru/platform/graphics/Font.h
index 7144fdc2..de24222c 100644
--- a/include/cru/platform/graphics/Font.h
+++ b/include/cru/platform/graphics/Font.h
@@ -1,9 +1,11 @@
#pragma once
#include "Resource.h"
+#include <string>
+
namespace cru::platform::graphics {
struct CRU_PLATFORM_GRAPHICS_API IFont : virtual IGraphicsResource {
- virtual String GetFontName() = 0;
+ virtual std::string GetFontName() = 0;
virtual float GetFontSize() = 0;
};
} // namespace cru::platform::graphics
diff --git a/include/cru/platform/graphics/Geometry.h b/include/cru/platform/graphics/Geometry.h
index b4b05194..2b251495 100644
--- a/include/cru/platform/graphics/Geometry.h
+++ b/include/cru/platform/graphics/Geometry.h
@@ -95,9 +95,10 @@ struct CRU_PLATFORM_GRAPHICS_API IGeometryBuilder : virtual IGraphicsResource {
virtual std::unique_ptr<IGeometry> Build() = 0;
- virtual void ParseAndApplySvgPathData(StringView path_d);
+ virtual void ParseAndApplySvgPathData(std::string_view path_d);
};
std::unique_ptr<IGeometry> CRU_PLATFORM_GRAPHICS_API
-CreateGeometryFromSvgPathData(IGraphicsFactory* factory, StringView path_d);
+CreateGeometryFromSvgPathData(IGraphicsFactory* factory,
+ std::string_view path_d);
} // namespace cru::platform::graphics
diff --git a/include/cru/platform/graphics/NullPainter.h b/include/cru/platform/graphics/NullPainter.h
index 27cb6393..74d71c16 100644
--- a/include/cru/platform/graphics/NullPainter.h
+++ b/include/cru/platform/graphics/NullPainter.h
@@ -14,9 +14,9 @@ class CRU_PLATFORM_GRAPHICS_API NullPainter : public Object,
~NullPainter() override = default;
public:
- String GetPlatformId() const override { return u"NULL"; }
+ std::string GetPlatformId() const override { return "NULL"; }
- String GetDebugString() override { return u"NullPainter"; }
+ std::string GetDebugString() override { return "NullPainter"; }
Matrix GetTransform() override { return Matrix(); }
void SetTransform(const Matrix& matrix) override { CRU_UNUSED(matrix) }
diff --git a/include/cru/platform/graphics/Resource.h b/include/cru/platform/graphics/Resource.h
index ab1b8de6..f910ca8a 100644
--- a/include/cru/platform/graphics/Resource.h
+++ b/include/cru/platform/graphics/Resource.h
@@ -1,6 +1,8 @@
#pragma once
#include "Base.h"
+#include <cru/platform/Resource.h>
+
namespace cru::platform::graphics {
struct IGraphicsFactory;
diff --git a/include/cru/platform/graphics/SvgGeometryBuilderMixin.h b/include/cru/platform/graphics/SvgGeometryBuilderMixin.h
index 32b665a5..586872b0 100644
--- a/include/cru/platform/graphics/SvgGeometryBuilderMixin.h
+++ b/include/cru/platform/graphics/SvgGeometryBuilderMixin.h
@@ -45,25 +45,24 @@ class CRU_PLATFORM_GRAPHICS_API SvgGeometryBuilderMixin
void CloseFigure(bool close) override;
- void ParseAndApplySvgPathData(StringView path_d) override;
+ void ParseAndApplySvgPathData(std::string_view path_d) override;
protected:
- String GetPathData() const { return current_; }
+ std::string GetPathData() const { return current_; }
private:
template <typename... Args>
- void Append(StringView format, Args&&... args) {
- current_ += String::FromUtf8(
- std::format(format.ToUtf8(), std::forward<Args>(args)...));
- current_ += u' ';
+ void Append(std::string_view format, Args&&... args) {
+ current_ += std::format(format, std::forward<Args>(args)...);
+ current_ += ' ';
}
- void AppendCommand(StringView command);
+ void AppendCommand(std::string_view command);
void Append(bool flag);
void Append(float number);
void Append(const Point& point);
private:
- String current_;
+ std::string current_;
};
} // namespace cru::platform::graphics
diff --git a/include/cru/platform/graphics/TextLayout.h b/include/cru/platform/graphics/TextLayout.h
index e060186b..4c5302eb 100644
--- a/include/cru/platform/graphics/TextLayout.h
+++ b/include/cru/platform/graphics/TextLayout.h
@@ -8,8 +8,8 @@ namespace cru::platform::graphics {
// Requirement:
// All text must be left-top aligned.
struct CRU_PLATFORM_GRAPHICS_API ITextLayout : virtual IGraphicsResource {
- virtual String GetText() = 0;
- virtual void SetText(String new_text) = 0;
+ virtual std::string GetText() = 0;
+ virtual void SetText(std::string new_text) = 0;
virtual std::shared_ptr<IFont> GetFont() = 0;
virtual void SetFont(std::shared_ptr<IFont> font) = 0;
diff --git a/include/cru/platform/graphics/cairo/CairoGraphicsFactory.h b/include/cru/platform/graphics/cairo/CairoGraphicsFactory.h
index f0f7ecc5..563c6b40 100644
--- a/include/cru/platform/graphics/cairo/CairoGraphicsFactory.h
+++ b/include/cru/platform/graphics/cairo/CairoGraphicsFactory.h
@@ -26,11 +26,11 @@ class CRU_PLATFORM_GRAPHICS_CAIRO_API CairoGraphicsFactory
std::unique_ptr<IGeometryBuilder> CreateGeometryBuilder() override;
- std::unique_ptr<IFont> CreateFont(String font_family,
+ std::unique_ptr<IFont> CreateFont(std::string font_family,
float font_size) override;
std::unique_ptr<ITextLayout> CreateTextLayout(std::shared_ptr<IFont> font,
- String text) override;
+ std::string text) override;
IImageFactory* GetImageFactory() override;
diff --git a/include/cru/platform/graphics/cairo/CairoResource.h b/include/cru/platform/graphics/cairo/CairoResource.h
index bf35ab26..14730e8a 100644
--- a/include/cru/platform/graphics/cairo/CairoResource.h
+++ b/include/cru/platform/graphics/cairo/CairoResource.h
@@ -17,7 +17,7 @@ class CRU_PLATFORM_GRAPHICS_CAIRO_API CairoResource
~CairoResource() override;
- String GetPlatformId() const override;
+ std::string GetPlatformId() const override;
IGraphicsFactory* GetGraphicsFactory() override;
CairoGraphicsFactory* GetCairoGraphicsFactory() const { return factory_; }
diff --git a/include/cru/platform/graphics/cairo/PangoFont.h b/include/cru/platform/graphics/cairo/PangoFont.h
index 3014739d..e8dbf3ec 100644
--- a/include/cru/platform/graphics/cairo/PangoFont.h
+++ b/include/cru/platform/graphics/cairo/PangoFont.h
@@ -9,12 +9,12 @@ namespace cru::platform::graphics::cairo {
class CRU_PLATFORM_GRAPHICS_CAIRO_API PangoFont : public CairoResource,
public virtual IFont {
public:
- PangoFont(CairoGraphicsFactory* factory, String font_family, float font_size);
+ PangoFont(CairoGraphicsFactory* factory, std::string font_family, float font_size);
~PangoFont() override;
public:
- String GetFontName() override;
+ std::string GetFontName() override;
float GetFontSize() override;
PangoFontDescription* GetPangoFontDescription() {
@@ -22,7 +22,7 @@ class CRU_PLATFORM_GRAPHICS_CAIRO_API PangoFont : public CairoResource,
}
private:
- String font_family_;
+ std::string font_family_;
float font_size_;
PangoFontDescription* pango_font_description_;
};
diff --git a/include/cru/platform/graphics/cairo/PangoTextLayout.h b/include/cru/platform/graphics/cairo/PangoTextLayout.h
index cdc54e8d..270022ee 100644
--- a/include/cru/platform/graphics/cairo/PangoTextLayout.h
+++ b/include/cru/platform/graphics/cairo/PangoTextLayout.h
@@ -15,8 +15,8 @@ class CRU_PLATFORM_GRAPHICS_CAIRO_API PangoTextLayout
~PangoTextLayout() override;
public:
- String GetText() override;
- void SetText(String new_text) override;
+ std::string GetText() override;
+ void SetText(std::string new_text) override;
std::shared_ptr<IFont> GetFont() override;
void SetFont(std::shared_ptr<IFont> font) override;
@@ -40,12 +40,7 @@ class CRU_PLATFORM_GRAPHICS_CAIRO_API PangoTextLayout
PangoLayout* GetPangoLayout() { return pango_layout_; }
private:
- Index FromUtf8IndexToUtf16Index(Index index);
- Index FromUtf16IndexToUtf8Index(Index index);
-
- private:
- String text_;
- std::string utf8_text_;
+ std::string text_;
bool edit_mode_ = false;
diff --git a/include/cru/platform/gui/Base.h b/include/cru/platform/gui/Base.h
index affce4cd..f8ffbc51 100644
--- a/include/cru/platform/gui/Base.h
+++ b/include/cru/platform/gui/Base.h
@@ -1,9 +1,6 @@
#pragma once
-#include "cru/base/Base.h"
-#include "cru/base/Bitmask.h"
-#include "cru/platform/graphics/Base.h"
-
-#include "../Resource.h"
+#include <cru/platform/Base.h> // IWYU pragma: export
+#include <cru/platform/Resource.h> // IWYU pragma: export
#ifdef CRU_IS_DLL
#ifdef CRU_PLATFORM_GUI_EXPORT_API
@@ -14,30 +11,3 @@
#else
#define CRU_PLATFORM_GUI_API
#endif
-
-namespace cru::platform::gui {
-struct ICursor;
-struct ICursorManager;
-struct IUiApplication;
-struct INativeWindow;
-struct IInputMethodContext;
-struct IClipboard;
-
-namespace details {
-struct TagMouseButton {};
-} // namespace details
-
-using MouseButton = Bitmask<details::TagMouseButton>;
-struct MouseButtons {
- constexpr static MouseButton None = MouseButton::FromOffset(0);
- constexpr static MouseButton Left = MouseButton::FromOffset(1);
- constexpr static MouseButton Middle = MouseButton::FromOffset(2);
- constexpr static MouseButton Right = MouseButton::FromOffset(3);
-};
-
-namespace mouse_buttons {
-constexpr MouseButton left{MouseButtons::Left};
-constexpr MouseButton middle{MouseButtons::Middle};
-constexpr MouseButton right{MouseButtons::Right};
-} // namespace mouse_buttons
-} // namespace cru::platform::gui
diff --git a/include/cru/platform/gui/Clipboard.h b/include/cru/platform/gui/Clipboard.h
index 47267895..63932683 100644
--- a/include/cru/platform/gui/Clipboard.h
+++ b/include/cru/platform/gui/Clipboard.h
@@ -3,7 +3,7 @@
namespace cru::platform::gui {
struct IClipboard : virtual IPlatformResource {
- virtual String GetText() = 0;
- virtual void SetText(String text) = 0;
+ virtual std::string GetText() = 0;
+ virtual void SetText(std::string text) = 0;
};
} // namespace cru::platform::gui
diff --git a/include/cru/platform/gui/Keyboard.h b/include/cru/platform/gui/Input.h
index 97665e41..dca064d4 100644
--- a/include/cru/platform/gui/Keyboard.h
+++ b/include/cru/platform/gui/Input.h
@@ -1,8 +1,23 @@
#pragma once
-#include "cru/base/Bitmask.h"
-#include "cru/platform/gui/Base.h"
+#include "Base.h"
+
+#include <cru/base/Bitmask.h>
+
+#include <string>
namespace cru::platform::gui {
+namespace details {
+struct TagMouseButton {};
+} // namespace details
+
+using MouseButton = Bitmask<details::TagMouseButton>;
+struct MouseButtons {
+ constexpr static MouseButton None = MouseButton::FromOffset(0);
+ constexpr static MouseButton Left = MouseButton::FromOffset(1);
+ constexpr static MouseButton Middle = MouseButton::FromOffset(2);
+ constexpr static MouseButton Right = MouseButton::FromOffset(3);
+};
+
// Because of the complexity of keyboard layout, I only add code in US keyboard
// layout, the most widely used layout in China. We should try to make it easy
// to add new keyboard layout.
@@ -123,20 +138,15 @@ struct KeyModifiers {
static constexpr KeyModifier Ctrl = KeyModifier::FromOffset(2);
static constexpr KeyModifier Alt = KeyModifier::FromOffset(3);
static constexpr KeyModifier Command = KeyModifier::FromOffset(4);
- static constexpr KeyModifier none = None;
- static constexpr KeyModifier shift = Shift;
- static constexpr KeyModifier ctrl = Ctrl;
- static constexpr KeyModifier alt = Alt;
- static constexpr KeyModifier command = Command;
};
#ifdef CRU_PLATFORM_OSX
-constexpr KeyModifier kKeyModifierCommand = KeyModifiers::command;
+constexpr KeyModifier kKeyModifierCommand = KeyModifiers::Command;
#else
-constexpr KeyModifier kKeyModifierCommand = KeyModifiers::ctrl;
+constexpr KeyModifier kKeyModifierCommand = KeyModifiers::Ctrl;
#endif
-CRU_PLATFORM_GUI_API String ToString(KeyCode key_code);
-CRU_PLATFORM_GUI_API String ToString(KeyModifier key_modifier,
- StringView separator = u"+");
+CRU_PLATFORM_GUI_API std::string ToString(KeyCode key_code);
+CRU_PLATFORM_GUI_API std::string ToString(KeyModifier key_modifier,
+ std::string_view separator = "+");
} // namespace cru::platform::gui
diff --git a/include/cru/platform/gui/InputMethod.h b/include/cru/platform/gui/InputMethod.h
index b4a1e9d9..d178cb8a 100644
--- a/include/cru/platform/gui/InputMethod.h
+++ b/include/cru/platform/gui/InputMethod.h
@@ -1,9 +1,9 @@
#pragma once
#include "Base.h"
-#include "cru/base/Event.h"
+#include <cru/base/Event.h>
+#include <cru/platform/GraphicsBase.h>
-#include <memory>
#include <vector>
namespace cru::platform::gui {
@@ -16,7 +16,7 @@ struct CompositionClause {
using CompositionClauses = std::vector<CompositionClause>;
struct CompositionText {
- String text;
+ std::string text;
CompositionClauses clauses;
TextRange selection;
};
@@ -61,6 +61,6 @@ struct IInputMethodContext : virtual IPlatformResource {
virtual IEvent<std::nullptr_t>* CompositionStartEvent() = 0;
virtual IEvent<std::nullptr_t>* CompositionEndEvent() = 0;
virtual IEvent<std::nullptr_t>* CompositionEvent() = 0;
- virtual IEvent<StringView>* TextEvent() = 0;
+ virtual IEvent<std::string>* TextEvent() = 0;
};
} // namespace cru::platform::gui
diff --git a/include/cru/platform/gui/Menu.h b/include/cru/platform/gui/Menu.h
index 6e2a8902..d076ca69 100644
--- a/include/cru/platform/gui/Menu.h
+++ b/include/cru/platform/gui/Menu.h
@@ -1,7 +1,6 @@
#pragma once
#include "Base.h"
-
-#include "Keyboard.h"
+#include "Input.h"
#include <functional>
@@ -9,8 +8,8 @@ namespace cru::platform::gui {
struct IMenu;
struct CRU_PLATFORM_GUI_API IMenuItem : virtual IPlatformResource {
- virtual String GetTitle() = 0;
- virtual void SetTitle(String title) = 0;
+ virtual std::string GetTitle() = 0;
+ virtual void SetTitle(std::string title) = 0;
virtual bool IsEnabled() = 0;
virtual void SetEnabled(bool enabled) = 0;
virtual IMenu* GetParentMenu() = 0;
diff --git a/include/cru/platform/gui/SaveOpenDialogOptions.h b/include/cru/platform/gui/SaveOpenDialogOptions.h
index cff4a44f..484a1552 100644
--- a/include/cru/platform/gui/SaveOpenDialogOptions.h
+++ b/include/cru/platform/gui/SaveOpenDialogOptions.h
@@ -1,12 +1,15 @@
#pragma once
#include "Base.h"
+#include <string>
+#include <vector>
+
namespace cru::platform::gui {
struct CRU_PLATFORM_GUI_API SaveDialogOptions {
- String title;
- String prompt;
- String message;
- std::vector<String> allowed_file_types;
+ std::string title;
+ std::string prompt;
+ std::string message;
+ std::vector<std::string> allowed_file_types;
bool allow_all_file_types = false;
};
@@ -20,29 +23,29 @@ template <typename T>
struct CRU_PLATFORM_GUI_API SaveDialogOptionsBuilderTemplate {
T options;
- SaveDialogOptionsBuilderTemplate& SetTitle(String title) {
+ SaveDialogOptionsBuilderTemplate& SetTitle(std::string title) {
options.title = std::move(title);
return *this;
}
- SaveDialogOptionsBuilderTemplate& SetPrompt(String prompt) {
+ SaveDialogOptionsBuilderTemplate& SetPrompt(std::string prompt) {
options.prompt = std::move(prompt);
return *this;
}
- SaveDialogOptionsBuilderTemplate& SetMessage(String message) {
+ SaveDialogOptionsBuilderTemplate& SetMessage(std::string message) {
options.message = std::move(message);
return *this;
}
SaveDialogOptionsBuilderTemplate& SetAllowedFileTypes(
- std::vector<String> allowed_file_types) {
+ std::vector<std::string> allowed_file_types) {
options.allowed_file_types = std::move(allowed_file_types);
return *this;
}
SaveDialogOptionsBuilderTemplate& AddAllowedFileType(
- String allowed_file_type) {
+ std::string allowed_file_type) {
options.allowed_file_types.push_back(allowed_file_type);
return *this;
}
diff --git a/include/cru/platform/gui/UiApplication.h b/include/cru/platform/gui/UiApplication.h
index b44a450f..d15a3c72 100644
--- a/include/cru/platform/gui/UiApplication.h
+++ b/include/cru/platform/gui/UiApplication.h
@@ -1,17 +1,20 @@
#pragma once
#include "Base.h"
-
-#include "cru/base/Bitmask.h"
-#include "cru/platform/gui/Menu.h"
-
+#include "Menu.h"
#include "SaveOpenDialogOptions.h"
+#include <cru/platform/graphics/Factory.h>
+
#include <chrono>
#include <functional>
-#include <memory>
#include <vector>
namespace cru::platform::gui {
+struct ICursorManager;
+struct INativeWindow;
+struct IInputMethodContext;
+struct IClipboard;
+
// The entry point of a ui application.
struct CRU_PLATFORM_GUI_API IUiApplication : public virtual IPlatformResource {
public:
@@ -63,12 +66,12 @@ struct CRU_PLATFORM_GUI_API IUiApplication : public virtual IPlatformResource {
/**
* \todo Implement on Windows/X11.
*/
- virtual std::optional<String> ShowSaveDialog(SaveDialogOptions options);
+ virtual std::optional<std::string> ShowSaveDialog(SaveDialogOptions options);
/**
* \todo Implement on Windows/X11.
*/
- virtual std::optional<std::vector<String>> ShowOpenDialog(
+ virtual std::optional<std::vector<std::string>> ShowOpenDialog(
OpenDialogOptions options);
};
} // namespace cru::platform::gui
diff --git a/include/cru/platform/gui/Window.h b/include/cru/platform/gui/Window.h
index 06fbdb65..3be5b21b 100644
--- a/include/cru/platform/gui/Window.h
+++ b/include/cru/platform/gui/Window.h
@@ -1,11 +1,16 @@
#pragma once
#include "Base.h"
-#include "Keyboard.h"
+#include "Input.h"
-#include "cru/base/Event.h"
+#include <cru/base/Event.h>
+#include <cru/platform/GraphicsBase.h>
+#include <cru/platform/graphics/Painter.h>
namespace cru::platform::gui {
+class ICursor;
+class IInputMethodContext;
+
namespace details {
struct WindowStyleFlagTag;
}
@@ -53,8 +58,8 @@ struct CRU_PLATFORM_GUI_API INativeWindow : virtual IPlatformResource {
virtual WindowStyleFlag GetStyleFlag() = 0;
virtual void SetStyleFlag(WindowStyleFlag flag) = 0;
- virtual String GetTitle() = 0;
- virtual void SetTitle(String title) = 0;
+ virtual std::string GetTitle() = 0;
+ virtual void SetTitle(std::string title) = 0;
virtual WindowVisibilityType GetVisibility() = 0;
virtual void SetVisibility(WindowVisibilityType visibility) = 0;
diff --git a/include/cru/platform/gui/osx/Keyboard.h b/include/cru/platform/gui/osx/Keyboard.h
index 89e0fa05..619fdd1f 100644
--- a/include/cru/platform/gui/osx/Keyboard.h
+++ b/include/cru/platform/gui/osx/Keyboard.h
@@ -1,5 +1,5 @@
#pragma once
-#include "cru/platform/gui/Keyboard.h"
+#include <cru/platform/gui/Input.h>
namespace cru::platform::gui::osx {
KeyCode KeyCodeFromOsxToCru(unsigned short n);
diff --git a/include/cru/platform/gui/sdl/Base.h b/include/cru/platform/gui/sdl/Base.h
index 9dd2eff6..0de2fd1f 100644
--- a/include/cru/platform/gui/sdl/Base.h
+++ b/include/cru/platform/gui/sdl/Base.h
@@ -8,13 +8,13 @@
namespace cru::platform::gui::sdl {
class SdlResource : public Object, public virtual IPlatformResource {
public:
- static constexpr const char16_t* kPlatformId = u"SDL";
+ static constexpr const char* kPlatformId = "SDL";
protected:
SdlResource() = default;
public:
- String GetPlatformId() const final { return String(kPlatformId); }
+ std::string GetPlatformId() const final { return kPlatformId; }
};
class SdlException : public PlatformException {
diff --git a/include/cru/platform/gui/sdl/Window.h b/include/cru/platform/gui/sdl/Window.h
index 1bcd42bf..4eb0a11d 100644
--- a/include/cru/platform/gui/sdl/Window.h
+++ b/include/cru/platform/gui/sdl/Window.h
@@ -29,8 +29,8 @@ class SdlWindow : public SdlResource, public virtual INativeWindow {
WindowStyleFlag GetStyleFlag() override;
void SetStyleFlag(WindowStyleFlag flag) override;
- String GetTitle() override;
- void SetTitle(String title) override;
+ std::string GetTitle() override;
+ void SetTitle(std::string title) override;
WindowVisibilityType GetVisibility() override;
void SetVisibility(WindowVisibilityType visibility) override;
diff --git a/include/cru/platform/gui/win/Keyboard.h b/include/cru/platform/gui/win/Keyboard.h
index 18b37b60..c98c49a3 100644
--- a/include/cru/platform/gui/win/Keyboard.h
+++ b/include/cru/platform/gui/win/Keyboard.h
@@ -1,7 +1,7 @@
#pragma once
#include "Base.h"
-#include "cru/platform/gui/Keyboard.h"
+#include <cru/platform/gui/Input.h>
namespace cru::platform::gui::win {
KeyCode CRU_WIN_GUI_API VirtualKeyToKeyCode(int virtual_key);
diff --git a/include/cru/platform/gui/xcb/Base.h b/include/cru/platform/gui/xcb/Base.h
index ad571a40..71007f87 100644
--- a/include/cru/platform/gui/xcb/Base.h
+++ b/include/cru/platform/gui/xcb/Base.h
@@ -1,19 +1,19 @@
#pragma once
#include <cru/base/Exception.h>
-
-#include "../../Resource.h"
+#include <cru/platform/Resource.h>
+#include <cru/platform/gui/Base.h>
namespace cru::platform::gui::xcb {
class XcbResource : public Object, public virtual IPlatformResource {
public:
- static constexpr const char16_t* kPlatformId = u"XCB";
+ static constexpr const char* kPlatformId = "XCB";
protected:
XcbResource() = default;
public:
- String GetPlatformId() const final { return String(kPlatformId); }
+ std::string GetPlatformId() const final { return std::string(kPlatformId); }
};
class XcbException : public PlatformException {
diff --git a/include/cru/platform/gui/xcb/Clipboard.h b/include/cru/platform/gui/xcb/Clipboard.h
index 44294cbc..690cd2b1 100644
--- a/include/cru/platform/gui/xcb/Clipboard.h
+++ b/include/cru/platform/gui/xcb/Clipboard.h
@@ -10,8 +10,8 @@ class XcbClipboard : public XcbResource, public virtual IClipboard {
explicit XcbClipboard(XcbUiApplication* application);
~XcbClipboard() override;
- String GetText() override;
- void SetText(String text) override;
+ std::string GetText() override;
+ void SetText(std::string text) override;
private:
XcbUiApplication* application_;
diff --git a/include/cru/platform/gui/xcb/Cursor.h b/include/cru/platform/gui/xcb/Cursor.h
index 02ede7dd..03399333 100644
--- a/include/cru/platform/gui/xcb/Cursor.h
+++ b/include/cru/platform/gui/xcb/Cursor.h
@@ -1,9 +1,10 @@
#pragma once
-#include <cru/base/io/Stream.h>
-#include "../Cursor.h"
#include "Base.h"
+#include <cru/base/io/Stream.h>
+#include <cru/platform/gui/Cursor.h>
+
#include <xcb/xcb.h>
#include <xcb/xcb_cursor.h>
#include <memory>
diff --git a/include/cru/platform/gui/xcb/Keyboard.h b/include/cru/platform/gui/xcb/Input.h
index adff95c1..77e213de 100644
--- a/include/cru/platform/gui/xcb/Keyboard.h
+++ b/include/cru/platform/gui/xcb/Input.h
@@ -1,6 +1,6 @@
#pragma once
-#include <cru/platform/gui/Keyboard.h>
+#include <cru/platform/gui/Input.h>
#include <xcb/xcb.h>
#include <xkbcommon/xkbcommon.h>
diff --git a/include/cru/platform/gui/xcb/InputMethod.h b/include/cru/platform/gui/xcb/InputMethod.h
index c5ffd416..e32ed63e 100644
--- a/include/cru/platform/gui/xcb/InputMethod.h
+++ b/include/cru/platform/gui/xcb/InputMethod.h
@@ -1,9 +1,10 @@
#pragma once
-#include <cru/base/Base.h>
-#include "../InputMethod.h"
#include "Base.h"
+#include <cru/base/Base.h>
+#include <cru/platform/gui/InputMethod.h>
+
#include <xcb-imdkit/imclient.h>
#include <xcb/xcb.h>
#include <optional>
@@ -66,7 +67,7 @@ class XcbXimInputMethodContext : public XcbResource,
IEvent<std::nullptr_t>* CompositionStartEvent() override;
IEvent<std::nullptr_t>* CompositionEndEvent() override;
IEvent<std::nullptr_t>* CompositionEvent() override;
- IEvent<StringView>* TextEvent() override;
+ IEvent<std::string>* TextEvent() override;
private:
void CreateIc(xcb_window_t window);
@@ -83,6 +84,6 @@ class XcbXimInputMethodContext : public XcbResource,
Event<std::nullptr_t> composition_start_event_;
Event<std::nullptr_t> composition_end_event_;
Event<std::nullptr_t> composition_event_;
- Event<StringView> text_event_;
+ Event<std::string> text_event_;
};
} // namespace cru::platform::gui::xcb
diff --git a/include/cru/platform/gui/xcb/UiApplication.h b/include/cru/platform/gui/xcb/UiApplication.h
index ab481c79..55138fd3 100644
--- a/include/cru/platform/gui/xcb/UiApplication.h
+++ b/include/cru/platform/gui/xcb/UiApplication.h
@@ -1,9 +1,9 @@
#pragma once
-#include "../UiApplication.h"
#include "Base.h"
#include <cru/base/platform/unix/EventLoop.h>
#include <cru/platform/graphics/cairo/CairoGraphicsFactory.h>
+#include <cru/platform/gui/UiApplication.h>
#include <xcb/xcb.h>
#include <functional>
diff --git a/include/cru/platform/gui/xcb/Window.h b/include/cru/platform/gui/xcb/Window.h
index 5f1fd66e..bfd86297 100644
--- a/include/cru/platform/gui/xcb/Window.h
+++ b/include/cru/platform/gui/xcb/Window.h
@@ -1,11 +1,10 @@
#pragma once
-#include <cru/base/Base.h>
-#include "../../GraphicsBase.h"
-#include "../TimerHelper.h"
-#include "../Window.h"
#include "Base.h"
+#include <cru/platform/gui/TimerHelper.h>
+#include <cru/platform/gui/Window.h>
+
#include <cairo.h>
#include <xcb/xcb.h>
#include <cstddef>
@@ -34,8 +33,8 @@ class XcbWindow : public XcbResource, public virtual INativeWindow {
WindowStyleFlag GetStyleFlag() override;
void SetStyleFlag(WindowStyleFlag flag) override;
- String GetTitle() override;
- void SetTitle(String title) override;
+ std::string GetTitle() override;
+ void SetTitle(std::string title) override;
WindowVisibilityType GetVisibility() override;
void SetVisibility(WindowVisibilityType visibility) override;
diff --git a/include/cru/ui/Base.h b/include/cru/ui/Base.h
index b4b2f18e..3f270b39 100644
--- a/include/cru/ui/Base.h
+++ b/include/cru/ui/Base.h
@@ -1,7 +1,9 @@
#pragma once
-#include "cru/base/Base.h"
-#include "cru/platform/graphics/Base.h"
-#include "cru/platform/gui/Base.h"
+#include <cru/base/Base.h>
+#include <cru/platform/Color.h>
+#include <cru/platform/GraphicsBase.h>
+#include <cru/platform/Matrix.h>
+#include <cru/platform/gui/Input.h>
#ifdef CRU_IS_DLL
#ifdef CRU_UI_EXPORT_API
@@ -25,8 +27,7 @@ using cru::platform::Size;
using cru::platform::TextRange;
using cru::platform::Thickness;
using cru::platform::gui::MouseButton;
-
-namespace mouse_buttons = cru::platform::gui::mouse_buttons;
+using cru::platform::gui::MouseButtons;
namespace colors = cru::platform::colors;
diff --git a/include/cru/ui/ThemeManager.h b/include/cru/ui/ThemeManager.h
index 72ade899..10d90060 100644
--- a/include/cru/ui/ThemeManager.h
+++ b/include/cru/ui/ThemeManager.h
@@ -27,7 +27,7 @@ class CRU_UI_API ThemeManager : public Object {
std::unique_ptr<ThemeResourceDictionary> theme_resource_dictionary);
template <typename T>
- T GetResource(const String& key) {
+ T GetResource(std::string_view key) {
for (const auto& resource_dictionary : theme_resource_dictionary_list_) {
try {
return resource_dictionary->GetResource<T>(key);
@@ -35,18 +35,19 @@ class CRU_UI_API ThemeManager : public Object {
}
}
throw ThemeResourceKeyNotExistException(
- std::format("Theme resource key {} not exist.", key.ToUtf8()));
+ std::format("Theme resource key {} not exist.", key));
}
- String GetResourceString(const String& key);
+ std::string GetResourceString(std::string_view key);
std::shared_ptr<platform::graphics::IBrush> GetResourceBrush(
- const String& key);
+ std::string_view key);
- std::shared_ptr<platform::graphics::IFont> GetResourceFont(const String& key);
+ std::shared_ptr<platform::graphics::IFont> GetResourceFont(
+ std::string_view key);
std::shared_ptr<style::StyleRuleSet> GetResourceStyleRuleSet(
- const String& key);
+ std::string_view key);
IEvent<std::nullptr_t>* ThemeResourceChangeEvent() {
return &theme_resource_change_event_;
diff --git a/include/cru/ui/ThemeResourceDictionary.h b/include/cru/ui/ThemeResourceDictionary.h
index 0cbda01b..90cbe520 100644
--- a/include/cru/ui/ThemeResourceDictionary.h
+++ b/include/cru/ui/ThemeResourceDictionary.h
@@ -44,11 +44,11 @@ class CRU_UI_API ThemeResourceDictionary : public Object {
public:
template <typename T>
- T GetResource(const String& key) {
- auto find_result = resource_map_.find(key);
+ T GetResource(std::string_view key) {
+ auto find_result = resource_map_.find(std::string(key));
if (find_result == resource_map_.cend()) {
throw ThemeResourceKeyNotExistException(
- std::format("Theme resource key {} not exist.", key.ToUtf8()));
+ std::format("Theme resource key {} not exist.", key));
}
auto& cache = find_result->second.cache;
@@ -73,12 +73,12 @@ class CRU_UI_API ThemeResourceDictionary : public Object {
CRU_DEFAULT_COPY(ResourceEntry)
CRU_DEFAULT_MOVE(ResourceEntry)
- String name;
+ std::string name;
xml::XmlElementNode* xml_node;
std::unordered_map<std::type_index, std::any> cache;
};
std::unique_ptr<xml::XmlElementNode> xml_root_;
- std::unordered_map<String, ResourceEntry> resource_map_;
+ std::unordered_map<std::string, ResourceEntry> resource_map_;
};
} // namespace cru::ui
diff --git a/include/cru/ui/components/Input.h b/include/cru/ui/components/Input.h
index e808afd7..0f077983 100644
--- a/include/cru/ui/components/Input.h
+++ b/include/cru/ui/components/Input.h
@@ -5,17 +5,17 @@
namespace cru::ui::components {
struct CRU_UI_API InputValidateResult {
bool valid;
- String message;
+ std::string message;
};
struct CRU_UI_API IInputValidator : public virtual Interface {
- virtual InputValidateResult Validate(StringView text) const = 0;
+ virtual InputValidateResult Validate(std::string_view text) const = 0;
};
struct CRU_UI_API InputChangeEventArgs {
- String text;
+ std::string text;
bool valid;
- String message;
+ std::string message;
};
class CRU_UI_API Input : public Component {
@@ -26,8 +26,8 @@ class CRU_UI_API Input : public Component {
public:
controls::Control* GetRootControl() override;
- String GetText() const;
- void SetText(String text);
+ std::string GetText() const;
+ void SetText(std::string text);
IInputValidator* GetValidator() const;
void SetValidator(IInputValidator* validator);
@@ -48,7 +48,7 @@ class CRU_UI_API Input : public Component {
class CRU_UI_API FloatInputValidator : public Object,
public virtual IInputValidator {
public:
- InputValidateResult Validate(StringView text) const override;
+ InputValidateResult Validate(std::string_view text) const override;
std::optional<float> min;
std::optional<float> max;
diff --git a/include/cru/ui/components/Menu.h b/include/cru/ui/components/Menu.h
index 913f5c92..554a8898 100644
--- a/include/cru/ui/components/Menu.h
+++ b/include/cru/ui/components/Menu.h
@@ -14,7 +14,7 @@ namespace cru::ui::components {
class CRU_UI_API MenuItem : public Component {
public:
MenuItem();
- explicit MenuItem(String text);
+ explicit MenuItem(std::string text);
CRU_DELETE_COPY(MenuItem)
CRU_DELETE_MOVE(MenuItem)
@@ -24,7 +24,7 @@ class CRU_UI_API MenuItem : public Component {
public:
controls::Control* GetRootControl() override { return &container_; }
- void SetText(String text);
+ void SetText(std::string text);
void SetOnClick(std::function<void()> on_click) {
on_click_ = std::move(on_click);
@@ -55,10 +55,10 @@ class CRU_UI_API Menu : public Component {
Component* RemoveItemAt(Index index);
void ClearItems();
- void AddTextItem(String text, std::function<void()> on_click) {
+ void AddTextItem(std::string text, std::function<void()> on_click) {
AddTextItemAt(std::move(text), GetItemCount(), std::move(on_click));
}
- void AddTextItemAt(String text, Index index, std::function<void()> on_click);
+ void AddTextItemAt(std::string text, Index index, std::function<void()> on_click);
void SetOnItemClick(std::function<void(Index)> on_item_click) {
on_item_click_ = std::move(on_item_click);
diff --git a/include/cru/ui/components/PopupButton.h b/include/cru/ui/components/PopupButton.h
index c8ef9c50..5fa69044 100644
--- a/include/cru/ui/components/PopupButton.h
+++ b/include/cru/ui/components/PopupButton.h
@@ -18,14 +18,14 @@ class CRU_UI_API PopupMenuTextButton : public Component {
ui::controls::Button* GetButton() { return &button_; }
- String GetButtonText() { return button_text_.GetText(); }
- void SetButtonText(String text) { button_text_.SetText(std::move(text)); }
+ std::string GetButtonText() { return button_text_.GetText(); }
+ void SetButtonText(std::string text) { button_text_.SetText(std::move(text)); }
void SetButtonTextColor(const Color& color) {
button_text_.SetTextColor(color);
}
- void SetMenuItems(std::vector<String> items);
+ void SetMenuItems(std::vector<std::string> items);
IEvent<Index>* MenuItemSelectedEvent() { return &menu_item_selected_event_; }
@@ -47,7 +47,7 @@ class CRU_UI_API PopupMenuIconButton : public Component {
ui::controls::IconButton* GetButton() { return &button_; }
- void SetMenuItems(std::vector<String> items);
+ void SetMenuItems(std::vector<std::string> items);
IEvent<Index>* MenuItemSelectedEvent() { return &menu_item_selected_event_; }
diff --git a/include/cru/ui/components/Select.h b/include/cru/ui/components/Select.h
index d5ff0b43..9efe9a04 100644
--- a/include/cru/ui/components/Select.h
+++ b/include/cru/ui/components/Select.h
@@ -13,8 +13,8 @@ class CRU_UI_API Select : public Component {
public:
ui::controls::Control* GetRootControl() override { return &button_; }
- std::vector<String> GetItems() const { return items_; }
- void SetItems(std::vector<String> items);
+ std::vector<std::string> GetItems() const { return items_; }
+ void SetItems(std::vector<std::string> items);
Index GetSelectedIndex() const { return selected_index_; }
void SetSelectedIndex(Index index);
@@ -23,7 +23,7 @@ class CRU_UI_API Select : public Component {
private:
Index selected_index_;
- std::vector<String> items_;
+ std::vector<std::string> items_;
ui::controls::Button button_;
ui::controls::TextBlock button_text_;
diff --git a/include/cru/ui/controls/IconButton.h b/include/cru/ui/controls/IconButton.h
index 632450e2..9dbb3a3d 100644
--- a/include/cru/ui/controls/IconButton.h
+++ b/include/cru/ui/controls/IconButton.h
@@ -21,7 +21,7 @@ class CRU_UI_API IconButton : public NoChildControl,
public:
IconButton();
- IconButton(StringView icon_svg_path_data_string, const Rect& view_port);
+ IconButton(std::string_view icon_svg_path_data_string, const Rect& view_port);
~IconButton() override;
String GetControlType() const final { return kControlType.ToString(); }
@@ -84,10 +84,10 @@ class CRU_UI_API IconButton : public NoChildControl,
}
void SetIconFillColor(const Color& color);
- void SetIconWithSvgPathDataString(StringView icon_svg_path_data_string,
+ void SetIconWithSvgPathDataString(std::string_view icon_svg_path_data_string,
const Rect& view_port);
void SetIconWithSvgPathDataStringResourceKey(
- StringView icon_svg_path_data_string_resource_key, const Rect& view_port);
+ std::string_view icon_svg_path_data_string_resource_key, const Rect& view_port);
std::shared_ptr<platform::graphics::IBrush> GetContentBrush() const override {
return GetIconFillBrush();
diff --git a/include/cru/ui/controls/TextBlock.h b/include/cru/ui/controls/TextBlock.h
index 52e227eb..66330b23 100644
--- a/include/cru/ui/controls/TextBlock.h
+++ b/include/cru/ui/controls/TextBlock.h
@@ -16,8 +16,8 @@ class CRU_UI_API TextBlock : public NoChildControl,
public:
static constexpr StringView kControlType = u"TextBlock";
- static std::unique_ptr<TextBlock> Create(String text,
- bool selectable = false) {
+ static std::unique_ptr<TextBlock> Create(std::string text,
+ bool selectable = false) {
auto c = std::make_unique<TextBlock>();
c->SetText(std::move(text));
c->SetSelectable(selectable);
@@ -36,8 +36,8 @@ class CRU_UI_API TextBlock : public NoChildControl,
render::RenderObject* GetRenderObject() const override;
- String GetText() const;
- void SetText(String text);
+ std::string GetText() const;
+ void SetText(std::string text);
bool IsSelectable() const;
void SetSelectable(bool value);
diff --git a/include/cru/ui/controls/TextBox.h b/include/cru/ui/controls/TextBox.h
index 9388d3fd..13f5d356 100644
--- a/include/cru/ui/controls/TextBox.h
+++ b/include/cru/ui/controls/TextBox.h
@@ -37,9 +37,9 @@ class CRU_UI_API TextBox : public NoChildControl,
void ApplyBorderStyle(const style::ApplyBorderStyleInfo& style) override;
- String GetText() const { return service_->GetText(); }
- StringView GetTextView() const { return service_->GetTextView(); }
- void SetText(String text) { service_->SetText(std::move(text)); }
+ std::string GetText() const { return service_->GetText(); }
+ std::string_view GetTextView() const { return service_->GetTextView(); }
+ void SetText(std::string text) { service_->SetText(std::move(text)); }
IEvent<std::nullptr_t>* TextChangeEvent() {
return service_->TextChangeEvent();
diff --git a/include/cru/ui/controls/TextHostControlService.h b/include/cru/ui/controls/TextHostControlService.h
index 95f7a067..a945e427 100644
--- a/include/cru/ui/controls/TextHostControlService.h
+++ b/include/cru/ui/controls/TextHostControlService.h
@@ -48,10 +48,10 @@ class TextControlMovePattern : public Object {
static std::vector<TextControlMovePattern> kDefaultPatterns;
using MoveFunction =
- std::function<Index(TextHostControlService* service, StringView text,
- Index current_position)>;
+ std::function<Index(TextHostControlService* service,
+ std::string_view text, Index current_position)>;
- TextControlMovePattern(String name, helper::ShortcutKeyBind key_bind,
+ TextControlMovePattern(std::string name, helper::ShortcutKeyBind key_bind,
MoveFunction move_function)
: name_(std::move(name)),
key_bind_(key_bind),
@@ -63,15 +63,15 @@ class TextControlMovePattern : public Object {
~TextControlMovePattern() override = default;
public:
- String GetName() const { return name_; }
+ std::string GetName() const { return name_; }
helper::ShortcutKeyBind GetKeyBind() const { return key_bind_; }
- Index Move(TextHostControlService* service, StringView text,
+ Index Move(TextHostControlService* service, std::string_view text,
Index current_position) const {
return move_function_(service, text, current_position);
}
private:
- String name_;
+ std::string name_;
helper::ShortcutKeyBind key_bind_;
MoveFunction move_function_;
};
@@ -101,11 +101,11 @@ class CRU_UI_API TextHostControlService : public Object {
// If text contains line feed characters, it will be converted to space.
void SetMultiLine(bool multi_line);
- String GetText() { return this->text_; }
- StringView GetTextView() { return this->text_; }
- void SetText(String text, bool stop_composition = false);
+ std::string GetText() { return this->text_; }
+ std::string_view GetTextView() { return this->text_; }
+ void SetText(std::string text, bool stop_composition = false);
- void InsertText(Index position, StringView text,
+ void InsertText(Index position, std::string_view text,
bool stop_composition = false);
void DeleteChar(Index position, bool stop_composition = false);
@@ -126,7 +126,7 @@ class CRU_UI_API TextHostControlService : public Object {
Index GetCaretPosition() { return selection_.GetEnd(); }
TextRange GetSelection() { return selection_; }
- StringView GetSelectedText();
+ std::string_view GetSelectedText();
void SetSelection(Index caret_position);
void SetSelection(TextRange selection, bool scroll_to_caret = true);
@@ -139,7 +139,7 @@ class CRU_UI_API TextHostControlService : public Object {
void DeleteSelectedText();
// If some text is selected, then they are deleted first. Then insert text
// into caret position.
- void ReplaceSelectedText(StringView text);
+ void ReplaceSelectedText(std::string_view text);
void ScrollToCaret();
@@ -199,7 +199,7 @@ class CRU_UI_API TextHostControlService : public Object {
EventRevokerListGuard event_guard_;
EventRevokerListGuard input_method_context_event_guard_;
- String text_;
+ std::string text_;
TextRange selection_;
bool enable_ = false;
diff --git a/include/cru/ui/events/KeyEventArgs.h b/include/cru/ui/events/KeyEventArgs.h
index 0ece9126..bf6c8c0f 100644
--- a/include/cru/ui/events/KeyEventArgs.h
+++ b/include/cru/ui/events/KeyEventArgs.h
@@ -1,7 +1,7 @@
#pragma once
#include "UiEventArgs.h"
-#include "cru/platform/gui/Keyboard.h"
+#include "cru/platform/gui/Input.h"
namespace cru::ui::events {
class CRU_UI_API KeyEventArgs : public UiEventArgs {
@@ -26,4 +26,4 @@ class CRU_UI_API KeyEventArgs : public UiEventArgs {
platform::gui::KeyModifier key_modifier_;
};
-} // namespace cru::ui::event
+} // namespace cru::ui::events
diff --git a/include/cru/ui/events/MouseButtonEventArgs.h b/include/cru/ui/events/MouseButtonEventArgs.h
index 13b3b0a4..57a84cfb 100644
--- a/include/cru/ui/events/MouseButtonEventArgs.h
+++ b/include/cru/ui/events/MouseButtonEventArgs.h
@@ -1,20 +1,21 @@
#pragma once
#include "MouseEventArgs.h"
-#include "cru/platform/gui/Keyboard.h"
+#include "cru/platform/gui/Input.h"
namespace cru::ui::events {
class CRU_UI_API MouseButtonEventArgs : public MouseEventArgs {
public:
MouseButtonEventArgs(Object* sender, Object* original_sender,
- const Point& point, const MouseButton button,
+ const Point& point,
+ const platform::gui::MouseButton button,
platform::gui::KeyModifier key_modifier)
: MouseEventArgs(sender, original_sender, point),
button_(button),
key_modifier_(key_modifier) {}
MouseButtonEventArgs(Object* sender, Object* original_sender,
- const MouseButton button,
+ const platform::gui::MouseButton button,
platform::gui::KeyModifier key_modifier)
: MouseEventArgs(sender, original_sender),
button_(button),
@@ -25,11 +26,11 @@ class CRU_UI_API MouseButtonEventArgs : public MouseEventArgs {
MouseButtonEventArgs& operator=(MouseButtonEventArgs&& other) = default;
~MouseButtonEventArgs() override = default;
- MouseButton GetButton() const { return button_; }
+ platform::gui::MouseButton GetButton() const { return button_; }
platform::gui::KeyModifier GetKeyModifier() const { return key_modifier_; }
private:
- MouseButton button_;
+ platform::gui::MouseButton button_;
platform::gui::KeyModifier key_modifier_;
};
-} // namespace cru::ui::event
+} // namespace cru::ui::events
diff --git a/include/cru/ui/events/MouseWheelEventArgs.h b/include/cru/ui/events/MouseWheelEventArgs.h
index 85791491..9ed63924 100644
--- a/include/cru/ui/events/MouseWheelEventArgs.h
+++ b/include/cru/ui/events/MouseWheelEventArgs.h
@@ -1,7 +1,7 @@
#pragma once
#include "MouseEventArgs.h"
-#include "cru/platform/gui/Keyboard.h"
+#include <cru/platform/gui/Input.h>
namespace cru::ui::events {
class CRU_UI_API MouseWheelEventArgs : public MouseEventArgs {
@@ -26,4 +26,4 @@ class CRU_UI_API MouseWheelEventArgs : public MouseEventArgs {
float delta_;
platform::gui::KeyModifier key_modifier_;
};
-} // namespace cru::ui::event
+} // namespace cru::ui::events
diff --git a/include/cru/ui/helper/ClickDetector.h b/include/cru/ui/helper/ClickDetector.h
index ec63b92a..b83f0e20 100644
--- a/include/cru/ui/helper/ClickDetector.h
+++ b/include/cru/ui/helper/ClickDetector.h
@@ -79,7 +79,7 @@ class ClickDetector : public Object {
ClickState state_ = ClickState::None;
bool enable_ = true;
- MouseButton trigger_button_ = mouse_buttons::left | mouse_buttons::right;
+ MouseButton trigger_button_ = MouseButtons::Left | MouseButtons::Right;
Event<ClickEventArgs> event_;
Event<ClickState> state_change_event_;
diff --git a/include/cru/ui/helper/ShortcutHub.h b/include/cru/ui/helper/ShortcutHub.h
index 19d8c8c9..a5973ab5 100644
--- a/include/cru/ui/helper/ShortcutHub.h
+++ b/include/cru/ui/helper/ShortcutHub.h
@@ -4,7 +4,7 @@
#include "../events/KeyEventArgs.h"
#include "cru/base/Base.h"
#include "cru/base/Event.h"
-#include "cru/platform/gui/Keyboard.h"
+#include <cru/platform/gui/Input.h>
#include <cstddef>
#include <functional>
@@ -18,7 +18,7 @@ class ShortcutKeyBind {
public:
ShortcutKeyBind(
platform::gui::KeyCode key,
- platform::gui::KeyModifier modifier = platform::gui::KeyModifiers::none)
+ platform::gui::KeyModifier modifier = platform::gui::KeyModifiers::None)
: key_(key), modifier_(modifier) {}
CRU_DEFAULT_COPY(ShortcutKeyBind)
@@ -46,10 +46,10 @@ class ShortcutKeyBind {
return !this->operator==(other);
}
- String ToString() const {
- String result = u"(";
+ std::string ToString() const {
+ std::string result = "(";
result += platform::gui::ToString(modifier_);
- result += u")";
+ result += ")";
result += platform::gui::ToString(key_);
return result;
}
@@ -59,7 +59,7 @@ class ShortcutKeyBind {
platform::gui::KeyModifier modifier_;
};
-inline String ToString(const ShortcutKeyBind& key_bind) {
+inline std::string ToString(const ShortcutKeyBind& key_bind) {
return key_bind.ToString();
}
} // namespace cru::ui::helper
@@ -79,7 +79,7 @@ struct hash<cru::ui::helper::ShortcutKeyBind> {
namespace cru::ui::helper {
struct Shortcut {
// Just for debug.
- String name;
+ std::string name;
ShortcutKeyBind key_bind;
// Return true if it consumes the shortcut. Or return false if it does not
// handle the shortcut.
@@ -88,7 +88,7 @@ struct Shortcut {
struct ShortcutInfo {
int id;
- String name;
+ std::string name;
ShortcutKeyBind key_bind;
std::function<bool()> handler;
};
@@ -103,7 +103,7 @@ class CRU_UI_API ShortcutHub : public Object {
~ShortcutHub() override = default;
- int RegisterShortcut(String name, ShortcutKeyBind bind,
+ int RegisterShortcut(std::string name, ShortcutKeyBind bind,
std::function<bool()> handler) {
return RegisterShortcut({std::move(name), bind, std::move(handler)});
}
diff --git a/include/cru/ui/mapper/Mapper.h b/include/cru/ui/mapper/Mapper.h
index f7467120..709288f5 100644
--- a/include/cru/ui/mapper/Mapper.h
+++ b/include/cru/ui/mapper/Mapper.h
@@ -41,14 +41,14 @@ class CRU_UI_API MapperBase : public Object {
virtual bool XmlElementIsOfThisType(xml::XmlElementNode* node);
protected:
- void SetAllowedTags(std::vector<String> allowed_tags) {
+ void SetAllowedTags(std::vector<std::string> allowed_tags) {
allowed_tags_ = std::move(allowed_tags);
}
private:
std::type_index type_index_;
- std::vector<String> allowed_tags_;
+ std::vector<std::string> allowed_tags_;
};
template <typename T>
diff --git a/include/cru/ui/mapper/StringMapper.h b/include/cru/ui/mapper/StringMapper.h
index bfb7314b..01f58c77 100644
--- a/include/cru/ui/mapper/StringMapper.h
+++ b/include/cru/ui/mapper/StringMapper.h
@@ -1,6 +1,8 @@
#pragma once
#include "Mapper.h"
+#include <cru/base/String.h>
+
namespace cru::ui::mapper {
class CRU_UI_API StringMapper : public BasicMapper<String> {
public:
diff --git a/include/cru/ui/render/RenderObject.h b/include/cru/ui/render/RenderObject.h
index 80fa2e10..eba3b6c4 100644
--- a/include/cru/ui/render/RenderObject.h
+++ b/include/cru/ui/render/RenderObject.h
@@ -4,6 +4,8 @@
#include "MeasureRequirement.h"
#include "cru/base/String.h"
+#include <cru/platform/graphics/Painter.h>
+
namespace cru::ui::render {
struct BoxConstraint {
static const BoxConstraint kNotLimit;
diff --git a/include/cru/ui/render/ScrollBar.h b/include/cru/ui/render/ScrollBar.h
index 45f80389..fbe14244 100644
--- a/include/cru/ui/render/ScrollBar.h
+++ b/include/cru/ui/render/ScrollBar.h
@@ -39,7 +39,7 @@ enum class ScrollBarAreaKind {
enum class ScrollBarBrushUsageKind { Arrow, ArrowBackground, Slot, Thumb };
enum class ScrollBarBrushStateKind { Normal, Hover, Press, Disable };
-String CRU_UI_API GenerateScrollBarThemeColorKey(ScrollBarBrushUsageKind usage,
+std::string CRU_UI_API GenerateScrollBarThemeColorKey(ScrollBarBrushUsageKind usage,
ScrollBarBrushStateKind state);
class CRU_UI_API ScrollBar : public Object {
diff --git a/include/cru/ui/render/TextRenderObject.h b/include/cru/ui/render/TextRenderObject.h
index 72958f6f..b8d1882d 100644
--- a/include/cru/ui/render/TextRenderObject.h
+++ b/include/cru/ui/render/TextRenderObject.h
@@ -35,8 +35,8 @@ class CRU_UI_API TextRenderObject : public RenderObject {
TextRenderObject& operator=(TextRenderObject&& other) = delete;
~TextRenderObject() override;
- String GetText() const;
- void SetText(String new_text);
+ std::string GetText() const;
+ void SetText(std::string new_text);
std::shared_ptr<platform::graphics::IBrush> GetBrush() { return brush_; }
void SetBrush(std::shared_ptr<platform::graphics::IBrush> new_brush);
diff --git a/include/cru/ui/style/ApplyBorderStyleInfo.h b/include/cru/ui/style/ApplyBorderStyleInfo.h
index 2a3a7db1..857f73f8 100644
--- a/include/cru/ui/style/ApplyBorderStyleInfo.h
+++ b/include/cru/ui/style/ApplyBorderStyleInfo.h
@@ -1,6 +1,8 @@
#pragma once
#include "../Base.h"
+#include <cru/platform/graphics/Brush.h>
+
#include <optional>
namespace cru::ui::style {
diff --git a/src/ThemeBuilder/components/HeadBodyEditor.cpp b/src/ThemeBuilder/components/HeadBodyEditor.cpp
index 6d7ace66..3cc71d53 100644
--- a/src/ThemeBuilder/components/HeadBodyEditor.cpp
+++ b/src/ThemeBuilder/components/HeadBodyEditor.cpp
@@ -16,8 +16,8 @@ HeadBodyEditor::HeadBodyEditor() {
remove_button_.GetStyleRuleSet()->SetParent(
ui::ThemeManager::GetInstance()->GetResourceStyleRuleSet(
- u"cru.theme_builder.icon-button.style"));
- remove_button_.SetIconWithSvgPathDataStringResourceKey(u"icon.close",
+ "cru.theme_builder.icon-button.style"));
+ remove_button_.SetIconWithSvgPathDataStringResourceKey("icon.close",
{0, 0, 16, 16});
remove_button_.SetIconFillColor(ui::colors::red);
head_container_.AddChild(&remove_button_);
diff --git a/src/ThemeBuilder/components/HeadBodyEditor.h b/src/ThemeBuilder/components/HeadBodyEditor.h
index 1fcf2f63..c8671841 100644
--- a/src/ThemeBuilder/components/HeadBodyEditor.h
+++ b/src/ThemeBuilder/components/HeadBodyEditor.h
@@ -19,8 +19,8 @@ class HeadBodyEditor : public Editor {
ui::controls::FlexLayout* GetContainer() { return &container_; }
ui::controls::FlexLayout* GetHeadContainer() { return &head_container_; }
- String GetLabel() const { return label_.GetText(); }
- void SetLabel(String label) { label_.SetText(std::move(label)); }
+ std::string GetLabel() const { return label_.GetText(); }
+ void SetLabel(std::string label) { label_.SetText(std::move(label)); }
IEvent<std::nullptr_t>* RemoveEvent() { return &remove_event_; }
diff --git a/src/ThemeBuilder/components/MainWindow.cpp b/src/ThemeBuilder/components/MainWindow.cpp
index 0c78ef25..4f5812b1 100644
--- a/src/ThemeBuilder/components/MainWindow.cpp
+++ b/src/ThemeBuilder/components/MainWindow.cpp
@@ -9,12 +9,12 @@ using namespace cru::ui::controls;
using namespace cru::platform::gui;
MainWindow::MainWindow() {
- window_.GetNativeWindow()->SetTitle(u"CruUI Theme Builder");
+ window_.GetNativeWindow()->SetTitle("CruUI Theme Builder");
main_layout_.SetFlexDirection(FlexDirection::Horizontal);
window_.AddChild(&main_layout_);
main_layout_.AddChild(&preview_layout_);
- preview_button_text_.SetText(u"Preview");
+ preview_button_text_.SetText("Preview");
preview_button_.SetChild(&preview_button_text_);
preview_layout_.AddChild(&preview_button_);
preview_layout_.SetChildLayoutData(
diff --git a/src/ThemeBuilder/components/StyleRuleEditor.cpp b/src/ThemeBuilder/components/StyleRuleEditor.cpp
index dcb33184..f3de97b4 100644
--- a/src/ThemeBuilder/components/StyleRuleEditor.cpp
+++ b/src/ThemeBuilder/components/StyleRuleEditor.cpp
@@ -14,14 +14,14 @@ StyleRuleEditor::StyleRuleEditor() {
main_layout_.AddChild(&head_layout_);
- label_.SetText(u"Style Rule");
+ label_.SetText("Style Rule");
head_layout_.AddChild(&label_);
head_layout_.AddChild(&remove_button_);
remove_button_.GetStyleRuleSet()->SetParent(
ui::ThemeManager::GetInstance()->GetResourceStyleRuleSet(
- u"cru.theme_builder.icon-button.style"));
- remove_button_.SetIconWithSvgPathDataStringResourceKey(u"icon.close",
+ "cru.theme_builder.icon-button.style"));
+ remove_button_.SetIconWithSvgPathDataStringResourceKey("icon.close",
{0, 0, 16, 16});
remove_button_.SetIconFillColor(ui::colors::red);
diff --git a/src/ThemeBuilder/components/StyleRuleSetEditor.cpp b/src/ThemeBuilder/components/StyleRuleSetEditor.cpp
index 1410ff7c..ccffa591 100644
--- a/src/ThemeBuilder/components/StyleRuleSetEditor.cpp
+++ b/src/ThemeBuilder/components/StyleRuleSetEditor.cpp
@@ -23,8 +23,8 @@ StyleRuleSetEditor::StyleRuleSetEditor() {
add_button_.GetStyleRuleSet()->SetParent(
ui::ThemeManager::GetInstance()->GetResourceStyleRuleSet(
- u"cru.theme_builder.icon-button.style"));
- add_button_.SetIconWithSvgPathDataStringResourceKey(u"icon.plus",
+ "cru.theme_builder.icon-button.style"));
+ add_button_.SetIconWithSvgPathDataStringResourceKey("icon.plus",
{0, 0, 16, 16});
add_button_.SetPreferredSize({24, 24});
add_button_.SetPadding(ui::Thickness(2));
diff --git a/src/ThemeBuilder/components/conditions/CheckedConditionEditor.cpp b/src/ThemeBuilder/components/conditions/CheckedConditionEditor.cpp
index 57e72a0f..04f2ed29 100644
--- a/src/ThemeBuilder/components/conditions/CheckedConditionEditor.cpp
+++ b/src/ThemeBuilder/components/conditions/CheckedConditionEditor.cpp
@@ -4,9 +4,9 @@
namespace cru::theme_builder::components::conditions {
CheckedConditionEditor::CheckedConditionEditor() {
- SetLabel(u"Checked Condition");
+ SetLabel("Checked Condition");
- checked_check_box_.SetLabel(u"Checked");
+ checked_check_box_.SetLabel("Checked");
GetContainer()->AddChild(checked_check_box_.GetRootControl());
ConnectChangeEvent(checked_check_box_);
diff --git a/src/ThemeBuilder/components/conditions/ClickStateConditionEditor.cpp b/src/ThemeBuilder/components/conditions/ClickStateConditionEditor.cpp
index bf0b1d98..57652ef6 100644
--- a/src/ThemeBuilder/components/conditions/ClickStateConditionEditor.cpp
+++ b/src/ThemeBuilder/components/conditions/ClickStateConditionEditor.cpp
@@ -6,11 +6,11 @@
namespace cru::theme_builder::components::conditions {
using ui::helper::ClickState;
namespace {
-const std::vector<String> kClickStates{
- u"None",
- u"Hover",
- u"Press",
- u"PressInactive",
+const std::vector<std::string> kClickStates{
+ "None",
+ "Hover",
+ "Press",
+ "PressInactive",
};
Index ConvertClickStateToIndex(ClickState click_state) {
@@ -43,10 +43,10 @@ ClickState ConvertIndexToClickState(Index index) {
} // namespace
ClickStateConditionEditor::ClickStateConditionEditor() {
- SetLabel(u"Click State Condition");
+ SetLabel("Click State Condition");
GetContainer()->AddChild(click_state_select_.GetRootControl());
- click_state_select_.SetLabel(u"Click State");
+ click_state_select_.SetLabel("Click State");
click_state_select_.SetItems(kClickStates);
click_state_select_.SetSelectedIndex(0, false);
diff --git a/src/ThemeBuilder/components/conditions/CompoundConditionEditor.cpp b/src/ThemeBuilder/components/conditions/CompoundConditionEditor.cpp
index 8be3aa0f..a641c2df 100644
--- a/src/ThemeBuilder/components/conditions/CompoundConditionEditor.cpp
+++ b/src/ThemeBuilder/components/conditions/CompoundConditionEditor.cpp
@@ -14,7 +14,7 @@
namespace cru::theme_builder::components::conditions {
CompoundConditionEditor::CompoundConditionEditor() {
- SetLabel(u"Compound Condition");
+ SetLabel("Compound Condition");
GetContainer()->AddChild(&children_container_);
children_container_.SetMargin({10, 0, 0, 0});
@@ -26,15 +26,15 @@ CompoundConditionEditor::CompoundConditionEditor() {
add_child_button_.GetButton()->GetStyleRuleSet()->SetParent(
ui::ThemeManager::GetInstance()->GetResourceStyleRuleSet(
- u"cru.theme_builder.icon-button.style"));
+ "cru.theme_builder.icon-button.style"));
add_child_button_.GetButton()->SetIconWithSvgPathDataStringResourceKey(
- u"icon.plus", {0, 0, 16, 16});
+ "icon.plus", {0, 0, 16, 16});
add_child_button_.GetButton()->SetPreferredSize({24, 24});
add_child_button_.GetButton()->SetPadding(ui::Thickness(2));
add_child_button_.GetButton()->SetIconFillColor(ui::colors::green);
- add_child_button_.SetMenuItems({u"And Condition", u"Or Condition",
- u"Click State Condition", u"Focus Condition",
- u"Checked Condition", u"No Condition"});
+ add_child_button_.SetMenuItems({"And Condition", "Or Condition",
+ "Click State Condition", "Focus Condition",
+ "Checked Condition", "No Condition"});
add_child_button_.MenuItemSelectedEvent()->AddHandler([this](Index index) {
std::unique_ptr<ConditionEditor> editor;
switch (index) {
diff --git a/src/ThemeBuilder/components/conditions/FocusConditionEditor.cpp b/src/ThemeBuilder/components/conditions/FocusConditionEditor.cpp
index 78c99b5c..0ac3e224 100644
--- a/src/ThemeBuilder/components/conditions/FocusConditionEditor.cpp
+++ b/src/ThemeBuilder/components/conditions/FocusConditionEditor.cpp
@@ -4,10 +4,10 @@
namespace cru::theme_builder::components::conditions {
FocusConditionEditor::FocusConditionEditor() {
- SetLabel(u"Focus Condition");
+ SetLabel("Focus Condition");
GetContainer()->AddChild(focus_check_box_.GetRootControl());
- focus_check_box_.SetLabel(u"Focus");
+ focus_check_box_.SetLabel("Focus");
ConnectChangeEvent(focus_check_box_);
}
diff --git a/src/ThemeBuilder/components/conditions/NoConditionEditor.cpp b/src/ThemeBuilder/components/conditions/NoConditionEditor.cpp
index a5087159..31b906de 100644
--- a/src/ThemeBuilder/components/conditions/NoConditionEditor.cpp
+++ b/src/ThemeBuilder/components/conditions/NoConditionEditor.cpp
@@ -1,7 +1,7 @@
#include "NoConditionEditor.h"
namespace cru::theme_builder::components::conditions {
-NoConditionEditor::NoConditionEditor() { SetLabel(u"No condition"); }
+NoConditionEditor::NoConditionEditor() { SetLabel("No condition"); }
NoConditionEditor::~NoConditionEditor() {}
} // namespace cru::theme_builder::components::conditions
diff --git a/src/ThemeBuilder/components/properties/CheckBoxPropertyEditor.h b/src/ThemeBuilder/components/properties/CheckBoxPropertyEditor.h
index f78ed6c9..8cdd541b 100644
--- a/src/ThemeBuilder/components/properties/CheckBoxPropertyEditor.h
+++ b/src/ThemeBuilder/components/properties/CheckBoxPropertyEditor.h
@@ -15,8 +15,8 @@ class CheckBoxPropertyEditor : public Editor {
public:
ui::controls::Control* GetRootControl() override { return &container_; }
- String GetLabel() const { return label_.GetText(); }
- void SetLabel(String label) { label_.SetText(std::move(label)); }
+ std::string GetLabel() const { return label_.GetText(); }
+ void SetLabel(std::string label) { label_.SetText(std::move(label)); }
bool GetValue() const { return check_box_.IsChecked(); }
void SetValue(bool value, bool trigger_change = true);
diff --git a/src/ThemeBuilder/components/properties/ColorPropertyEditor.cpp b/src/ThemeBuilder/components/properties/ColorPropertyEditor.cpp
index 0fe3908e..c048734c 100644
--- a/src/ThemeBuilder/components/properties/ColorPropertyEditor.cpp
+++ b/src/ThemeBuilder/components/properties/ColorPropertyEditor.cpp
@@ -12,7 +12,7 @@ ColorPropertyEditor::ColorPropertyEditor() {
color_cube_.SetBorderEnabled(true);
color_cube_.GetStyleRuleSet()->SetParent(
ui::ThemeManager::GetInstance()->GetResourceStyleRuleSet(
- u"cru.theme_builder.color_cube.style"));
+ "cru.theme_builder.color_cube.style"));
color_cube_brush_ = platform::gui::IUiApplication::GetInstance()
->GetGraphicsFactory()
@@ -20,12 +20,12 @@ ColorPropertyEditor::ColorPropertyEditor() {
color_cube_.SetForegroundBrush(color_cube_brush_);
- color_text_.SetText(String::FromUtf8(color_.ToString()));
+ color_text_.SetText(color_.ToString());
color_text_.SetMargin(ui::Thickness(10, 0, 0, 0));
color_text_.TextChangeEvent()->AddHandler([this](std::nullptr_t) {
auto text = color_text_.GetTextView();
- auto color = ui::Color::Parse(text.ToUtf8());
+ auto color = ui::Color::Parse(text);
if (color) {
color_ = *color;
color_cube_brush_->SetColor(*color);
@@ -43,6 +43,6 @@ ColorPropertyEditor::~ColorPropertyEditor() {}
void ColorPropertyEditor::SetValue(const ui::Color &color,
bool trigger_change) {
if (!trigger_change) SuppressNextChangeEvent();
- color_text_.SetText(String::FromUtf8(color.ToString()));
+ color_text_.SetText(color.ToString());
}
} // namespace cru::theme_builder::components::properties
diff --git a/src/ThemeBuilder/components/properties/ColorPropertyEditor.h b/src/ThemeBuilder/components/properties/ColorPropertyEditor.h
index aa6cfcfa..7c76297b 100644
--- a/src/ThemeBuilder/components/properties/ColorPropertyEditor.h
+++ b/src/ThemeBuilder/components/properties/ColorPropertyEditor.h
@@ -17,8 +17,8 @@ class ColorPropertyEditor : public Editor {
public:
ui::controls::Control* GetRootControl() override { return &container_; }
- String GetLabel() const { return label_.GetText(); }
- void SetLabel(String label) { label_.SetText(std::move(label)); }
+ std::string GetLabel() const { return label_.GetText(); }
+ void SetLabel(std::string label) { label_.SetText(std::move(label)); }
ui::Color GetValue() const { return color_; }
void SetValue(const ui::Color& color, bool trigger_change = true);
diff --git a/src/ThemeBuilder/components/properties/CornerRadiusPropertyEditor.cpp b/src/ThemeBuilder/components/properties/CornerRadiusPropertyEditor.cpp
index fc86b0ed..47a51ddd 100644
--- a/src/ThemeBuilder/components/properties/CornerRadiusPropertyEditor.cpp
+++ b/src/ThemeBuilder/components/properties/CornerRadiusPropertyEditor.cpp
@@ -6,10 +6,10 @@ namespace cru::theme_builder::components::properties {
CornerRadiusPropertyEditor::CornerRadiusPropertyEditor() {
container_.SetItemCrossAlign(ui::controls::FlexCrossAlignment::Start);
- left_top_editor_.SetLabel(u"⌜");
- right_top_editor_.SetLabel(u"⌝");
- left_bottom_editor_.SetLabel(u"⌞");
- right_bottom_editor_.SetLabel(u"⌟");
+ left_top_editor_.SetLabel("⌜");
+ right_top_editor_.SetLabel("⌝");
+ left_bottom_editor_.SetLabel("⌞");
+ right_bottom_editor_.SetLabel("⌟");
container_.SetFlexDirection(ui::controls::FlexDirection::Vertical);
container_.AddChild(left_top_editor_.GetRootControl());
diff --git a/src/ThemeBuilder/components/properties/FontPropertyEditor.cpp b/src/ThemeBuilder/components/properties/FontPropertyEditor.cpp
index 927ada7d..231e45dd 100644
--- a/src/ThemeBuilder/components/properties/FontPropertyEditor.cpp
+++ b/src/ThemeBuilder/components/properties/FontPropertyEditor.cpp
@@ -20,12 +20,12 @@ FontPropertyEditor::FontPropertyEditor() {
font_family_container_.SetFlexDirection(FlexDirection::Horizontal);
font_family_container_.AddChild(&font_family_label_);
font_family_container_.AddChild(&font_family_text_);
- font_family_label_.SetText(u"Font Family");
+ font_family_label_.SetText("Font Family");
font_size_container_.SetFlexDirection(FlexDirection::Horizontal);
font_size_container_.AddChild(&font_size_label_);
font_size_container_.AddChild(font_size_input_.GetRootControl());
- font_size_label_.SetText(u"Font Size");
+ font_size_label_.SetText("Font Size");
font_size_input_.SetMin(0.0f);
font_family_text_.TextChangeEvent()->AddSpyOnlyHandler(
diff --git a/src/ThemeBuilder/components/properties/FontPropertyEditor.h b/src/ThemeBuilder/components/properties/FontPropertyEditor.h
index d349f1f2..ec6a6b56 100644
--- a/src/ThemeBuilder/components/properties/FontPropertyEditor.h
+++ b/src/ThemeBuilder/components/properties/FontPropertyEditor.h
@@ -17,8 +17,8 @@ class FontPropertyEditor : public Editor {
ui::controls::Control* GetRootControl() override;
- String GetLabelText() const { return label_.GetText(); }
- void SetLabelText(String label) { label_.SetText(std::move(label)); }
+ std::string GetLabelText() const { return label_.GetText(); }
+ void SetLabelText(std::string label) { label_.SetText(std::move(label)); }
std::shared_ptr<platform::graphics::IFont> GetValue() const;
void SetValue(std::shared_ptr<platform::graphics::IFont> value,
diff --git a/src/ThemeBuilder/components/properties/MeasureLengthPropertyEditor.cpp b/src/ThemeBuilder/components/properties/MeasureLengthPropertyEditor.cpp
index 9280718d..001665ae 100644
--- a/src/ThemeBuilder/components/properties/MeasureLengthPropertyEditor.cpp
+++ b/src/ThemeBuilder/components/properties/MeasureLengthPropertyEditor.cpp
@@ -10,12 +10,12 @@ MeasureLengthPropertyEditor::MeasureLengthPropertyEditor() {
container_.AddChild(&text_);
text_.TextChangeEvent()->AddHandler([this](std::nullptr_t) {
- auto text = text_.GetTextView();
+ auto text = text_.GetText();
auto measure_length_mapper = ui::mapper::MapperRegistry::GetInstance()
->GetMapper<ui::render::MeasureLength>();
try {
auto measure_length =
- measure_length_mapper->MapFromString(text.ToString().ToUtf8());
+ measure_length_mapper->MapFromString(text);
measure_length_ = measure_length;
is_text_valid_ = true;
RaiseChangeEvent();
@@ -32,8 +32,7 @@ void MeasureLengthPropertyEditor::SetValue(
const ui::render::MeasureLength& value, bool trigger_change) {
if (!trigger_change) SuppressNextChangeEvent();
text_.SetText(measure_length_.IsNotSpecified()
- ? u"unspecified"
- : String::FromUtf8(std::to_string(
- measure_length_.GetLengthOrUndefined())));
+ ? "unspecified"
+ : std::to_string(measure_length_.GetLengthOrUndefined()));
}
} // namespace cru::theme_builder::components::properties
diff --git a/src/ThemeBuilder/components/properties/MeasureLengthPropertyEditor.h b/src/ThemeBuilder/components/properties/MeasureLengthPropertyEditor.h
index 43e783c5..ee99579f 100644
--- a/src/ThemeBuilder/components/properties/MeasureLengthPropertyEditor.h
+++ b/src/ThemeBuilder/components/properties/MeasureLengthPropertyEditor.h
@@ -18,8 +18,8 @@ class MeasureLengthPropertyEditor : public Editor {
public:
ui::controls::Control* GetRootControl() override { return &container_; }
- String GetLabel() const { return label_.GetText(); }
- void SetLabel(String label) { label_.SetText(std::move(label)); }
+ std::string GetLabel() const { return label_.GetText(); }
+ void SetLabel(std::string label) { label_.SetText(std::move(label)); }
PropertyType GetValue() const { return measure_length_; }
void SetValue(const PropertyType& value, bool trigger_change = true);
diff --git a/src/ThemeBuilder/components/properties/OptionalPropertyEditor.h b/src/ThemeBuilder/components/properties/OptionalPropertyEditor.h
index 0f22616a..8db14114 100644
--- a/src/ThemeBuilder/components/properties/OptionalPropertyEditor.h
+++ b/src/ThemeBuilder/components/properties/OptionalPropertyEditor.h
@@ -28,8 +28,8 @@ class OptionalPropertyEditor : public Editor {
ui::controls::Control* GetRootControl() override { return &container_; }
- String GetLabel() const { return label_.GetText(); }
- void SetLabel(String label) { label_.SetText(std::move(label)); }
+ std::string GetLabel() const { return label_.GetText(); }
+ void SetLabel(std::string label) { label_.SetText(std::move(label)); }
bool IsEnabled() const { return check_box_.IsChecked(); }
void SetEnabled(bool enabled, bool trigger_change = true) {
diff --git a/src/ThemeBuilder/components/properties/PointPropertyEditor.cpp b/src/ThemeBuilder/components/properties/PointPropertyEditor.cpp
index 8d7ac942..82fee18f 100644
--- a/src/ThemeBuilder/components/properties/PointPropertyEditor.cpp
+++ b/src/ThemeBuilder/components/properties/PointPropertyEditor.cpp
@@ -10,11 +10,11 @@ PointPropertyEditor::PointPropertyEditor() {
container_.AddChild(&text_);
text_.TextChangeEvent()->AddHandler([this](std::nullptr_t) {
- auto text = text_.GetTextView();
+ auto text = text_.GetText();
auto point_mapper =
ui::mapper::MapperRegistry::GetInstance()->GetMapper<ui::Point>();
try {
- auto point = point_mapper->MapFromString(text.ToString().ToUtf8());
+ auto point = point_mapper->MapFromString(text);
point_ = point;
is_text_valid_ = true;
RaiseChangeEvent();
@@ -33,7 +33,7 @@ void PointPropertyEditor::SetValue(const ui::Point& point,
text_.SetText(ConvertPointToString(point));
}
-String PointPropertyEditor::ConvertPointToString(const ui::Point& point) {
- return String::FromUtf8(std::format("{} {}", point.x, point.y));
+std::string PointPropertyEditor::ConvertPointToString(const ui::Point& point) {
+ return std::format("{} {}", point.x, point.y);
}
} // namespace cru::theme_builder::components::properties
diff --git a/src/ThemeBuilder/components/properties/PointPropertyEditor.h b/src/ThemeBuilder/components/properties/PointPropertyEditor.h
index bd852e3a..4f078c8b 100644
--- a/src/ThemeBuilder/components/properties/PointPropertyEditor.h
+++ b/src/ThemeBuilder/components/properties/PointPropertyEditor.h
@@ -15,14 +15,14 @@ class PointPropertyEditor : public Editor {
public:
ui::controls::Control* GetRootControl() override { return &container_; }
- String GetLabel() const { return label_.GetText(); }
- void SetLabel(String label) { label_.SetText(std::move(label)); }
+ std::string GetLabel() const { return label_.GetText(); }
+ void SetLabel(std::string label) { label_.SetText(std::move(label)); }
ui::Point GetValue() const { return point_; }
void SetValue(const ui::Point& point, bool trigger_change = true);
private:
- static String ConvertPointToString(const ui::Point& point);
+ static std::string ConvertPointToString(const ui::Point& point);
private:
ui::Point point_;
diff --git a/src/ThemeBuilder/components/properties/SelectPropertyEditor.h b/src/ThemeBuilder/components/properties/SelectPropertyEditor.h
index 475d2d0a..0d6cbfcd 100644
--- a/src/ThemeBuilder/components/properties/SelectPropertyEditor.h
+++ b/src/ThemeBuilder/components/properties/SelectPropertyEditor.h
@@ -15,8 +15,8 @@ class SelectPropertyEditor : public Editor {
public:
ui::controls::Control* GetRootControl() override { return &container_; }
- String GetLabel() const { return label_.GetText(); }
- void SetLabel(String label) { label_.SetText(std::move(label)); }
+ std::string GetLabel() const { return label_.GetText(); }
+ void SetLabel(std::string label) { label_.SetText(std::move(label)); }
Index GetSelectedIndex() const { return select_.GetSelectedIndex(); }
void SetSelectedIndex(Index index, bool trigger_change = true) {
@@ -24,8 +24,8 @@ class SelectPropertyEditor : public Editor {
select_.SetSelectedIndex(index);
}
- std::vector<String> GetItems() const { return select_.GetItems(); }
- void SetItems(std::vector<String> items) {
+ std::vector<std::string> GetItems() const { return select_.GetItems(); }
+ void SetItems(std::vector<std::string> items) {
select_.SetItems(std::move(items));
}
diff --git a/src/ThemeBuilder/components/properties/TextPropertyEditor.cpp b/src/ThemeBuilder/components/properties/TextPropertyEditor.cpp
index 9854019c..4d34c9e6 100644
--- a/src/ThemeBuilder/components/properties/TextPropertyEditor.cpp
+++ b/src/ThemeBuilder/components/properties/TextPropertyEditor.cpp
@@ -4,7 +4,7 @@ namespace cru::theme_builder::components::properties {
TextPropertyEditor::TextPropertyEditor() {
editor_.TextChangeEvent()->AddHandler([this](std::nullptr_t) {
auto text_view = editor_.GetTextView();
- String error_message;
+ std::string error_message;
auto validation_result = Validate(text_view, &error_message);
if (validation_result) {
OnTextChanged(text_view);
@@ -14,9 +14,10 @@ TextPropertyEditor::TextPropertyEditor() {
TextPropertyEditor::~TextPropertyEditor() {}
-bool TextPropertyEditor::Validate(StringView text, String* error_message) {
+bool TextPropertyEditor::Validate(std::string_view text,
+ std::string* error_message) {
return true;
}
-void TextPropertyEditor::OnTextChanged(StringView text) {}
+void TextPropertyEditor::OnTextChanged(std::string_view text) {}
} // namespace cru::theme_builder::components::properties
diff --git a/src/ThemeBuilder/components/properties/TextPropertyEditor.h b/src/ThemeBuilder/components/properties/TextPropertyEditor.h
index c4944228..040f776a 100644
--- a/src/ThemeBuilder/components/properties/TextPropertyEditor.h
+++ b/src/ThemeBuilder/components/properties/TextPropertyEditor.h
@@ -12,16 +12,16 @@ class TextPropertyEditor : public ui::components::Component {
ui::controls::Control* GetRootControl() override { return &container_; }
- String GetLabel() const { return label_.GetText(); }
- void SetLabel(String label) { label_.SetText(std::move(label)); }
+ std::string GetLabel() const { return label_.GetText(); }
+ void SetLabel(std::string label) { label_.SetText(std::move(label)); }
- String GetText() const { return editor_.GetText(); }
- StringView GetTextView() const { return editor_.GetTextView(); }
- void SetText(String text) { editor_.SetText(std::move(text)); }
+ std::string GetText() const { return editor_.GetText(); }
+ std::string_view GetTextView() const { return editor_.GetTextView(); }
+ void SetText(std::string text) { editor_.SetText(std::move(text)); }
protected:
- virtual bool Validate(StringView text, String* error_message);
- virtual void OnTextChanged(StringView text);
+ virtual bool Validate(std::string_view text, std::string* error_message);
+ virtual void OnTextChanged(std::string_view text);
private:
ui::controls::FlexLayout container_;
diff --git a/src/ThemeBuilder/components/properties/ThicknessPropertyEditor.cpp b/src/ThemeBuilder/components/properties/ThicknessPropertyEditor.cpp
index 0790cd98..2ee13c06 100644
--- a/src/ThemeBuilder/components/properties/ThicknessPropertyEditor.cpp
+++ b/src/ThemeBuilder/components/properties/ThicknessPropertyEditor.cpp
@@ -1,4 +1,5 @@
#include "ThicknessPropertyEditor.h"
+#include <format>
#include "cru/base/Format.h"
#include "cru/ui/mapper/MapperRegistry.h"
#include "cru/ui/mapper/ThicknessMapper.h"
@@ -13,7 +14,7 @@ ThicknessPropertyEditor::ThicknessPropertyEditor() {
auto thickness_mapper =
ui::mapper::MapperRegistry::GetInstance()->GetMapper<ui::Thickness>();
try {
- auto thickness = thickness_mapper->MapFromString(text.ToUtf8());
+ auto thickness = thickness_mapper->MapFromString(text);
thickness_ = thickness;
is_text_valid_ = true;
RaiseChangeEvent();
@@ -29,7 +30,7 @@ ThicknessPropertyEditor::~ThicknessPropertyEditor() {}
void ThicknessPropertyEditor::SetValue(const ui::Thickness &thickness,
bool trigger_change) {
if (!trigger_change) SuppressNextChangeEvent();
- text_.SetText(Format(u"{} {} {} {}", thickness.left, thickness.top,
- thickness.right, thickness.bottom));
+ text_.SetText(std::format("{} {} {} {}", thickness.left, thickness.top,
+ thickness.right, thickness.bottom));
}
} // namespace cru::theme_builder::components::properties
diff --git a/src/ThemeBuilder/components/properties/ThicknessPropertyEditor.h b/src/ThemeBuilder/components/properties/ThicknessPropertyEditor.h
index cea9ae9d..dae2e612 100644
--- a/src/ThemeBuilder/components/properties/ThicknessPropertyEditor.h
+++ b/src/ThemeBuilder/components/properties/ThicknessPropertyEditor.h
@@ -14,8 +14,8 @@ class ThicknessPropertyEditor : public Editor {
ui::controls::Control* GetRootControl() override { return &container_; }
- String GetLabel() const { return label_.GetText(); }
- void SetLabel(String label) { label_.SetText(std::move(label)); }
+ std::string GetLabel() const { return label_.GetText(); }
+ void SetLabel(std::string label) { label_.SetText(std::move(label)); }
ui::Thickness GetValue() const { return thickness_; }
void SetValue(const ui::Thickness& thickness, bool trigger_change = true);
diff --git a/src/ThemeBuilder/components/stylers/BorderStylerEditor.cpp b/src/ThemeBuilder/components/stylers/BorderStylerEditor.cpp
index 1329a08a..5f046a44 100644
--- a/src/ThemeBuilder/components/stylers/BorderStylerEditor.cpp
+++ b/src/ThemeBuilder/components/stylers/BorderStylerEditor.cpp
@@ -8,17 +8,17 @@
namespace cru::theme_builder::components::stylers {
BorderStylerEditor::BorderStylerEditor() {
- SetLabel(u"Border Styler");
+ SetLabel("Border Styler");
GetContainer()->AddChild(corner_radius_editor_.GetRootControl());
GetContainer()->AddChild(thickness_editor_.GetRootControl());
GetContainer()->AddChild(brush_editor_.GetRootControl());
GetContainer()->AddChild(foreground_brush_editor_.GetRootControl());
GetContainer()->AddChild(background_brush_editor_.GetRootControl());
- thickness_editor_.GetEditor()->SetLabel(u"Thickness");
- brush_editor_.GetEditor()->SetLabel(u"Border");
- foreground_brush_editor_.GetEditor()->SetLabel(u"Foreground");
- background_brush_editor_.GetEditor()->SetLabel(u"Background");
+ thickness_editor_.GetEditor()->SetLabel("Thickness");
+ brush_editor_.GetEditor()->SetLabel("Border");
+ foreground_brush_editor_.GetEditor()->SetLabel("Foreground");
+ background_brush_editor_.GetEditor()->SetLabel("Background");
ConnectChangeEvent(corner_radius_editor_);
ConnectChangeEvent(thickness_editor_);
diff --git a/src/ThemeBuilder/components/stylers/CompoundStylerEditor.cpp b/src/ThemeBuilder/components/stylers/CompoundStylerEditor.cpp
index c8b2a871..af22217b 100644
--- a/src/ThemeBuilder/components/stylers/CompoundStylerEditor.cpp
+++ b/src/ThemeBuilder/components/stylers/CompoundStylerEditor.cpp
@@ -12,7 +12,7 @@
namespace cru::theme_builder::components::stylers {
CompoundStylerEditor::CompoundStylerEditor() {
- SetLabel(u"Compound Styler");
+ SetLabel("Compound Styler");
GetContainer()->AddChild(&children_container_);
children_container_.SetFlexDirection(ui::controls::FlexDirection::Vertical);
children_container_.SetItemCrossAlign(
@@ -21,16 +21,16 @@ CompoundStylerEditor::CompoundStylerEditor() {
GetHeadContainer()->AddChild(add_child_button_.GetRootControl());
add_child_button_.GetButton()->GetStyleRuleSet()->SetParent(
ui::ThemeManager::GetInstance()->GetResourceStyleRuleSet(
- u"cru.theme_builder.icon-button.style"));
+ "cru.theme_builder.icon-button.style"));
add_child_button_.GetButton()->SetIconWithSvgPathDataStringResourceKey(
- u"icon.plus", {0, 0, 16, 16});
+ "icon.plus", {0, 0, 16, 16});
add_child_button_.GetButton()->SetPreferredSize({24, 24});
add_child_button_.GetButton()->SetPadding(ui::Thickness(2));
add_child_button_.GetButton()->SetIconFillColor(ui::colors::green);
- add_child_button_.SetMenuItems({u"Compound Styler", u"Border Styler",
- u"Cursor Styler", u"Content Brush Styler",
- u"Font Styler", u"Margin Styler",
- u"Padding Styler", u"Preferred Size Styler"});
+ add_child_button_.SetMenuItems({"Compound Styler", "Border Styler",
+ "Cursor Styler", "Content Brush Styler",
+ "Font Styler", "Margin Styler",
+ "Padding Styler", "Preferred Size Styler"});
add_child_button_.MenuItemSelectedEvent()->AddHandler([this](Index index) {
std::unique_ptr<StylerEditor> editor;
switch (index) {
diff --git a/src/ThemeBuilder/components/stylers/CursorStylerEditor.cpp b/src/ThemeBuilder/components/stylers/CursorStylerEditor.cpp
index 9984d81a..71de739a 100644
--- a/src/ThemeBuilder/components/stylers/CursorStylerEditor.cpp
+++ b/src/ThemeBuilder/components/stylers/CursorStylerEditor.cpp
@@ -4,11 +4,11 @@
namespace cru::theme_builder::components::stylers {
CursorStylerEditor::CursorStylerEditor() {
- SetLabel(u"Cursor Styler");
+ SetLabel("Cursor Styler");
GetContainer()->AddChild(cursor_select_.GetRootControl());
- cursor_select_.SetLabel(u"Cursor");
- cursor_select_.SetItems({u"arrow", u"hand", u"ibeam"});
+ cursor_select_.SetLabel("Cursor");
+ cursor_select_.SetItems({"arrow", "hand", "ibeam"});
cursor_select_.SetSelectedIndex(0);
ConnectChangeEvent(cursor_select_);
diff --git a/src/ThemeBuilder/components/stylers/MarginStylerEditor.cpp b/src/ThemeBuilder/components/stylers/MarginStylerEditor.cpp
index d7d89acb..c750e9b6 100644
--- a/src/ThemeBuilder/components/stylers/MarginStylerEditor.cpp
+++ b/src/ThemeBuilder/components/stylers/MarginStylerEditor.cpp
@@ -3,10 +3,10 @@
namespace cru::theme_builder::components::stylers {
MarginStylerEditor::MarginStylerEditor() {
- SetLabel(u"Margin Styler");
+ SetLabel("Margin Styler");
GetContainer()->AddChild(thickness_editor_.GetRootControl());
- thickness_editor_.SetLabel(u"Thickness");
+ thickness_editor_.SetLabel("Thickness");
ConnectChangeEvent(thickness_editor_);
}
diff --git a/src/ThemeBuilder/components/stylers/PaddingStylerEditor.cpp b/src/ThemeBuilder/components/stylers/PaddingStylerEditor.cpp
index 476d21f1..5cf9d3d8 100644
--- a/src/ThemeBuilder/components/stylers/PaddingStylerEditor.cpp
+++ b/src/ThemeBuilder/components/stylers/PaddingStylerEditor.cpp
@@ -3,10 +3,10 @@
namespace cru::theme_builder::components::stylers {
PaddingStylerEditor::PaddingStylerEditor() {
- SetLabel(u"Padding Styler");
+ SetLabel("Padding Styler");
GetContainer()->AddChild(thickness_editor_.GetRootControl());
- thickness_editor_.SetLabel(u"Thickness");
+ thickness_editor_.SetLabel("Thickness");
ConnectChangeEvent(thickness_editor_);
}
diff --git a/src/ThemeBuilder/components/stylers/PreferredSizeStylerEditor.cpp b/src/ThemeBuilder/components/stylers/PreferredSizeStylerEditor.cpp
index fb713c8c..f0e700a1 100644
--- a/src/ThemeBuilder/components/stylers/PreferredSizeStylerEditor.cpp
+++ b/src/ThemeBuilder/components/stylers/PreferredSizeStylerEditor.cpp
@@ -3,12 +3,12 @@
namespace cru::theme_builder::components::stylers {
PreferredSizeStylerEditor::PreferredSizeStylerEditor() {
- SetLabel(u"Preferred Size Styler");
+ SetLabel("Preferred Size Styler");
GetContainer()->AddChild(width_editor_.GetRootControl());
GetContainer()->AddChild(height_editor_.GetRootControl());
- width_editor_.SetLabel(u"Width");
- height_editor_.SetLabel(u"Height");
+ width_editor_.SetLabel("Width");
+ height_editor_.SetLabel("Height");
ConnectChangeEvent(width_editor_);
ConnectChangeEvent(height_editor_);
diff --git a/src/base/StringUtil.cpp b/src/base/StringUtil.cpp
index 42aea114..4e622dab 100644
--- a/src/base/StringUtil.cpp
+++ b/src/base/StringUtil.cpp
@@ -317,4 +317,42 @@ Utf8CodePointIterator CreateUtf8Iterator(const std::vector<std::byte>& buffer) {
return CreateUtf8Iterator(buffer.data(), buffer.size());
}
+CodePoint Utf8NextCodePoint(std::string_view str, Index current,
+ Index* next_position) {
+ NotImplemented();
+}
+
+CodePoint Utf8PreviousCodePoint(std::string_view str, Index current,
+ Index* next_position) {
+ NotImplemented();
+}
+
+// Return position after the character making predicate returns true or 0 if no
+// character doing so.
+Index Utf8BackwardUntil(std::string_view str, Index position,
+ const std::function<bool(CodePoint)>& predicate) {
+ NotImplemented();
+}
+
+// Return position before the character making predicate returns true or
+// str.size() if no character doing so.
+Index Utf8ForwardUntil(std::string_view str, Index position,
+ const std::function<bool(CodePoint)>& predicate) {
+ NotImplemented();
+}
+
+bool Utf8IsValidInsertPosition(std::string_view str, Index position) {
+ NotImplemented();
+}
+
+Index Utf8PreviousWord(std::string_view str, Index position,
+ bool* is_space) {
+ NotImplemented();
+}
+
+Index Utf8NextWord(std::string_view str, Index position,
+ bool* is_space) {
+ NotImplemented();
+}
+
} // namespace cru
diff --git a/src/platform/CMakeLists.txt b/src/platform/CMakeLists.txt
index a917f81f..9122e499 100644
--- a/src/platform/CMakeLists.txt
+++ b/src/platform/CMakeLists.txt
@@ -2,7 +2,6 @@ add_library(CruPlatformBase
Color.cpp
Exception.cpp
GraphicsBase.cpp
- Resource.cpp
)
target_link_libraries(CruPlatformBase PUBLIC CruBase)
target_compile_definitions(CruPlatformBase PRIVATE CRU_PLATFORM_EXPORT_API)
diff --git a/src/platform/Resource.cpp b/src/platform/Resource.cpp
deleted file mode 100644
index d0dbf53b..00000000
--- a/src/platform/Resource.cpp
+++ /dev/null
@@ -1,7 +0,0 @@
-#include "cru/platform/Resource.h"
-
-namespace cru::platform {
-std::string IPlatformResource::GetPlatformIdUtf8() const {
- return GetPlatformId().ToUtf8();
-}
-} // namespace cru::platform
diff --git a/src/platform/graphics/CMakeLists.txt b/src/platform/graphics/CMakeLists.txt
index 43ef80e0..e86e9c89 100644
--- a/src/platform/graphics/CMakeLists.txt
+++ b/src/platform/graphics/CMakeLists.txt
@@ -1,8 +1,6 @@
add_library(CruPlatformGraphics
- ForDllExport.cpp
Geometry.cpp
Image.cpp
- NullPainter.cpp
SvgGeometryBuilderMixin.cpp
)
target_compile_definitions(CruPlatformGraphics PRIVATE CRU_PLATFORM_GRAPHICS_EXPORT_API)
diff --git a/src/platform/graphics/Geometry.cpp b/src/platform/graphics/Geometry.cpp
index 2c842a6e..e88577ce 100644
--- a/src/platform/graphics/Geometry.cpp
+++ b/src/platform/graphics/Geometry.cpp
@@ -1,6 +1,7 @@
#include "cru/platform/graphics/Geometry.h"
#include "cru/base/Exception.h"
+#include "cru/base/String.h"
#include "cru/platform/Exception.h"
#include "cru/platform/graphics/Factory.h"
@@ -15,7 +16,7 @@ bool IGeometry::StrokeContains(float width, const Point& point) {
std::unique_ptr<IGeometry> IGeometry::CreateStrokeGeometry(
[[maybe_unused]] float width) {
- throw PlatformUnsupportedException(GetPlatformIdUtf8(), "CreateStrokeGeometry",
+ throw PlatformUnsupportedException(GetPlatformId(), "CreateStrokeGeometry",
"Create stroke geometry of a geometry is "
"not supported on this platform.");
}
@@ -207,7 +208,7 @@ const std::unordered_set<char16_t> kSvgPathDataCommands = {
'S', 's', 'Q', 'q', 'T', 't', 'A', 'a', 'Z', 'z'};
}
-void IGeometryBuilder::ParseAndApplySvgPathData(StringView path_d) {
+void IGeometryBuilder::ParseAndApplySvgPathData(std::string_view path_d) {
Index position = 0;
const auto size = path_d.size();
@@ -236,8 +237,9 @@ void IGeometryBuilder::ParseAndApplySvgPathData(StringView path_d) {
Index processed_count = 0;
- auto result = path_d.substr(position).ParseToFloat(
- &processed_count, StringToNumberFlags::kAllowTrailingJunk);
+ auto result = String::FromUtf8(path_d.substr(position))
+ .ParseToFloat(&processed_count,
+ StringToNumberFlags::kAllowTrailingJunk);
if (std::isnan(result)) throw Exception("Invalid svg path data number.");
@@ -252,7 +254,7 @@ void IGeometryBuilder::ParseAndApplySvgPathData(StringView path_d) {
return Point(x, y);
};
- auto do_command = [&, this](char16_t command) {
+ auto do_command = [&, this](char command) {
last_command = command;
last_is_cubic = false;
last_is_quad = false;
@@ -442,7 +444,7 @@ void IGeometryBuilder::ParseAndApplySvgPathData(StringView path_d) {
}
std::unique_ptr<IGeometry> CreateGeometryFromSvgPathData(
- IGraphicsFactory* factory, StringView path_d) {
+ IGraphicsFactory* factory, std::string_view path_d) {
auto builder = factory->CreateGeometryBuilder();
builder->ParseAndApplySvgPathData(path_d);
return builder->Build();
diff --git a/src/platform/graphics/SvgGeometryBuilderMixin.cpp b/src/platform/graphics/SvgGeometryBuilderMixin.cpp
index 73290da5..0863e5eb 100644
--- a/src/platform/graphics/SvgGeometryBuilderMixin.cpp
+++ b/src/platform/graphics/SvgGeometryBuilderMixin.cpp
@@ -1,7 +1,7 @@
#include "cru/platform/graphics/SvgGeometryBuilderMixin.h"
#include "cru/platform/Exception.h"
-#include "cru/base/Format.h"
+#include <string>
namespace cru::platform::graphics {
SvgGeometryBuilderMixin::SvgGeometryBuilderMixin() {}
@@ -10,34 +10,34 @@ SvgGeometryBuilderMixin::~SvgGeometryBuilderMixin() {}
Point SvgGeometryBuilderMixin::GetCurrentPosition() {
throw PlatformUnsupportedException(
- GetPlatformIdUtf8(), "GetCurrentPosition",
+ GetPlatformId(), "GetCurrentPosition",
"Svg-based geometry does not support get current position.");
}
void SvgGeometryBuilderMixin::MoveTo(const Point& point) {
- AppendCommand(u"M");
+ AppendCommand("M");
Append(point);
}
void SvgGeometryBuilderMixin::RelativeMoveTo(const Point& offset) {
- AppendCommand(u"m");
+ AppendCommand("m");
Append(offset);
}
void SvgGeometryBuilderMixin::LineTo(const Point& point) {
- AppendCommand(u"L");
+ AppendCommand("L");
Append(point);
}
void SvgGeometryBuilderMixin::RelativeLineTo(const Point& offset) {
- AppendCommand(u"l");
+ AppendCommand("l");
Append(offset);
}
void SvgGeometryBuilderMixin::CubicBezierTo(const Point& start_control_point,
const Point& end_control_point,
const Point& end_point) {
- AppendCommand(u"C");
+ AppendCommand("C");
Append(start_control_point);
Append(end_control_point);
Append(end_point);
@@ -46,7 +46,7 @@ void SvgGeometryBuilderMixin::CubicBezierTo(const Point& start_control_point,
void SvgGeometryBuilderMixin::RelativeCubicBezierTo(
const Point& start_control_offset, const Point& end_control_offset,
const Point& end_offset) {
- AppendCommand(u"c");
+ AppendCommand("c");
Append(start_control_offset);
Append(end_control_offset);
Append(end_offset);
@@ -54,14 +54,14 @@ void SvgGeometryBuilderMixin::RelativeCubicBezierTo(
void SvgGeometryBuilderMixin::QuadraticBezierTo(const Point& control_point,
const Point& end_point) {
- AppendCommand(u"Q");
+ AppendCommand("Q");
Append(control_point);
Append(end_point);
}
void SvgGeometryBuilderMixin::RelativeQuadraticBezierTo(
const Point& control_offset, const Point& end_offset) {
- AppendCommand(u"q");
+ AppendCommand("q");
Append(control_offset);
Append(end_offset);
}
@@ -69,7 +69,7 @@ void SvgGeometryBuilderMixin::RelativeQuadraticBezierTo(
void SvgGeometryBuilderMixin::ArcTo(const Point& radius, float angle,
bool is_large_arc, bool is_clockwise,
const Point& end_point) {
- AppendCommand(u"A");
+ AppendCommand("A");
Append(radius.x);
Append(radius.y);
Append(angle);
@@ -82,7 +82,7 @@ void SvgGeometryBuilderMixin::RelativeArcTo(const Point& radius, float angle,
bool is_large_arc,
bool is_clockwise,
const Point& end_offset) {
- AppendCommand(u"a");
+ AppendCommand("a");
Append(radius.x);
Append(radius.y);
Append(angle);
@@ -92,14 +92,15 @@ void SvgGeometryBuilderMixin::RelativeArcTo(const Point& radius, float angle,
}
void SvgGeometryBuilderMixin::CloseFigure(bool close) {
- if (close) AppendCommand(u"z");
+ if (close) AppendCommand("z");
}
-void SvgGeometryBuilderMixin::ParseAndApplySvgPathData(StringView path_d) {
+void SvgGeometryBuilderMixin::ParseAndApplySvgPathData(
+ std::string_view path_d) {
AppendCommand(path_d);
}
-void SvgGeometryBuilderMixin::AppendCommand(StringView command) {
+void SvgGeometryBuilderMixin::AppendCommand(std::string_view command) {
current_ += command;
current_ += u' ';
}
@@ -110,14 +111,14 @@ void SvgGeometryBuilderMixin::Append(bool flag) {
}
void SvgGeometryBuilderMixin::Append(float number) {
- current_ += cru::ToString(number);
+ current_ += std::to_string(number);
current_ += u' ';
}
void SvgGeometryBuilderMixin::Append(const Point& point) {
- current_ += cru::ToString(point.x);
+ current_ += std::to_string(point.x);
current_ += u',';
- current_ += cru::ToString(point.y);
+ current_ += std::to_string(point.y);
current_ += u' ';
}
} // namespace cru::platform::graphics
diff --git a/src/platform/graphics/cairo/CairoGraphicsFactory.cpp b/src/platform/graphics/cairo/CairoGraphicsFactory.cpp
index 11d2e734..7414e14f 100644
--- a/src/platform/graphics/cairo/CairoGraphicsFactory.cpp
+++ b/src/platform/graphics/cairo/CairoGraphicsFactory.cpp
@@ -32,13 +32,13 @@ CairoGraphicsFactory::CreateGeometryBuilder() {
return std::make_unique<CairoGeometryBuilder>(this);
}
-std::unique_ptr<IFont> CairoGraphicsFactory::CreateFont(String font_family,
+std::unique_ptr<IFont> CairoGraphicsFactory::CreateFont(std::string font_family,
float font_size) {
return std::make_unique<PangoFont>(this, std::move(font_family), font_size);
}
std::unique_ptr<ITextLayout> CairoGraphicsFactory::CreateTextLayout(
- std::shared_ptr<IFont> font, String text) {
+ std::shared_ptr<IFont> font, std::string text) {
auto text_layout = std::make_unique<PangoTextLayout>(this, std::move(font));
text_layout->SetText(std::move(text));
return text_layout;
diff --git a/src/platform/graphics/cairo/CairoImageFactory.cpp b/src/platform/graphics/cairo/CairoImageFactory.cpp
index ff922e77..6225247a 100644
--- a/src/platform/graphics/cairo/CairoImageFactory.cpp
+++ b/src/platform/graphics/cairo/CairoImageFactory.cpp
@@ -212,7 +212,7 @@ std::unique_ptr<IImage> CairoImageFactory::DecodeFromStream(
void CairoImageFactory::EncodeToStream(IImage* image, io::Stream* stream,
ImageFormat format, float quality) {
- auto cairo_image = CheckPlatform<CairoImage>(image, GetPlatformIdUtf8());
+ auto cairo_image = CheckPlatform<CairoImage>(image, GetPlatformId());
if (format == ImageFormat::Png) {
EncodePng(cairo_image->GetCairoSurface(), stream);
diff --git a/src/platform/graphics/cairo/CairoPainter.cpp b/src/platform/graphics/cairo/CairoPainter.cpp
index 94111098..d043e686 100644
--- a/src/platform/graphics/cairo/CairoPainter.cpp
+++ b/src/platform/graphics/cairo/CairoPainter.cpp
@@ -56,7 +56,7 @@ void CairoPainter::Clear(const Color& color) {
void CairoPainter::DrawLine(const Point& start, const Point& end, IBrush* brush,
float width) {
CheckValidation();
- auto cairo_brush = CheckPlatform<CairoBrush>(brush, GetPlatformIdUtf8());
+ auto cairo_brush = CheckPlatform<CairoBrush>(brush, GetPlatformId());
auto cairo_pattern = cairo_brush->GetCairoPattern();
cairo_save(cairo_);
cairo_set_source(cairo_, cairo_pattern);
@@ -71,7 +71,7 @@ void CairoPainter::DrawLine(const Point& start, const Point& end, IBrush* brush,
void CairoPainter::StrokeRectangle(const Rect& rectangle, IBrush* brush,
float width) {
CheckValidation();
- auto cairo_brush = CheckPlatform<CairoBrush>(brush, GetPlatformIdUtf8());
+ auto cairo_brush = CheckPlatform<CairoBrush>(brush, GetPlatformId());
auto cairo_pattern = cairo_brush->GetCairoPattern();
cairo_save(cairo_);
cairo_set_source(cairo_, cairo_pattern);
@@ -85,7 +85,7 @@ void CairoPainter::StrokeRectangle(const Rect& rectangle, IBrush* brush,
void CairoPainter::FillRectangle(const Rect& rectangle, IBrush* brush) {
CheckValidation();
- auto cairo_brush = CheckPlatform<CairoBrush>(brush, GetPlatformIdUtf8());
+ auto cairo_brush = CheckPlatform<CairoBrush>(brush, GetPlatformId());
auto cairo_pattern = cairo_brush->GetCairoPattern();
cairo_save(cairo_);
cairo_set_source(cairo_, cairo_pattern);
@@ -99,7 +99,7 @@ void CairoPainter::FillRectangle(const Rect& rectangle, IBrush* brush) {
void CairoPainter::StrokeEllipse(const Rect& outline_rect, IBrush* brush,
float width) {
CheckValidation();
- auto cairo_brush = CheckPlatform<CairoBrush>(brush, GetPlatformIdUtf8());
+ auto cairo_brush = CheckPlatform<CairoBrush>(brush, GetPlatformId());
auto cairo_pattern = cairo_brush->GetCairoPattern();
cairo_save(cairo_);
cairo_set_source(cairo_, cairo_pattern);
@@ -122,7 +122,7 @@ void CairoPainter::StrokeEllipse(const Rect& outline_rect, IBrush* brush,
void CairoPainter::FillEllipse(const Rect& outline_rect, IBrush* brush) {
CheckValidation();
- auto cairo_brush = CheckPlatform<CairoBrush>(brush, GetPlatformIdUtf8());
+ auto cairo_brush = CheckPlatform<CairoBrush>(brush, GetPlatformId());
auto cairo_pattern = cairo_brush->GetCairoPattern();
cairo_save(cairo_);
cairo_set_source(cairo_, cairo_pattern);
@@ -145,8 +145,8 @@ void CairoPainter::FillEllipse(const Rect& outline_rect, IBrush* brush) {
void CairoPainter::StrokeGeometry(IGeometry* geometry, IBrush* brush,
float width) {
CheckValidation();
- auto cairo_geometry = CheckPlatform<CairoGeometry>(geometry, GetPlatformIdUtf8());
- auto cairo_brush = CheckPlatform<CairoBrush>(brush, GetPlatformIdUtf8());
+ auto cairo_geometry = CheckPlatform<CairoGeometry>(geometry, GetPlatformId());
+ auto cairo_brush = CheckPlatform<CairoBrush>(brush, GetPlatformId());
auto cairo_path = cairo_geometry->GetCairoPath();
auto cairo_pattern = cairo_brush->GetCairoPattern();
@@ -162,8 +162,8 @@ void CairoPainter::StrokeGeometry(IGeometry* geometry, IBrush* brush,
void CairoPainter::FillGeometry(IGeometry* geometry, IBrush* brush) {
CheckValidation();
- auto cairo_geometry = CheckPlatform<CairoGeometry>(geometry, GetPlatformIdUtf8());
- auto cairo_brush = CheckPlatform<CairoBrush>(brush, GetPlatformIdUtf8());
+ auto cairo_geometry = CheckPlatform<CairoGeometry>(geometry, GetPlatformId());
+ auto cairo_brush = CheckPlatform<CairoBrush>(brush, GetPlatformId());
auto cairo_path = cairo_geometry->GetCairoPath();
auto cairo_pattern = cairo_brush->GetCairoPattern();
@@ -181,9 +181,9 @@ void CairoPainter::DrawText(const Point& offset, ITextLayout* text_layout,
CheckValidation();
auto pango_text_layout =
- CheckPlatform<PangoTextLayout>(text_layout, GetPlatformIdUtf8());
+ CheckPlatform<PangoTextLayout>(text_layout, GetPlatformId());
- auto cairo_brush = CheckPlatform<CairoBrush>(brush, GetPlatformIdUtf8());
+ auto cairo_brush = CheckPlatform<CairoBrush>(brush, GetPlatformId());
auto cairo_pattern = cairo_brush->GetCairoPattern();
cairo_save(cairo_);
@@ -196,7 +196,7 @@ void CairoPainter::DrawText(const Point& offset, ITextLayout* text_layout,
void CairoPainter::DrawImage(const Point& offset, IImage* image) {
CheckValidation();
- auto cairo_image = CheckPlatform<CairoImage>(image, GetPlatformIdUtf8());
+ auto cairo_image = CheckPlatform<CairoImage>(image, GetPlatformId());
cairo_save(cairo_);
cairo_set_source_surface(cairo_, cairo_image->GetCairoSurface(), 0, 0);
cairo_new_path(cairo_);
diff --git a/src/platform/graphics/cairo/CairoResource.cpp b/src/platform/graphics/cairo/CairoResource.cpp
index ee371efc..f8ce9666 100644
--- a/src/platform/graphics/cairo/CairoResource.cpp
+++ b/src/platform/graphics/cairo/CairoResource.cpp
@@ -2,14 +2,16 @@
#include "cru/platform/graphics/cairo/CairoGraphicsFactory.h"
namespace cru::platform::graphics::cairo {
-static const String kCairoGraphicsPlatformId(u"cairo");
+static const std::string kCairoGraphicsPlatformId("cairo");
CairoResource::CairoResource(CairoGraphicsFactory* factory)
: factory_(factory) {}
CairoResource::~CairoResource() {}
-String CairoResource::GetPlatformId() const { return kCairoGraphicsPlatformId; }
+std::string CairoResource::GetPlatformId() const {
+ return kCairoGraphicsPlatformId;
+}
IGraphicsFactory* CairoResource::GetGraphicsFactory() { return factory_; }
} // namespace cru::platform::graphics::cairo
diff --git a/src/platform/graphics/cairo/PangoFont.cpp b/src/platform/graphics/cairo/PangoFont.cpp
index d5c1ad0b..e375d674 100644
--- a/src/platform/graphics/cairo/PangoFont.cpp
+++ b/src/platform/graphics/cairo/PangoFont.cpp
@@ -1,23 +1,24 @@
#include "cru/platform/graphics/cairo/PangoFont.h"
namespace cru::platform::graphics::cairo {
-PangoFont::PangoFont(CairoGraphicsFactory* factory, String font_family,
+PangoFont::PangoFont(CairoGraphicsFactory* factory, std::string font_family,
float font_size)
: CairoResource(factory),
font_family_(std::move(font_family)),
font_size_(font_size) {
pango_font_description_ = pango_font_description_new();
- auto font_family_str = font_family_.ToUtf8();
+ auto font_family_str = font_family_;
pango_font_description_set_family(pango_font_description_,
font_family_str.c_str());
- pango_font_description_set_size(pango_font_description_, font_size * PANGO_SCALE);
+ pango_font_description_set_size(pango_font_description_,
+ font_size * PANGO_SCALE);
}
PangoFont::~PangoFont() {
pango_font_description_free(pango_font_description_);
}
-String PangoFont::GetFontName() { return font_family_; }
+std::string PangoFont::GetFontName() { return font_family_; }
float PangoFont::GetFontSize() { return font_size_; }
} // namespace cru::platform::graphics::cairo
diff --git a/src/platform/graphics/cairo/PangoTextLayout.cpp b/src/platform/graphics/cairo/PangoTextLayout.cpp
index 746056e2..f8ed20c7 100644
--- a/src/platform/graphics/cairo/PangoTextLayout.cpp
+++ b/src/platform/graphics/cairo/PangoTextLayout.cpp
@@ -1,5 +1,4 @@
#include "cru/platform/graphics/cairo/PangoTextLayout.h"
-#include "cru/base/StringUtil.h"
#include "cru/platform/Check.h"
#include "cru/platform/GraphicsBase.h"
#include "cru/platform/graphics/Base.h"
@@ -24,7 +23,7 @@ PangoTextLayout::PangoTextLayout(CairoGraphicsFactory* factory,
std::shared_ptr<IFont> font)
: CairoResource(factory) {
Expects(font);
- font_ = CheckPlatform<PangoFont>(font, GetPlatformIdUtf8());
+ font_ = CheckPlatform<PangoFont>(font, GetPlatformId());
pango_layout_ = pango_cairo_create_layout(factory->GetDefaultCairo());
pango_layout_set_font_description(pango_layout_,
font_->GetPangoFontDescription());
@@ -32,19 +31,18 @@ PangoTextLayout::PangoTextLayout(CairoGraphicsFactory* factory,
PangoTextLayout::~PangoTextLayout() { g_object_unref(pango_layout_); }
-String PangoTextLayout::GetText() { return text_; }
+std::string PangoTextLayout::GetText() { return text_; }
-void PangoTextLayout::SetText(String new_text) {
+void PangoTextLayout::SetText(std::string new_text) {
text_ = std::move(new_text);
- utf8_text_ = text_.ToUtf8();
- pango_layout_set_text(pango_layout_, utf8_text_.c_str(), utf8_text_.size());
+ pango_layout_set_text(pango_layout_, text_.c_str(), text_.size());
}
std::shared_ptr<IFont> PangoTextLayout::GetFont() { return font_; }
void PangoTextLayout::SetFont(std::shared_ptr<IFont> font) {
Expects(font);
- font_ = CheckPlatform<PangoFont>(font, GetPlatformIdUtf8());
+ font_ = CheckPlatform<PangoFont>(font, GetPlatformId());
pango_layout_set_font_description(pango_layout_,
font_->GetPangoFontDescription());
}
@@ -63,9 +61,8 @@ void PangoTextLayout::SetEditMode(bool enable) { edit_mode_ = enable; }
Index PangoTextLayout::GetLineIndexFromCharIndex(Index char_index) {
int line;
- pango_layout_index_to_line_x(pango_layout_,
- FromUtf16IndexToUtf8Index(char_index), false,
- &line, nullptr);
+ pango_layout_index_to_line_x(pango_layout_, char_index, false, &line,
+ nullptr);
return line;
}
@@ -80,27 +77,6 @@ float PangoTextLayout::GetLineHeight(Index line_index) {
return static_cast<float>(height) / PANGO_SCALE;
}
-Index PangoTextLayout::FromUtf8IndexToUtf16Index(Index index) {
- Utf8CodePointIterator iter(utf8_text_.data(), utf8_text_.size());
- int cp_count = 0;
- while ((!iter.IsPastEnd()) && iter.GetPosition() < index) {
- ++iter;
- cp_count++;
- }
- return text_.IndexFromCodePointToCodeUnit(cp_count);
-}
-
-Index PangoTextLayout::FromUtf16IndexToUtf8Index(Index index) {
- Index cp_index = text_.IndexFromCodeUnitToCodePoint(index);
- Utf8CodePointIterator iter(utf8_text_.data(), utf8_text_.size());
-
- for (Index i = 0; i < cp_index; ++i) {
- ++iter;
- }
-
- return iter.GetPosition();
-}
-
Rect PangoTextLayout::GetTextBounds(bool includingTrailingSpace) {
PangoRectangle rectangle;
pango_layout_get_extents(pango_layout_, nullptr, &rectangle);
@@ -110,17 +86,17 @@ Rect PangoTextLayout::GetTextBounds(bool includingTrailingSpace) {
std::vector<Rect> PangoTextLayout::TextRangeRect(const TextRange& text_range) {
auto tr = text_range.Normalize();
- auto utf8_start_index = FromUtf16IndexToUtf8Index(tr.GetStart());
- auto utf8_end_index = FromUtf16IndexToUtf8Index(tr.GetEnd());
+ auto start_index = tr.GetStart();
+ auto end_index = tr.GetEnd();
PangoRectangle rectangle;
int start_line_index, end_line_index, start_x_pos, end_x_pos;
- pango_layout_index_to_line_x(pango_layout_, utf8_start_index, false,
+ pango_layout_index_to_line_x(pango_layout_, start_index, false,
&start_line_index, &start_x_pos);
- pango_layout_index_to_line_x(pango_layout_, utf8_end_index, false,
- &end_line_index, &end_x_pos);
+ pango_layout_index_to_line_x(pango_layout_, end_index, false, &end_line_index,
+ &end_x_pos);
- pango_layout_index_to_pos(pango_layout_, utf8_start_index, &rectangle);
+ pango_layout_index_to_pos(pango_layout_, start_index, &rectangle);
auto top = rectangle.y;
if (start_line_index == end_line_index) {
@@ -161,9 +137,8 @@ std::vector<Rect> PangoTextLayout::TextRangeRect(const TextRange& text_range) {
}
Rect PangoTextLayout::TextSinglePoint(Index position, bool trailing) {
- auto utf8_index = FromUtf16IndexToUtf8Index(position);
int line_index, x_pos, y_pos = 0;
- pango_layout_index_to_line_x(pango_layout_, utf8_index, trailing, &line_index,
+ pango_layout_index_to_line_x(pango_layout_, position, trailing, &line_index,
&x_pos);
for (int i = 0; i < line_index; i++) {
@@ -186,8 +161,7 @@ TextHitTestResult PangoTextLayout::HitTest(const Point& point) {
auto inside_text =
pango_layout_xy_to_index(pango_layout_, point.x * PANGO_SCALE,
point.y * PANGO_SCALE, &index, &trailing);
- return TextHitTestResult{FromUtf8IndexToUtf16Index(index), trailing != 0,
- inside_text != 0};
+ return TextHitTestResult{index, trailing != 0, inside_text != 0};
}
} // namespace cru::platform::graphics::cairo
diff --git a/src/platform/graphics/direct2d/ImageFactory.cpp b/src/platform/graphics/direct2d/ImageFactory.cpp
index b9e9221a..aff411c4 100644
--- a/src/platform/graphics/direct2d/ImageFactory.cpp
+++ b/src/platform/graphics/direct2d/ImageFactory.cpp
@@ -74,7 +74,7 @@ GUID ConvertImageFormatToGUID(ImageFormat format) {
void WinImageFactory::EncodeToStream(IImage* image, io::Stream* stream,
ImageFormat format, float quality) {
- auto direct_image = CheckPlatform<Direct2DImage>(image, GetPlatformIdUtf8());
+ auto direct_image = CheckPlatform<Direct2DImage>(image, GetPlatformId());
Microsoft::WRL::ComPtr<IStream> com_stream(
platform::win::ConvertStreamToComStream(stream));
diff --git a/src/platform/graphics/direct2d/Painter.cpp b/src/platform/graphics/direct2d/Painter.cpp
index 29ddcabb..fabcdafd 100644
--- a/src/platform/graphics/direct2d/Painter.cpp
+++ b/src/platform/graphics/direct2d/Painter.cpp
@@ -55,7 +55,7 @@ void D2DDeviceContextPainter::Clear(const Color& color) {
void D2DDeviceContextPainter::DrawLine(const Point& start, const Point& end,
IBrush* brush, float width) {
CheckValidation();
- const auto b = CheckPlatform<ID2DBrush>(brush, GetPlatformIdUtf8());
+ const auto b = CheckPlatform<ID2DBrush>(brush, GetPlatformId());
device_context_->DrawLine(Convert(start), Convert(end),
b->GetD2DBrushInterface(), width);
}
@@ -63,7 +63,7 @@ void D2DDeviceContextPainter::DrawLine(const Point& start, const Point& end,
void D2DDeviceContextPainter::StrokeRectangle(const Rect& rectangle,
IBrush* brush, float width) {
CheckValidation();
- const auto b = CheckPlatform<ID2DBrush>(brush, GetPlatformIdUtf8());
+ const auto b = CheckPlatform<ID2DBrush>(brush, GetPlatformId());
device_context_->DrawRectangle(Convert(rectangle), b->GetD2DBrushInterface(),
width);
}
@@ -71,14 +71,14 @@ void D2DDeviceContextPainter::StrokeRectangle(const Rect& rectangle,
void D2DDeviceContextPainter::FillRectangle(const Rect& rectangle,
IBrush* brush) {
CheckValidation();
- const auto b = CheckPlatform<ID2DBrush>(brush, GetPlatformIdUtf8());
+ const auto b = CheckPlatform<ID2DBrush>(brush, GetPlatformId());
device_context_->FillRectangle(Convert(rectangle), b->GetD2DBrushInterface());
}
void D2DDeviceContextPainter::StrokeEllipse(const Rect& outline_rect,
IBrush* brush, float width) {
CheckValidation();
- const auto b = CheckPlatform<ID2DBrush>(brush, GetPlatformIdUtf8());
+ const auto b = CheckPlatform<ID2DBrush>(brush, GetPlatformId());
device_context_->DrawEllipse(
D2D1::Ellipse(Convert(outline_rect.GetCenter()),
outline_rect.width / 2.0f, outline_rect.height / 2.0f),
@@ -87,7 +87,7 @@ void D2DDeviceContextPainter::StrokeEllipse(const Rect& outline_rect,
void D2DDeviceContextPainter::FillEllipse(const Rect& outline_rect,
IBrush* brush) {
CheckValidation();
- const auto b = CheckPlatform<ID2DBrush>(brush, GetPlatformIdUtf8());
+ const auto b = CheckPlatform<ID2DBrush>(brush, GetPlatformId());
device_context_->FillEllipse(
D2D1::Ellipse(Convert(outline_rect.GetCenter()),
outline_rect.width / 2.0f, outline_rect.height / 2.0f),
@@ -97,16 +97,16 @@ void D2DDeviceContextPainter::FillEllipse(const Rect& outline_rect,
void D2DDeviceContextPainter::StrokeGeometry(IGeometry* geometry, IBrush* brush,
float width) {
CheckValidation();
- const auto g = CheckPlatform<D2DGeometry>(geometry, GetPlatformIdUtf8());
- const auto b = CheckPlatform<ID2DBrush>(brush, GetPlatformIdUtf8());
+ const auto g = CheckPlatform<D2DGeometry>(geometry, GetPlatformId());
+ const auto b = CheckPlatform<ID2DBrush>(brush, GetPlatformId());
device_context_->DrawGeometry(g->GetComInterface(), b->GetD2DBrushInterface(),
width);
}
void D2DDeviceContextPainter::FillGeometry(IGeometry* geometry, IBrush* brush) {
CheckValidation();
- const auto g = CheckPlatform<D2DGeometry>(geometry, GetPlatformIdUtf8());
- const auto b = CheckPlatform<ID2DBrush>(brush, GetPlatformIdUtf8());
+ const auto g = CheckPlatform<D2DGeometry>(geometry, GetPlatformId());
+ const auto b = CheckPlatform<ID2DBrush>(brush, GetPlatformId());
device_context_->FillGeometry(g->GetComInterface(),
b->GetD2DBrushInterface());
}
@@ -115,15 +115,15 @@ void D2DDeviceContextPainter::DrawText(const Point& offset,
ITextLayout* text_layout,
IBrush* brush) {
CheckValidation();
- const auto t = CheckPlatform<DWriteTextLayout>(text_layout, GetPlatformIdUtf8());
- const auto b = CheckPlatform<ID2DBrush>(brush, GetPlatformIdUtf8());
+ const auto t = CheckPlatform<DWriteTextLayout>(text_layout, GetPlatformId());
+ const auto b = CheckPlatform<ID2DBrush>(brush, GetPlatformId());
device_context_->DrawTextLayout(Convert(offset), t->GetComInterface(),
b->GetD2DBrushInterface());
}
void D2DDeviceContextPainter::DrawImage(const Point& offset, IImage* image) {
CheckValidation();
- const auto i = CheckPlatform<Direct2DImage>(image, GetPlatformIdUtf8());
+ const auto i = CheckPlatform<Direct2DImage>(image, GetPlatformId());
Microsoft::WRL::ComPtr<ID2D1DeviceContext> device_context;
diff --git a/src/platform/graphics/direct2d/TextLayout.cpp b/src/platform/graphics/direct2d/TextLayout.cpp
index 7a2074ec..06bbcaa6 100644
--- a/src/platform/graphics/direct2d/TextLayout.cpp
+++ b/src/platform/graphics/direct2d/TextLayout.cpp
@@ -14,7 +14,7 @@ DWriteTextLayout::DWriteTextLayout(DirectGraphicsFactory* factory,
std::shared_ptr<IFont> font, String text)
: DirectGraphicsResource(factory), text_(std::move(text)) {
Expects(font);
- font_ = CheckPlatform<DWriteFont>(font, GetPlatformIdUtf8());
+ font_ = CheckPlatform<DWriteFont>(font, GetPlatformId());
ThrowIfFailed(factory->GetDWriteFactory()->CreateTextLayout(
reinterpret_cast<const wchar_t*>(text_.c_str()),
@@ -39,7 +39,7 @@ std::shared_ptr<IFont> DWriteTextLayout::GetFont() {
}
void DWriteTextLayout::SetFont(std::shared_ptr<IFont> font) {
- font_ = CheckPlatform<DWriteFont>(font, GetPlatformIdUtf8());
+ font_ = CheckPlatform<DWriteFont>(font, GetPlatformId());
ThrowIfFailed(GetDirectFactory()->GetDWriteFactory()->CreateTextLayout(
reinterpret_cast<const wchar_t*>(text_.c_str()),
static_cast<UINT32>(text_.size()), font_->GetComInterface(), max_width_,
diff --git a/src/platform/graphics/quartz/Factory.cpp b/src/platform/graphics/quartz/Factory.cpp
index 5d5b48b5..862c0966 100644
--- a/src/platform/graphics/quartz/Factory.cpp
+++ b/src/platform/graphics/quartz/Factory.cpp
@@ -33,7 +33,7 @@ std::unique_ptr<IFont> QuartzGraphicsFactory::CreateFont(String font_family,
std::unique_ptr<ITextLayout> QuartzGraphicsFactory::CreateTextLayout(
std::shared_ptr<IFont> font, String text) {
- auto f = CheckPlatform<OsxCTFont>(font, GetPlatformIdUtf8());
+ auto f = CheckPlatform<OsxCTFont>(font, GetPlatformId());
return std::make_unique<OsxCTTextLayout>(this, f, text);
}
diff --git a/src/platform/graphics/quartz/ImageFactory.cpp b/src/platform/graphics/quartz/ImageFactory.cpp
index 62229bcb..2090828c 100644
--- a/src/platform/graphics/quartz/ImageFactory.cpp
+++ b/src/platform/graphics/quartz/ImageFactory.cpp
@@ -49,7 +49,7 @@ void QuartzImageFactory::EncodeToStream(IImage* image, io::Stream* stream,
throw Exception("Invalid quality value.");
}
- auto quartz_image = CheckPlatform<QuartzImage>(image, GetPlatformIdUtf8());
+ auto quartz_image = CheckPlatform<QuartzImage>(image, GetPlatformId());
auto cg_image = quartz_image->GetCGImage();
auto uti = ToCFString(GetImageFormatUniformTypeIdentifier(format));
diff --git a/src/platform/graphics/quartz/Painter.cpp b/src/platform/graphics/quartz/Painter.cpp
index fe0f5d43..45dee716 100644
--- a/src/platform/graphics/quartz/Painter.cpp
+++ b/src/platform/graphics/quartz/Painter.cpp
@@ -66,7 +66,7 @@ void QuartzCGContextPainter::DrawLine(const Point& start, const Point& end,
CGContextMoveToPoint(cg_context_, start.x, start.y);
CGContextAddLineToPoint(cg_context_, end.x, end.y);
- QuartzBrush* b = CheckPlatform<QuartzBrush>(brush, GetPlatformIdUtf8());
+ QuartzBrush* b = CheckPlatform<QuartzBrush>(brush, GetPlatformId());
b->Select(cg_context_);
SetLineWidth(width);
@@ -77,7 +77,7 @@ void QuartzCGContextPainter::StrokeRectangle(const Rect& rectangle,
IBrush* brush, float width) {
Validate();
- QuartzBrush* b = CheckPlatform<QuartzBrush>(brush, GetPlatformIdUtf8());
+ QuartzBrush* b = CheckPlatform<QuartzBrush>(brush, GetPlatformId());
b->Select(cg_context_);
CGContextStrokeRectWithWidth(cg_context_, Convert(rectangle), width);
}
@@ -86,7 +86,7 @@ void QuartzCGContextPainter::FillRectangle(const Rect& rectangle,
IBrush* brush) {
Validate();
- QuartzBrush* b = CheckPlatform<QuartzBrush>(brush, GetPlatformIdUtf8());
+ QuartzBrush* b = CheckPlatform<QuartzBrush>(brush, GetPlatformId());
b->Select(cg_context_);
CGContextFillRect(cg_context_, Convert(rectangle));
}
@@ -95,7 +95,7 @@ void QuartzCGContextPainter::StrokeEllipse(const Rect& outline_rect,
IBrush* brush, float width) {
Validate();
- QuartzBrush* b = CheckPlatform<QuartzBrush>(brush, GetPlatformIdUtf8());
+ QuartzBrush* b = CheckPlatform<QuartzBrush>(brush, GetPlatformId());
b->Select(cg_context_);
SetLineWidth(width);
@@ -106,7 +106,7 @@ void QuartzCGContextPainter::FillEllipse(const Rect& outline_rect,
IBrush* brush) {
Validate();
- QuartzBrush* b = CheckPlatform<QuartzBrush>(brush, GetPlatformIdUtf8());
+ QuartzBrush* b = CheckPlatform<QuartzBrush>(brush, GetPlatformId());
b->Select(cg_context_);
CGContextFillEllipseInRect(cg_context_, Convert(outline_rect));
}
@@ -115,8 +115,8 @@ void QuartzCGContextPainter::StrokeGeometry(IGeometry* geometry, IBrush* brush,
float width) {
Validate();
- QuartzGeometry* g = CheckPlatform<QuartzGeometry>(geometry, GetPlatformIdUtf8());
- QuartzBrush* b = CheckPlatform<QuartzBrush>(brush, GetPlatformIdUtf8());
+ QuartzGeometry* g = CheckPlatform<QuartzGeometry>(geometry, GetPlatformId());
+ QuartzBrush* b = CheckPlatform<QuartzBrush>(brush, GetPlatformId());
b->Select(cg_context_);
SetLineWidth(width);
@@ -129,8 +129,8 @@ void QuartzCGContextPainter::StrokeGeometry(IGeometry* geometry, IBrush* brush,
void QuartzCGContextPainter::FillGeometry(IGeometry* geometry, IBrush* brush) {
Validate();
- QuartzGeometry* g = CheckPlatform<QuartzGeometry>(geometry, GetPlatformIdUtf8());
- QuartzBrush* b = CheckPlatform<QuartzBrush>(brush, GetPlatformIdUtf8());
+ QuartzGeometry* g = CheckPlatform<QuartzGeometry>(geometry, GetPlatformId());
+ QuartzBrush* b = CheckPlatform<QuartzBrush>(brush, GetPlatformId());
b->Select(cg_context_);
CGContextBeginPath(cg_context_);
@@ -142,7 +142,7 @@ void QuartzCGContextPainter::DrawText(const Point& offset,
ITextLayout* text_layout, IBrush* brush) {
Validate();
- auto tl = CheckPlatform<OsxCTTextLayout>(text_layout, GetPlatformIdUtf8());
+ auto tl = CheckPlatform<OsxCTTextLayout>(text_layout, GetPlatformId());
Color color;
@@ -169,7 +169,7 @@ void QuartzCGContextPainter::DrawText(const Point& offset,
void QuartzCGContextPainter::DrawImage(const Point& offset, IImage* image) {
Validate();
- auto i = CheckPlatform<QuartzImage>(image, GetPlatformIdUtf8());
+ auto i = CheckPlatform<QuartzImage>(image, GetPlatformId());
auto cg_image = i->GetCGImage();
diff --git a/src/platform/graphics/quartz/TextLayout.cpp b/src/platform/graphics/quartz/TextLayout.cpp
index 41a2f176..8c573c7a 100644
--- a/src/platform/graphics/quartz/TextLayout.cpp
+++ b/src/platform/graphics/quartz/TextLayout.cpp
@@ -31,7 +31,7 @@ OsxCTTextLayout::~OsxCTTextLayout() {
}
void OsxCTTextLayout::SetFont(std::shared_ptr<IFont> font) {
- font_ = CheckPlatform<OsxCTFont>(font, GetPlatformIdUtf8());
+ font_ = CheckPlatform<OsxCTFont>(font, GetPlatformId());
RecreateFrame();
}
diff --git a/src/platform/graphics/web_canvas/Painter.cpp b/src/platform/graphics/web_canvas/Painter.cpp
index f928de35..c9184165 100644
--- a/src/platform/graphics/web_canvas/Painter.cpp
+++ b/src/platform/graphics/web_canvas/Painter.cpp
@@ -94,7 +94,7 @@ void WebCanvasPainter::SetFillStyle(IBrush* brush) {
}
WebCanvasBrush* WebCanvasPainter::ConvertBrush(IBrush* brush) const {
- return CheckPlatform<WebCanvasBrush>(brush, GetPlatformIdUtf8());
+ return CheckPlatform<WebCanvasBrush>(brush, GetPlatformId());
}
WebCanvasRef WebCanvasPainter::GetCanvas() {
diff --git a/src/platform/gui/CMakeLists.txt b/src/platform/gui/CMakeLists.txt
index b541428e..70ae62f9 100644
--- a/src/platform/gui/CMakeLists.txt
+++ b/src/platform/gui/CMakeLists.txt
@@ -1,5 +1,5 @@
add_library(CruPlatformGui
- Keyboard.cpp
+ Input.cpp
Menu.cpp
UiApplication.cpp
Window.cpp
diff --git a/src/platform/gui/Input.cpp b/src/platform/gui/Input.cpp
new file mode 100644
index 00000000..a5e25dc8
--- /dev/null
+++ b/src/platform/gui/Input.cpp
@@ -0,0 +1,140 @@
+#include "cru/platform/gui/Input.h"
+
+#include <array>
+#include <string>
+#include <string_view>
+
+namespace cru::platform::gui {
+const std::array<std::string_view, static_cast<int>(KeyCode::NumPad9) + 1>
+ key_code_string_list{"Unknown",
+ "LeftButton",
+ "MiddleButton",
+ "RightButton",
+ "Escape",
+ "F1",
+ "F2",
+ "F3",
+ "F4",
+ "F5",
+ "F6",
+ "F7",
+ "F8",
+ "F9",
+ "F10",
+ "F11",
+ "F12",
+ "N0",
+ "N1",
+ "N2",
+ "N3",
+ "N4",
+ "N5",
+ "N6",
+ "N7",
+ "N8",
+ "N9",
+ "A",
+ "B",
+ "C",
+ "D",
+ "E",
+ "F",
+ "G",
+ "H",
+ "I",
+ "J",
+ "K",
+ "L",
+ "M",
+ "N",
+ "O",
+ "P",
+ "Q",
+ "R",
+ "S",
+ "T",
+ "U",
+ "V",
+ "W",
+ "X",
+ "Y",
+ "Z",
+ "GraveAccent",
+ "Tab",
+ "CapsLock",
+ "LeftShift",
+ "LeftCtrl",
+ "LeftSuper",
+ "LeftAlt",
+ "Minus",
+ "Equal",
+ "Backspace",
+ "LeftSquareBracket",
+ "RightSquareBracket",
+ "BackSlash",
+ "Semicolon",
+ "Quote",
+ "Comma",
+ "Period",
+ "Slash",
+ "RightShift",
+ "RightCtrl",
+ "RightSuper",
+ "RightAlt",
+ "Insert",
+ "Delete",
+ "Home",
+ "End",
+ "PageUp",
+ "PageDown",
+ "Up",
+ "Left",
+ "Down",
+ "Right",
+ "PrintScreen",
+ "ScrollLock",
+ "Pause",
+ "NumPad0",
+ "NumPad1",
+ "NumPad2",
+ "NumPad3",
+ "NumPad4",
+ "NumPad5",
+ "NumPad6",
+ "NumPad7",
+ "NumPad8",
+ "NumPad9"};
+
+std::string ToString(KeyCode key_code) {
+ if (static_cast<int>(key_code) < 0 ||
+ static_cast<int>(key_code) >=
+ static_cast<int>(key_code_string_list.size()))
+ return "UNKNOWN_KEYCODENAME";
+
+ return std::string(key_code_string_list[static_cast<int>(key_code)]);
+}
+
+std::string ToString(KeyModifier key_modifier, std::string_view separator) {
+ std::vector<std::string> list;
+ if (key_modifier & KeyModifiers::Shift) {
+ list.push_back("Shift");
+ }
+
+ if (key_modifier & KeyModifiers::Ctrl) {
+ list.push_back("Ctrl");
+ }
+
+ if (key_modifier & KeyModifiers::Alt) {
+ list.push_back("Shift");
+ }
+
+ if (list.empty()) return "";
+ std::string result = list.front();
+ for (auto iter = list.cbegin() + 1; iter != list.cend(); ++iter) {
+ result += separator;
+ result += *iter;
+ }
+
+ return result;
+}
+} // namespace cru::platform::gui
diff --git a/src/platform/gui/Keyboard.cpp b/src/platform/gui/Keyboard.cpp
deleted file mode 100644
index 775995c2..00000000
--- a/src/platform/gui/Keyboard.cpp
+++ /dev/null
@@ -1,140 +0,0 @@
-#include "cru/platform/gui/Keyboard.h"
-
-#include <array>
-#include <string>
-#include <string_view>
-
-namespace cru::platform::gui {
-const std::array<StringView, static_cast<int>(KeyCode::NumPad9) + 1>
- key_code_string_list{u"Unknown",
- u"LeftButton",
- u"MiddleButton",
- u"RightButton",
- u"Escape",
- u"F1",
- u"F2",
- u"F3",
- u"F4",
- u"F5",
- u"F6",
- u"F7",
- u"F8",
- u"F9",
- u"F10",
- u"F11",
- u"F12",
- u"N0",
- u"N1",
- u"N2",
- u"N3",
- u"N4",
- u"N5",
- u"N6",
- u"N7",
- u"N8",
- u"N9",
- u"A",
- u"B",
- u"C",
- u"D",
- u"E",
- u"F",
- u"G",
- u"H",
- u"I",
- u"J",
- u"K",
- u"L",
- u"M",
- u"N",
- u"O",
- u"P",
- u"Q",
- u"R",
- u"S",
- u"T",
- u"U",
- u"V",
- u"W",
- u"X",
- u"Y",
- u"Z",
- u"GraveAccent",
- u"Tab",
- u"CapsLock",
- u"LeftShift",
- u"LeftCtrl",
- u"LeftSuper",
- u"LeftAlt",
- u"Minus",
- u"Equal",
- u"Backspace",
- u"LeftSquareBracket",
- u"RightSquareBracket",
- u"BackSlash",
- u"Semicolon",
- u"Quote",
- u"Comma",
- u"Period",
- u"Slash",
- u"RightShift",
- u"RightCtrl",
- u"RightSuper",
- u"RightAlt",
- u"Insert",
- u"Delete",
- u"Home",
- u"End",
- u"PageUp",
- u"PageDown",
- u"Up",
- u"Left",
- u"Down",
- u"Right",
- u"PrintScreen",
- u"ScrollLock",
- u"Pause",
- u"NumPad0",
- u"NumPad1",
- u"NumPad2",
- u"NumPad3",
- u"NumPad4",
- u"NumPad5",
- u"NumPad6",
- u"NumPad7",
- u"NumPad8",
- u"NumPad9"};
-
-String ToString(KeyCode key_code) {
- if (static_cast<int>(key_code) < 0 ||
- static_cast<int>(key_code) >=
- static_cast<int>(key_code_string_list.size()))
- return u"UNKNOWN_KEYCODENAME";
-
- return key_code_string_list[static_cast<int>(key_code)].ToString();
-}
-
-String ToString(KeyModifier key_modifier, StringView separator) {
- std::vector<String> list;
- if (key_modifier & KeyModifiers::shift) {
- list.push_back(u"Shift");
- }
-
- if (key_modifier & KeyModifiers::ctrl) {
- list.push_back(u"Ctrl");
- }
-
- if (key_modifier & KeyModifiers::alt) {
- list.push_back(u"Shift");
- }
-
- if (list.empty()) return u"";
- String result = list.front();
- for (auto iter = list.cbegin() + 1; iter != list.cend(); ++iter) {
- result += separator;
- result += *iter;
- }
-
- return result;
-}
-} // namespace cru::platform::gui
diff --git a/src/platform/gui/UiApplication.cpp b/src/platform/gui/UiApplication.cpp
index ac93a57d..086440c0 100644
--- a/src/platform/gui/UiApplication.cpp
+++ b/src/platform/gui/UiApplication.cpp
@@ -1,5 +1,6 @@
#include "cru/platform/gui/UiApplication.h"
+#include "cru/base/Base.h"
#include "cru/base/Exception.h"
namespace cru::platform::gui {
@@ -22,13 +23,13 @@ IUiApplication::~IUiApplication() { instance = nullptr; }
IMenu* IUiApplication::GetApplicationMenu() { return nullptr; }
-std::optional<String> IUiApplication::ShowSaveDialog(
+std::optional<std::string> IUiApplication::ShowSaveDialog(
SaveDialogOptions options) {
- throw Exception("Not implemented.");
+ NotImplemented();
}
-std::optional<std::vector<String>> IUiApplication::ShowOpenDialog(
+std::optional<std::vector<std::string>> IUiApplication::ShowOpenDialog(
OpenDialogOptions options) {
- throw Exception("Not implemented.");
+ NotImplemented();
}
} // namespace cru::platform::gui
diff --git a/src/platform/gui/osx/Window.mm b/src/platform/gui/osx/Window.mm
index 7381ca55..6559cf70 100644
--- a/src/platform/gui/osx/Window.mm
+++ b/src/platform/gui/osx/Window.mm
@@ -64,7 +64,7 @@ void OsxWindowPrivate::OnWindowWillClose() {
bool quit = true;
for (auto window : all_window) {
- auto w = CheckPlatform<OsxWindow>(window, osx_window_->GetPlatformIdUtf8());
+ auto w = CheckPlatform<OsxWindow>(window, osx_window_->GetPlatformId());
if (w->p_->window_) {
quit = false;
break;
@@ -179,7 +179,7 @@ void OsxWindowPrivate::CreateWindow() {
[window_ setDelegate:window_delegate_];
if (parent_) {
- auto parent = CheckPlatform<OsxWindow>(parent_, this->osx_window_->GetPlatformIdUtf8());
+ auto parent = CheckPlatform<OsxWindow>(parent_, this->osx_window_->GetPlatformId());
[window_ setParentWindow:parent->p_->window_];
}
@@ -231,7 +231,7 @@ void OsxWindow::Close() {
INativeWindow* OsxWindow::GetParent() { return p_->parent_; }
void OsxWindow::SetParent(INativeWindow* parent) {
- auto p = CheckPlatform<OsxWindow>(parent, GetPlatformIdUtf8());
+ auto p = CheckPlatform<OsxWindow>(parent, GetPlatformId());
p_->parent_ = parent;
@@ -366,7 +366,7 @@ bool OsxWindow::CaptureMouse() { return true; }
bool OsxWindow::ReleaseMouse() { return true; }
void OsxWindow::SetCursor(std::shared_ptr<ICursor> cursor) {
- p_->cursor_ = CheckPlatform<OsxCursor>(cursor, GetPlatformIdUtf8());
+ p_->cursor_ = CheckPlatform<OsxCursor>(cursor, GetPlatformId());
p_->UpdateCursor();
}
diff --git a/src/platform/gui/sdl/Window.cpp b/src/platform/gui/sdl/Window.cpp
index e802b82f..84cf0ad4 100644
--- a/src/platform/gui/sdl/Window.cpp
+++ b/src/platform/gui/sdl/Window.cpp
@@ -35,7 +35,7 @@ void SdlWindow::Close() {
INativeWindow *SdlWindow::GetParent() { return parent_; }
void SdlWindow::SetParent(INativeWindow *parent) {
- parent_ = CheckPlatform<SdlWindow>(parent, GetPlatformIdUtf8());
+ parent_ = CheckPlatform<SdlWindow>(parent, GetPlatformId());
NotImplemented();
}
@@ -46,9 +46,9 @@ void SdlWindow::SetStyleFlag(WindowStyleFlag flag) {
NotImplemented();
}
-String SdlWindow::GetTitle() { NotImplemented(); }
+std::string SdlWindow::GetTitle() { NotImplemented(); }
-void SdlWindow::SetTitle(String title) { NotImplemented(); }
+void SdlWindow::SetTitle(std::string title) { NotImplemented(); }
WindowVisibilityType SdlWindow::GetVisibility() { NotImplemented(); }
diff --git a/src/platform/gui/win/Window.cpp b/src/platform/gui/win/Window.cpp
index 5739d0f3..eeb2cde4 100644
--- a/src/platform/gui/win/Window.cpp
+++ b/src/platform/gui/win/Window.cpp
@@ -79,7 +79,7 @@ void WinNativeWindow::Close() {
}
void WinNativeWindow::SetParent(INativeWindow* parent) {
- auto p = CheckPlatform<WinNativeWindow>(parent, GetPlatformIdUtf8());
+ auto p = CheckPlatform<WinNativeWindow>(parent, GetPlatformId());
parent_window_ = p;
if (hwnd_) {
@@ -228,7 +228,7 @@ void WinNativeWindow::SetCursor(std::shared_ptr<ICursor> cursor) {
throw std::runtime_error("Can't use a nullptr as cursor.");
}
- cursor_ = CheckPlatform<WinCursor>(cursor, GetPlatformIdUtf8());
+ cursor_ = CheckPlatform<WinCursor>(cursor, GetPlatformId());
if (hwnd_) return;
diff --git a/src/platform/gui/xcb/CMakeLists.txt b/src/platform/gui/xcb/CMakeLists.txt
index cafc2e67..676fc7b1 100644
--- a/src/platform/gui/xcb/CMakeLists.txt
+++ b/src/platform/gui/xcb/CMakeLists.txt
@@ -6,8 +6,8 @@ find_library(LIBRARY_XKBCOMMON_X11 xkbcommon-x11 REQUIRED)
add_library(CruPlatformGuiXcb
Clipboard.cpp
Cursor.cpp
+ Input.cpp
InputMethod.cpp
- Keyboard.cpp
UiApplication.cpp
Window.cpp
)
diff --git a/src/platform/gui/xcb/Clipboard.cpp b/src/platform/gui/xcb/Clipboard.cpp
index d0d9d74f..a42130ab 100644
--- a/src/platform/gui/xcb/Clipboard.cpp
+++ b/src/platform/gui/xcb/Clipboard.cpp
@@ -7,7 +7,7 @@ XcbClipboard::XcbClipboard(XcbUiApplication* application)
XcbClipboard::~XcbClipboard() {}
-String XcbClipboard::GetText() { return String{}; }
+std::string XcbClipboard::GetText() { return {}; }
-void XcbClipboard::SetText(String text) {}
+void XcbClipboard::SetText(std::string text) {}
} // namespace cru::platform::gui::xcb
diff --git a/src/platform/gui/xcb/Cursor.cpp b/src/platform/gui/xcb/Cursor.cpp
index 5582c6a6..69d904df 100644
--- a/src/platform/gui/xcb/Cursor.cpp
+++ b/src/platform/gui/xcb/Cursor.cpp
@@ -1,6 +1,5 @@
#include "cru/platform/gui/xcb/Cursor.h"
#include "cru/base/Exception.h"
-#include "cru/platform/gui/Cursor.h"
#include "cru/platform/gui/xcb/UiApplication.h"
#include <xcb/xcb.h>
diff --git a/src/platform/gui/xcb/Keyboard.cpp b/src/platform/gui/xcb/Input.cpp
index 4bfc448c..9b6d76c2 100644
--- a/src/platform/gui/xcb/Keyboard.cpp
+++ b/src/platform/gui/xcb/Input.cpp
@@ -1,7 +1,6 @@
-#include "cru/platform/gui/xcb/Keyboard.h"
+#include "cru/platform/gui/xcb/Input.h"
#include "cru/base/Exception.h"
#include "cru/base/Guard.h"
-#include "cru/platform/gui/Keyboard.h"
#include "cru/platform/gui/xcb/UiApplication.h"
#include <xcb/xcb.h>
@@ -200,11 +199,11 @@ KeyModifier ConvertModifiersOfEvent(uint32_t mask) {
// "Shift", "Lock", "Ctrl", "Alt", "Mod2", "Mod3", "Mod4",
// "Mod5", "Button1", "Button2", "Button3", "Button4", "Button5"};
constexpr KeyModifier MODIFIERS[] = {
- KeyModifiers::Shift, KeyModifiers::none, KeyModifiers::Ctrl,
- KeyModifiers::Alt, KeyModifiers::none, KeyModifiers::none,
- KeyModifiers::none, KeyModifiers::none, KeyModifiers::none,
- KeyModifiers::none, KeyModifiers::none, KeyModifiers::none,
- KeyModifiers::none,
+ KeyModifiers::Shift, KeyModifiers::None, KeyModifiers::Ctrl,
+ KeyModifiers::Alt, KeyModifiers::None, KeyModifiers::None,
+ KeyModifiers::None, KeyModifiers::None, KeyModifiers::None,
+ KeyModifiers::None, KeyModifiers::None, KeyModifiers::None,
+ KeyModifiers::None,
};
KeyModifier result;
diff --git a/src/platform/gui/xcb/InputMethod.cpp b/src/platform/gui/xcb/InputMethod.cpp
index 16d6b4bd..5ee06ab4 100644
--- a/src/platform/gui/xcb/InputMethod.cpp
+++ b/src/platform/gui/xcb/InputMethod.cpp
@@ -1,10 +1,7 @@
#include "cru/platform/gui/xcb/InputMethod.h"
#include "cru/base/log/Logger.h"
#include "cru/platform/Check.h"
-#include "cru/platform/gui/InputMethod.h"
-#include "cru/platform/gui/Keyboard.h"
-#include "cru/platform/gui/Window.h"
-#include "cru/platform/gui/xcb/Keyboard.h"
+#include "cru/platform/gui/xcb/Input.h"
#include "cru/platform/gui/xcb/UiApplication.h"
#include "cru/platform/gui/xcb/Window.h"
@@ -99,7 +96,7 @@ void XcbXimInputMethodManager::DispatchCommit(xcb_xim_t *im, xcb_xic_t ic,
if (focus_context_) {
focus_context_->composition_event_.Raise(nullptr);
focus_context_->composition_end_event_.Raise(nullptr);
- focus_context_->text_event_.Raise(String::FromUtf8(text));
+ focus_context_->text_event_.Raise(std::move(text));
}
}
@@ -135,7 +132,7 @@ XcbXimInputMethodContext::XcbXimInputMethodContext(
window->FocusEvent()->AddHandler([this, window](FocusChangeType type) {
auto context = CheckPlatform<XcbXimInputMethodContext>(
- window->GetInputMethodContext(), GetPlatformIdUtf8());
+ window->GetInputMethodContext(), GetPlatformId());
if (type == FocusChangeType::Gain) {
SetFocus();
}
@@ -208,7 +205,7 @@ IEvent<std::nullptr_t> *XcbXimInputMethodContext::CompositionEvent() {
return &composition_event_;
}
-IEvent<StringView> *XcbXimInputMethodContext::TextEvent() {
+IEvent<std::string> *XcbXimInputMethodContext::TextEvent() {
return &text_event_;
}
diff --git a/src/platform/gui/xcb/UiApplication.cpp b/src/platform/gui/xcb/UiApplication.cpp
index a0a949b7..436bb335 100644
--- a/src/platform/gui/xcb/UiApplication.cpp
+++ b/src/platform/gui/xcb/UiApplication.cpp
@@ -1,13 +1,12 @@
#include "cru/platform/gui/xcb/UiApplication.h"
-#include "cru/base/Base.h"
#include "cru/base/Guard.h"
#include "cru/platform/graphics/cairo/CairoGraphicsFactory.h"
#include "cru/platform/gui/Window.h"
#include "cru/platform/gui/xcb/Clipboard.h"
#include "cru/platform/gui/xcb/Cursor.h"
+#include "cru/platform/gui/xcb/Input.h"
#include "cru/platform/gui/xcb/InputMethod.h"
-#include "cru/platform/gui/xcb/Keyboard.h"
#include "cru/platform/gui/xcb/Window.h"
#include <poll.h>
diff --git a/src/platform/gui/xcb/Window.cpp b/src/platform/gui/xcb/Window.cpp
index 6458046b..003afc40 100644
--- a/src/platform/gui/xcb/Window.cpp
+++ b/src/platform/gui/xcb/Window.cpp
@@ -7,12 +7,9 @@
#include "cru/platform/graphics/NullPainter.h"
#include "cru/platform/graphics/Painter.h"
#include "cru/platform/graphics/cairo/CairoPainter.h"
-#include "cru/platform/gui/Base.h"
-#include "cru/platform/gui/Keyboard.h"
-#include "cru/platform/gui/Window.h"
#include "cru/platform/gui/xcb/Cursor.h"
+#include "cru/platform/gui/xcb/Input.h"
#include "cru/platform/gui/xcb/InputMethod.h"
-#include "cru/platform/gui/xcb/Keyboard.h"
#include "cru/platform/gui/xcb/UiApplication.h"
#include <cairo-xcb.h>
@@ -73,7 +70,7 @@ void XcbWindow::Close() {
INativeWindow *XcbWindow::GetParent() { return parent_; }
void XcbWindow::SetParent(INativeWindow *parent) {
- parent_ = CheckPlatform<XcbWindow>(parent, GetPlatformIdUtf8());
+ parent_ = CheckPlatform<XcbWindow>(parent, GetPlatformId());
if (xcb_window_) {
DoSetParent(*xcb_window_);
}
@@ -90,10 +87,10 @@ void XcbWindow::SetStyleFlag(WindowStyleFlag flag) {
application_->XcbFlush();
}
-String XcbWindow::GetTitle() { return String::FromUtf8(title_); }
+std::string XcbWindow::GetTitle() { return title_; }
-void XcbWindow::SetTitle(String title) {
- title_ = title.ToUtf8();
+void XcbWindow::SetTitle(std::string title) {
+ title_ = std::move(title);
if (xcb_window_) {
DoSetTitle(*xcb_window_);
}
@@ -271,7 +268,7 @@ bool XcbWindow::ReleaseMouse() {
void XcbWindow::SetCursor(std::shared_ptr<ICursor> cursor) {
if (!xcb_window_) return;
- auto xcb_cursor = CheckPlatform<XcbCursor>(cursor, GetPlatformIdUtf8());
+ auto xcb_cursor = CheckPlatform<XcbCursor>(cursor, GetPlatformId());
cursor_ = xcb_cursor;
DoSetCursor(*xcb_window_, xcb_cursor.get());
}
diff --git a/src/ui/Helper.h b/src/ui/Helper.h
index 8bee72a6..625ba6e3 100644
--- a/src/ui/Helper.h
+++ b/src/ui/Helper.h
@@ -1,14 +1,5 @@
#pragma once
-#include "cru/ui/Base.h"
-
-namespace cru::platform {
-namespace graphics {
-struct IGraphicsFactory;
-}
-namespace native {
-struct IUiApplication;
-} // namespace native
-} // namespace cru::platform
+#include <cru/platform/gui/UiApplication.h>
namespace cru::ui {
cru::platform::graphics::IGraphicsFactory* GetGraphicsFactory();
diff --git a/src/ui/ThemeManager.cpp b/src/ui/ThemeManager.cpp
index a95900b4..0f4daeb7 100644
--- a/src/ui/ThemeManager.cpp
+++ b/src/ui/ThemeManager.cpp
@@ -1,14 +1,9 @@
#include "cru/ui/ThemeManager.h"
-#include "Helper.h"
-#include "cru/base/StringUtil.h"
#include "cru/base/io/Resource.h"
#include "cru/platform/graphics/Brush.h"
-#include "cru/platform/graphics/Factory.h"
-#include "cru/platform/gui/UiApplication.h"
#include "cru/ui/ThemeResourceDictionary.h"
#include "cru/ui/style/StyleRuleSet.h"
-#include "cru/xml/XmlParser.h"
namespace cru::ui {
ThemeManager* ThemeManager::GetInstance() {
@@ -48,22 +43,22 @@ void ThemeManager::PrependThemeResourceDictionary(
theme_resource_change_event_.Raise(nullptr);
}
-String ThemeManager::GetResourceString(const String& key) {
- return GetResource<String>(key);
+std::string ThemeManager::GetResourceString(std::string_view key) {
+ return GetResource<String>(key).ToUtf8();
}
std::shared_ptr<platform::graphics::IBrush> ThemeManager::GetResourceBrush(
- const String& key) {
+ std::string_view key) {
return GetResource<std::shared_ptr<platform::graphics::IBrush>>(key);
}
std::shared_ptr<platform::graphics::IFont> ThemeManager::GetResourceFont(
- const String& key) {
+ std::string_view key) {
return GetResource<std::shared_ptr<platform::graphics::IFont>>(key);
}
std::shared_ptr<style::StyleRuleSet> ThemeManager::GetResourceStyleRuleSet(
- const String& key) {
+ std::string_view key) {
return GetResource<std::shared_ptr<style::StyleRuleSet>>(key);
}
} // namespace cru::ui
diff --git a/src/ui/ThemeResourceDictionary.cpp b/src/ui/ThemeResourceDictionary.cpp
index d6f2d3e3..f76bdde8 100644
--- a/src/ui/ThemeResourceDictionary.cpp
+++ b/src/ui/ThemeResourceDictionary.cpp
@@ -43,7 +43,7 @@ void ThemeResourceDictionary::UpdateResourceMap(xml::XmlElementNode* xml_root) {
ResourceEntry entry;
- entry.name = String::FromUtf8(*key_attr);
+ entry.name = *key_attr;
entry.xml_node = c->GetFirstChildElement();
resource_map_[entry.name] = std::move(entry);
diff --git a/src/ui/components/Input.cpp b/src/ui/components/Input.cpp
index 6a53b938..e75eccc5 100644
--- a/src/ui/components/Input.cpp
+++ b/src/ui/components/Input.cpp
@@ -1,13 +1,13 @@
#include "cru/ui/components/Input.h"
-#include "cru/base/Format.h"
#include "cru/base/StringToNumberConverter.h"
#include "cru/ui/controls/Control.h"
#include <cmath>
#include <optional>
+#include <string>
namespace cru::ui::components {
-Input::Input() : last_validate_result_{true, u"Good value"} {
+Input::Input() : last_validate_result_{true, "Good value"} {
text_box_.TextChangeEvent()->AddSpyOnlyHandler([this] {
auto text = text_box_.GetText();
auto validate_result = Validate();
@@ -20,9 +20,9 @@ Input::~Input() {}
controls::Control* Input::GetRootControl() { return &text_box_; }
-String Input::GetText() const { return text_box_.GetText(); }
+std::string Input::GetText() const { return text_box_.GetText(); }
-void Input::SetText(String text) { text_box_.SetText(std::move(text)); }
+void Input::SetText(std::string text) { text_box_.SetText(std::move(text)); }
IInputValidator* Input::GetValidator() const { return validator_; }
@@ -35,7 +35,7 @@ InputValidateResult Input::Validate() {
if (validator_)
last_validate_result_ = validator_->Validate(text_box_.GetTextView());
else
- last_validate_result_ = {true, u"Good value"};
+ last_validate_result_ = {true, "Good value"};
return last_validate_result_;
}
@@ -43,23 +43,23 @@ InputValidateResult Input::GetLastValidateResult() const {
return last_validate_result_;
}
-InputValidateResult FloatInputValidator::Validate(StringView text) const {
- auto result =
- text.ParseToFloat(nullptr, StringToNumberFlags::kAllowLeadingSpaces &
- StringToNumberFlags::kAllowTrailingSpaces);
+InputValidateResult FloatInputValidator::Validate(std::string_view text) const {
+ auto result = String::FromUtf8(text).ParseToFloat(
+ nullptr, StringToNumberFlags::kAllowLeadingSpaces &
+ StringToNumberFlags::kAllowTrailingSpaces);
if (std::isnan(result)) {
- return InputValidateResult{false, u"Invalid number."};
+ return InputValidateResult{false, "Invalid number."};
}
if (min && result < *min) {
- return InputValidateResult{false, u"Value is less than minimum."};
+ return InputValidateResult{false, "Value is less than minimum."};
}
if (max && result > *max) {
- return InputValidateResult{false, u"Value is greater than maximum."};
+ return InputValidateResult{false, "Value is greater than maximum."};
}
- return InputValidateResult{true, u"Good number"};
+ return InputValidateResult{true, "Good number"};
}
FloatInput::FloatInput() {
@@ -67,7 +67,7 @@ FloatInput::FloatInput() {
ChangeEvent()->AddHandler([this](const InputChangeEventArgs& args) {
if (args.valid) {
- value_ = args.text.ParseToFloat(
+ value_ = String::FromUtf8(args.text).ParseToFloat(
nullptr, StringToNumberFlags::kAllowLeadingSpaces &
StringToNumberFlags::kAllowTrailingSpaces);
}
@@ -78,7 +78,7 @@ FloatInput::~FloatInput() {}
float FloatInput::GetValue() const { return value_; }
-void FloatInput::SetValue(float value) { SetText(ToString(value)); }
+void FloatInput::SetValue(float value) { SetText(std::to_string(value)); }
std::optional<float> FloatInput::GetMin() const { return validator_.min; }
diff --git a/src/ui/components/Menu.cpp b/src/ui/components/Menu.cpp
index 2da38990..59bcf8ec 100644
--- a/src/ui/components/Menu.cpp
+++ b/src/ui/components/Menu.cpp
@@ -14,17 +14,17 @@ namespace cru::ui::components {
MenuItem::MenuItem() {
container_.SetChild(&text_);
container_.GetStyleRuleSet()->SetParent(
- ThemeManager::GetInstance()->GetResourceStyleRuleSet(u"menuitem.style"));
+ ThemeManager::GetInstance()->GetResourceStyleRuleSet("menuitem.style"));
container_.ClickEvent()->AddHandler([this](const helper::ClickEventArgs&) {
if (this->on_click_) this->on_click_();
});
}
-MenuItem::MenuItem(String text) : MenuItem() { SetText(std::move(text)); }
+MenuItem::MenuItem(std::string text) : MenuItem() { SetText(std::move(text)); }
MenuItem::~MenuItem() {}
-void MenuItem::SetText(String text) { text_.SetText(std::move(text)); }
+void MenuItem::SetText(std::string text) { text_.SetText(std::move(text)); }
Menu::Menu() {
container_.SetFlexDirection(controls::FlexDirection::Vertical);
@@ -65,7 +65,7 @@ void Menu::ClearItems() {
container_.ClearChildren();
}
-void Menu::AddTextItemAt(String text, Index index,
+void Menu::AddTextItemAt(std::string text, Index index,
std::function<void()> on_click) {
MenuItem* item = new MenuItem(std::move(text));
item->SetOnClick([this, index, on_click = std::move(on_click)] {
diff --git a/src/ui/components/PopupButton.cpp b/src/ui/components/PopupButton.cpp
index 41e0ad6c..5ea41d78 100644
--- a/src/ui/components/PopupButton.cpp
+++ b/src/ui/components/PopupButton.cpp
@@ -14,7 +14,7 @@ PopupMenuTextButton::PopupMenuTextButton() : popup_menu_(&button_) {
PopupMenuTextButton::~PopupMenuTextButton() {}
-void PopupMenuTextButton::SetMenuItems(std::vector<String> items) {
+void PopupMenuTextButton::SetMenuItems(std::vector<std::string> items) {
popup_menu_.GetMenu()->ClearItems();
for (Index i = 0; i < items.size(); i++) {
popup_menu_.GetMenu()->AddTextItem(
@@ -31,7 +31,7 @@ PopupMenuIconButton::PopupMenuIconButton() : popup_menu_(&button_) {
PopupMenuIconButton::~PopupMenuIconButton() {}
-void PopupMenuIconButton::SetMenuItems(std::vector<String> items) {
+void PopupMenuIconButton::SetMenuItems(std::vector<std::string> items) {
popup_menu_.GetMenu()->ClearItems();
for (Index i = 0; i < items.size(); i++) {
popup_menu_.GetMenu()->AddTextItem(
diff --git a/src/ui/components/Select.cpp b/src/ui/components/Select.cpp
index 90b49d30..5dbb727c 100644
--- a/src/ui/components/Select.cpp
+++ b/src/ui/components/Select.cpp
@@ -15,7 +15,7 @@ Select::Select() {
Select::~Select() {}
-void Select::SetItems(std::vector<String> items) {
+void Select::SetItems(std::vector<std::string> items) {
items_ = items;
popup_menu_.GetMenu()->ClearItems();
for (Index i = 0; i < items.size(); i++) {
diff --git a/src/ui/controls/Button.cpp b/src/ui/controls/Button.cpp
index d7d157c5..a44a7074 100644
--- a/src/ui/controls/Button.cpp
+++ b/src/ui/controls/Button.cpp
@@ -1,9 +1,5 @@
#include "cru/ui/controls/Button.h"
-#include "../Helper.h"
-#include "cru/platform/graphics/Brush.h"
-#include "cru/platform/gui/Cursor.h"
-#include "cru/platform/gui/UiApplication.h"
#include "cru/ui/ThemeManager.h"
#include "cru/ui/helper/ClickDetector.h"
#include "cru/ui/render/BorderRenderObject.h"
@@ -12,7 +8,7 @@ namespace cru::ui::controls {
Button::Button() : click_detector_(this) {
GetContainerRenderObject()->SetBorderEnabled(true);
auto default_button_style =
- ThemeManager::GetInstance()->GetResourceStyleRuleSet(u"button.style");
+ ThemeManager::GetInstance()->GetResourceStyleRuleSet("button.style");
GetStyleRuleSet()->SetParent(std::move(default_button_style));
}
diff --git a/src/ui/controls/CheckBox.cpp b/src/ui/controls/CheckBox.cpp
index a28c4633..778a7b4f 100644
--- a/src/ui/controls/CheckBox.cpp
+++ b/src/ui/controls/CheckBox.cpp
@@ -11,7 +11,7 @@ CheckBox::CheckBox()
container_render_object_->SetBorderEnabled(true);
auto default_checkbox_style =
- ThemeManager::GetInstance()->GetResourceStyleRuleSet(u"checkbox.style");
+ ThemeManager::GetInstance()->GetResourceStyleRuleSet("checkbox.style");
GetStyleRuleSet()->SetParent(std::move(default_checkbox_style));
click_detector_.ClickEvent()->AddHandler(
diff --git a/src/ui/controls/IconButton.cpp b/src/ui/controls/IconButton.cpp
index 01ecabdd..059a7784 100644
--- a/src/ui/controls/IconButton.cpp
+++ b/src/ui/controls/IconButton.cpp
@@ -17,10 +17,10 @@ IconButton::IconButton()
container_render_object_->SetBorderEnabled(true);
GetStyleRuleSet()->SetParent(
ThemeManager::GetInstance()->GetResourceStyleRuleSet(
- u"icon-button.style"));
+ "icon-button.style"));
}
-IconButton::IconButton(StringView icon_svg_path_data_string,
+IconButton::IconButton(std::string_view icon_svg_path_data_string,
const Rect& view_port)
: IconButton() {
SetIconWithSvgPathDataString(icon_svg_path_data_string, view_port);
@@ -33,18 +33,18 @@ void IconButton::SetIconFillColor(const Color& color) {
}
void IconButton::SetIconWithSvgPathDataString(
- StringView icon_svg_path_data_string, const Rect& view_port) {
+ std::string_view icon_svg_path_data_string, const Rect& view_port) {
SetIconGeometry(platform::graphics::CreateGeometryFromSvgPathData(
GetGraphicsFactory(), icon_svg_path_data_string),
view_port);
}
void IconButton::SetIconWithSvgPathDataStringResourceKey(
- StringView icon_svg_path_data_string_resource_key, const Rect& view_port) {
- SetIconWithSvgPathDataString(
- ThemeManager::GetInstance()->GetResourceString(
- icon_svg_path_data_string_resource_key.ToString()),
- view_port);
+ std::string_view icon_svg_path_data_string_resource_key,
+ const Rect& view_port) {
+ SetIconWithSvgPathDataString(ThemeManager::GetInstance()->GetResourceString(
+ icon_svg_path_data_string_resource_key),
+ view_port);
}
} // namespace cru::ui::controls
diff --git a/src/ui/controls/TextBlock.cpp b/src/ui/controls/TextBlock.cpp
index 0dad4f5d..790c534b 100644
--- a/src/ui/controls/TextBlock.cpp
+++ b/src/ui/controls/TextBlock.cpp
@@ -15,10 +15,10 @@ TextBlock::TextBlock() {
const auto theme_manager = ThemeManager::GetInstance();
text_render_object_ = std::make_unique<TextRenderObject>(
- theme_manager->GetResourceBrush(u"text.brush"),
- theme_manager->GetResourceFont(u"text.font"),
- theme_manager->GetResourceBrush(u"text.selection.brush"),
- theme_manager->GetResourceBrush(u"text.caret.brush"));
+ theme_manager->GetResourceBrush("text.brush"),
+ theme_manager->GetResourceFont("text.font"),
+ theme_manager->GetResourceBrush("text.selection.brush"),
+ theme_manager->GetResourceBrush("text.caret.brush"));
text_render_object_->SetAttachedControl(this);
@@ -34,9 +34,11 @@ render::RenderObject* TextBlock::GetRenderObject() const {
return text_render_object_.get();
}
-String TextBlock::GetText() const { return service_->GetText(); }
+std::string TextBlock::GetText() const { return service_->GetText(); }
-void TextBlock::SetText(String text) { service_->SetText(std::move(text)); }
+void TextBlock::SetText(std::string text) {
+ service_->SetText(std::move(text));
+}
bool TextBlock::IsSelectable() const { return service_->IsEnabled(); }
diff --git a/src/ui/controls/TextBox.cpp b/src/ui/controls/TextBox.cpp
index 87672b4f..70695a01 100644
--- a/src/ui/controls/TextBox.cpp
+++ b/src/ui/controls/TextBox.cpp
@@ -18,10 +18,10 @@ TextBox::TextBox()
auto theme_manager = ThemeManager::GetInstance();
text_render_object_ = std::make_unique<TextRenderObject>(
- theme_manager->GetResourceBrush(u"text.brush"),
- theme_manager->GetResourceFont(u"text.font"),
- theme_manager->GetResourceBrush(u"text.selection.brush"),
- theme_manager->GetResourceBrush(u"text.caret.brush"));
+ theme_manager->GetResourceBrush("text.brush"),
+ theme_manager->GetResourceFont("text.font"),
+ theme_manager->GetResourceBrush("text.selection.brush"),
+ theme_manager->GetResourceBrush("text.caret.brush"));
text_render_object_->SetEditMode(true);
border_render_object_->SetChild(scroll_render_object_.get());
@@ -40,7 +40,7 @@ TextBox::TextBox()
border_render_object_->SetBorderEnabled(true);
GetStyleRuleSet()->SetParent(
- theme_manager->GetResourceStyleRuleSet(u"textbox.style"));
+ theme_manager->GetResourceStyleRuleSet("textbox.style"));
}
TextBox::~TextBox() {}
diff --git a/src/ui/controls/TextHostControlService.cpp b/src/ui/controls/TextHostControlService.cpp
index 690aa95d..bb723e3f 100644
--- a/src/ui/controls/TextHostControlService.cpp
+++ b/src/ui/controls/TextHostControlService.cpp
@@ -1,8 +1,8 @@
#include "cru/ui/controls/TextHostControlService.h"
+#include <cru/platform/gui/Input.h>
#include "../Helper.h"
#include "cru/base/Base.h"
-#include "cru/base/String.h"
#include "cru/base/StringUtil.h"
#include "cru/base/log/Logger.h"
#include "cru/platform/graphics/Font.h"
@@ -10,7 +10,6 @@
#include "cru/platform/gui/Clipboard.h"
#include "cru/platform/gui/Cursor.h"
#include "cru/platform/gui/InputMethod.h"
-#include "cru/platform/gui/Keyboard.h"
#include "cru/platform/gui/UiApplication.h"
#include "cru/platform/gui/Window.h"
#include "cru/ui/Base.h"
@@ -27,42 +26,42 @@
namespace cru::ui::controls {
TextControlMovePattern TextControlMovePattern::kLeft(
- u"Left", helper::ShortcutKeyBind(platform::gui::KeyCode::Left),
- [](TextHostControlService* service, StringView text,
+ "Left", helper::ShortcutKeyBind(platform::gui::KeyCode::Left),
+ [](TextHostControlService* service, std::string_view text,
Index current_position) {
CRU_UNUSED(service)
- Utf16PreviousCodePoint(text, current_position, &current_position);
+ Utf8PreviousCodePoint(text, current_position, &current_position);
return current_position;
});
TextControlMovePattern TextControlMovePattern::kRight(
- u"Right", helper::ShortcutKeyBind(platform::gui::KeyCode::Right),
- [](TextHostControlService* service, StringView text,
+ "Right", helper::ShortcutKeyBind(platform::gui::KeyCode::Right),
+ [](TextHostControlService* service, std::string_view text,
Index current_position) {
CRU_UNUSED(service)
- Utf16NextCodePoint(text, current_position, &current_position);
+ Utf8NextCodePoint(text, current_position, &current_position);
return current_position;
});
TextControlMovePattern TextControlMovePattern::kCtrlLeft(
- u"Ctrl+Left(Previous Word)",
+ "Ctrl+Left(Previous Word)",
helper::ShortcutKeyBind(platform::gui::KeyCode::Left,
- platform::gui::KeyModifiers::ctrl),
- [](TextHostControlService* service, StringView text,
+ platform::gui::KeyModifiers::Ctrl),
+ [](TextHostControlService* service, std::string_view text,
Index current_position) {
CRU_UNUSED(service)
- return Utf16PreviousWord(text, current_position);
+ return Utf8PreviousWord(text, current_position);
});
TextControlMovePattern TextControlMovePattern::kCtrlRight(
- u"Ctrl+Right(Next Word)",
+ "Ctrl+Right(Next Word)",
helper::ShortcutKeyBind(platform::gui::KeyCode::Right,
- platform::gui::KeyModifiers::ctrl),
- [](TextHostControlService* service, StringView text,
+ platform::gui::KeyModifiers::Ctrl),
+ [](TextHostControlService* service, std::string_view text,
Index current_position) {
CRU_UNUSED(service)
- return Utf16NextWord(text, current_position);
+ return Utf8NextWord(text, current_position);
});
TextControlMovePattern TextControlMovePattern::kUp(
- u"Up", helper::ShortcutKeyBind(platform::gui::KeyCode::Up),
- [](TextHostControlService* service, StringView text,
+ "Up", helper::ShortcutKeyBind(platform::gui::KeyCode::Up),
+ [](TextHostControlService* service, std::string_view text,
Index current_position) {
CRU_UNUSED(text)
auto text_render_object = service->GetTextRenderObject();
@@ -72,8 +71,8 @@ TextControlMovePattern TextControlMovePattern::kUp(
return result.trailing ? result.position + 1 : result.position;
});
TextControlMovePattern TextControlMovePattern::kDown(
- u"Down", helper::ShortcutKeyBind(platform::gui::KeyCode::Down),
- [](TextHostControlService* service, StringView text,
+ "Down", helper::ShortcutKeyBind(platform::gui::KeyCode::Down),
+ [](TextHostControlService* service, std::string_view text,
Index current_position) {
CRU_UNUSED(text)
auto text_render_object = service->GetTextRenderObject();
@@ -83,26 +82,26 @@ TextControlMovePattern TextControlMovePattern::kDown(
return result.trailing ? result.position + 1 : result.position;
});
TextControlMovePattern TextControlMovePattern::kHome(
- u"Home(Line Begin)", helper::ShortcutKeyBind(platform::gui::KeyCode::Home),
- [](TextHostControlService* service, StringView text,
+ "Home(Line Begin)", helper::ShortcutKeyBind(platform::gui::KeyCode::Home),
+ [](TextHostControlService* service, std::string_view text,
Index current_position) {
CRU_UNUSED(service)
- return Utf16BackwardUntil(text, current_position,
- [](CodePoint c) { return c == u'\n'; });
+ return Utf8BackwardUntil(text, current_position,
+ [](CodePoint c) { return c == u'\n'; });
});
TextControlMovePattern TextControlMovePattern::kEnd(
- u"End(Line End)", helper::ShortcutKeyBind(platform::gui::KeyCode::End),
- [](TextHostControlService* service, StringView text,
+ "End(Line End)", helper::ShortcutKeyBind(platform::gui::KeyCode::End),
+ [](TextHostControlService* service, std::string_view text,
Index current_position) {
CRU_UNUSED(service)
- return Utf16ForwardUntil(text, current_position,
- [](CodePoint c) { return c == u'\n'; });
+ return Utf8ForwardUntil(text, current_position,
+ [](CodePoint c) { return c == u'\n'; });
});
TextControlMovePattern TextControlMovePattern::kCtrlHome(
- u"Ctrl+Home(Document Begin)",
+ "Ctrl+Home(Document Begin)",
helper::ShortcutKeyBind(platform::gui::KeyCode::Home,
- platform::gui::KeyModifiers::ctrl),
- [](TextHostControlService* service, StringView text,
+ platform::gui::KeyModifiers::Ctrl),
+ [](TextHostControlService* service, std::string_view text,
Index current_position) {
CRU_UNUSED(service)
CRU_UNUSED(text)
@@ -110,10 +109,10 @@ TextControlMovePattern TextControlMovePattern::kCtrlHome(
return 0;
});
TextControlMovePattern TextControlMovePattern::kCtrlEnd(
- u"Ctrl+End(Document End)",
+ "Ctrl+End(Document End)",
helper::ShortcutKeyBind(platform::gui::KeyCode::End,
- platform::gui::KeyModifiers::ctrl),
- [](TextHostControlService* service, StringView text,
+ platform::gui::KeyModifiers::Ctrl),
+ [](TextHostControlService* service, std::string_view text,
Index current_position) {
CRU_UNUSED(service)
CRU_UNUSED(text)
@@ -121,8 +120,8 @@ TextControlMovePattern TextControlMovePattern::kCtrlEnd(
return text.size();
});
TextControlMovePattern TextControlMovePattern::kPageUp(
- u"PageUp", helper::ShortcutKeyBind(platform::gui::KeyCode::PageUp),
- [](TextHostControlService* service, StringView text,
+ "PageUp", helper::ShortcutKeyBind(platform::gui::KeyCode::PageUp),
+ [](TextHostControlService* service, std::string_view text,
Index current_position) {
CRU_UNUSED(service)
CRU_UNUSED(text)
@@ -130,8 +129,8 @@ TextControlMovePattern TextControlMovePattern::kPageUp(
return current_position;
});
TextControlMovePattern TextControlMovePattern::kPageDown(
- u"PageDown", helper::ShortcutKeyBind(platform::gui::KeyCode::PageDown),
- [](TextHostControlService* service, StringView text,
+ "PageDown", helper::ShortcutKeyBind(platform::gui::KeyCode::PageDown),
+ [](TextHostControlService* service, std::string_view text,
Index current_position) {
CRU_UNUSED(service)
CRU_UNUSED(text)
@@ -214,7 +213,7 @@ void TextHostControlService::SetMultiLine(bool multi_line) {
}
}
-void TextHostControlService::SetText(String text, bool stop_composition) {
+void TextHostControlService::SetText(std::string text, bool stop_composition) {
this->text_ = std::move(text);
CoerceSelection();
if (stop_composition) {
@@ -224,13 +223,14 @@ void TextHostControlService::SetText(String text, bool stop_composition) {
text_change_event_.Raise(nullptr);
}
-void TextHostControlService::InsertText(Index position, StringView text,
+void TextHostControlService::InsertText(Index position, std::string_view text,
bool stop_composition) {
- if (!Utf16IsValidInsertPosition(this->text_, position)) {
+ if (!Utf8IsValidInsertPosition(this->text_, position)) {
CRU_LOG_TAG_ERROR("Invalid text insert position.");
return;
}
- this->text_.insert(this->text_.cbegin() + position, text);
+ this->text_.insert(this->text_.cbegin() + position, text.cbegin(),
+ text.cend());
if (stop_composition) {
CancelComposition();
}
@@ -239,26 +239,26 @@ void TextHostControlService::InsertText(Index position, StringView text,
}
void TextHostControlService::DeleteChar(Index position, bool stop_composition) {
- if (!Utf16IsValidInsertPosition(this->text_, position)) {
+ if (!Utf8IsValidInsertPosition(this->text_, position)) {
CRU_LOG_TAG_ERROR("Invalid text delete position.");
return;
}
if (position == static_cast<Index>(this->text_.size())) return;
Index next;
- Utf16NextCodePoint(this->text_, position, &next);
+ Utf8NextCodePoint(this->text_, position, &next);
this->DeleteText(TextRange::FromTwoSides(position, next), stop_composition);
}
// Return the position of deleted character.
Index TextHostControlService::DeleteCharPrevious(Index position,
bool stop_composition) {
- if (!Utf16IsValidInsertPosition(this->text_, position)) {
+ if (!Utf8IsValidInsertPosition(this->text_, position)) {
CRU_LOG_TAG_ERROR("Invalid text delete position.");
return 0;
}
if (position == 0) return 0;
Index previous;
- Utf16PreviousCodePoint(this->text_, position, &previous);
+ Utf8PreviousCodePoint(this->text_, position, &previous);
this->DeleteText(TextRange::FromTwoSides(previous, position),
stop_composition);
return previous;
@@ -268,11 +268,11 @@ void TextHostControlService::DeleteText(TextRange range,
bool stop_composition) {
if (range.count == 0) return;
range = range.Normalize();
- if (!Utf16IsValidInsertPosition(this->text_, range.GetStart())) {
+ if (!Utf8IsValidInsertPosition(this->text_, range.GetStart())) {
CRU_LOG_TAG_ERROR("Invalid text delete start position.");
return;
}
- if (!Utf16IsValidInsertPosition(this->text_, range.GetStart())) {
+ if (!Utf8IsValidInsertPosition(this->text_, range.GetStart())) {
CRU_LOG_TAG_ERROR("Invalid text delete end position.");
return;
}
@@ -352,7 +352,7 @@ render::ScrollRenderObject* TextHostControlService::GetScrollRenderObject() {
return this->text_host_control_->GetScrollRenderObject();
}
-StringView TextHostControlService::GetSelectedText() {
+std::string_view TextHostControlService::GetSelectedText() {
auto selection = this->GetSelection().Normalize();
return GetTextView().substr(selection.position, selection.count);
}
@@ -372,7 +372,7 @@ void TextHostControlService::SetSelection(TextRange selection,
}
void TextHostControlService::SelectAll() {
- this->SetSelection(TextRange{0, this->text_.size()});
+ this->SetSelection(TextRange{0, static_cast<Index>(this->text_.size())});
}
void TextHostControlService::ChangeSelectionEnd(Index new_end) {
@@ -389,7 +389,7 @@ void TextHostControlService::AbortSelection() {
SetSelection(GetCaretPosition());
}
-void TextHostControlService::ReplaceSelectedText(StringView text) {
+void TextHostControlService::ReplaceSelectedText(std::string_view text) {
DeleteSelectedText();
InsertText(GetSelection().GetStart(), text);
SetSelection(GetSelection().GetStart() + text.size());
@@ -402,14 +402,14 @@ void TextHostControlService::DeleteSelectedText() {
void TextHostControlService::Cut() {
Copy();
- ReplaceSelectedText(StringView{});
+ ReplaceSelectedText(std::string_view{});
}
void TextHostControlService::Copy() {
auto selected_text = GetSelectedText();
if (selected_text.size() == 0) return;
auto clipboard = GetUiApplication()->GetClipboard();
- clipboard->SetText(selected_text.ToString());
+ clipboard->SetText(std::string(selected_text));
}
void TextHostControlService::Paste() {
@@ -442,7 +442,8 @@ void TextHostControlService::SyncTextRenderObject() {
if (composition_info) {
const auto caret_position = GetCaretPosition();
auto text = this->text_;
- text.insert(text.cbegin() + caret_position, composition_info->text);
+ text.insert(text.cbegin() + caret_position, composition_info->text.cbegin(),
+ composition_info->text.cend());
text_render_object->SetText(text);
text_render_object->SetCaretPosition(caret_position +
composition_info->selection.GetEnd());
@@ -477,7 +478,7 @@ void TextHostControlService::MouseDownHandler(
events::MouseButtonEventArgs& args) {
if (IsEnabled()) {
this->control_->SetFocus();
- if (args.GetButton() == mouse_buttons::left &&
+ if (args.GetButton() == MouseButtons::Left &&
!this->mouse_move_selecting_) {
if (!this->control_->CaptureMouse()) return;
this->mouse_move_selecting_ = true;
@@ -487,7 +488,7 @@ void TextHostControlService::MouseDownHandler(
const auto position = result.position + (result.trailing ? 1 : 0);
SetSelection(position);
args.SetHandled(true);
- } else if (args.GetButton() == mouse_buttons::right) {
+ } else if (args.GetButton() == MouseButtons::Right) {
// TODO: Finish context menu logic here.
const Point p = args.GetPointToContent(GetTextRenderObject());
@@ -536,7 +537,7 @@ void TextHostControlService::MouseDownHandler(
void TextHostControlService::MouseUpHandler(
events::MouseButtonEventArgs& args) {
- if (args.GetButton() == mouse_buttons::left && mouse_move_selecting_) {
+ if (args.GetButton() == MouseButtons::Left && mouse_move_selecting_) {
this->control_->ReleaseMouse();
this->mouse_move_selecting_ = false;
args.SetHandled();
@@ -573,12 +574,13 @@ void TextHostControlService::GainFocusHandler(
input_method_context_event_guard_ +=
input_method_context->CompositionEndEvent()->AddHandler(sync);
input_method_context_event_guard_ +=
- input_method_context->TextEvent()->AddHandler([this](StringView text) {
- if (!multi_line_ && text == u"\n") {
- return;
- }
- this->ReplaceSelectedText(text);
- });
+ input_method_context->TextEvent()->AddHandler(
+ [this](std::string_view text) {
+ if (!multi_line_ && text == "\n") {
+ return;
+ }
+ this->ReplaceSelectedText(text);
+ });
host::WindowHost* window_host = control_->GetWindowHost();
if (window_host)
@@ -606,7 +608,7 @@ void TextHostControlService::SetUpShortcuts() {
using platform::gui::KeyModifiers;
using platform::gui::kKeyModifierCommand;
- shortcut_hub_.RegisterShortcut(u"Select All",
+ shortcut_hub_.RegisterShortcut("Select All",
{KeyCode::A, kKeyModifierCommand}, [this] {
if (IsEnabled()) {
this->SelectAll();
@@ -615,7 +617,7 @@ void TextHostControlService::SetUpShortcuts() {
return false;
});
- shortcut_hub_.RegisterShortcut(u"Cut", {KeyCode::X, kKeyModifierCommand},
+ shortcut_hub_.RegisterShortcut("Cut", {KeyCode::X, kKeyModifierCommand},
[this] {
if (IsEnabled() && IsEditable()) {
this->Cut();
@@ -624,7 +626,7 @@ void TextHostControlService::SetUpShortcuts() {
return false;
});
- shortcut_hub_.RegisterShortcut(u"Copy", {KeyCode::C, kKeyModifierCommand},
+ shortcut_hub_.RegisterShortcut("Copy", {KeyCode::C, kKeyModifierCommand},
[this] {
if (IsEnabled()) {
this->Copy();
@@ -633,7 +635,7 @@ void TextHostControlService::SetUpShortcuts() {
return false;
});
- shortcut_hub_.RegisterShortcut(u"Paste", {KeyCode::V, kKeyModifierCommand},
+ shortcut_hub_.RegisterShortcut("Paste", {KeyCode::V, kKeyModifierCommand},
[this] {
if (IsEnabled() && IsEditable()) {
this->Paste();
@@ -642,7 +644,7 @@ void TextHostControlService::SetUpShortcuts() {
return false;
});
- shortcut_hub_.RegisterShortcut(u"Backspace", KeyCode::Backspace, [this] {
+ shortcut_hub_.RegisterShortcut("Backspace", KeyCode::Backspace, [this] {
if (!IsEnabled()) return false;
if (!IsEditable()) return false;
const auto selection = GetSelection();
@@ -654,7 +656,7 @@ void TextHostControlService::SetUpShortcuts() {
return true;
});
- shortcut_hub_.RegisterShortcut(u"Delete", KeyCode::Delete, [this] {
+ shortcut_hub_.RegisterShortcut("Delete", KeyCode::Delete, [this] {
if (!IsEnabled()) return false;
if (!IsEditable()) return false;
const auto selection = GetSelection();
@@ -669,7 +671,7 @@ void TextHostControlService::SetUpShortcuts() {
for (const auto& pattern : TextControlMovePattern::kDefaultPatterns) {
auto name = pattern.GetName();
shortcut_hub_.RegisterShortcut(
- u"Move " + name, pattern.GetKeyBind(), [this, &pattern] {
+ "Move " + name, pattern.GetKeyBind(), [this, &pattern] {
auto text = this->GetTextView();
auto caret = this->GetCaretPosition();
auto new_position = pattern.Move(this, text, caret);
@@ -678,8 +680,8 @@ void TextHostControlService::SetUpShortcuts() {
});
shortcut_hub_.RegisterShortcut(
- u"Move And Select " + name,
- pattern.GetKeyBind().AddModifier(platform::gui::KeyModifiers::shift),
+ "Move And Select " + name,
+ pattern.GetKeyBind().AddModifier(platform::gui::KeyModifiers::Shift),
[this, &pattern] {
auto text = this->GetTextView();
auto caret = this->GetCaretPosition();
@@ -695,16 +697,16 @@ void TextHostControlService::OpenContextMenu(const Point& position,
context_menu_ = MakeDeleteLaterPtr<components::PopupMenu>();
auto menu = context_menu_->GetMenu();
if (items & ContextMenuItem::kSelectAll) {
- menu->AddTextItem(u"Select All", [this] { this->SelectAll(); });
+ menu->AddTextItem("Select All", [this] { this->SelectAll(); });
}
if (items & ContextMenuItem::kCopy) {
- menu->AddTextItem(u"Copy", [this] { this->Copy(); });
+ menu->AddTextItem("Copy", [this] { this->Copy(); });
}
if (items & ContextMenuItem::kCut) {
- menu->AddTextItem(u"Cut", [this] { this->Cut(); });
+ menu->AddTextItem("Cut", [this] { this->Cut(); });
}
if (items & ContextMenuItem::kPaste) {
- menu->AddTextItem(u"Paste", [this] { this->Paste(); });
+ menu->AddTextItem("Paste", [this] { this->Paste(); });
}
context_menu_->SetPosition(position);
context_menu_->Show();
diff --git a/src/ui/helper/ShortcutHub.cpp b/src/ui/helper/ShortcutHub.cpp
index 80e70fe1..fd23802e 100644
--- a/src/ui/helper/ShortcutHub.cpp
+++ b/src/ui/helper/ShortcutHub.cpp
@@ -89,18 +89,17 @@ void ShortcutHub::OnKeyDown(events::KeyEventArgs& event) {
if constexpr (debug_flags::shortcut) {
if (shortcut_list.empty()) {
- CRU_LOG_TAG_DEBUG("No shortcut for key bind {}.",
- key_bind.ToString().ToUtf8());
+ CRU_LOG_TAG_DEBUG("No shortcut for key bind {}.", key_bind.ToString());
}
CRU_LOG_TAG_DEBUG("Begin to handle shortcut for key bind {}.",
- key_bind.ToString().ToUtf8());
+ key_bind.ToString());
}
for (const auto& shortcut : shortcut_list) {
auto is_handled = shortcut.handler();
if (is_handled) {
if constexpr (debug_flags::shortcut) {
- CRU_LOG_TAG_DEBUG("Handle {} handled it.", shortcut.name.ToUtf8());
+ CRU_LOG_TAG_DEBUG("Handle {} handled it.", shortcut.name);
}
handled = true;
@@ -109,8 +108,7 @@ void ShortcutHub::OnKeyDown(events::KeyEventArgs& event) {
break;
} else {
if constexpr (debug_flags::shortcut) {
- CRU_LOG_TAG_DEBUG("Handle {} didn't handle it.",
- shortcut.name.ToUtf8());
+ CRU_LOG_TAG_DEBUG("Handle {} didn't handle it.", shortcut.name);
}
}
}
@@ -118,7 +116,7 @@ void ShortcutHub::OnKeyDown(events::KeyEventArgs& event) {
if constexpr (debug_flags::shortcut) {
if (!shortcut_list.empty()) {
CRU_LOG_TAG_DEBUG("End handling shortcut for key bind {}.",
- key_bind.ToString().ToUtf8());
+ key_bind.ToString());
}
}
@@ -126,7 +124,7 @@ void ShortcutHub::OnKeyDown(events::KeyEventArgs& event) {
if constexpr (debug_flags::shortcut) {
CRU_LOG_TAG_DEBUG(
"Raise fallback event for unhandled shortcut of key bind {}.",
- key_bind.ToString().ToUtf8());
+ key_bind.ToString());
}
fallback_event_.Raise(event);
}
diff --git a/src/ui/mapper/ColorMapper.cpp b/src/ui/mapper/ColorMapper.cpp
index dcf3a522..82e9dfbc 100644
--- a/src/ui/mapper/ColorMapper.cpp
+++ b/src/ui/mapper/ColorMapper.cpp
@@ -1,5 +1,7 @@
#include "cru/ui/mapper/ColorMapper.h"
+#include <cru/base/String.h>
+
namespace cru::ui::mapper {
bool ColorMapper::XmlElementIsOfThisType(xml::XmlElementNode* node) {
return cru::string::CaseInsensitiveCompare(node->GetTag(), "Color") == 0;
diff --git a/src/ui/mapper/FontMapper.cpp b/src/ui/mapper/FontMapper.cpp
index bb3550ea..1f749513 100644
--- a/src/ui/mapper/FontMapper.cpp
+++ b/src/ui/mapper/FontMapper.cpp
@@ -1,5 +1,6 @@
#include "cru/ui/mapper/FontMapper.h"
#include "../Helper.h"
+#include "cru/base/String.h"
#include "cru/platform/graphics/Factory.h"
namespace cru::ui::mapper {
@@ -16,7 +17,6 @@ std::shared_ptr<platform::graphics::IFont> FontMapper::DoMapFromXml(
auto font_size =
font_size_attr ? String::FromUtf8(*font_size_attr).ParseToFloat() : 24.0f;
- return GetGraphicsFactory()->CreateFont(String::FromUtf8(font_family),
- font_size);
+ return GetGraphicsFactory()->CreateFont(font_family, font_size);
}
} // namespace cru::ui::mapper
diff --git a/src/ui/mapper/Mapper.cpp b/src/ui/mapper/Mapper.cpp
index ca6cf0b3..47e783c9 100644
--- a/src/ui/mapper/Mapper.cpp
+++ b/src/ui/mapper/Mapper.cpp
@@ -9,8 +9,7 @@ MapperBase::MapperBase(std::type_index type_index)
bool MapperBase::XmlElementIsOfThisType(xml::XmlElementNode* node) {
for (const auto& tag : allowed_tags_) {
- if (cru::string::CaseInsensitiveCompare(node->GetTag(), tag.ToUtf8()) ==
- 0) {
+ if (cru::string::CaseInsensitiveCompare(node->GetTag(), tag) == 0) {
return true;
}
}
diff --git a/src/ui/mapper/PointMapper.cpp b/src/ui/mapper/PointMapper.cpp
index 16731544..12f000ef 100644
--- a/src/ui/mapper/PointMapper.cpp
+++ b/src/ui/mapper/PointMapper.cpp
@@ -1,5 +1,7 @@
#include "cru/ui/mapper/PointMapper.h"
+#include <cru/base/String.h>
+
namespace cru::ui::mapper {
bool PointMapper::XmlElementIsOfThisType(xml::XmlElementNode* node) {
return cru::string::CaseInsensitiveCompare(node->GetTag(), "Point") == 0;
diff --git a/src/ui/mapper/SizeMapper.cpp b/src/ui/mapper/SizeMapper.cpp
index f976bfe4..de8a0ded 100644
--- a/src/ui/mapper/SizeMapper.cpp
+++ b/src/ui/mapper/SizeMapper.cpp
@@ -1,5 +1,7 @@
#include "cru/ui/mapper/SizeMapper.h"
+#include <cru/base/String.h>
+
namespace cru::ui::mapper {
bool SizeMapper::XmlElementIsOfThisType(xml::XmlElementNode* node) {
return cru::string::CaseInsensitiveCompare(node->GetTag(), "Size") == 0;
diff --git a/src/ui/mapper/StringMapper.cpp b/src/ui/mapper/StringMapper.cpp
index 6e224d3f..5914da17 100644
--- a/src/ui/mapper/StringMapper.cpp
+++ b/src/ui/mapper/StringMapper.cpp
@@ -1,8 +1,9 @@
#include "cru/ui/mapper/StringMapper.h"
#include "cru/xml/XmlNode.h"
+#include "cru/base/String.h"
namespace cru::ui::mapper {
-StringMapper::StringMapper() { SetAllowedTags({u"String"}); }
+StringMapper::StringMapper() { SetAllowedTags({"String"}); }
StringMapper::~StringMapper() {}
diff --git a/src/ui/mapper/ThicknessMapper.cpp b/src/ui/mapper/ThicknessMapper.cpp
index 61c3641c..96f016a7 100644
--- a/src/ui/mapper/ThicknessMapper.cpp
+++ b/src/ui/mapper/ThicknessMapper.cpp
@@ -1,5 +1,6 @@
#include "cru/ui/mapper/ThicknessMapper.h"
#include "cru/xml/XmlNode.h"
+#include "cru/base/String.h"
namespace cru::ui::mapper {
bool ThicknessMapper::XmlElementIsOfThisType(xml::XmlElementNode* node) {
diff --git a/src/ui/mapper/style/ContentBrushStylerMapper.cpp b/src/ui/mapper/style/ContentBrushStylerMapper.cpp
index b3571374..027622fe 100644
--- a/src/ui/mapper/style/ContentBrushStylerMapper.cpp
+++ b/src/ui/mapper/style/ContentBrushStylerMapper.cpp
@@ -7,7 +7,7 @@
namespace cru::ui::mapper::style {
ContentBrushStylerMapper::ContentBrushStylerMapper() {
- SetAllowedTags({u"ContentBrushStyler"});
+ SetAllowedTags({"ContentBrushStyler"});
}
ContentBrushStylerMapper::~ContentBrushStylerMapper() {}
diff --git a/src/ui/mapper/style/FontStylerMapper.cpp b/src/ui/mapper/style/FontStylerMapper.cpp
index 3b1817ac..1555c071 100644
--- a/src/ui/mapper/style/FontStylerMapper.cpp
+++ b/src/ui/mapper/style/FontStylerMapper.cpp
@@ -3,7 +3,7 @@
#include "cru/ui/mapper/MapperRegistry.h"
namespace cru::ui::mapper::style {
-FontStylerMapper::FontStylerMapper() { SetAllowedTags({u"FontStyler"}); }
+FontStylerMapper::FontStylerMapper() { SetAllowedTags({"FontStyler"}); }
FontStylerMapper::~FontStylerMapper() {}
diff --git a/src/ui/mapper/style/MarginStylerMapper.cpp b/src/ui/mapper/style/MarginStylerMapper.cpp
index 0968b53e..ffbdcd75 100644
--- a/src/ui/mapper/style/MarginStylerMapper.cpp
+++ b/src/ui/mapper/style/MarginStylerMapper.cpp
@@ -4,7 +4,7 @@
#include "cru/ui/style/Styler.h"
namespace cru::ui::mapper::style {
-MarginStylerMapper::MarginStylerMapper() { SetAllowedTags({u"MarginStyler"}); }
+MarginStylerMapper::MarginStylerMapper() { SetAllowedTags({"MarginStyler"}); }
MarginStylerMapper::~MarginStylerMapper() {}
diff --git a/src/ui/mapper/style/PaddingStylerMapper.cpp b/src/ui/mapper/style/PaddingStylerMapper.cpp
index 0f0f87d7..faa86082 100644
--- a/src/ui/mapper/style/PaddingStylerMapper.cpp
+++ b/src/ui/mapper/style/PaddingStylerMapper.cpp
@@ -5,7 +5,7 @@
namespace cru::ui::mapper::style {
PaddingStylerMapper::PaddingStylerMapper() {
- SetAllowedTags({u"PaddingStyler"});
+ SetAllowedTags({"PaddingStyler"});
}
PaddingStylerMapper::~PaddingStylerMapper() {}
diff --git a/src/ui/render/BorderRenderObject.cpp b/src/ui/render/BorderRenderObject.cpp
index 03fdff24..957cf9bb 100644
--- a/src/ui/render/BorderRenderObject.cpp
+++ b/src/ui/render/BorderRenderObject.cpp
@@ -83,12 +83,10 @@ void BorderRenderObject::Draw(platform::graphics::IPainter* painter) {
if constexpr (debug_flags::draw) {
CRU_LOG_TAG_DEBUG(
"BorderRenderObject draw, background: {}, foreground: {}.",
- background_brush_ == nullptr
- ? "NONE"
- : background_brush_->GetDebugString().ToUtf8(),
- foreground_brush_ == nullptr
- ? "NONE"
- : foreground_brush_->GetDebugString().ToUtf8());
+ background_brush_ == nullptr ? "NONE"
+ : background_brush_->GetDebugString(),
+ foreground_brush_ == nullptr ? "NONE"
+ : foreground_brush_->GetDebugString());
}
if (background_brush_ != nullptr)
diff --git a/src/ui/render/ScrollBar.cpp b/src/ui/render/ScrollBar.cpp
index af2851cd..f4f9496e 100644
--- a/src/ui/render/ScrollBar.cpp
+++ b/src/ui/render/ScrollBar.cpp
@@ -9,6 +9,7 @@
#include "cru/platform/graphics/util/Painter.h"
#include "cru/platform/gui/Base.h"
#include "cru/platform/gui/Cursor.h"
+#include "cru/platform/gui/Input.h"
#include "cru/ui/Base.h"
#include "cru/ui/ThemeManager.h"
#include "cru/ui/events/UiEvents.h"
@@ -38,39 +39,39 @@ constexpr std::array<ScrollBarAreaKind, 5> kScrollBarAreaKindList{
ScrollBarAreaKind::UpSlot, ScrollBarAreaKind::DownSlot,
ScrollBarAreaKind::Thumb};
-String GenerateScrollBarThemeColorKey(ScrollBarBrushUsageKind usage,
+std::string GenerateScrollBarThemeColorKey(ScrollBarBrushUsageKind usage,
ScrollBarBrushStateKind state) {
- String result = u"scrollbar.";
+ std::string result = "scrollbar.";
switch (usage) {
case ScrollBarBrushUsageKind::Arrow:
- result.append(u"arrow");
+ result.append("arrow");
break;
case ScrollBarBrushUsageKind::ArrowBackground:
- result.append(u"arrow-background");
+ result.append("arrow-background");
break;
case ScrollBarBrushUsageKind::Slot:
- result.append(u"slot");
+ result.append("slot");
break;
case ScrollBarBrushUsageKind::Thumb:
- result.append(u"thumb");
+ result.append("thumb");
break;
}
- result.push_back(u'.');
+ result.push_back('.');
switch (state) {
case ScrollBarBrushStateKind::Normal:
- result.append(u"normal");
+ result.append("normal");
break;
case ScrollBarBrushStateKind::Hover:
- result.append(u"hover");
+ result.append("hover");
break;
case ScrollBarBrushStateKind::Press:
- result.append(u"press");
+ result.append("press");
break;
case ScrollBarBrushStateKind::Disable:
- result.append(u"disable");
+ result.append("disable");
break;
}
- result.append(u".color");
+ result.append(".color");
return result;
}
@@ -123,7 +124,7 @@ void ScrollBar::InstallHandlers(controls::Control* control) {
event_guard_ +=
control->MouseDownEvent()->Tunnel()->PrependShortCircuitHandler(
[control, this](events::MouseButtonEventArgs& event) {
- if (event.GetButton() == mouse_buttons::left && IsEnabled() &&
+ if (event.GetButton() == MouseButtons::Left && IsEnabled() &&
IsExpanded()) {
auto hit_test_result =
ExpandedHitTest(event.GetPoint(render_object_));
@@ -182,7 +183,7 @@ void ScrollBar::InstallHandlers(controls::Control* control) {
render_object_->InvalidatePaint();
}
- if (event.GetButton() == mouse_buttons::left &&
+ if (event.GetButton() == MouseButtons::Left &&
move_thumb_start_) {
move_thumb_start_ = std::nullopt;
@@ -264,7 +265,7 @@ std::shared_ptr<platform::graphics::IBrush>
ScrollBar::GetCollapsedThumbBrush() {
return collapsed_thumb_brush_ ? collapsed_thumb_brush_
: ThemeManager::GetInstance()->GetResourceBrush(
- u"scrollbar.collapse-thumb.color");
+ "scrollbar.collapse-thumb.color");
}
void ScrollBar::SetCollapsedThumbBrush(
diff --git a/src/ui/render/TextRenderObject.cpp b/src/ui/render/TextRenderObject.cpp
index 346b4957..18020032 100644
--- a/src/ui/render/TextRenderObject.cpp
+++ b/src/ui/render/TextRenderObject.cpp
@@ -28,14 +28,16 @@ TextRenderObject::TextRenderObject(
caret_brush.swap(caret_brush_);
const auto graph_factory = GetGraphicsFactory();
- text_layout_ = graph_factory->CreateTextLayout(font_, u"");
+ text_layout_ = graph_factory->CreateTextLayout(font_, "");
}
TextRenderObject::~TextRenderObject() = default;
-String TextRenderObject::GetText() const { return text_layout_->GetText(); }
+std::string TextRenderObject::GetText() const {
+ return text_layout_->GetText();
+}
-void TextRenderObject::SetText(String new_text) {
+void TextRenderObject::SetText(std::string new_text) {
text_layout_->SetText(std::move(new_text));
InvalidateLayout();
}
@@ -181,8 +183,7 @@ void TextRenderObject::Draw(platform::graphics::IPainter* painter) {
"Begin to paint, total_offset: {}, size: {}, text_layout: "
"{}, brush: {}.",
this->GetTotalOffset(), this->GetDesiredSize(),
- this->text_layout_->GetDebugString().ToUtf8(),
- this->brush_->GetDebugString().ToUtf8());
+ this->text_layout_->GetDebugString(), this->brush_->GetDebugString());
}
if (this->selection_range_.has_value()) {