From 762b740102f9328ee7e751e3647754ec747b589d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADn=20Lucas=20Golini?= Date: Sun, 2 Mar 2025 13:24:10 -0300 Subject: [PATCH] Implement UICodeEditor::isScrollable so it can have a parent scrollable element. --- include/eepp/ui/uicodeeditor.hpp | 6 ++++-- include/eepp/ui/uimenu.hpp | 2 +- src/eepp/ui/doc/documentview.cpp | 2 +- src/eepp/ui/uicodeeditor.cpp | 15 +++++++++++---- src/eepp/ui/uimenu.cpp | 2 +- 5 files changed, 18 insertions(+), 9 deletions(-) diff --git a/include/eepp/ui/uicodeeditor.hpp b/include/eepp/ui/uicodeeditor.hpp index 327283473..69ac4c068 100644 --- a/include/eepp/ui/uicodeeditor.hpp +++ b/include/eepp/ui/uicodeeditor.hpp @@ -683,9 +683,11 @@ class EE_API UICodeEditor : public UIWidget, public TextDocument::Client { Sizef getMaxScroll() const; - void setScrollX( const Float& val, bool emmitEvent = true ); + virtual bool isScrollable() const; - void setScrollY( const Float& val, bool emmitEvent = true ); + bool setScrollX( const Float& val, bool emmitEvent = true ); + + bool setScrollY( const Float& val, bool emmitEvent = true ); Vector2f getScreenStart() const; diff --git a/include/eepp/ui/uimenu.hpp b/include/eepp/ui/uimenu.hpp index d418ea331..121c6382e 100644 --- a/include/eepp/ui/uimenu.hpp +++ b/include/eepp/ui/uimenu.hpp @@ -15,7 +15,7 @@ class EE_API UIMenu : public UIWidget { public: static UIMenu* New(); - static void findBestMenuPos( Vector2f& position, UIMenu* menu, UIMenu* parent = NULL, + static void findBestMenuPos( Vector2f& position, UIWidget* menu, UIMenu* parent = NULL, UIMenuSubMenu* subMenu = NULL ); UIMenu(); diff --git a/src/eepp/ui/doc/documentview.cpp b/src/eepp/ui/doc/documentview.cpp index 460fd4627..aa99bf02a 100644 --- a/src/eepp/ui/doc/documentview.cpp +++ b/src/eepp/ui/doc/documentview.cpp @@ -470,7 +470,7 @@ Float DocumentView::getWhiteSpaceWidth() const { } void DocumentView::updateCache( Int64 fromLine, Int64 toLine, Int64 numLines ) { - if ( isOneToOne() ) + if ( 0 == mMaxWidth || isOneToOne() ) return; // Unfold ANY modification over a folded range diff --git a/src/eepp/ui/uicodeeditor.cpp b/src/eepp/ui/uicodeeditor.cpp index c6b63d973..134ce4096 100644 --- a/src/eepp/ui/uicodeeditor.cpp +++ b/src/eepp/ui/uicodeeditor.cpp @@ -1720,7 +1720,6 @@ Uint32 UICodeEditor::onMouseUp( const Vector2i& position, const Uint32& flags ) } else { setScrollY( mScroll.y + mMouseWheelScroll ); } - invalidateDraw(); } else if ( flags & EE_BUTTON_WUMASK ) { if ( getUISceneNode()->getWindow()->getInput()->isKeyModPressed() ) { mDoc->execute( "font-size-grow" ); @@ -1729,7 +1728,6 @@ Uint32 UICodeEditor::onMouseUp( const Vector2i& position, const Uint32& flags ) } else { setScrollY( mScroll.y - mMouseWheelScroll ); } - invalidateDraw(); } else if ( flags & EE_BUTTON_WRMASK ) { setScrollX( mScroll.x + mMouseWheelScroll ); } else if ( flags & EE_BUTTON_WLMASK ) { @@ -2370,7 +2368,7 @@ void UICodeEditor::showMinimap( bool showMinimap ) { } } -void UICodeEditor::setScrollX( const Float& val, bool emmitEvent ) { +bool UICodeEditor::setScrollX( const Float& val, bool emmitEvent ) { Float oldVal = mScroll.x; mScroll.x = eefloor( eeclamp( val, 0.f, getMaxScroll().x ) ); if ( oldVal != mScroll.x ) { @@ -2380,10 +2378,12 @@ void UICodeEditor::setScrollX( const Float& val, bool emmitEvent ) { sendCommonEvent( Event::OnScrollChange ); if ( mHorizontalScrollBarEnabled && emmitEvent ) mHScrollBar->setValue( mScroll.x / getMaxScroll().x, false ); + return true; } + return false; } -void UICodeEditor::setScrollY( const Float& val, bool emmitEvent ) { +bool UICodeEditor::setScrollY( const Float& val, bool emmitEvent ) { Float oldVal = mScroll.y; mScroll.y = eefloor( eeclamp( val, 0, getMaxScroll().y ) ); if ( oldVal != mScroll.y ) { @@ -2393,7 +2393,9 @@ void UICodeEditor::setScrollY( const Float& val, bool emmitEvent ) { sendCommonEvent( Event::OnScrollChange ); if ( mVerticalScrollBarEnabled && emmitEvent ) mVScrollBar->setValue( mScroll.y / getMaxScroll().y, false ); + return true; } + return false; } Vector2d UICodeEditor::getTextPositionOffset( const TextPosition& position, @@ -5274,4 +5276,9 @@ Float UICodeEditor::editorHeight() const { return eemax( 0.f, mSize.getHeight() - mPaddingPx.Top - mPaddingPx.Bottom ); } +bool UICodeEditor::isScrollable() const { + return UIWidget::isScrollable() && + ( (Int64)getTotalVisibleLines() - (Int64)getViewPortLineCount().y > 0 ); +} + }} // namespace EE::UI diff --git a/src/eepp/ui/uimenu.cpp b/src/eepp/ui/uimenu.cpp index 8d5d8990b..d24b3a67e 100644 --- a/src/eepp/ui/uimenu.cpp +++ b/src/eepp/ui/uimenu.cpp @@ -693,7 +693,7 @@ bool UIMenu::isChildOrSubMenu( Node* node ) { ( mCurrentSubMenu && mCurrentSubMenu->isChildOrSubMenu( node ) ); } -void UIMenu::findBestMenuPos( Vector2f& pos, UIMenu* menu, UIMenu* parent, +void UIMenu::findBestMenuPos( Vector2f& pos, UIWidget* menu, UIMenu* parent, UIMenuSubMenu* subMenu ) { SceneNode* sceneNode = menu->getSceneNode();