aboutsummaryrefslogtreecommitdiff
path: root/include/cru
diff options
context:
space:
mode:
Diffstat (limited to 'include/cru')
-rw-r--r--include/cru/common/Base.h22
-rw-r--r--include/cru/common/Event.h3
-rw-r--r--include/cru/platform/graphics/Base.h2
-rw-r--r--include/cru/platform/graphics/direct2d/WindowRenderTarget.h3
-rw-r--r--include/cru/platform/gui/win/InputMethod.h2
-rw-r--r--include/cru/ui/components/Menu.h8
-rw-r--r--include/cru/ui/controls/TextBlock.h2
-rw-r--r--include/cru/ui/controls/TextBox.h2
-rw-r--r--include/cru/ui/controls/TextHostControlService.h31
-rw-r--r--include/cru/ui/render/ScrollBar.h64
-rw-r--r--include/cru/ui/render/TextRenderObject.h8
-rw-r--r--include/cru/ui/style/StyleRuleSet.h8
12 files changed, 79 insertions, 76 deletions
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.