aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/cru/platform/GraphicsBase.h34
-rw-r--r--src/platform/gui/osx/Cursor.mm9
-rw-r--r--src/platform/gui/osx/Keyboard.mm5
-rw-r--r--src/ui/controls/TextHostControlService.cpp2
-rw-r--r--src/ui/helper/ClickDetector.cpp15
-rw-r--r--src/ui/helper/ShortcutHub.cpp2
-rw-r--r--src/ui/host/RoutedEventDispatch.h2
7 files changed, 50 insertions, 19 deletions
diff --git a/include/cru/platform/GraphicsBase.h b/include/cru/platform/GraphicsBase.h
index 3d131e22..fb8d6bdd 100644
--- a/include/cru/platform/GraphicsBase.h
+++ b/include/cru/platform/GraphicsBase.h
@@ -43,8 +43,12 @@ constexpr bool operator!=(const Point& left, const Point& right) {
return !(left == right);
}
+inline std::string ToUtf8String(const Point& point) {
+ return std::format("(x: {}, y: {})", point.x, point.y);
+}
+
inline String ToString(const Point& point) {
- return String::FromUtf8(std::format("(x: {}, y: {})", point.x, point.y));
+ return String::FromUtf8(ToUtf8String(point));
}
struct CRU_PLATFORM_API Size final {
@@ -84,9 +88,12 @@ constexpr bool operator!=(const Size& left, const Size& right) {
return !(left == right);
}
+inline std::string ToUtf8String(const Size& size) {
+ return std::format("(width: {}, height: {})", size.width, size.height);
+}
+
inline String ToString(const Size& size) {
- return String::FromUtf8(
- std::format("(width: {}, height: {})", size.width, size.height));
+ return String::FromUtf8(ToUtf8String(size));
}
struct Thickness final {
@@ -287,3 +294,24 @@ constexpr bool operator!=(const Ellipse& left, const Ellipse& right) {
using TextRange = Range;
} // namespace cru::platform
+
+template <typename T>
+struct ImplementFormatterByToUtf8String {
+ template <class ParseContext>
+ constexpr ParseContext::iterator parse(ParseContext& ctx) const {
+ return ctx.end();
+ }
+
+ template <class FmtContext>
+ FmtContext::iterator format(const T& object, FmtContext& ctx) const {
+ return std::ranges::copy(ToUtf8String(object), ctx.out()).out;
+ }
+};
+
+template <>
+struct std::formatter<cru::platform::Point, char>
+ : ImplementFormatterByToUtf8String<cru::platform::Point> {};
+
+template <>
+struct std::formatter<cru::platform::Size, char>
+ : ImplementFormatterByToUtf8String<cru::platform::Size> {};
diff --git a/src/platform/gui/osx/Cursor.mm b/src/platform/gui/osx/Cursor.mm
index e923e34c..ec364fa7 100644
--- a/src/platform/gui/osx/Cursor.mm
+++ b/src/platform/gui/osx/Cursor.mm
@@ -1,9 +1,10 @@
#include "cru/platform/gui/osx/Cursor.h"
#include "CursorPrivate.h"
+#include "cru/base/Exception.h"
-#include "cru/platform/gui/osx/Resource.h"
#include "cru/platform/gui/Cursor.h"
#include "cru/platform/gui/UiApplication.h"
+#include "cru/platform/gui/osx/Resource.h"
#include <memory>
@@ -28,7 +29,7 @@ OsxCursorPrivate::OsxCursorPrivate(OsxCursor* cursor, SystemCursorType cursor_ty
}
OsxCursorPrivate::~OsxCursorPrivate() {}
-}
+} // namespace details
OsxCursor::OsxCursor(IUiApplication* ui_application, SystemCursorType cursor_type)
: OsxGuiResource(ui_application) {
@@ -68,7 +69,7 @@ OsxCursorManagerPrivate::OsxCursorManagerPrivate(OsxCursorManager* cursor_manage
}
OsxCursorManagerPrivate::~OsxCursorManagerPrivate() {}
-}
+} // namespace details
OsxCursorManager::OsxCursorManager(IUiApplication* ui_application)
: OsxGuiResource(ui_application) {
@@ -89,4 +90,4 @@ std::shared_ptr<ICursor> OsxCursorManager::GetSystemCursor(SystemCursorType type
throw Exception(u"Unknown system cursor type.");
}
}
-}
+} // namespace cru::platform::gui::osx
diff --git a/src/platform/gui/osx/Keyboard.mm b/src/platform/gui/osx/Keyboard.mm
index d4489c96..8a419009 100644
--- a/src/platform/gui/osx/Keyboard.mm
+++ b/src/platform/gui/osx/Keyboard.mm
@@ -1,8 +1,9 @@
#include "cru/platform/gui/osx/Keyboard.h"
+#import "KeyboardPrivate.h"
+#include "cru/base/Exception.h"
#import <AppKit/NSText.h>
#import <Carbon/Carbon.h>
-#import "KeyboardPrivate.h"
namespace cru::platform::gui::osx {
KeyCode KeyCodeFromOsxToCru(unsigned short n) {
@@ -280,4 +281,4 @@ NSEventModifierFlags ConvertKeyModifier(KeyModifier k) {
}
return flags;
}
-}
+} // namespace cru::platform::gui::osx
diff --git a/src/ui/controls/TextHostControlService.cpp b/src/ui/controls/TextHostControlService.cpp
index ace02a46..690aa95d 100644
--- a/src/ui/controls/TextHostControlService.cpp
+++ b/src/ui/controls/TextHostControlService.cpp
@@ -466,7 +466,7 @@ void TextHostControlService::UpdateInputMethodPosition() {
if constexpr (debug_flags::text_service) {
CRU_LOG_TAG_DEBUG("Calculate input method candidate window position: {}.",
- right_bottom);
+ right_bottom);
}
input_method_context->SetCandidateWindowPosition(right_bottom);
diff --git a/src/ui/helper/ClickDetector.cpp b/src/ui/helper/ClickDetector.cpp
index 2e3dc1a0..21caff35 100644
--- a/src/ui/helper/ClickDetector.cpp
+++ b/src/ui/helper/ClickDetector.cpp
@@ -5,7 +5,7 @@
#include "cru/ui/controls/Control.h"
#include "cru/ui/host/WindowHost.h"
-#include <optional>
+#include <string>
namespace cru::ui::helper {
Point ClickEventArgs::GetDownPointOfScreen() const {
@@ -58,7 +58,8 @@ ClickDetector::ClickDetector(controls::Control* control) {
this->state_ == ClickState::Hover) {
if (!this->control_->CaptureMouse()) {
if constexpr (debug_flags::click_detector) {
- CRU_LOG_TAG_DEBUG("Failed to capture mouse when begin click.");
+ CRU_LOG_TAG_DEBUG(
+ "Failed to capture mouse when begin click.");
}
return;
}
@@ -123,16 +124,16 @@ void ClickDetector::SetTriggerButton(MouseButton trigger_button) {
void ClickDetector::SetState(ClickState state) {
if constexpr (debug_flags::click_detector) {
- auto to_string = [](ClickState state) -> std::u16string_view {
+ auto to_string = [](ClickState state) -> const char* {
switch (state) {
case ClickState::None:
- return u"None";
+ return "None";
case ClickState::Hover:
- return u"Hover";
+ return "Hover";
case ClickState::Press:
- return u"Press";
+ return "Press";
case ClickState::PressInactive:
- return u"PressInvactive";
+ return "PressInactive";
default:
UnreachableCode();
}
diff --git a/src/ui/helper/ShortcutHub.cpp b/src/ui/helper/ShortcutHub.cpp
index e3a06e8c..80e70fe1 100644
--- a/src/ui/helper/ShortcutHub.cpp
+++ b/src/ui/helper/ShortcutHub.cpp
@@ -93,7 +93,7 @@ void ShortcutHub::OnKeyDown(events::KeyEventArgs& event) {
key_bind.ToString().ToUtf8());
}
CRU_LOG_TAG_DEBUG("Begin to handle shortcut for key bind {}.",
- key_bind.ToString());
+ key_bind.ToString().ToUtf8());
}
for (const auto& shortcut : shortcut_list) {
diff --git a/src/ui/host/RoutedEventDispatch.h b/src/ui/host/RoutedEventDispatch.h
index 4efc9208..98042841 100644
--- a/src/ui/host/RoutedEventDispatch.h
+++ b/src/ui/host/RoutedEventDispatch.h
@@ -64,7 +64,7 @@ void DispatchEvent(
log += " -> ";
}
log += i->Resolve()->GetControlType().ToUtf8();
- CRU_LOG_TAG_DEBUG(log);
+ CRU_LOG_TAG_DEBUG("{}", log);
}
auto handled = false;