From 32aa6f116acc6e3e20a1ec76cef45b29f7005ad7 Mon Sep 17 00:00:00 2001 From: Yuqian Yang Date: Fri, 17 Oct 2025 12:06:14 +0800 Subject: Remove String stage 1. --- include/cru/base/StringUtil.h | 24 ++++ include/cru/platform/Check.h | 4 +- include/cru/platform/Resource.h | 14 +- include/cru/platform/graphics/Base.h | 8 +- include/cru/platform/graphics/Factory.h | 7 +- include/cru/platform/graphics/Font.h | 4 +- include/cru/platform/graphics/Geometry.h | 5 +- include/cru/platform/graphics/NullPainter.h | 4 +- include/cru/platform/graphics/Resource.h | 2 + .../platform/graphics/SvgGeometryBuilderMixin.h | 15 +- include/cru/platform/graphics/TextLayout.h | 4 +- .../platform/graphics/cairo/CairoGraphicsFactory.h | 4 +- .../cru/platform/graphics/cairo/CairoResource.h | 2 +- include/cru/platform/graphics/cairo/PangoFont.h | 6 +- .../cru/platform/graphics/cairo/PangoTextLayout.h | 11 +- include/cru/platform/gui/Base.h | 34 +---- include/cru/platform/gui/Clipboard.h | 4 +- include/cru/platform/gui/Input.h | 152 +++++++++++++++++++++ include/cru/platform/gui/InputMethod.h | 8 +- include/cru/platform/gui/Keyboard.h | 142 ------------------- include/cru/platform/gui/Menu.h | 7 +- include/cru/platform/gui/SaveOpenDialogOptions.h | 21 +-- include/cru/platform/gui/UiApplication.h | 17 ++- include/cru/platform/gui/Window.h | 13 +- include/cru/platform/gui/osx/Keyboard.h | 2 +- include/cru/platform/gui/sdl/Base.h | 4 +- include/cru/platform/gui/sdl/Window.h | 4 +- include/cru/platform/gui/win/Keyboard.h | 2 +- include/cru/platform/gui/xcb/Base.h | 8 +- include/cru/platform/gui/xcb/Clipboard.h | 4 +- include/cru/platform/gui/xcb/Cursor.h | 5 +- include/cru/platform/gui/xcb/Input.h | 41 ++++++ include/cru/platform/gui/xcb/InputMethod.h | 9 +- include/cru/platform/gui/xcb/Keyboard.h | 41 ------ include/cru/platform/gui/xcb/UiApplication.h | 2 +- include/cru/platform/gui/xcb/Window.h | 11 +- include/cru/ui/Base.h | 11 +- include/cru/ui/ThemeManager.h | 13 +- include/cru/ui/ThemeResourceDictionary.h | 10 +- include/cru/ui/components/Input.h | 14 +- include/cru/ui/components/Menu.h | 8 +- include/cru/ui/components/PopupButton.h | 8 +- include/cru/ui/components/Select.h | 6 +- include/cru/ui/controls/IconButton.h | 6 +- include/cru/ui/controls/TextBlock.h | 8 +- include/cru/ui/controls/TextBox.h | 6 +- include/cru/ui/controls/TextHostControlService.h | 26 ++-- include/cru/ui/events/KeyEventArgs.h | 4 +- include/cru/ui/events/MouseButtonEventArgs.h | 13 +- include/cru/ui/events/MouseWheelEventArgs.h | 4 +- include/cru/ui/helper/ClickDetector.h | 2 +- include/cru/ui/helper/ShortcutHub.h | 18 +-- include/cru/ui/mapper/Mapper.h | 4 +- include/cru/ui/mapper/StringMapper.h | 2 + include/cru/ui/render/RenderObject.h | 2 + include/cru/ui/render/ScrollBar.h | 2 +- include/cru/ui/render/TextRenderObject.h | 4 +- include/cru/ui/style/ApplyBorderStyleInfo.h | 2 + 58 files changed, 418 insertions(+), 400 deletions(-) create mode 100644 include/cru/platform/gui/Input.h delete mode 100644 include/cru/platform/gui/Keyboard.h create mode 100644 include/cru/platform/gui/xcb/Input.h delete mode 100644 include/cru/platform/gui/xcb/Keyboard.h (limited to 'include') 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& 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& 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& 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(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 CheckPlatform(const std::shared_ptr& resource, const auto result = std::dynamic_pointer_cast(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 + +#include 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 // IWYU pragma: export +#include // IWYU pragma: export +#include // IWYU pragma: export +#include // 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 CreateGeometryBuilder() = 0; - virtual std::unique_ptr CreateFont(String font_family, + virtual std::unique_ptr CreateFont(std::string font_family, float font_size) = 0; virtual std::unique_ptr CreateTextLayout( - std::shared_ptr font, String text) = 0; + std::shared_ptr font, std::string text) = 0; std::unique_ptr CreateSolidColorBrush(const Color& color) { std::unique_ptr 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 + 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 Build() = 0; - virtual void ParseAndApplySvgPathData(StringView path_d); + virtual void ParseAndApplySvgPathData(std::string_view path_d); }; std::unique_ptr 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 + 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 - void Append(StringView format, Args&&... args) { - current_ += String::FromUtf8( - std::format(format.ToUtf8(), std::forward(args)...)); - current_ += u' '; + void Append(std::string_view format, Args&&... args) { + current_ += std::format(format, std::forward(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 GetFont() = 0; virtual void SetFont(std::shared_ptr 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 CreateGeometryBuilder() override; - std::unique_ptr CreateFont(String font_family, + std::unique_ptr CreateFont(std::string font_family, float font_size) override; std::unique_ptr CreateTextLayout(std::shared_ptr 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 GetFont() override; void SetFont(std::shared_ptr 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 // IWYU pragma: export +#include // 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; -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/Input.h b/include/cru/platform/gui/Input.h new file mode 100644 index 00000000..dca064d4 --- /dev/null +++ b/include/cru/platform/gui/Input.h @@ -0,0 +1,152 @@ +#pragma once +#include "Base.h" + +#include + +#include + +namespace cru::platform::gui { +namespace details { +struct TagMouseButton {}; +} // namespace details + +using MouseButton = Bitmask; +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. +enum class KeyCode { + 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, + LeftCommand, + RightCommand, + Return, + Space +}; + +namespace details { +struct TagKeyModifier {}; +} // namespace details + +using KeyModifier = Bitmask; + +struct KeyModifiers { + static constexpr KeyModifier None = KeyModifier::FromOffset(0); + static constexpr KeyModifier Shift = KeyModifier::FromOffset(1); + static constexpr KeyModifier Ctrl = KeyModifier::FromOffset(2); + static constexpr KeyModifier Alt = KeyModifier::FromOffset(3); + static constexpr KeyModifier Command = KeyModifier::FromOffset(4); +}; + +#ifdef CRU_PLATFORM_OSX +constexpr KeyModifier kKeyModifierCommand = KeyModifiers::Command; +#else +constexpr KeyModifier kKeyModifierCommand = KeyModifiers::Ctrl; +#endif + +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 +#include -#include #include namespace cru::platform::gui { @@ -16,7 +16,7 @@ struct CompositionClause { using CompositionClauses = std::vector; struct CompositionText { - String text; + std::string text; CompositionClauses clauses; TextRange selection; }; @@ -61,6 +61,6 @@ struct IInputMethodContext : virtual IPlatformResource { virtual IEvent* CompositionStartEvent() = 0; virtual IEvent* CompositionEndEvent() = 0; virtual IEvent* CompositionEvent() = 0; - virtual IEvent* TextEvent() = 0; + virtual IEvent* TextEvent() = 0; }; } // namespace cru::platform::gui diff --git a/include/cru/platform/gui/Keyboard.h b/include/cru/platform/gui/Keyboard.h deleted file mode 100644 index 97665e41..00000000 --- a/include/cru/platform/gui/Keyboard.h +++ /dev/null @@ -1,142 +0,0 @@ -#pragma once -#include "cru/base/Bitmask.h" -#include "cru/platform/gui/Base.h" - -namespace cru::platform::gui { -// 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. -enum class KeyCode { - 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, - LeftCommand, - RightCommand, - Return, - Space -}; - -namespace details { -struct TagKeyModifier {}; -} // namespace details - -using KeyModifier = Bitmask; - -struct KeyModifiers { - static constexpr KeyModifier None = KeyModifier::FromOffset(0); - static constexpr KeyModifier Shift = KeyModifier::FromOffset(1); - 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; -#else -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"+"); -} // 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 @@ -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 +#include + namespace cru::platform::gui { struct CRU_PLATFORM_GUI_API SaveDialogOptions { - String title; - String prompt; - String message; - std::vector allowed_file_types; + std::string title; + std::string prompt; + std::string message; + std::vector allowed_file_types; bool allow_all_file_types = false; }; @@ -20,29 +23,29 @@ template 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 allowed_file_types) { + std::vector 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 + #include #include -#include #include 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 ShowSaveDialog(SaveDialogOptions options); + virtual std::optional ShowSaveDialog(SaveDialogOptions options); /** * \todo Implement on Windows/X11. */ - virtual std::optional> ShowOpenDialog( + virtual std::optional> 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 +#include +#include 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 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 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 - -#include "../../Resource.h" +#include +#include 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 -#include "../Cursor.h" #include "Base.h" +#include +#include + #include #include #include diff --git a/include/cru/platform/gui/xcb/Input.h b/include/cru/platform/gui/xcb/Input.h new file mode 100644 index 00000000..77e213de --- /dev/null +++ b/include/cru/platform/gui/xcb/Input.h @@ -0,0 +1,41 @@ +#pragma once + +#include + +#include +#include +#include + +namespace cru::platform::gui::xcb { +struct XcbUiApplication; + +KeyCode XorgKeysymToCruKeyCode(xcb_keysym_t keysym); +std::vector XorgKeycodeToKeysyms(XcbUiApplication* application, + xcb_keycode_t keycode); +KeyCode XorgKeycodeToCruKeyCode(XcbUiApplication* application, + xcb_keycode_t keycode); +std::unordered_map GetKeyboardState( + XcbUiApplication* application); +KeyModifier GetCurrentKeyModifiers(XcbUiApplication* application); + +/** + * Used to convert state field of xcb_button_press_event_t, + * xcb_button_release_event_t, xcb_key_press_event_t, xcb_key_release_event_t. + */ +KeyModifier ConvertModifiersOfEvent(uint32_t mask); + +class XcbKeyboardManager { + public: + explicit XcbKeyboardManager(XcbUiApplication* application); + ~XcbKeyboardManager(); + + std::string KeysymToUtf8(xcb_keysym_t keysym); + std::string KeycodeToUtf8(xcb_keycode_t keycode); + + private: + XcbUiApplication* application_; + xkb_context* xkb_context_; + xkb_keymap* xkb_keymap_; + xkb_state* xkb_state_; +}; +} // namespace cru::platform::gui::xcb 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 -#include "../InputMethod.h" #include "Base.h" +#include +#include + #include #include #include @@ -66,7 +67,7 @@ class XcbXimInputMethodContext : public XcbResource, IEvent* CompositionStartEvent() override; IEvent* CompositionEndEvent() override; IEvent* CompositionEvent() override; - IEvent* TextEvent() override; + IEvent* TextEvent() override; private: void CreateIc(xcb_window_t window); @@ -83,6 +84,6 @@ class XcbXimInputMethodContext : public XcbResource, Event composition_start_event_; Event composition_end_event_; Event composition_event_; - Event text_event_; + Event text_event_; }; } // namespace cru::platform::gui::xcb diff --git a/include/cru/platform/gui/xcb/Keyboard.h b/include/cru/platform/gui/xcb/Keyboard.h deleted file mode 100644 index adff95c1..00000000 --- a/include/cru/platform/gui/xcb/Keyboard.h +++ /dev/null @@ -1,41 +0,0 @@ -#pragma once - -#include - -#include -#include -#include - -namespace cru::platform::gui::xcb { -struct XcbUiApplication; - -KeyCode XorgKeysymToCruKeyCode(xcb_keysym_t keysym); -std::vector XorgKeycodeToKeysyms(XcbUiApplication* application, - xcb_keycode_t keycode); -KeyCode XorgKeycodeToCruKeyCode(XcbUiApplication* application, - xcb_keycode_t keycode); -std::unordered_map GetKeyboardState( - XcbUiApplication* application); -KeyModifier GetCurrentKeyModifiers(XcbUiApplication* application); - -/** - * Used to convert state field of xcb_button_press_event_t, - * xcb_button_release_event_t, xcb_key_press_event_t, xcb_key_release_event_t. - */ -KeyModifier ConvertModifiersOfEvent(uint32_t mask); - -class XcbKeyboardManager { - public: - explicit XcbKeyboardManager(XcbUiApplication* application); - ~XcbKeyboardManager(); - - std::string KeysymToUtf8(xcb_keysym_t keysym); - std::string KeycodeToUtf8(xcb_keycode_t keycode); - - private: - XcbUiApplication* application_; - xkb_context* xkb_context_; - xkb_keymap* xkb_keymap_; - xkb_state* xkb_state_; -}; -} // 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 #include +#include #include #include 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 -#include "../../GraphicsBase.h" -#include "../TimerHelper.h" -#include "../Window.h" #include "Base.h" +#include +#include + #include #include #include @@ -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 +#include +#include +#include +#include #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 theme_resource_dictionary); template - 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(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 GetResourceBrush( - const String& key); + std::string_view key); - std::shared_ptr GetResourceFont(const String& key); + std::shared_ptr GetResourceFont( + std::string_view key); std::shared_ptr GetResourceStyleRuleSet( - const String& key); + std::string_view key); IEvent* 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 - 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 cache; }; std::unique_ptr xml_root_; - std::unordered_map resource_map_; + std::unordered_map 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 min; std::optional 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 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 on_click) { + void AddTextItem(std::string text, std::function on_click) { AddTextItemAt(std::move(text), GetItemCount(), std::move(on_click)); } - void AddTextItemAt(String text, Index index, std::function on_click); + void AddTextItemAt(std::string text, Index index, std::function on_click); void SetOnItemClick(std::function 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 items); + void SetMenuItems(std::vector items); IEvent* 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 items); + void SetMenuItems(std::vector items); IEvent* 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 GetItems() const { return items_; } - void SetItems(std::vector items); + std::vector GetItems() const { return items_; } + void SetItems(std::vector 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 items_; + std::vector 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 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 Create(String text, - bool selectable = false) { + static std::unique_ptr Create(std::string text, + bool selectable = false) { auto c = std::make_unique(); 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* 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 kDefaultPatterns; using MoveFunction = - std::function; + std::function; - 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 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 event_; Event 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 #include #include @@ -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 { 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 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 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 allowed_tags) { + void SetAllowedTags(std::vector allowed_tags) { allowed_tags_ = std::move(allowed_tags); } private: std::type_index type_index_; - std::vector allowed_tags_; + std::vector allowed_tags_; }; template 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 + namespace cru::ui::mapper { class CRU_UI_API StringMapper : public BasicMapper { 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 + 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 GetBrush() { return brush_; } void SetBrush(std::shared_ptr 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 + #include namespace cru::ui::style { -- cgit v1.2.3