Skip to content

Commit

Permalink
Implement UICodeEditor::isScrollable so it can have a parent scrollab…
Browse files Browse the repository at this point in the history
…le element.
  • Loading branch information
SpartanJ committed Mar 2, 2025
1 parent 2f2f934 commit 762b740
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 9 deletions.
6 changes: 4 additions & 2 deletions include/eepp/ui/uicodeeditor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion include/eepp/ui/uimenu.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion src/eepp/ui/doc/documentview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 11 additions & 4 deletions src/eepp/ui/uicodeeditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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" );
Expand All @@ -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 ) {
Expand Down Expand Up @@ -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<Float>( val, 0.f, getMaxScroll().x ) );
if ( oldVal != mScroll.x ) {
Expand All @@ -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<Float>( val, 0, getMaxScroll().y ) );
if ( oldVal != mScroll.y ) {
Expand All @@ -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,
Expand Down Expand Up @@ -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
2 changes: 1 addition & 1 deletion src/eepp/ui/uimenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down

0 comments on commit 762b740

Please sign in to comment.