diff options
-rw-r--r-- | CMakeLists.txt | 2 | ||||
-rw-r--r-- | include/cru/common/String.hpp | 2 | ||||
-rw-r--r-- | include/cru/osx/graphics/quartz/Brush.hpp | 2 | ||||
-rw-r--r-- | include/cru/osx/graphics/quartz/TextLayout.hpp | 2 | ||||
-rw-r--r-- | include/cru/platform/Resource.hpp | 2 | ||||
-rw-r--r-- | include/cru/ui/DebugFlags.hpp | 1 | ||||
-rw-r--r-- | src/common/String.cpp | 3 | ||||
-rw-r--r-- | src/osx/Resource.cpp | 1 | ||||
-rw-r--r-- | src/osx/graphics/quartz/Brush.cpp | 5 | ||||
-rw-r--r-- | src/osx/graphics/quartz/TextLayout.cpp | 6 | ||||
-rw-r--r-- | src/ui/render/TextRenderObject.cpp | 21 |
11 files changed, 36 insertions, 11 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 1de2d440..dc35a11e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 3.14) set(CMAKE_TOOLCHAIN_FILE $ENV{VCPKG_INSTALLATION_ROOT}/scripts/buildsystems/vcpkg.cmake CACHE STRING "Vcpkg toolchain file") -set(CMAKE_CXX_STANDARD 20) +set(CMAKE_CXX_STANDARD 17) project(cru) diff --git a/include/cru/common/String.hpp b/include/cru/common/String.hpp index 5d09d380..c05ab6e0 100644 --- a/include/cru/common/String.hpp +++ b/include/cru/common/String.hpp @@ -80,7 +80,7 @@ class CRU_BASE_API String { } } - String(std::initializer_list<value_type> l) : String(l.begin(), l.end()) {} + String(std::initializer_list<value_type> l); #ifdef CRU_PLATFORM_WINDOWS String(const wchar_t* str); diff --git a/include/cru/osx/graphics/quartz/Brush.hpp b/include/cru/osx/graphics/quartz/Brush.hpp index 11f05292..1fa26794 100644 --- a/include/cru/osx/graphics/quartz/Brush.hpp +++ b/include/cru/osx/graphics/quartz/Brush.hpp @@ -38,6 +38,8 @@ class QuartzSolidColorBrush : public QuartzBrush, void Select(CGContextRef context) override; + String GetDebugString() override; + private: Color color_; CGColorRef cg_color_; diff --git a/include/cru/osx/graphics/quartz/TextLayout.hpp b/include/cru/osx/graphics/quartz/TextLayout.hpp index 03b1b1cb..95e3d1be 100644 --- a/include/cru/osx/graphics/quartz/TextLayout.hpp +++ b/include/cru/osx/graphics/quartz/TextLayout.hpp @@ -37,6 +37,8 @@ class OsxCTTextLayout : public OsxQuartzResource, public virtual ITextLayout { CTFrameRef CreateFrameWithColor(const Color& color); + String GetDebugString() override; + private: void ReleaseResource(); void RecreateFrame(); diff --git a/include/cru/platform/Resource.hpp b/include/cru/platform/Resource.hpp index b55da43a..c89068fa 100644 --- a/include/cru/platform/Resource.hpp +++ b/include/cru/platform/Resource.hpp @@ -11,5 +11,7 @@ struct CRU_PLATFORM_API IPlatformResource : virtual Interface { CRU_DEFAULT_CONSTRUCTOR_DESTRUCTOR(IPlatformResource) virtual String GetPlatformId() const = 0; + + virtual String GetDebugString() { return String(); } }; } // namespace cru::platform diff --git a/include/cru/ui/DebugFlags.hpp b/include/cru/ui/DebugFlags.hpp index 51482135..c25c10fa 100644 --- a/include/cru/ui/DebugFlags.hpp +++ b/include/cru/ui/DebugFlags.hpp @@ -6,4 +6,5 @@ constexpr bool layout = false; constexpr bool shortcut = false; constexpr bool text_service = false; constexpr int click_detector = 0; +constexpr int draw = 1; } // namespace cru::ui::debug_flags diff --git a/src/common/String.cpp b/src/common/String.cpp index 65d303fb..699d807f 100644 --- a/src/common/String.cpp +++ b/src/common/String.cpp @@ -38,6 +38,9 @@ String::String(const_pointer str, Index size) { this->capacity_ = size; } +String::String(std::initializer_list<char16_t> l) + : String(l.begin(), l.size()) {} + #ifdef CRU_PLATFORM_WINDOWS String::String(const wchar_t* str) : String(str, GetStrSize(str)) {} String::String(const wchar_t* str, Index size) diff --git a/src/osx/Resource.cpp b/src/osx/Resource.cpp index 76381d14..e8140856 100644 --- a/src/osx/Resource.cpp +++ b/src/osx/Resource.cpp @@ -1,2 +1 @@ #include "cru/osx/Resource.hpp" - diff --git a/src/osx/graphics/quartz/Brush.cpp b/src/osx/graphics/quartz/Brush.cpp index b55ff4e8..83ac20a2 100644 --- a/src/osx/graphics/quartz/Brush.cpp +++ b/src/osx/graphics/quartz/Brush.cpp @@ -1,4 +1,5 @@ #include "cru/osx/graphics/quartz/Brush.hpp" +#include "cru/common/String.hpp" namespace cru::platform::graphics::osx::quartz { QuartzSolidColorBrush::QuartzSolidColorBrush(IGraphicsFactory* graphics_factory, @@ -27,4 +28,8 @@ void QuartzSolidColorBrush::Select(CGContextRef context) { CGContextSetStrokeColorWithColor(context, cg_color_); CGContextSetFillColorWithColor(context, cg_color_); } + +String QuartzSolidColorBrush::GetDebugString() { + return Format(u"QuartzSolidColorBrush(Color: {})", color_); +} } // namespace cru::platform::graphics::osx::quartz diff --git a/src/osx/graphics/quartz/TextLayout.cpp b/src/osx/graphics/quartz/TextLayout.cpp index 29735606..41d04958 100644 --- a/src/osx/graphics/quartz/TextLayout.cpp +++ b/src/osx/graphics/quartz/TextLayout.cpp @@ -235,4 +235,10 @@ CTFrameRef OsxCTTextLayout::CreateFrameWithColor(const Color& color) { return frame; } + +String OsxCTTextLayout::GetDebugString() { + return Format(u"OsxCTTextLayout(text: {}, size: ({}, {}))", text_, max_width_, + max_height_); +} + } // namespace cru::platform::graphics::osx::quartz diff --git a/src/ui/render/TextRenderObject.cpp b/src/ui/render/TextRenderObject.cpp index ff9ebc58..189c5532 100644 --- a/src/ui/render/TextRenderObject.cpp +++ b/src/ui/render/TextRenderObject.cpp @@ -5,6 +5,7 @@ #include "cru/platform/graphics/Factory.hpp" #include "cru/platform/graphics/TextLayout.hpp" #include "cru/platform/graphics/util/Painter.hpp" +#include "cru/ui/DebugFlags.hpp" #include <algorithm> #include <limits> @@ -161,6 +162,15 @@ RenderObject* TextRenderObject::HitTest(const Point& point) { } void TextRenderObject::OnDrawContent(platform::graphics::IPainter* painter) { + if constexpr (debug_flags::draw) { + log::TagDebug(log_tag, + u"Begin to paint, total_offset: {}, size: {}, text_layout: " + u"{}, brush: {}.", + this->GetTotalOffset(), this->GetSize(), + this->text_layout_->GetDebugString(), + this->brush_->GetDebugString()); + } + if (this->selection_range_.has_value()) { const auto&& rects = text_layout_->TextRangeRect(this->selection_range_.value()); @@ -186,9 +196,9 @@ Size TextRenderObject::OnMeasureContent(const MeasureRequirement& requirement, text_layout_->SetMaxWidth(measure_width); text_layout_->SetMaxHeight(std::numeric_limits<float>::max()); - const auto text_size = + const Size text_size( text_layout_->GetTextBounds(is_measure_including_trailing_space_) - .GetSize(); + .GetRightBottom()); auto result = text_size; result.width = std::max(result.width, preferred_size.width.GetLengthOr0()); @@ -205,10 +215,5 @@ void TextRenderObject::OnLayoutContent(const Rect& content_rect) { CRU_UNUSED(content_rect) } -void TextRenderObject::OnAfterLayout() { - const auto&& size = GetContentRect().GetSize(); - text_layout_->SetMaxWidth(size.width); - text_layout_->SetMaxHeight(size.height); -} - +void TextRenderObject::OnAfterLayout() {} } // namespace cru::ui::render |