diff options
author | crupest <crupest@outlook.com> | 2024-02-08 15:12:29 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2024-02-08 15:12:29 +0800 |
commit | f3af6c7e5b46f4209a4981e5d7be217368f40b15 (patch) | |
tree | e932747ad91a718abb667a6170b21f1521a04d1e | |
parent | bfe23251a54b036abef9241ba0994c9e51db25b2 (diff) | |
download | cru-f3af6c7e5b46f4209a4981e5d7be217368f40b15.tar.gz cru-f3af6c7e5b46f4209a4981e5d7be217368f40b15.tar.bz2 cru-f3af6c7e5b46f4209a4981e5d7be217368f40b15.zip |
Get rid of GSL.
32 files changed, 165 insertions, 182 deletions
diff --git a/.gitmodules b/.gitmodules index 056b9ef1..c87b5454 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,9 +1,6 @@ [submodule "lib/double-conversion"] path = lib/double-conversion url = https://github.com/google/double-conversion.git -[submodule "lib/GSL"] - path = lib/GSL - url = https://github.com/microsoft/GSL.git [submodule "lib/Catch2"] path = lib/Catch2 url = https://github.com/catchorg/Catch2.git diff --git a/CMakeLists.txt b/CMakeLists.txt index 75da1485..9a5b497d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -32,7 +32,6 @@ set(BUILD_SHARED_LIBS OFF) add_subdirectory(lib/Catch2) set(BUILD_SHARED_LIBS ${OLD_BUILD_SHARED_LIBS}) add_subdirectory(lib/double-conversion) -add_subdirectory(lib/GSL) enable_testing() diff --git a/demos/InputMethod/main.cpp b/demos/InputMethod/main.cpp index fc63dd5e..cf42d3c2 100644 --- a/demos/InputMethod/main.cpp +++ b/demos/InputMethod/main.cpp @@ -146,7 +146,7 @@ int main() { text_layout->SetText(committed_text + composition_text.text); const auto cursor_pos = composition_text.selection.position + - gsl::narrow_cast<int>(committed_text.size()); + static_cast<int>(committed_text.size()); state->cursor_rect = text_layout->TextSinglePoint(cursor_pos, false); input_method_context->SetCandidateWindowPosition( diff --git a/include/cru/common/Base.h b/include/cru/common/Base.h index 34faf779..8a6a7634 100644 --- a/include/cru/common/Base.h +++ b/include/cru/common/Base.h @@ -1,5 +1,10 @@ #pragma once -#include "PreConfig.h" // IWYU pragma: keep +#include "PreConfig.h" // IWYU pragma: keep + +#include <cassert> +#include <cstddef> +#include <functional> +#include <memory> #ifdef CRU_PLATFORM_WINDOWS #ifdef CRU_BASE_EXPORT_API @@ -11,8 +16,6 @@ #define CRU_BASE_API #endif -#include <gsl/gsl> - #define CRU_UNUSED(entity) static_cast<void>(entity); #define CRU__CONCAT(a, b) a##b @@ -83,7 +86,18 @@ struct CRU_BASE_API Interface { [[noreturn]] void CRU_BASE_API UnreachableCode(); -using Index = gsl::index; +using Index = std::ptrdiff_t; + +inline void Expects(bool condition) { assert(condition); } +inline void Ensures(bool condition) { assert(condition); } +template <typename T> +inline void Expects(const std::shared_ptr<T>& ptr) { + assert(ptr != nullptr); +} +template <typename T> +inline void Ensures(const std::shared_ptr<T>& ptr) { + assert(ptr != nullptr); +} // https://www.boost.org/doc/libs/1_54_0/doc/html/hash/reference.html#boost.hash_combine template <class T> diff --git a/include/cru/common/Event.h b/include/cru/common/Event.h index 14d68833..18d2c570 100644 --- a/include/cru/common/Event.h +++ b/include/cru/common/Event.h @@ -4,6 +4,7 @@ #include "SelfResolvable.h" #include <algorithm> +#include <cassert> #include <functional> #include <memory> #include <utility> @@ -235,7 +236,7 @@ class EventRevokerGuard { EventRevoker Get() { // revoker is only null when this is moved // you shouldn't use a moved instance - Expects(revoker_); + assert(revoker_); return *revoker_; } diff --git a/include/cru/platform/graphics/Base.h b/include/cru/platform/graphics/Base.h index 3bb9b7b4..3f3ae0b4 100644 --- a/include/cru/platform/graphics/Base.h +++ b/include/cru/platform/graphics/Base.h @@ -28,7 +28,7 @@ struct IPainter; struct ITextLayout; struct TextHitTestResult { - gsl::index position; + Index position; bool trailing; bool inside_text; }; diff --git a/include/cru/platform/graphics/direct2d/WindowRenderTarget.h b/include/cru/platform/graphics/direct2d/WindowRenderTarget.h index c0251880..f77ce471 100644 --- a/include/cru/platform/graphics/direct2d/WindowRenderTarget.h +++ b/include/cru/platform/graphics/direct2d/WindowRenderTarget.h @@ -5,8 +5,7 @@ namespace cru::platform::graphics::direct2d { // Represents a window render target. class CRU_WIN_GRAPHICS_DIRECT_API D2DWindowRenderTarget : public Object { public: - D2DWindowRenderTarget(gsl::not_null<DirectGraphicsFactory*> factory, - HWND hwnd); + D2DWindowRenderTarget(DirectGraphicsFactory* factory, HWND hwnd); CRU_DELETE_COPY(D2DWindowRenderTarget) CRU_DELETE_MOVE(D2DWindowRenderTarget) diff --git a/include/cru/platform/gui/win/InputMethod.h b/include/cru/platform/gui/win/InputMethod.h index 8e28f857..3a9faeaa 100644 --- a/include/cru/platform/gui/win/InputMethod.h +++ b/include/cru/platform/gui/win/InputMethod.h @@ -39,7 +39,7 @@ class CRU_WIN_GUI_API WinInputMethodContext CRU_DEFINE_CLASS_LOG_TAG(u"WinInputMethodContext") public: - WinInputMethodContext(gsl::not_null<WinNativeWindow*> window); + WinInputMethodContext(WinNativeWindow* window); CRU_DELETE_COPY(WinInputMethodContext) CRU_DELETE_MOVE(WinInputMethodContext) diff --git a/include/cru/ui/components/Menu.h b/include/cru/ui/components/Menu.h index f4e54c9f..82766aa5 100644 --- a/include/cru/ui/components/Menu.h +++ b/include/cru/ui/components/Menu.h @@ -48,13 +48,11 @@ class CRU_UI_API Menu : public Component { public: controls::Control* GetRootControl() override { return &container_; } - gsl::index GetItemCount() const { - return static_cast<gsl::index>(items_.size()); - } + Index GetItemCount() const { return static_cast<Index>(items_.size()); } void AddItem(Component* component) { AddItemAt(component, GetItemCount()); } - void AddItemAt(Component* component, gsl::index index); - Component* RemoveItemAt(gsl::index index); + void AddItemAt(Component* component, Index index); + Component* RemoveItemAt(Index index); void ClearItems(); void AddTextItem(String text, std::function<void()> on_click) { diff --git a/include/cru/ui/controls/TextBlock.h b/include/cru/ui/controls/TextBlock.h index 12c9d2f9..ad44ad2d 100644 --- a/include/cru/ui/controls/TextBlock.h +++ b/include/cru/ui/controls/TextBlock.h @@ -47,7 +47,7 @@ class CRU_UI_API TextBlock : public NoChildControl, } void SetTextColor(const Color& color); - gsl::not_null<render::TextRenderObject*> GetTextRenderObject() override; + render::TextRenderObject* GetTextRenderObject() override; render::ScrollRenderObject* GetScrollRenderObject() override { return nullptr; } diff --git a/include/cru/ui/controls/TextBox.h b/include/cru/ui/controls/TextBox.h index c3d8fc4d..9388d3fd 100644 --- a/include/cru/ui/controls/TextBox.h +++ b/include/cru/ui/controls/TextBox.h @@ -29,7 +29,7 @@ class CRU_UI_API TextBox : public NoChildControl, render::RenderObject* GetRenderObject() const override; - gsl::not_null<render::TextRenderObject*> GetTextRenderObject() override; + render::TextRenderObject* GetTextRenderObject() override; render::ScrollRenderObject* GetScrollRenderObject() override; bool GetMultiLine() const; diff --git a/include/cru/ui/controls/TextHostControlService.h b/include/cru/ui/controls/TextHostControlService.h index ae86e1e9..7efd7760 100644 --- a/include/cru/ui/controls/TextHostControlService.h +++ b/include/cru/ui/controls/TextHostControlService.h @@ -23,7 +23,7 @@ namespace cru::ui::controls { constexpr int k_default_caret_blink_duration = 500; struct CRU_UI_API ITextHostControl : virtual Interface { - virtual gsl::not_null<render::TextRenderObject*> GetTextRenderObject() = 0; + virtual render::TextRenderObject* GetTextRenderObject() = 0; // May return nullptr. virtual render::ScrollRenderObject* GetScrollRenderObject() = 0; }; @@ -48,8 +48,8 @@ class TextControlMovePattern : public Object { static std::vector<TextControlMovePattern> kDefaultPatterns; using MoveFunction = - std::function<gsl::index(TextHostControlService* service, StringView text, - gsl::index current_position)>; + std::function<Index(TextHostControlService* service, StringView text, + Index current_position)>; TextControlMovePattern(String name, helper::ShortcutKeyBind key_bind, MoveFunction move_function) @@ -65,8 +65,8 @@ class TextControlMovePattern : public Object { public: String GetName() const { return name_; } helper::ShortcutKeyBind GetKeyBind() const { return key_bind_; } - gsl::index Move(TextHostControlService* service, StringView text, - gsl::index current_position) const { + Index Move(TextHostControlService* service, StringView text, + Index current_position) const { return move_function_(service, text, current_position); } @@ -80,7 +80,7 @@ class CRU_UI_API TextHostControlService : public Object { CRU_DEFINE_CLASS_LOG_TAG(u"TextControlService") public: - TextHostControlService(gsl::not_null<Control*> control); + TextHostControlService(Control* control); CRU_DELETE_COPY(TextHostControlService) CRU_DELETE_MOVE(TextHostControlService) @@ -105,13 +105,12 @@ class CRU_UI_API TextHostControlService : public Object { StringView GetTextView() { return this->text_; } void SetText(String text, bool stop_composition = false); - void InsertText(gsl::index position, StringView text, + void InsertText(Index position, StringView text, bool stop_composition = false); - void DeleteChar(gsl::index position, bool stop_composition = false); + void DeleteChar(Index position, bool stop_composition = false); // Return the position of deleted character. - gsl::index DeleteCharPrevious(gsl::index position, - bool stop_composition = false); + Index DeleteCharPrevious(Index position, bool stop_composition = false); void DeleteText(TextRange range, bool stop_composition = false); void CancelComposition(); @@ -124,17 +123,17 @@ class CRU_UI_API TextHostControlService : public Object { int GetCaretBlinkDuration() { return caret_blink_duration_; } void SetCaretBlinkDuration(int milliseconds); - gsl::index GetCaretPosition() { return selection_.GetEnd(); } + Index GetCaretPosition() { return selection_.GetEnd(); } TextRange GetSelection() { return selection_; } StringView GetSelectedText(); - void SetSelection(gsl::index caret_position); + void SetSelection(Index caret_position); void SetSelection(TextRange selection, bool scroll_to_caret = true); void SelectAll(); - void ChangeSelectionEnd(gsl::index new_end); + void ChangeSelectionEnd(Index new_end); void AbortSelection(); void DeleteSelectedText(); @@ -150,7 +149,7 @@ class CRU_UI_API TextHostControlService : public Object { IEvent<std::nullptr_t>* TextChangeEvent() { return &text_change_event_; } - gsl::not_null<render::TextRenderObject*> GetTextRenderObject(); + render::TextRenderObject* GetTextRenderObject(); render::ScrollRenderObject* GetScrollRenderObject(); private: @@ -192,8 +191,8 @@ class CRU_UI_API TextHostControlService : public Object { void OpenContextMenu(const Point& position, ContextMenuItem items); private: - gsl::not_null<Control*> control_; - gsl::not_null<ITextHostControl*> text_host_control_; + Control* control_; + ITextHostControl* text_host_control_; Event<std::nullptr_t> text_change_event_; diff --git a/include/cru/ui/render/ScrollBar.h b/include/cru/ui/render/ScrollBar.h index c65c0345..20b6e6cf 100644 --- a/include/cru/ui/render/ScrollBar.h +++ b/include/cru/ui/render/ScrollBar.h @@ -12,7 +12,6 @@ #include "cru/ui/controls/Control.h" #include "cru/ui/helper/ClickDetector.h" -#include <gsl/pointers> #include <memory> #include <optional> #include <unordered_map> @@ -45,8 +44,7 @@ String CRU_UI_API GenerateScrollBarThemeColorKey(ScrollBarBrushUsageKind usage, class CRU_UI_API ScrollBar : public Object { public: - ScrollBar(gsl::not_null<ScrollRenderObject*> render_object, - Direction direction); + ScrollBar(ScrollRenderObject* render_object, Direction direction); CRU_DELETE_COPY(ScrollBar) CRU_DELETE_MOVE(ScrollBar) @@ -69,12 +67,11 @@ class CRU_UI_API ScrollBar : public Object { void InstallHandlers(controls::Control* control); void UninstallHandlers() { InstallHandlers(nullptr); } - gsl::not_null<std::shared_ptr<platform::graphics::IBrush>> - GetCollapsedThumbBrush(); + std::shared_ptr<platform::graphics::IBrush> GetCollapsedThumbBrush(); // Brush could be nullptr to use the theme brush. void SetCollapsedThumbBrush( std::shared_ptr<platform::graphics::IBrush> brush); - gsl::not_null<std::shared_ptr<platform::graphics::IBrush>> GetBrush( + std::shared_ptr<platform::graphics::IBrush> GetBrush( ScrollBarBrushUsageKind usage, ScrollBarBrushStateKind state); // Brush could be nullptr to use the theme brush. void SetBrush(ScrollBarBrushUsageKind usage, ScrollBarBrushStateKind state, @@ -83,14 +80,14 @@ class CRU_UI_API ScrollBar : public Object { protected: void OnDraw(platform::graphics::IPainter* painter, bool expand); - virtual void DrawUpArrow( - platform::graphics::IPainter* painter, const Rect& area, - gsl::not_null<platform::graphics::IBrush*> arrow_brush, - gsl::not_null<platform::graphics::IBrush*> background_brush) = 0; - virtual void DrawDownArrow( - platform::graphics::IPainter* painter, const Rect& area, - gsl::not_null<platform::graphics::IBrush*> arrow_brush, - gsl::not_null<platform::graphics::IBrush*> background_brush) = 0; + virtual void DrawUpArrow(platform::graphics::IPainter* painter, + const Rect& area, + platform::graphics::IBrush* arrow_brush, + platform::graphics::IBrush* background_brush) = 0; + virtual void DrawDownArrow(platform::graphics::IPainter* painter, + const Rect& area, + platform::graphics::IBrush* arrow_brush, + platform::graphics::IBrush* background_brush) = 0; std::optional<ScrollBarAreaKind> ExpandedHitTest(const Point& point); @@ -119,7 +116,7 @@ class CRU_UI_API ScrollBar : public Object { ScrollBarBrushStateKind GetState(ScrollBarAreaKind area); protected: - gsl::not_null<ScrollRenderObject*> render_object_; + ScrollRenderObject* render_object_; std::unique_ptr<platform::graphics::IGeometry> arrow_geometry_; @@ -154,8 +151,7 @@ class CRU_UI_API ScrollBar : public Object { class CRU_UI_API HorizontalScrollBar : public ScrollBar { public: - explicit HorizontalScrollBar( - gsl::not_null<ScrollRenderObject*> render_object); + explicit HorizontalScrollBar(ScrollRenderObject* render_object); CRU_DELETE_COPY(HorizontalScrollBar) CRU_DELETE_MOVE(HorizontalScrollBar) @@ -163,14 +159,12 @@ class CRU_UI_API HorizontalScrollBar : public ScrollBar { ~HorizontalScrollBar() override = default; protected: - void DrawUpArrow( - platform::graphics::IPainter* painter, const Rect& area, - gsl::not_null<platform::graphics::IBrush*> arrow_brush, - gsl::not_null<platform::graphics::IBrush*> background_brush) override; - void DrawDownArrow( - platform::graphics::IPainter* painter, const Rect& area, - gsl::not_null<platform::graphics::IBrush*> arrow_brush, - gsl::not_null<platform::graphics::IBrush*> background_brush) override; + void DrawUpArrow(platform::graphics::IPainter* painter, const Rect& area, + platform::graphics::IBrush* arrow_brush, + platform::graphics::IBrush* background_brush) override; + void DrawDownArrow(platform::graphics::IPainter* painter, const Rect& area, + platform::graphics::IBrush* arrow_brush, + platform::graphics::IBrush* background_brush) override; bool IsShowBar() override; @@ -187,7 +181,7 @@ class CRU_UI_API HorizontalScrollBar : public ScrollBar { class CRU_UI_API VerticalScrollBar : public ScrollBar { public: - explicit VerticalScrollBar(gsl::not_null<ScrollRenderObject*> render_object); + explicit VerticalScrollBar(ScrollRenderObject* render_object); CRU_DELETE_COPY(VerticalScrollBar) CRU_DELETE_MOVE(VerticalScrollBar) @@ -195,14 +189,12 @@ class CRU_UI_API VerticalScrollBar : public ScrollBar { ~VerticalScrollBar() override = default; protected: - void DrawUpArrow( - platform::graphics::IPainter* painter, const Rect& area, - gsl::not_null<platform::graphics::IBrush*> arrow_brush, - gsl::not_null<platform::graphics::IBrush*> background_brush) override; - void DrawDownArrow( - platform::graphics::IPainter* painter, const Rect& area, - gsl::not_null<platform::graphics::IBrush*> arrow_brush, - gsl::not_null<platform::graphics::IBrush*> background_brush) override; + void DrawUpArrow(platform::graphics::IPainter* painter, const Rect& area, + platform::graphics::IBrush* arrow_brush, + platform::graphics::IBrush* background_brush) override; + void DrawDownArrow(platform::graphics::IPainter* painter, const Rect& area, + platform::graphics::IBrush* arrow_brush, + platform::graphics::IBrush* background_brush) override; bool IsShowBar() override; @@ -220,7 +212,7 @@ class CRU_UI_API VerticalScrollBar : public ScrollBar { // A delegate to draw scrollbar and register related events. class CRU_UI_API ScrollBarDelegate : public Object { public: - explicit ScrollBarDelegate(gsl::not_null<ScrollRenderObject*> render_object); + explicit ScrollBarDelegate(ScrollRenderObject* render_object); CRU_DELETE_COPY(ScrollBarDelegate) CRU_DELETE_MOVE(ScrollBarDelegate) @@ -244,7 +236,7 @@ class CRU_UI_API ScrollBarDelegate : public Object { void UninstallHandlers() { InstallHandlers(nullptr); } private: - gsl::not_null<ScrollRenderObject*> render_object_; + ScrollRenderObject* render_object_; HorizontalScrollBar horizontal_bar_; VerticalScrollBar vertical_bar_; diff --git a/include/cru/ui/render/TextRenderObject.h b/include/cru/ui/render/TextRenderObject.h index f12ac72f..0cb3623d 100644 --- a/include/cru/ui/render/TextRenderObject.h +++ b/include/cru/ui/render/TextRenderObject.h @@ -51,7 +51,7 @@ class CRU_UI_API TextRenderObject : public RenderObject { Index GetLineIndexFromCharIndex(Index char_index); float GetLineHeight(Index line_index); std::vector<Rect> TextRangeRect(const TextRange& text_range); - Rect TextSinglePoint(gsl::index position, bool trailing); + Rect TextSinglePoint(Index position, bool trailing); platform::graphics::TextHitTestResult TextHitTest(const Point& point); std::optional<TextRange> GetSelectionRange() const { @@ -70,8 +70,8 @@ class CRU_UI_API TextRenderObject : public RenderObject { // Caret position can be any value. When it is negative, 0 is used. When it // exceeds the size of the string, the size of the string is used. - gsl::index GetCaretPosition() const { return caret_position_; } - void SetCaretPosition(gsl::index position); + Index GetCaretPosition() const { return caret_position_; } + void SetCaretPosition(Index position); // Lefttop relative to content lefttop. Rect GetCaretRectInContent(); @@ -115,7 +115,7 @@ class CRU_UI_API TextRenderObject : public RenderObject { std::shared_ptr<platform::graphics::IBrush> selection_brush_; bool draw_caret_ = false; - gsl::index caret_position_ = 0; + Index caret_position_ = 0; std::shared_ptr<platform::graphics::IBrush> caret_brush_; float caret_width_ = default_caret_width; diff --git a/include/cru/ui/style/StyleRuleSet.h b/include/cru/ui/style/StyleRuleSet.h index 8f3495bc..080c2eb8 100644 --- a/include/cru/ui/style/StyleRuleSet.h +++ b/include/cru/ui/style/StyleRuleSet.h @@ -27,16 +27,16 @@ class CRU_UI_API StyleRuleSet : public Object, public model::IListChangeNotify { std::shared_ptr<StyleRuleSet> GetParent() const { return parent_; } void SetParent(std::shared_ptr<StyleRuleSet> parent); - gsl::index GetSize() const { return static_cast<gsl::index>(rules_.size()); } + Index GetSize() const { return static_cast<Index>(rules_.size()); } const std::vector<StyleRule>& GetRules() const { return rules_; } void AddStyleRule(StyleRule rule) { AddStyleRule(std::move(rule), GetSize()); } - void AddStyleRule(StyleRule rule, gsl::index index); + void AddStyleRule(StyleRule rule, Index index); - void RemoveStyleRule(gsl::index index, gsl::index count = 1); + void RemoveStyleRule(Index index, Index count = 1); const StyleRule& GetStyleRule(Index index) const { return rules_[index]; } void SetStyleRule(Index index, StyleRule rule); @@ -45,7 +45,7 @@ class CRU_UI_API StyleRuleSet : public Object, public model::IListChangeNotify { void Set(const StyleRuleSet& other, bool set_parent = false); - const StyleRule& operator[](gsl::index index) const { return rules_[index]; } + const StyleRule& operator[](Index index) const { return rules_[index]; } // Triggered whenever a change happened to this (rule add or remove, parent // change ...). Subscribe to this and update style change listeners and style. diff --git a/lib/GSL b/lib/GSL deleted file mode 160000 -Subproject f1a494cfd2ce55fe88b5134eab985f5852667b8 diff --git a/src/common/CMakeLists.txt b/src/common/CMakeLists.txt index 45688deb..2414831b 100644 --- a/src/common/CMakeLists.txt +++ b/src/common/CMakeLists.txt @@ -73,4 +73,4 @@ else() target_compile_definitions(CruBase PUBLIC CRU_PLATFORM_LINUX) endif() -target_link_libraries(CruBase PUBLIC GSL double-conversion) +target_link_libraries(CruBase PUBLIC double-conversion) diff --git a/src/common/String.cpp b/src/common/String.cpp index cac807b0..0d1c38b8 100644 --- a/src/common/String.cpp +++ b/src/common/String.cpp @@ -6,7 +6,6 @@ #include <double-conversion/double-conversion.h> #include <double-conversion/string-to-double.h> -#include <gsl/gsl> #include <algorithm> #include <cmath> diff --git a/src/platform/Color.cpp b/src/platform/Color.cpp index a35ef535..bbb78628 100644 --- a/src/platform/Color.cpp +++ b/src/platform/Color.cpp @@ -1,7 +1,5 @@ #include "cru/platform/Color.h" -#include <gsl/gsl> - #include <cmath> #include <cstdint> #include <optional> @@ -61,9 +59,8 @@ std::optional<Color> Color::Parse(StringView string, if (!g) return std::nullopt; auto b = get_num_for_two_digit(string.substr(5, 2)); if (!b) return std::nullopt; - return Color(gsl::narrow_cast<std::uint8_t>(*r), - gsl::narrow_cast<std::uint8_t>(*g), - gsl::narrow_cast<std::uint8_t>(*b)); + return Color(static_cast<std::uint8_t>(*r), static_cast<std::uint8_t>(*g), + static_cast<std::uint8_t>(*b)); } else if (string_size == 9) { if (string[0] != u'#') return std::nullopt; auto r = get_num_for_two_digit(string.substr(1, 2)); @@ -74,9 +71,8 @@ std::optional<Color> Color::Parse(StringView string, if (!b) return std::nullopt; auto a = get_num_for_two_digit(string.substr(7, 2)); if (!a) return std::nullopt; - return Color( - gsl::narrow_cast<std::uint8_t>(*r), gsl::narrow_cast<std::uint8_t>(*g), - gsl::narrow_cast<std::uint8_t>(*b), gsl::narrow_cast<std::uint8_t>(*a)); + return Color(static_cast<std::uint8_t>(*r), static_cast<std::uint8_t>(*g), + static_cast<std::uint8_t>(*b), static_cast<std::uint8_t>(*a)); } else { return std::nullopt; } diff --git a/src/platform/graphics/direct2d/WindowRenderTarget.cpp b/src/platform/graphics/direct2d/WindowRenderTarget.cpp index 0227f084..a8d988f4 100644 --- a/src/platform/graphics/direct2d/WindowRenderTarget.cpp +++ b/src/platform/graphics/direct2d/WindowRenderTarget.cpp @@ -4,8 +4,8 @@ #include "cru/platform/graphics/direct2d/Factory.h" namespace cru::platform::graphics::direct2d { -D2DWindowRenderTarget::D2DWindowRenderTarget( - gsl::not_null<DirectGraphicsFactory*> factory, HWND hwnd) +D2DWindowRenderTarget::D2DWindowRenderTarget(DirectGraphicsFactory* factory, + HWND hwnd) : factory_(factory), hwnd_(hwnd) { const auto d3d11_device = factory->GetD3D11Device(); const auto dxgi_factory = factory->GetDxgiFactory(); diff --git a/src/platform/gui/osx/Window.mm b/src/platform/gui/osx/Window.mm index 8773678d..d6bee564 100644 --- a/src/platform/gui/osx/Window.mm +++ b/src/platform/gui/osx/Window.mm @@ -471,7 +471,7 @@ cru::platform::gui::KeyModifier GetKeyModifier(NSEvent* event) { - (void)drawRect:(NSRect)dirtyRect { auto cg_context = [[NSGraphicsContext currentContext] CGContext]; auto layer = _p->GetDrawLayer(); - Ensures(layer); + cru::Ensures(layer); CGContextDrawLayerAtPoint(cg_context, CGPointMake(0, 0), layer); } diff --git a/src/platform/gui/win/InputMethod.cpp b/src/platform/gui/win/InputMethod.cpp index d9c179ad..4c5b3b8c 100644 --- a/src/platform/gui/win/InputMethod.cpp +++ b/src/platform/gui/win/InputMethod.cpp @@ -144,8 +144,7 @@ CompositionText GetCompositionInfo(HIMC imm_context) { } // namespace -WinInputMethodContext::WinInputMethodContext( - gsl::not_null<WinNativeWindow*> window) +WinInputMethodContext::WinInputMethodContext(WinNativeWindow* window) : native_window_(window) { event_guard_ += window->NativeMessageEvent()->AddHandler( std::bind(&WinInputMethodContext::OnWindowNativeMessage, this, diff --git a/src/platform/gui/win/TimerManager.cpp b/src/platform/gui/win/TimerManager.cpp index 1bc32b51..c6128b85 100644 --- a/src/platform/gui/win/TimerManager.cpp +++ b/src/platform/gui/win/TimerManager.cpp @@ -22,7 +22,7 @@ long long TimerManager::SetTimer(TimerType type, int period, std::move(action)}; if (type == TimerType::Immediate) { if (!::PostMessageW(god_window_->GetHandle(), kSetImmediateWindowMessageId, - gsl::narrow<UINT_PTR>(id), 0)) { + static_cast<UINT_PTR>(id), 0)) { throw Win32Error( ::GetLastError(), u"Failed to post window message to god window for set immediate."); @@ -46,7 +46,7 @@ void TimerManager::CancelTimer(long long id) { } void TimerManager::CreateNativeTimer(TimerInfo* info) { - info->native_timer_id = gsl::narrow<UINT_PTR>(info->id); + info->native_timer_id = static_cast<UINT_PTR>(info->id); ::SetTimer(god_window_->GetHandle(), info->native_timer_id, info->period, nullptr); } diff --git a/src/platform/gui/win/UiApplication.cpp b/src/platform/gui/win/UiApplication.cpp index 90eb20ca..94d6b9c5 100644 --- a/src/platform/gui/win/UiApplication.cpp +++ b/src/platform/gui/win/UiApplication.cpp @@ -71,14 +71,14 @@ long long WinUiApplication::SetImmediate(std::function<void()> action) { long long WinUiApplication::SetTimeout(std::chrono::milliseconds milliseconds, std::function<void()> action) { return this->timer_manager_->SetTimer(TimerType::Timeout, - gsl::narrow<int>(milliseconds.count()), + static_cast<int>(milliseconds.count()), std::move(action)); } long long WinUiApplication::SetInterval(std::chrono::milliseconds milliseconds, std::function<void()> action) { return this->timer_manager_->SetTimer(TimerType::Interval, - gsl::narrow<int>(milliseconds.count()), + static_cast<int>(milliseconds.count()), std::move(action)); } diff --git a/src/ui/components/Menu.cpp b/src/ui/components/Menu.cpp index 005147a1..2da38990 100644 --- a/src/ui/components/Menu.cpp +++ b/src/ui/components/Menu.cpp @@ -37,14 +37,14 @@ Menu::~Menu() { } } -void Menu::AddItemAt(Component* item, gsl::index index) { +void Menu::AddItemAt(Component* item, Index index) { Expects(index >= 0 && index <= GetItemCount()); items_.insert(items_.cbegin() + index, item); container_.AddChildAt(item->GetRootControl(), index); } -Component* Menu::RemoveItemAt(gsl::index index) { +Component* Menu::RemoveItemAt(Index index) { Expects(index >= 0 && index < GetItemCount()); Component* item = items_[index]; @@ -65,7 +65,7 @@ void Menu::ClearItems() { container_.ClearChildren(); } -void Menu::AddTextItemAt(String text, gsl::index index, +void Menu::AddTextItemAt(String text, Index index, std::function<void()> on_click) { MenuItem* item = new MenuItem(std::move(text)); item->SetOnClick([this, index, on_click = std::move(on_click)] { diff --git a/src/ui/controls/TextBlock.cpp b/src/ui/controls/TextBlock.cpp index 79c66865..0dad4f5d 100644 --- a/src/ui/controls/TextBlock.cpp +++ b/src/ui/controls/TextBlock.cpp @@ -47,7 +47,7 @@ void TextBlock::SetTextColor(const Color& color) { GetUiApplication()->GetGraphicsFactory()->CreateSolidColorBrush(color)); } -gsl::not_null<render::TextRenderObject*> TextBlock::GetTextRenderObject() { +render::TextRenderObject* TextBlock::GetTextRenderObject() { return text_render_object_.get(); } } // namespace cru::ui::controls diff --git a/src/ui/controls/TextBox.cpp b/src/ui/controls/TextBox.cpp index 66b6bd43..87672b4f 100644 --- a/src/ui/controls/TextBox.cpp +++ b/src/ui/controls/TextBox.cpp @@ -53,7 +53,7 @@ bool TextBox::GetMultiLine() const { return service_->IsMultiLine(); } void TextBox::SetMultiLine(bool value) { service_->SetMultiLine(value); } -gsl::not_null<render::TextRenderObject*> TextBox::GetTextRenderObject() { +render::TextRenderObject* TextBox::GetTextRenderObject() { return text_render_object_.get(); } diff --git a/src/ui/controls/TextHostControlService.cpp b/src/ui/controls/TextHostControlService.cpp index d6c40a36..36703986 100644 --- a/src/ui/controls/TextHostControlService.cpp +++ b/src/ui/controls/TextHostControlService.cpp @@ -29,7 +29,7 @@ namespace cru::ui::controls { TextControlMovePattern TextControlMovePattern::kLeft( u"Left", helper::ShortcutKeyBind(platform::gui::KeyCode::Left), [](TextHostControlService* service, StringView text, - gsl::index current_position) { + Index current_position) { CRU_UNUSED(service) Utf16PreviousCodePoint(text, current_position, ¤t_position); return current_position; @@ -37,7 +37,7 @@ TextControlMovePattern TextControlMovePattern::kLeft( TextControlMovePattern TextControlMovePattern::kRight( u"Right", helper::ShortcutKeyBind(platform::gui::KeyCode::Right), [](TextHostControlService* service, StringView text, - gsl::index current_position) { + Index current_position) { CRU_UNUSED(service) Utf16NextCodePoint(text, current_position, ¤t_position); return current_position; @@ -47,7 +47,7 @@ TextControlMovePattern TextControlMovePattern::kCtrlLeft( helper::ShortcutKeyBind(platform::gui::KeyCode::Left, platform::gui::KeyModifiers::ctrl), [](TextHostControlService* service, StringView text, - gsl::index current_position) { + Index current_position) { CRU_UNUSED(service) return Utf16PreviousWord(text, current_position); }); @@ -56,14 +56,14 @@ TextControlMovePattern TextControlMovePattern::kCtrlRight( helper::ShortcutKeyBind(platform::gui::KeyCode::Right, platform::gui::KeyModifiers::ctrl), [](TextHostControlService* service, StringView text, - gsl::index current_position) { + Index current_position) { CRU_UNUSED(service) return Utf16NextWord(text, current_position); }); TextControlMovePattern TextControlMovePattern::kUp( u"Up", helper::ShortcutKeyBind(platform::gui::KeyCode::Up), [](TextHostControlService* service, StringView text, - gsl::index current_position) { + Index current_position) { CRU_UNUSED(text) auto text_render_object = service->GetTextRenderObject(); auto rect = text_render_object->TextSinglePoint(current_position, false); @@ -74,7 +74,7 @@ TextControlMovePattern TextControlMovePattern::kUp( TextControlMovePattern TextControlMovePattern::kDown( u"Down", helper::ShortcutKeyBind(platform::gui::KeyCode::Down), [](TextHostControlService* service, StringView text, - gsl::index current_position) { + Index current_position) { CRU_UNUSED(text) auto text_render_object = service->GetTextRenderObject(); auto rect = text_render_object->TextSinglePoint(current_position, false); @@ -85,7 +85,7 @@ TextControlMovePattern TextControlMovePattern::kDown( TextControlMovePattern TextControlMovePattern::kHome( u"Home(Line Begin)", helper::ShortcutKeyBind(platform::gui::KeyCode::Home), [](TextHostControlService* service, StringView text, - gsl::index current_position) { + Index current_position) { CRU_UNUSED(service) return Utf16BackwardUntil(text, current_position, [](CodePoint c) { return c == u'\n'; }); @@ -93,7 +93,7 @@ TextControlMovePattern TextControlMovePattern::kHome( TextControlMovePattern TextControlMovePattern::kEnd( u"End(Line End)", helper::ShortcutKeyBind(platform::gui::KeyCode::End), [](TextHostControlService* service, StringView text, - gsl::index current_position) { + Index current_position) { CRU_UNUSED(service) return Utf16ForwardUntil(text, current_position, [](CodePoint c) { return c == u'\n'; }); @@ -103,7 +103,7 @@ TextControlMovePattern TextControlMovePattern::kCtrlHome( helper::ShortcutKeyBind(platform::gui::KeyCode::Home, platform::gui::KeyModifiers::ctrl), [](TextHostControlService* service, StringView text, - gsl::index current_position) { + Index current_position) { CRU_UNUSED(service) CRU_UNUSED(text) CRU_UNUSED(current_position) @@ -114,7 +114,7 @@ TextControlMovePattern TextControlMovePattern::kCtrlEnd( helper::ShortcutKeyBind(platform::gui::KeyCode::End, platform::gui::KeyModifiers::ctrl), [](TextHostControlService* service, StringView text, - gsl::index current_position) { + Index current_position) { CRU_UNUSED(service) CRU_UNUSED(text) CRU_UNUSED(current_position) @@ -123,7 +123,7 @@ TextControlMovePattern TextControlMovePattern::kCtrlEnd( TextControlMovePattern TextControlMovePattern::kPageUp( u"PageUp", helper::ShortcutKeyBind(platform::gui::KeyCode::PageUp), [](TextHostControlService* service, StringView text, - gsl::index current_position) { + Index current_position) { CRU_UNUSED(service) CRU_UNUSED(text) // TODO: Implement this. @@ -132,7 +132,7 @@ TextControlMovePattern TextControlMovePattern::kPageUp( TextControlMovePattern TextControlMovePattern::kPageDown( u"PageDown", helper::ShortcutKeyBind(platform::gui::KeyCode::PageDown), [](TextHostControlService* service, StringView text, - gsl::index current_position) { + Index current_position) { CRU_UNUSED(service) CRU_UNUSED(text) // TODO: Implement this. @@ -147,9 +147,9 @@ std::vector<TextControlMovePattern> TextControlMovePattern::kDefaultPatterns = { TextControlMovePattern::kCtrlHome, TextControlMovePattern::kCtrlEnd, TextControlMovePattern::kPageUp, TextControlMovePattern::kPageDown}; -TextHostControlService::TextHostControlService(gsl::not_null<Control*> control) +TextHostControlService::TextHostControlService(Control* control) : control_(control), - text_host_control_(dynamic_cast<ITextHostControl*>(control.get())) { + text_host_control_(dynamic_cast<ITextHostControl*>(control)) { context_menu_ = MakeDeleteLaterPtr<components::PopupMenu>(); SetUpShortcuts(); @@ -224,7 +224,7 @@ void TextHostControlService::SetText(String text, bool stop_composition) { text_change_event_.Raise(nullptr); } -void TextHostControlService::InsertText(gsl::index position, StringView text, +void TextHostControlService::InsertText(Index position, StringView text, bool stop_composition) { if (!Utf16IsValidInsertPosition(this->text_, position)) { CRU_LOG_ERROR(u"Invalid text insert position."); @@ -238,21 +238,20 @@ void TextHostControlService::InsertText(gsl::index position, StringView text, text_change_event_.Raise(nullptr); } -void TextHostControlService::DeleteChar(gsl::index position, - bool stop_composition) { +void TextHostControlService::DeleteChar(Index position, bool stop_composition) { if (!Utf16IsValidInsertPosition(this->text_, position)) { CRU_LOG_ERROR(u"Invalid text delete position."); return; } - if (position == static_cast<gsl::index>(this->text_.size())) return; + if (position == static_cast<Index>(this->text_.size())) return; Index next; Utf16NextCodePoint(this->text_, position, &next); this->DeleteText(TextRange::FromTwoSides(position, next), stop_composition); } // Return the position of deleted character. -gsl::index TextHostControlService::DeleteCharPrevious(gsl::index position, - bool stop_composition) { +Index TextHostControlService::DeleteCharPrevious(Index position, + bool stop_composition) { if (!Utf16IsValidInsertPosition(this->text_, position)) { CRU_LOG_ERROR(u"Invalid text delete position."); return 0; @@ -345,8 +344,7 @@ void TextHostControlService::ScrollToCaret() { } } -gsl::not_null<render::TextRenderObject*> -TextHostControlService::GetTextRenderObject() { +render::TextRenderObject* TextHostControlService::GetTextRenderObject() { return this->text_host_control_->GetTextRenderObject(); } @@ -359,7 +357,7 @@ StringView TextHostControlService::GetSelectedText() { return GetTextView().substr(selection.position, selection.count); } -void TextHostControlService::SetSelection(gsl::index caret_position) { +void TextHostControlService::SetSelection(Index caret_position) { this->SetSelection(TextRange{caret_position, 0}); } diff --git a/src/ui/render/ScrollBar.cpp b/src/ui/render/ScrollBar.cpp index bcef74a2..3e578d37 100644 --- a/src/ui/render/ScrollBar.cpp +++ b/src/ui/render/ScrollBar.cpp @@ -84,8 +84,7 @@ std::unique_ptr<platform::graphics::IGeometry> CreateScrollBarArrowGeometry() { } } // namespace -ScrollBar::ScrollBar(gsl::not_null<ScrollRenderObject*> render_object, - Direction direction) +ScrollBar::ScrollBar(ScrollRenderObject* render_object, Direction direction) : render_object_(render_object), direction_(direction) { arrow_geometry_ = CreateScrollBarArrowGeometry(); } @@ -260,12 +259,11 @@ void ScrollBar::InstallHandlers(controls::Control* control) { } } -gsl::not_null<std::shared_ptr<platform::graphics::IBrush>> +std::shared_ptr<platform::graphics::IBrush> ScrollBar::GetCollapsedThumbBrush() { - return collapsed_thumb_brush_ - ? gsl::not_null(collapsed_thumb_brush_) - : gsl::not_null(ThemeManager::GetInstance()->GetResourceBrush( - u"scrollbar.collapse-thumb.color")); + return collapsed_thumb_brush_ ? collapsed_thumb_brush_ + : ThemeManager::GetInstance()->GetResourceBrush( + u"scrollbar.collapse-thumb.color"); } void ScrollBar::SetCollapsedThumbBrush( @@ -275,12 +273,12 @@ void ScrollBar::SetCollapsedThumbBrush( render_object_->InvalidatePaint(); } -gsl::not_null<std::shared_ptr<platform::graphics::IBrush>> ScrollBar::GetBrush( +std::shared_ptr<platform::graphics::IBrush> ScrollBar::GetBrush( ScrollBarBrushUsageKind usage, ScrollBarBrushStateKind state) { auto b = brushes_[usage][state]; - return b ? gsl::not_null(b) - : gsl::not_null(ThemeManager::GetInstance()->GetResourceBrush( - GenerateScrollBarThemeColorKey(usage, state))); + return b ? b + : ThemeManager::GetInstance()->GetResourceBrush( + GenerateScrollBarThemeColorKey(usage, state)); } // Brush could be nullptr to use the theme brush. @@ -300,7 +298,7 @@ void ScrollBar::OnDraw(platform::graphics::IPainter* painter, auto thumb_state = GetState(ScrollBarAreaKind::Thumb); painter->FillRectangle( *thumb_rect, - GetBrush(ScrollBarBrushUsageKind::Thumb, thumb_state).get().get()); + GetBrush(ScrollBarBrushUsageKind::Thumb, thumb_state).get()); } auto up_slot_rect = GetExpandedAreaRect(ScrollBarAreaKind::UpSlot); @@ -308,23 +306,23 @@ void ScrollBar::OnDraw(platform::graphics::IPainter* painter, if (up_slot_rect) painter->FillRectangle( *up_slot_rect, - GetBrush(ScrollBarBrushUsageKind::Slot, up_slot_state).get().get()); + GetBrush(ScrollBarBrushUsageKind::Slot, up_slot_state).get()); auto down_slot_rect = GetExpandedAreaRect(ScrollBarAreaKind::DownSlot); auto down_slot_state = GetState(ScrollBarAreaKind::DownSlot); if (down_slot_rect) painter->FillRectangle( *down_slot_rect, - GetBrush(ScrollBarBrushUsageKind::Slot, down_slot_state).get().get()); + GetBrush(ScrollBarBrushUsageKind::Slot, down_slot_state).get()); auto up_arrow_rect = GetExpandedAreaRect(ScrollBarAreaKind::UpArrow); auto up_arrow_state = GetState(ScrollBarAreaKind::UpArrow); if (up_arrow_rect) this->DrawUpArrow( painter, *up_arrow_rect, - GetBrush(ScrollBarBrushUsageKind::Arrow, up_arrow_state).get().get(), + GetBrush(ScrollBarBrushUsageKind::Arrow, up_arrow_state).get(), GetBrush(ScrollBarBrushUsageKind::ArrowBackground, up_arrow_state) - .get() + .get()); auto down_arrow_rect = GetExpandedAreaRect(ScrollBarAreaKind::DownArrow); @@ -332,17 +330,13 @@ void ScrollBar::OnDraw(platform::graphics::IPainter* painter, if (down_arrow_rect) this->DrawDownArrow( painter, *down_arrow_rect, - GetBrush(ScrollBarBrushUsageKind::Arrow, down_arrow_state) - .get() - .get(), + GetBrush(ScrollBarBrushUsageKind::Arrow, down_arrow_state).get(), GetBrush(ScrollBarBrushUsageKind::ArrowBackground, down_arrow_state) - .get() .get()); } else { auto optional_rect = GetCollapsedThumbRect(); if (optional_rect) { - painter->FillRectangle(*optional_rect, - GetCollapsedThumbBrush().get().get()); + painter->FillRectangle(*optional_rect, GetCollapsedThumbBrush().get()); } } } @@ -416,33 +410,32 @@ ScrollBarBrushStateKind ScrollBar::GetState(ScrollBarAreaKind area) { } } -HorizontalScrollBar::HorizontalScrollBar( - gsl::not_null<ScrollRenderObject*> render_object) +HorizontalScrollBar::HorizontalScrollBar(ScrollRenderObject* render_object) : ScrollBar(render_object, Direction::Horizontal) {} void HorizontalScrollBar::DrawUpArrow( platform::graphics::IPainter* painter, const Rect& area, - gsl::not_null<platform::graphics::IBrush*> arrow_brush, - gsl::not_null<platform::graphics::IBrush*> background_brush) { - painter->FillRectangle(area, background_brush.get()); + platform::graphics::IBrush* arrow_brush, + platform::graphics::IBrush* background_brush) { + painter->FillRectangle(area, background_brush); platform::graphics::util::WithTransform( painter, Matrix::Translation(area.GetCenter()), [this, arrow_brush](platform::graphics::IPainter* painter) { - painter->FillGeometry(arrow_geometry_.get(), arrow_brush.get()); + painter->FillGeometry(arrow_geometry_.get(), arrow_brush); }); } void HorizontalScrollBar::DrawDownArrow( platform::graphics::IPainter* painter, const Rect& area, - gsl::not_null<platform::graphics::IBrush*> arrow_brush, - gsl::not_null<platform::graphics::IBrush*> background_brush) { - painter->FillRectangle(area, background_brush.get()); + platform::graphics::IBrush* arrow_brush, + platform::graphics::IBrush* background_brush) { + painter->FillRectangle(area, background_brush); platform::graphics::util::WithTransform( painter, Matrix::Rotation(180) * Matrix::Translation(area.GetCenter()), [this, arrow_brush](platform::graphics::IPainter* painter) { - painter->FillGeometry(arrow_geometry_.get(), arrow_brush.get()); + painter->FillGeometry(arrow_geometry_.get(), arrow_brush); }); } @@ -565,33 +558,32 @@ bool HorizontalScrollBar::CanScrollDown() { return render_object_->HorizontalCanScrollDown(); } -VerticalScrollBar::VerticalScrollBar( - gsl::not_null<ScrollRenderObject*> render_object) +VerticalScrollBar::VerticalScrollBar(ScrollRenderObject* render_object) : ScrollBar(render_object, Direction::Vertical) {} void VerticalScrollBar::DrawUpArrow( platform::graphics::IPainter* painter, const Rect& area, - gsl::not_null<platform::graphics::IBrush*> arrow_brush, - gsl::not_null<platform::graphics::IBrush*> background_brush) { - painter->FillRectangle(area, background_brush.get()); + platform::graphics::IBrush* arrow_brush, + platform::graphics::IBrush* background_brush) { + painter->FillRectangle(area, background_brush); platform::graphics::util::WithTransform( painter, Matrix::Rotation(90) * Matrix::Translation(area.GetCenter()), [this, arrow_brush](platform::graphics::IPainter* painter) { - painter->FillGeometry(arrow_geometry_.get(), arrow_brush.get()); + painter->FillGeometry(arrow_geometry_.get(), arrow_brush); }); } void VerticalScrollBar::DrawDownArrow( platform::graphics::IPainter* painter, const Rect& area, - gsl::not_null<platform::graphics::IBrush*> arrow_brush, - gsl::not_null<platform::graphics::IBrush*> background_brush) { - painter->FillRectangle(area, background_brush.get()); + platform::graphics::IBrush* arrow_brush, + platform::graphics::IBrush* background_brush) { + painter->FillRectangle(area, background_brush); platform::graphics::util::WithTransform( painter, Matrix::Rotation(270) * Matrix::Translation(area.GetCenter()), [this, arrow_brush](platform::graphics::IPainter* painter) { - painter->FillGeometry(arrow_geometry_.get(), arrow_brush.get()); + painter->FillGeometry(arrow_geometry_.get(), arrow_brush); }); } @@ -712,8 +704,7 @@ bool VerticalScrollBar::CanScrollDown() { return render_object_->VerticalCanScrollDown(); } -ScrollBarDelegate::ScrollBarDelegate( - gsl::not_null<ScrollRenderObject*> render_object) +ScrollBarDelegate::ScrollBarDelegate(ScrollRenderObject* render_object) : render_object_(render_object), horizontal_bar_(render_object), vertical_bar_(render_object) { diff --git a/src/ui/render/TextRenderObject.cpp b/src/ui/render/TextRenderObject.cpp index 11548106..135c2d02 100644 --- a/src/ui/render/TextRenderObject.cpp +++ b/src/ui/render/TextRenderObject.cpp @@ -77,7 +77,7 @@ std::vector<Rect> TextRenderObject::TextRangeRect(const TextRange& text_range) { return text_layout_->TextRangeRect(text_range); } -Rect TextRenderObject::TextSinglePoint(gsl::index position, bool trailing) { +Rect TextRenderObject::TextSinglePoint(Index position, bool trailing) { return text_layout_->TextSinglePoint(position, trailing); } @@ -107,7 +107,7 @@ void TextRenderObject::SetDrawCaret(bool draw_caret) { } } -void TextRenderObject::SetCaretPosition(gsl::index position) { +void TextRenderObject::SetCaretPosition(Index position) { if (position != caret_position_) { caret_position_ = position; if (draw_caret_) { @@ -136,7 +136,7 @@ void TextRenderObject::SetCaretWidth(const float width) { Rect TextRenderObject::GetCaretRectInContent() { auto caret_pos = this->caret_position_; - gsl::index text_size = this->GetText().size(); + Index text_size = this->GetText().size(); if (caret_pos < 0) { caret_pos = 0; } else if (caret_pos > text_size) { diff --git a/src/ui/style/StyleRuleSet.cpp b/src/ui/style/StyleRuleSet.cpp index 4deaaefa..7b6454ec 100644 --- a/src/ui/style/StyleRuleSet.cpp +++ b/src/ui/style/StyleRuleSet.cpp @@ -37,7 +37,7 @@ void StyleRuleSet::SetParent(std::shared_ptr<StyleRuleSet> parent) { RaiseChangeEvent(); } -void StyleRuleSet::AddStyleRule(StyleRule rule, gsl::index index) { +void StyleRuleSet::AddStyleRule(StyleRule rule, Index index) { Expects(index >= 0 && index <= GetSize()); rules_.insert(rules_.cbegin() + index, std::move(rule)); @@ -45,7 +45,7 @@ void StyleRuleSet::AddStyleRule(StyleRule rule, gsl::index index) { RaiseChangeEvent(model::ListChange::ItemAdd(index)); } -void StyleRuleSet::RemoveStyleRule(gsl::index index, gsl::index count) { +void StyleRuleSet::RemoveStyleRule(Index index, Index count) { Expects(index >= 0); Expects(count >= 0 && index + count <= GetSize()); diff --git a/test/common/StringUtilTest.cpp b/test/common/StringUtilTest.cpp index 2dd980f9..613243c5 100644 --- a/test/common/StringUtilTest.cpp +++ b/test/common/StringUtilTest.cpp @@ -3,12 +3,13 @@ #include <catch2/catch_test_macros.hpp> +using cru::Index; using cru::k_invalid_code_point; TEST_CASE("StringUtil Utf8NextCodePoint", "[string]") { using cru::Utf8NextCodePoint; std::string_view text = "aπ你🤣!"; - gsl::index current = 0; + Index current = 0; REQUIRE(Utf8NextCodePoint(text.data(), text.size(), current, ¤t) == 0x0061); REQUIRE(Utf8NextCodePoint(text.data(), text.size(), current, ¤t) == @@ -21,13 +22,13 @@ TEST_CASE("StringUtil Utf8NextCodePoint", "[string]") { 0x0021); REQUIRE(Utf8NextCodePoint(text.data(), text.size(), current, ¤t) == k_invalid_code_point); - REQUIRE(current == static_cast<gsl::index>(text.size())); + REQUIRE(current == static_cast<Index>(text.size())); } TEST_CASE("StringUtil Utf16NextCodePoint", "[string]") { using cru::Utf16NextCodePoint; std::u16string_view text = u"aπ你🤣!"; - gsl::index current = 0; + Index current = 0; REQUIRE(Utf16NextCodePoint(text.data(), text.size(), current, ¤t) == 0x0061); REQUIRE(Utf16NextCodePoint(text.data(), text.size(), current, ¤t) == @@ -40,13 +41,13 @@ TEST_CASE("StringUtil Utf16NextCodePoint", "[string]") { 0x0021); REQUIRE(Utf16NextCodePoint(text.data(), text.size(), current, ¤t) == k_invalid_code_point); - REQUIRE(current == static_cast<gsl::index>(text.size())); + REQUIRE(current == static_cast<Index>(text.size())); } TEST_CASE("StringUtil Utf16PreviousCodePoint", "[string]") { using cru::Utf16PreviousCodePoint; std::u16string_view text = u"aπ你🤣!"; - gsl::index current = text.size(); + Index current = text.size(); REQUIRE(Utf16PreviousCodePoint(text.data(), text.size(), current, ¤t) == 0x0021); REQUIRE(Utf16PreviousCodePoint(text.data(), text.size(), current, ¤t) == |