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 /src/ui | |
parent | bfe23251a54b036abef9241ba0994c9e51db25b2 (diff) | |
download | cru-f3af6c7e5b46f4209a4981e5d7be217368f40b15.tar.gz cru-f3af6c7e5b46f4209a4981e5d7be217368f40b15.tar.bz2 cru-f3af6c7e5b46f4209a4981e5d7be217368f40b15.zip |
Get rid of GSL.
Diffstat (limited to 'src/ui')
-rw-r--r-- | src/ui/components/Menu.cpp | 6 | ||||
-rw-r--r-- | src/ui/controls/TextBlock.cpp | 2 | ||||
-rw-r--r-- | src/ui/controls/TextBox.cpp | 2 | ||||
-rw-r--r-- | src/ui/controls/TextHostControlService.cpp | 44 | ||||
-rw-r--r-- | src/ui/render/ScrollBar.cpp | 79 | ||||
-rw-r--r-- | src/ui/render/TextRenderObject.cpp | 6 | ||||
-rw-r--r-- | src/ui/style/StyleRuleSet.cpp | 4 |
7 files changed, 66 insertions, 77 deletions
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()); |