From b91028faa5e4be43c8d025eaad8dba820ee88278 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADn=20Lucas=20Golini?= Date: Wed, 27 Jul 2022 01:31:16 -0300 Subject: [PATCH] Moved min/max size equation to to UINode and fixed setPixelsSize when using max/min size. Fixed mouse scroll in TerminalEmulator. Some minor fixes. --- include/eepp/ui/uinode.hpp | 32 +++ include/eepp/ui/uiscenenode.hpp | 5 + include/eepp/ui/uitheme.hpp | 7 + include/eepp/ui/uiwidget.hpp | 36 ---- src/eepp/ui/uinode.cpp | 202 +++++++++++++++++- src/eepp/ui/uiprogressbar.cpp | 13 +- src/eepp/ui/uipushbutton.cpp | 2 +- src/eepp/ui/uiscenenode.cpp | 10 +- src/eepp/ui/uitheme.cpp | 23 ++ src/eepp/ui/uiwidget.cpp | 174 --------------- .../src/eterm/terminal/terminalemulator.cpp | 32 ++- src/tools/uieditor/uieditor.cpp | 32 ++- 12 files changed, 332 insertions(+), 236 deletions(-) diff --git a/include/eepp/ui/uinode.hpp b/include/eepp/ui/uinode.hpp index 131abc01a..d0f9e6f65 100644 --- a/include/eepp/ui/uinode.hpp +++ b/include/eepp/ui/uinode.hpp @@ -276,6 +276,34 @@ class EE_API UINode : public Node { virtual const Rectf& getPixelsPadding() const; + const std::string& getMinWidthEq() const; + + void setMinSizeEq( const std::string& minWidthEq, const std::string& minHeightEq ); + + void setMinWidthEq( const std::string& minWidthEq ); + + const std::string& getMinHeightEq() const; + + void setMinHeightEq( const std::string& minHeightEq ); + + const std::string& getMaxWidthEq() const; + + void setMaxSizeEq( const std::string& maxWidthEq, const std::string& maxHeightEq ); + + void setMaxWidthEq( const std::string& maxWidthEq ); + + const std::string& getMaxHeightEq() const; + + void setMaxHeightEq( const std::string& maxHeightEq ); + + Sizef getMinSize(); + + Sizef getMaxSize(); + + Sizef fitMinMaxSizeDp( const Sizef& size ) const; + + Sizef fitMinMaxSizePx( const Sizef& size ) const; + protected: Vector2f mDpPos; Sizef mDpSize; @@ -293,6 +321,10 @@ class EE_API UINode : public Node { Rectf mPadding; Rectf mPaddingPx; UIClip mClip; + std::string mMinWidthEq; + std::string mMinHeightEq; + std::string mMaxWidthEq; + std::string mMaxHeightEq; virtual Uint32 onMouseDown( const Vector2i& position, const Uint32& flags ); diff --git a/include/eepp/ui/uiscenenode.hpp b/include/eepp/ui/uiscenenode.hpp index 9baa81c66..4cc219a95 100644 --- a/include/eepp/ui/uiscenenode.hpp +++ b/include/eepp/ui/uiscenenode.hpp @@ -143,6 +143,10 @@ class EE_API UISceneNode : public SceneNode { void setColorSchemePreference( const ColorSchemePreference& colorSchemePreference ); + const Uint32& getMaxInvalidationDepth() const; + + void setMaxInvalidationDepth( const Uint32& maxInvalidationDepth ); + protected: friend class EE::UI::UIWindow; friend class EE::UI::UIWidget; @@ -166,6 +170,7 @@ class EE_API UISceneNode : public SceneNode { std::unordered_set mDirtyLayouts; std::vector> mTimes; ColorSchemePreference mColorSchemePreference{ ColorSchemePreference::Dark }; + Uint32 mMaxInvalidationDepth{ 2 }; virtual void resizeNode( EE::Window::Window* win ); diff --git a/include/eepp/ui/uitheme.hpp b/include/eepp/ui/uitheme.hpp index 17e825db4..d2b36456f 100644 --- a/include/eepp/ui/uitheme.hpp +++ b/include/eepp/ui/uitheme.hpp @@ -78,6 +78,12 @@ class EE_API UITheme : protected ResourceManagerMulti { UIIconTheme* getIconTheme() const; + const std::string& getStyleSheetPath() const; + + void setStyleSheetPath( const std::string& styleSheetPath ); + + bool reloadStyleSheet(); + protected: std::string mName; String::HashType mNameHash; @@ -86,6 +92,7 @@ class EE_API UITheme : protected ResourceManagerMulti { Font* mDefaultFont; Float mDefaultFontSize; CSS::StyleSheet mStyleSheet; + std::string mStyleSheetPath; UIIconTheme* mIconTheme; void setTextureAtlas( Graphics::TextureAtlas* SG ); diff --git a/include/eepp/ui/uiwidget.hpp b/include/eepp/ui/uiwidget.hpp index 542c1af67..1f0de25fb 100644 --- a/include/eepp/ui/uiwidget.hpp +++ b/include/eepp/ui/uiwidget.hpp @@ -35,8 +35,6 @@ class EE_API UIWidget : public UINode { virtual bool isType( const Uint32& type ) const; - virtual Node* setSize( const Sizef& size ); - virtual UINode* setFlags( const Uint32& flags ); virtual UINode* unsetFlags( const Uint32& flags ); @@ -49,12 +47,8 @@ class EE_API UIWidget : public UINode { virtual UINode* setThemeSkin( UITheme* Theme, const std::string& skinName ); - virtual Node* setSize( const Float& Width, const Float& Height ); - virtual Node* setId( const std::string& id ); - virtual const Sizef& getSize() const; - virtual bool acceptsDropOfWidget( const UIWidget* widget ); UIWidget* acceptsDropOfWidgetInTree( const UIWidget* widget ); @@ -214,35 +208,11 @@ class EE_API UIWidget : public UINode { bool isSceneNodeLoading() const; - const std::string& getMinWidthEq() const; - - void setMinSizeEq( const std::string& minWidthEq, const std::string& minHeightEq ); - - void setMinWidthEq( const std::string& minWidthEq ); - - const std::string& getMinHeightEq() const; - - void setMinHeightEq( const std::string& minHeightEq ); - - const std::string& getMaxWidthEq() const; - - void setMaxSizeEq( const std::string& maxWidthEq, const std::string& maxHeightEq ); - - void setMaxWidthEq( const std::string& maxWidthEq ); - - const std::string& getMaxHeightEq() const; - - void setMaxHeightEq( const std::string& maxHeightEq ); - void reportStyleStateChangeRecursive( bool disableAnimations = false, bool forceReApplyStyles = false ); void createTooltip(); - Sizef getMinSize(); - - Sizef getMaxSize(); - bool isTabStop() const; UIWidget* getNextTabWidget() const; @@ -253,8 +223,6 @@ class EE_API UIWidget : public UINode { void setTooltipEnabled( bool enabled ); - Sizef fitMinMaxSize( const Sizef& size ) const; - protected: friend class UIManager; friend class UISceneNode; @@ -279,10 +247,6 @@ class EE_API UIWidget : public UINode { std::string mSkinName; std::vector mClasses; std::vector mPseudoClasses; - std::string mMinWidthEq; - std::string mMinHeightEq; - std::string mMaxWidthEq; - std::string mMaxHeightEq; explicit UIWidget( const std::string& tag ); diff --git a/src/eepp/ui/uinode.cpp b/src/eepp/ui/uinode.cpp index db1296b24..8557baa7a 100644 --- a/src/eepp/ui/uinode.cpp +++ b/src/eepp/ui/uinode.cpp @@ -174,8 +174,8 @@ void UINode::setInternalPixelsSize( const Sizef& size ) { } } -Node* UINode::setSize( const Sizef& Size ) { - Sizef s( Size ); +Node* UINode::setSize( const Sizef& size ) { + Sizef s( fitMinMaxSizeDp( size ) ); if ( s.x < mMinSize.x ) s.x = mMinSize.x; @@ -203,7 +203,7 @@ Node* UINode::setSize( const Float& Width, const Float& Height ) { } UINode* UINode::setPixelsSize( const Sizef& size ) { - Sizef s( size ); + Sizef s( fitMinMaxSizePx( size ) ); Sizef pMinSize( PixelDensity::dpToPx( mMinSize ) ); if ( s.x < pMinSize.x ) @@ -264,6 +264,202 @@ const Sizef& UINode::getMinSize() const { return mMinSize; } +const std::string& UINode::getMinWidthEq() const { + return mMinWidthEq; +} + +void UINode::setMinSizeEq( const std::string& minWidthEq, const std::string& minHeightEq ) { + if ( mMinWidthEq != minWidthEq || mMinHeightEq != minHeightEq ) { + mMinWidthEq = minWidthEq; + mMinHeightEq = minHeightEq; + + if ( !mMinWidthEq.empty() ) { + mMinSize.x = lengthFromValueAsDp( mMinWidthEq, + CSS::PropertyRelativeTarget::ContainingBlockWidth ); + } + + if ( !mMinHeightEq.empty() ) { + mMinSize.y = lengthFromValueAsDp( mMinHeightEq, + CSS::PropertyRelativeTarget::ContainingBlockHeight ); + } + + setSize( mDpSize ); + } +} + +void UINode::setMinWidthEq( const std::string& minWidthEq ) { + if ( mMinWidthEq != minWidthEq ) { + mMinWidthEq = minWidthEq; + + if ( !mMinWidthEq.empty() ) { + mMinSize.x = lengthFromValueAsDp( mMinWidthEq, + CSS::PropertyRelativeTarget::ContainingBlockWidth ); + } + + setSize( mDpSize ); + } +} + +const std::string& UINode::getMinHeightEq() const { + return mMinHeightEq; +} + +void UINode::setMinHeightEq( const std::string& minHeightEq ) { + if ( mMinHeightEq != minHeightEq ) { + mMinHeightEq = minHeightEq; + + if ( !mMinHeightEq.empty() ) { + mMinSize.y = lengthFromValueAsDp( mMinHeightEq, + CSS::PropertyRelativeTarget::ContainingBlockHeight ); + } + + setSize( mDpSize ); + } +} + +const std::string& UINode::getMaxWidthEq() const { + return mMaxWidthEq; +} + +void UINode::setMaxSizeEq( const std::string& maxWidthEq, const std::string& maxHeightEq ) { + if ( mMaxWidthEq != maxWidthEq || mMaxHeightEq != maxHeightEq ) { + mMaxWidthEq = maxWidthEq; + mMaxHeightEq = maxHeightEq; + setSize( mDpSize ); + } +} + +void UINode::setMaxWidthEq( const std::string& maxWidthEq ) { + if ( mMaxWidthEq != maxWidthEq ) { + mMaxWidthEq = maxWidthEq; + setSize( mDpSize ); + } +} + +const std::string& UINode::getMaxHeightEq() const { + return mMaxHeightEq; +} + +void UINode::setMaxHeightEq( const std::string& maxHeightEq ) { + if ( mMaxHeightEq != maxHeightEq ) { + mMaxHeightEq = maxHeightEq; + setSize( mDpSize ); + } +} + +Sizef UINode::getMaxSize() { + Sizef s; + + if ( !mMaxWidthEq.empty() ) { + Float length = + lengthFromValueAsDp( mMaxWidthEq, CSS::PropertyRelativeTarget::ContainingBlockWidth ); + s.x = eemax( s.x, length ); + } + + if ( !mMaxHeightEq.empty() ) { + Float length = + lengthFromValueAsDp( mMaxHeightEq, CSS::PropertyRelativeTarget::ContainingBlockHeight ); + s.y = eemax( s.y, length ); + } + + return s; +} + +Sizef UINode::getMinSize() { + Sizef s; + + if ( s.x < mMinSize.x ) + s.x = mMinSize.x; + + if ( s.y < mMinSize.y ) + s.y = mMinSize.y; + + if ( !mMinWidthEq.empty() ) { + Float length = + lengthFromValueAsDp( mMinWidthEq, CSS::PropertyRelativeTarget::ContainingBlockWidth ); + s.x = eemax( s.x, length ); + } + + if ( !mMinHeightEq.empty() ) { + Float length = + lengthFromValueAsDp( mMinHeightEq, CSS::PropertyRelativeTarget::ContainingBlockHeight ); + s.y = eemax( s.y, length ); + } + return s; +} + +Sizef UINode::fitMinMaxSizePx( const Sizef& size ) const { + Sizef s( size ); + + if ( mMinSize.x != 0.f && s.x < PixelDensity::pxToDp( mMinSize.x ) ) + s.x = PixelDensity::pxToDp( mMinSize.x ); + + if ( mMinSize.y != 0.f && s.y < PixelDensity::pxToDp( mMinSize.y ) ) + s.y = PixelDensity::pxToDp( mMinSize.y ); + + if ( !mMinWidthEq.empty() ) { + Float length = + lengthFromValue( mMinWidthEq, CSS::PropertyRelativeTarget::ContainingBlockWidth ); + s.x = eemax( s.x, length ); + } + + if ( !mMinHeightEq.empty() ) { + Float length = + lengthFromValue( mMinHeightEq, CSS::PropertyRelativeTarget::ContainingBlockHeight ); + s.y = eemax( s.y, length ); + } + + if ( !mMaxWidthEq.empty() ) { + Float length = + lengthFromValue( mMaxWidthEq, CSS::PropertyRelativeTarget::ContainingBlockWidth ); + s.x = eemin( s.x, length ); + } + + if ( !mMaxHeightEq.empty() ) { + Float length = + lengthFromValue( mMaxHeightEq, CSS::PropertyRelativeTarget::ContainingBlockHeight ); + s.y = eemin( s.y, length ); + } + + return s; +} + +Sizef UINode::fitMinMaxSizeDp( const Sizef& size ) const { + Sizef s( size ); + + if ( s.x < mMinSize.x ) + s.x = mMinSize.x; + + if ( s.y < mMinSize.y ) + s.y = mMinSize.y; + + if ( !mMinWidthEq.empty() ) { + Float length = + lengthFromValueAsDp( mMinWidthEq, CSS::PropertyRelativeTarget::ContainingBlockWidth ); + s.x = eemax( s.x, length ); + } + + if ( !mMinHeightEq.empty() ) { + Float length = + lengthFromValueAsDp( mMinHeightEq, CSS::PropertyRelativeTarget::ContainingBlockHeight ); + s.y = eemax( s.y, length ); + } + + if ( !mMaxWidthEq.empty() ) { + Float length = + lengthFromValueAsDp( mMaxWidthEq, CSS::PropertyRelativeTarget::ContainingBlockWidth ); + s.x = eemin( s.x, length ); + } + + if ( !mMaxHeightEq.empty() ) { + Float length = + lengthFromValueAsDp( mMaxHeightEq, CSS::PropertyRelativeTarget::ContainingBlockHeight ); + s.y = eemin( s.y, length ); + } + + return s; +} + void UINode::updateOriginPoint() { Node::updateOriginPoint(); diff --git a/src/eepp/ui/uiprogressbar.cpp b/src/eepp/ui/uiprogressbar.cpp index 15e62c3b0..24573d01c 100644 --- a/src/eepp/ui/uiprogressbar.cpp +++ b/src/eepp/ui/uiprogressbar.cpp @@ -24,15 +24,14 @@ class UIProgressBarFiller : public UIWidget { if ( NULL == mFillerSkin ) return; - Float Height = (Float)mSize.getHeight(); + Sizef fSize( mSize ); if ( !mProgressBar->getStyleConfig().VerticalExpand ) - Height = (Float)mFillerSkin->getSize().getHeight(); + fSize.y = (Float)mFillerSkin->getSize().getHeight(); - if ( Height > mSize.getHeight() ) - Height = mSize.getHeight(); + if ( fSize.y > mSize.getHeight() ) + fSize.y = mSize.getHeight(); - Sizef fSize( mSize ); Sizei rSize( PixelDensity::dpToPxI( mFillerSkin->getSize() ) ); Sizei numTiles( (Int32)eeceil( (Float)fSize.getWidth() / (Float)rSize.getWidth() + 2 ), (Int32)eeceil( (Float)fSize.getHeight() / (Float)rSize.getHeight() ) + 2 ); @@ -94,7 +93,7 @@ void UIProgressBar::scheduledUpdate( const Time& time ) { Vector2f offset( mOffset ); - mOffset += mStyleConfig.MovementSpeed * ( Float )( time.asSeconds() ); + mOffset += mStyleConfig.MovementSpeed * (Float)( time.asSeconds() ); Sizei rSize( PixelDensity::dpToPxI( mFiller->mFillerSkin->getSize() ) ); @@ -211,7 +210,7 @@ const bool& UIProgressBar::getDisplayPercent() const { void UIProgressBar::updateTextBox() { mTextBox->setVisible( mStyleConfig.DisplayPercent ); - mTextBox->setText( String::toString( ( Int32 )( ( mProgress / mTotalSteps ) * 100.f ) ) + "%" ); + mTextBox->setText( String::toString( (Int32)( ( mProgress / mTotalSteps ) * 100.f ) ) + "%" ); mTextBox->center(); } diff --git a/src/eepp/ui/uipushbutton.cpp b/src/eepp/ui/uipushbutton.cpp index d1537e8ec..98677e27b 100644 --- a/src/eepp/ui/uipushbutton.cpp +++ b/src/eepp/ui/uipushbutton.cpp @@ -108,7 +108,7 @@ void UIPushButton::onAutoSize() { return; } - Sizef fsize = fitMinMaxSize( size ); + Sizef fsize = fitMinMaxSizePx( size ); if ( size.getWidth() != fsize.getWidth() ) { UIWidget* eiw = getExtraInnerWidget(); diff --git a/src/eepp/ui/uiscenenode.cpp b/src/eepp/ui/uiscenenode.cpp index 0a2c6cee7..060ded5a8 100644 --- a/src/eepp/ui/uiscenenode.cpp +++ b/src/eepp/ui/uiscenenode.cpp @@ -485,7 +485,7 @@ void UISceneNode::update( const Time& elapsed ) { // of any of these 3 steps. Usually during the layout update, this could trigger resizes that // provokes the creation of dynamic elements. This is the case of the UIListBox for example // that creates childs dynamically only when they are visible. - int invalidationDepth = 2; + int invalidationDepth = mMaxInvalidationDepth; while ( ( !mDirtyStyle.empty() || !mDirtyStyleState.empty() || !mDirtyLayouts.empty() ) && invalidationDepth > 0 ) { updateDirtyStyles(); @@ -894,4 +894,12 @@ void UISceneNode::setColorSchemePreference( const ColorSchemePreference& colorSc } } +const Uint32& UISceneNode::getMaxInvalidationDepth() const { + return mMaxInvalidationDepth; +} + +void UISceneNode::setMaxInvalidationDepth( const Uint32& maxInvalidationDepth ) { + mMaxInvalidationDepth = maxInvalidationDepth; +} + }} // namespace EE::UI diff --git a/src/eepp/ui/uitheme.cpp b/src/eepp/ui/uitheme.cpp index 42d7fbdb5..5df06ffed 100644 --- a/src/eepp/ui/uitheme.cpp +++ b/src/eepp/ui/uitheme.cpp @@ -45,6 +45,7 @@ UITheme* UITheme::load( const std::string& name, const std::string& abbr, if ( styleSheetParser.loadFromFile( styleSheetPath ) ) { theme->setStyleSheet( styleSheetParser.getStyleSheet() ); + theme->setStyleSheetPath( styleSheetPath ); } if ( textureAtlasPath.empty() ) @@ -336,6 +337,28 @@ UIIconTheme* UITheme::getIconTheme() const { return mIconTheme; } +const std::string& UITheme::getStyleSheetPath() const { + return mStyleSheetPath; +} + +void UITheme::setStyleSheetPath( const std::string& styleSheetPath ) { + mStyleSheetPath = styleSheetPath; +} + +bool UITheme::reloadStyleSheet() { + if ( mStyleSheetPath.empty() ) + return false; + + CSS::StyleSheetParser styleSheetParser; + + if ( styleSheetParser.loadFromFile( mStyleSheetPath ) ) { + setStyleSheet( styleSheetParser.getStyleSheet() ); + return true; + } + + return false; +} + Font* UITheme::getDefaultFont() const { return mDefaultFont; } diff --git a/src/eepp/ui/uiwidget.cpp b/src/eepp/ui/uiwidget.cpp index c5dbaf522..291118cfe 100644 --- a/src/eepp/ui/uiwidget.cpp +++ b/src/eepp/ui/uiwidget.cpp @@ -384,89 +384,6 @@ void UIWidget::tooltipRemove() { mTooltip = NULL; } -Sizef UIWidget::fitMinMaxSize( const Sizef& size ) const { - Sizef s( size ); - - if ( s.x < mMinSize.x ) - s.x = mMinSize.x; - - if ( s.y < mMinSize.y ) - s.y = mMinSize.y; - - if ( !mMinWidthEq.empty() ) { - Float length = - lengthFromValueAsDp( mMinWidthEq, CSS::PropertyRelativeTarget::ContainingBlockWidth ); - s.x = eemax( s.x, length ); - } - - if ( !mMinHeightEq.empty() ) { - Float length = - lengthFromValueAsDp( mMinHeightEq, CSS::PropertyRelativeTarget::ContainingBlockHeight ); - s.y = eemax( s.y, length ); - } - - if ( !mMaxWidthEq.empty() ) { - Float length = - lengthFromValueAsDp( mMaxWidthEq, CSS::PropertyRelativeTarget::ContainingBlockWidth ); - s.x = eemin( s.x, length ); - } - - if ( !mMaxHeightEq.empty() ) { - Float length = - lengthFromValueAsDp( mMaxHeightEq, CSS::PropertyRelativeTarget::ContainingBlockHeight ); - s.y = eemin( s.y, length ); - } - - return s; -} - -Node* UIWidget::setSize( const Sizef& size ) { - Sizef s( size ); - s = fitMinMaxSize( s ); - return UINode::setSize( s ); -} - -Sizef UIWidget::getMinSize() { - Sizef s; - - if ( s.x < mMinSize.x ) - s.x = mMinSize.x; - - if ( s.y < mMinSize.y ) - s.y = mMinSize.y; - - if ( !mMinWidthEq.empty() ) { - Float length = - lengthFromValueAsDp( mMinWidthEq, CSS::PropertyRelativeTarget::ContainingBlockWidth ); - s.x = eemax( s.x, length ); - } - - if ( !mMinHeightEq.empty() ) { - Float length = - lengthFromValueAsDp( mMinHeightEq, CSS::PropertyRelativeTarget::ContainingBlockHeight ); - s.y = eemax( s.y, length ); - } - return s; -} - -Sizef UIWidget::getMaxSize() { - Sizef s; - - if ( !mMaxWidthEq.empty() ) { - Float length = - lengthFromValueAsDp( mMaxWidthEq, CSS::PropertyRelativeTarget::ContainingBlockWidth ); - s.x = eemax( s.x, length ); - } - - if ( !mMaxHeightEq.empty() ) { - Float length = - lengthFromValueAsDp( mMaxHeightEq, CSS::PropertyRelativeTarget::ContainingBlockHeight ); - s.y = eemax( s.y, length ); - } - - return s; -} - UINode* UIWidget::setFlags( const Uint32& flags ) { if ( flags & ( UI_ANCHOR_LEFT | UI_ANCHOR_TOP | UI_ANCHOR_RIGHT | UI_ANCHOR_BOTTOM ) ) { updateAnchorsDistances(); @@ -509,10 +426,6 @@ UINode* UIWidget::setThemeSkin( UITheme* Theme, const std::string& skinName ) { return UINode::setThemeSkin( Theme, skinName ); } -Node* UIWidget::setSize( const Float& Width, const Float& Height ) { - return UINode::setSize( Width, Height ); -} - Node* UIWidget::setId( const std::string& id ) { Node::setId( id ); @@ -524,10 +437,6 @@ Node* UIWidget::setId( const std::string& id ) { return this; } -const Sizef& UIWidget::getSize() const { - return UINode::getSize(); -} - bool UIWidget::acceptsDropOfWidget( const UIWidget* ) { return false; } @@ -690,89 +599,6 @@ bool UIWidget::isSceneNodeLoading() const { return NULL != mUISceneNode ? mUISceneNode->isLoading() : false; } -const std::string& UIWidget::getMinWidthEq() const { - return mMinWidthEq; -} - -void UIWidget::setMinSizeEq( const std::string& minWidthEq, const std::string& minHeightEq ) { - if ( mMinWidthEq != minWidthEq || mMinHeightEq != minHeightEq ) { - mMinWidthEq = minWidthEq; - mMinHeightEq = minHeightEq; - - if ( !mMinWidthEq.empty() ) { - mMinSize.x = lengthFromValueAsDp( mMinWidthEq, - CSS::PropertyRelativeTarget::ContainingBlockWidth ); - } - - if ( !mMinHeightEq.empty() ) { - mMinSize.y = lengthFromValueAsDp( mMinHeightEq, - CSS::PropertyRelativeTarget::ContainingBlockHeight ); - } - - setSize( mDpSize ); - } -} - -void UIWidget::setMinWidthEq( const std::string& minWidthEq ) { - if ( mMinWidthEq != minWidthEq ) { - mMinWidthEq = minWidthEq; - - if ( !mMinWidthEq.empty() ) { - mMinSize.x = lengthFromValueAsDp( mMinWidthEq, - CSS::PropertyRelativeTarget::ContainingBlockWidth ); - } - - setSize( mDpSize ); - } -} - -const std::string& UIWidget::getMinHeightEq() const { - return mMinHeightEq; -} - -void UIWidget::setMinHeightEq( const std::string& minHeightEq ) { - if ( mMinHeightEq != minHeightEq ) { - mMinHeightEq = minHeightEq; - - if ( !mMinHeightEq.empty() ) { - mMinSize.y = lengthFromValueAsDp( mMinHeightEq, - CSS::PropertyRelativeTarget::ContainingBlockHeight ); - } - - setSize( mDpSize ); - } -} - -const std::string& UIWidget::getMaxWidthEq() const { - return mMaxWidthEq; -} - -void UIWidget::setMaxSizeEq( const std::string& maxWidthEq, const std::string& maxHeightEq ) { - if ( mMaxWidthEq != maxWidthEq || mMaxHeightEq != maxHeightEq ) { - mMaxWidthEq = maxWidthEq; - mMaxHeightEq = maxHeightEq; - setSize( mDpSize ); - } -} - -void UIWidget::setMaxWidthEq( const std::string& maxWidthEq ) { - if ( mMaxWidthEq != maxWidthEq ) { - mMaxWidthEq = maxWidthEq; - setSize( mDpSize ); - } -} - -const std::string& UIWidget::getMaxHeightEq() const { - return mMaxHeightEq; -} - -void UIWidget::setMaxHeightEq( const std::string& maxHeightEq ) { - if ( mMaxHeightEq != maxHeightEq ) { - mMaxHeightEq = maxHeightEq; - setSize( mDpSize ); - } -} - const Rectf& UIWidget::getPadding() const { return mPadding; } diff --git a/src/modules/eterm/src/eterm/terminal/terminalemulator.cpp b/src/modules/eterm/src/eterm/terminal/terminalemulator.cpp index 0280adfe0..31b3c94f1 100644 --- a/src/modules/eterm/src/eterm/terminal/terminalemulator.cpp +++ b/src/modules/eterm/src/eterm/terminal/terminalemulator.cpp @@ -1360,6 +1360,9 @@ void TerminalEmulator::tsetmode( int priv, int set, int* args, int narg ) { and can be mistaken for other control codes. */ break; + case 2026: // IGNORE DECSET/DECRST 2026 for sync updates + // (https://codeberg.org/dnkl/foot/pulls/461/files) + break; default: fprintf( stderr, "erresc: unknown private set/reset mode %d\n", *args ); break; @@ -2432,7 +2435,7 @@ void TerminalEmulator::mousereport( const TerminalMouseEventType& type, const Ve char buf[40]; static int ox, oy; - for ( btn = 1; btn <= 11 && !( flags & ( 1 << ( btn - 1 ) ) ); btn++ ) + for ( btn = 1; btn <= 31 && !( flags & ( 1 << ( btn - 1 ) ) ); btn++ ) ; if ( type == TerminalMouseEventType::MouseMotion ) { @@ -2448,6 +2451,27 @@ void TerminalEmulator::mousereport( const TerminalMouseEventType& type, const Ve code = 32; } else { + /* Fix button numbers from ee to tty */ + switch ( btn ) { + case 28: + btn = 4; + break; + case 29: + btn = 5; + break; + case 30: + btn = 6; + break; + case 31: + btn = 7; + break; + default: { + if ( btn >= 4 && btn <= 7 ) + btn += 4; + break; + } + } + /* Only buttons 1 through 11 can be encoded */ if ( btn < 1 || btn > 11 ) return; @@ -2456,7 +2480,7 @@ void TerminalEmulator::mousereport( const TerminalMouseEventType& type, const Ve if ( xgetmode( MODE_MOUSEX10 ) ) return; /* Don't send release events for the scroll wheel */ - if ( btn == 4 || btn == 5 ) + if ( btn >= 28 && btn <= 31 ) return; } code = 0; @@ -2472,9 +2496,9 @@ void TerminalEmulator::mousereport( const TerminalMouseEventType& type, const Ve code += 3; else if ( btn >= 8 ) code += 128 + btn - 8; - else if ( btn >= 4 ) + else if ( btn >= 4 ) { code += 64 + btn - 4; - else + } else code += btn - 1; if ( !xgetmode( MODE_MOUSEX10 ) ) { diff --git a/src/tools/uieditor/uieditor.cpp b/src/tools/uieditor/uieditor.cpp index 002851344..fb8daa144 100644 --- a/src/tools/uieditor/uieditor.cpp +++ b/src/tools/uieditor/uieditor.cpp @@ -50,13 +50,16 @@ UISceneNode* uiSceneNode = NULL; UISceneNode* appUiSceneNode = NULL; std::string currentLayout; std::string currentStyleSheet; +std::string baseStyleSheet; bool layoutExpanded = true; bool updateLayout = false; bool updateStyleSheet = false; +bool updateBaseStyleSheet = false; bool useDefaultTheme = false; bool preserveContainerSize = false; Clock waitClock; Clock cssWaitClock; +Clock cssBaseWaitClock; efsw::WatchID watch = 0; efsw::WatchID styleSheetWatch = 0; std::map widgetRegistered; @@ -116,6 +119,9 @@ class UpdateListener : public efsw::FileWatchListener { } else if ( dir + filename == currentStyleSheet ) { updateStyleSheet = true; cssWaitClock.restart(); + } else if ( dir + filename == baseStyleSheet ) { + updateBaseStyleSheet = true; + cssBaseWaitClock.restart(); } } } @@ -218,15 +224,13 @@ static void loadStyleSheet( std::string cssPath ) { bool keepWatch = false; for ( auto& directory : fileWatcher->directories() ) { - if ( directory == folder ) { + if ( directory == folder ) keepWatch = true; - } } if ( !keepWatch ) { - if ( styleSheetWatch != 0 ) { + if ( styleSheetWatch != 0 ) fileWatcher->removeWatch( styleSheetWatch ); - } styleSheetWatch = fileWatcher->addWatch( folder, listener ); } @@ -271,17 +275,23 @@ static void refreshLayout() { } static void refreshStyleSheet() { + if ( updateBaseStyleSheet ) + theme->reloadStyleSheet(); + if ( !currentStyleSheet.empty() && FileSystem::fileExists( currentStyleSheet ) && uiContainer != NULL ) { loadStyleSheet( currentStyleSheet ); + } else if ( updateBaseStyleSheet ) { + setUserDefaultTheme(); + } - if ( !currentLayout.empty() && FileSystem::fileExists( currentLayout ) && - uiContainer != NULL ) { - loadLayout( currentLayout ); - } + if ( !currentLayout.empty() && FileSystem::fileExists( currentLayout ) && + uiContainer != NULL ) { + loadLayout( currentLayout ); } updateStyleSheet = false; + updateBaseStyleSheet = false; } void onRecentProjectClick( const Event* event ) { @@ -741,7 +751,8 @@ void mainLoop() { if ( updateLayout && waitClock.getElapsedTime().asMilliseconds() > 250.f ) refreshLayout(); - if ( updateStyleSheet && cssWaitClock.getElapsedTime().asMilliseconds() > 250.f ) + if ( ( updateStyleSheet && cssWaitClock.getElapsedTime().asMilliseconds() > 250.f ) || + ( updateBaseStyleSheet && cssBaseWaitClock.getElapsedTime().asMilliseconds() > 250.f ) ) refreshStyleSheet(); SceneManager::instance()->update(); @@ -964,7 +975,8 @@ EE_MAIN_FUNC int main( int argc, char* argv[] ) { FontTrueType::New( "NotoSans-Regular", resPath + "assets/fonts/NotoSans-Regular.ttf" ); FontTrueType::New( "monospace", resPath + "assets/fonts/DejaVuSansMono.ttf" ); - theme = UITheme::load( "uitheme", "uitheme", "", font, resPath + "assets/ui/breeze.css" ); + baseStyleSheet = resPath + "assets/ui/breeze.css"; + theme = UITheme::load( "uitheme", "uitheme", "", font, baseStyleSheet ); uiSceneNode = UISceneNode::New(); uiSceneNode->setId( "uiSceneNode" );