diff options
Diffstat (limited to 'include')
56 files changed, 248 insertions, 230 deletions
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 { |