diff --git a/bin/assets/layouts/test.css b/bin/assets/layouts/test.css index 62cf6596f..fdf6ce6f6 100644 --- a/bin/assets/layouts/test.css +++ b/bin/assets/layouts/test.css @@ -12,7 +12,7 @@ /* Global rules */ * { - color: var(--font-color); + color: #E6E6E6FF; shadow-color: #32323296; selected-color: #000; selection-back-color: #969696FF; @@ -31,7 +31,7 @@ TabWidget::TabContainer { ProgressBar { display-percent: true; vertical-expand: true; - movement-speed: 32 0; + movement-speed: 32dp 0dp; padding: 2dp; } @@ -46,10 +46,27 @@ WinMenu::button { Menu, PopUpMenu { - color: var(--font-color); + color: #E6E6E6FF; min-width: 100dp; - min-icon-space: 24dp; - min-margin-right: 8dp; + min-icon-size: 16dp 16dp; +} + +Menu::Item, +Menu::CheckBox, +Menu::Separator, +Menu::SubMenu { + padding-left: 4dp; +} + +Menu::Item::text, +Menu::CheckBox::text, +Menu::Separator::text, +Menu::SubMenu::text { + padding-right: 4dp; +} + +Menu::SubMenu::arrow { + margin-right: 1dp; } Menu:hover, @@ -78,10 +95,15 @@ Window { } Window::title { - color: var(--font-color); + color: #E6E6E6FF; font-style: shadow; } +Tab::text { + padding-left: 4dp; + padding-right: 4dp; +} + Tooltip { padding: 8dp; color: #020203; diff --git a/bin/assets/layouts/test.xml b/bin/assets/layouts/test.xml index d99149264..70fb3785b 100644 --- a/bin/assets/layouts/test.xml +++ b/bin/assets/layouts/test.xml @@ -40,7 +40,9 @@ - + @@ -101,13 +103,13 @@ - - - - - - - - + + + + + + + + diff --git a/bin/assets/layouts/test_widgets.xml b/bin/assets/layouts/test_widgets.xml index b7858ba72..a1840c0f1 100644 --- a/bin/assets/layouts/test_widgets.xml +++ b/bin/assets/layouts/test_widgets.xml @@ -45,13 +45,13 @@ - + - + - + @@ -59,9 +59,9 @@ - - - + + + - + diff --git a/bin/assets/ui/uitheme.css b/bin/assets/ui/uitheme.css index 6d9b6fd82..04ce43634 100644 --- a/bin/assets/ui/uitheme.css +++ b/bin/assets/ui/uitheme.css @@ -19,7 +19,7 @@ TabWidget::TabContainer { ProgressBar { display-percent: true; vertical-expand: true; - movement-speed: 32 0; + movement-speed: 32dp 0dp; padding: 2dp; } @@ -36,8 +36,25 @@ Menu, PopUpMenu { color: #E6E6E6FF; min-width: 100dp; - min-icon-space: 24dp; - min-margin-right: 8dp; + min-icon-size: 16dp 16dp; +} + +Menu::Item, +Menu::CheckBox, +Menu::Separator, +Menu::SubMenu { + padding-left: 4dp; +} + +Menu::Item::text, +Menu::CheckBox::text, +Menu::Separator::text, +Menu::SubMenu::text { + padding-right: 4dp; +} + +Menu::SubMenu::arrow { + margin-right: 1dp; } Menu:hover, @@ -70,6 +87,11 @@ Window::title { font-style: shadow; } +Tab::text { + padding-left: 4dp; + padding-right: 4dp; +} + Tooltip { padding: 8dp; color: #020203; diff --git a/docs/articles/cssspecification.md b/docs/articles/cssspecification.md index 936bbd6a4..d0c67dfa1 100644 --- a/docs/articles/cssspecification.md +++ b/docs/articles/cssspecification.md @@ -1049,22 +1049,37 @@ Read [min-height](https://developer.mozilla.org/en-US/docs/Web/CSS/min-height) d ### min-icon-size ---- +Sets the minimum size of the icon inside a push button (or any widget that extends from it, for +example a menu item or a tab). It's usually required for the EE::UI::UIMenu (Menu) sice the icon +box must have a size if the menu contains items with icons and others without, otherwise the menu +items will be misaligned. -### min-icon-space - ---- - -### min-margin-right +* Applicatable to: EE::UI::UIPushButton (PushButton), EE::UI::UIMenuItem (Menu::item), + EE::UI::UITab (Tab), EE::UI::UISelectButton (SelectButton), EE::UI::UIMenuCheckBox (Menu::checkbox), + EE::UI::UIMenuSubMenu (Menu::SubMenu) +* Value Type: vector2-length +* Default value: _No value_ --- ### min-tab-width +Sets the minimum width that a tab can have inside a EE::UI::UITabWidget (TabWidget). + +* Applicable to: EE::UI::UITabWidget (TabWidget) +* Value Type: length +* Default value: `32dp` + --- ### min-value +Sets the minimum value that a range element will hold. + +* Applicable to: EE::UI::UISlider (Slider), EE::UI::UIScrollBar (ScrollBar), EE::UI::UISpinBox (SpinBox) +* Value Type: float +* Default value: `0` + --- ### min-width @@ -1075,13 +1090,22 @@ Read [min-width](https://developer.mozilla.org/en-US/docs/Web/CSS/min-width) doc ### movement-speed ---- +Sets the movement speed in displaced length per second of the progress bar filler. -### name +* Applicable to: EE::UI::UIProgressBar (ProgressBar) +* Value Type: vector2-length +* Default value: `0dp 0dp` --- -### only-numbers +### numeric + +Sets the text input as a numeric input, this means that only numbers will be accepted and +if [allow-float](#allow-float) also is enabled it will allow numeric float numbers. + +* Applicable to: EE::UI::UITextInput (TextInput) +* Value Type: boolean +* Default value: `false` --- @@ -1093,14 +1117,38 @@ Read [opacity](https://developer.mozilla.org/en-US/docs/Web/CSS/opacity) documen ### orientation +Sets the orientation to any element that allows vertical and horizontal orientation. + +* Applicable to: EE::UI::UILinearLayout (LinearLayout), EE::UI::UISlider (Slider), EE::UI::UIScrollBar + (ScrollBar), EE::UI::UIViewPager (ViewPager) +* Value Type: string-list +* Value List: + * `horizontal` + * `vertical` +* Default value: `vertical` for LinearLayout, Slider and ScrollBar, `horizontal` for ViewPager + --- ### outline-thickness +Sets the outline thickness of the loader spinner. + +* Applicable to: EE::UI::UILoader (Loader) +* Value Type: length +* Default value: `8dp` + --- ### owns +Indicates the element ID that the Tab element owns. The ownership indicates that the element ID +is going to be shown when the Tab element is selected, and will be closed if the Tab is closed. +The owned element will be automatically resized to the tab widget container size. + +* Applicable to: EE::UI::UITab (Tab) +* Value Type: string (element ID) +* Default value: _No value_ + --- ### padding-bottom diff --git a/include/eepp/ui/css/propertydefinition.hpp b/include/eepp/ui/css/propertydefinition.hpp index 0297ad04a..e77ec5e61 100644 --- a/include/eepp/ui/css/propertydefinition.hpp +++ b/include/eepp/ui/css/propertydefinition.hpp @@ -76,8 +76,6 @@ enum class PropertyId : Uint32 { TextAlign = String::hash( "text-align" ), Icon = String::hash( "icon" ), MinIconSize = String::hash( "min-icon-size" ), - IconHorizontalMargin = String::hash( "icon-horizontal-margin" ), - IconAutoMargin = String::hash( "icon-auto-margin" ), Src = String::hash( "src" ), ScaleType = String::hash( "scale-type" ), Tint = String::hash( "tint" ), @@ -118,8 +116,6 @@ enum class PropertyId : Uint32 { MinHeight = String::hash( "min-height" ), MaxWidth = String::hash( "max-width" ), MaxHeight = String::hash( "max-height" ), - MinMarginRight = String::hash( "min-margin-right" ), - MinIconSpace = String::hash( "min-icon-space" ), TotalSteps = String::hash( "total-steps" ), VerticalExpand = String::hash( "vertical-expand" ), DisplayPercent = String::hash( "display-percent" ), @@ -132,12 +128,11 @@ enum class PropertyId : Uint32 { BackgroundExpand = String::hash( "background-expand" ), ScrollBarMode = String::hash( "scrollbar-mode" ), HalfSlider = String::hash( "half-slider" ), - Name = String::hash( "name" ), Owns = String::hash( "owns" ), AllowEditing = String::hash( "allow-editing" ), MaxLength = String::hash( "max-length" ), FreeEditing = String::hash( "free-editing" ), - OnlyNumbers = String::hash( "only-numbers" ), + Numeric = String::hash( "numeric" ), AllowFloat = String::hash( "allow-float" ), TouchDrag = String::hash( "touch-drag" ), TouchDragDeceleration = String::hash( "touch-drag-deceleration" ), diff --git a/include/eepp/ui/uimenu.hpp b/include/eepp/ui/uimenu.hpp index 5406cd134..2c85187ab 100644 --- a/include/eepp/ui/uimenu.hpp +++ b/include/eepp/ui/uimenu.hpp @@ -6,20 +6,12 @@ #include #include #include -#include +#include namespace EE { namespace UI { class EE_API UIMenu : public UIWidget { public: - class StyleConfig { - public: - Rectf Padding = Rectf( 0, 0, 0, 0 ); - Uint32 MinWidth = 0; - Uint32 MinSpaceForIcons = 0; - Uint32 MinRightMargin = 0; - }; - static UIMenu* New(); static void fixMenuPos( Vector2f& position, UIMenu* Menu, UIMenu* parent = NULL, @@ -35,7 +27,7 @@ class EE_API UIMenu : public UIWidget { Uint32 add( const String& Text, Drawable* Icon = NULL ); - Uint32 add( UINode* Control ); + Uint32 add( UIWidget* widget ); Uint32 addSeparator(); @@ -43,23 +35,23 @@ class EE_API UIMenu : public UIWidget { Uint32 addSubMenu( const String& Text, Drawable* Icon = NULL, UIMenu* SubMenu = NULL ); - UINode* getItem( const Uint32& Index ); + UIWidget* getItem( const Uint32& Index ); - UINode* getItem( const String& Text ); + UIWidget* getItem( const String& Text ); - Uint32 getItemIndex( UINode* Item ); + Uint32 getItemIndex( UIWidget* Item ); Uint32 getCount() const; void remove( const Uint32& Index ); - void remove( UINode* Ctrl ); + void remove( UIWidget* Ctrl ); void removeAll(); void insert( const String& Text, Drawable* Icon, const Uint32& Index ); - void insert( UINode* Control, const Uint32& Index ); + void insert( UIWidget* Control, const Uint32& Index ); virtual void setTheme( UITheme* Theme ); @@ -67,12 +59,6 @@ class EE_API UIMenu : public UIWidget { virtual bool hide(); - Uint32 getMinRightMargin() const; - - void setMinRightMargin( const Uint32& minRightMargin ); - - const StyleConfig& getStyleConfig() const; - virtual void loadFromXmlNode( const pugi::xml_node& node ); virtual bool applyProperty( const StyleSheetProperty& attribute ); @@ -85,21 +71,25 @@ class EE_API UIMenu : public UIWidget { /** The owner node is the node who triggers the visibility of the menu */ void setOwnerNode( UINode* ownerNode ); + void setIconMinimumSize( const Sizei& minIconSize ); + + const Sizei& getIconMinimumSize() const; + protected: friend class UIMenuItem; friend class UIMenuCheckBox; friend class UIMenuSubMenu; - std::deque mItems; - StyleConfig mStyleConfig; + std::deque mItems; Uint32 mMaxWidth; Uint32 mNextPosY; - Uint32 mBiggestIcon; - UINode* mItemSelected; + Int32 mBiggestIcon; + UIWidget* mItemSelected; Uint32 mItemSelectedIndex; bool mClickHide; Uint32 mLastTickMove; UINode* mOwnerNode; + Sizei mIconMinSize; virtual void onSizeChange(); @@ -107,11 +97,11 @@ class EE_API UIMenu : public UIWidget { virtual Uint32 onMessage( const NodeMessage* Msg ); - void setControlSize( UINode* Control, const Uint32& position ); + void setWidgetSize( UIWidget* widget ); - void resizeControls(); + void widgetsResize(); - void rePosControls(); + void widgetsSetPos(); void resizeMe(); @@ -123,11 +113,13 @@ class EE_API UIMenu : public UIWidget { void onThemeLoaded(); - bool checkControlSize( UINode* Control, const bool& Resize = true ); + virtual void onPaddingChange(); + + bool widgetCheckSize( UIWidget* widget, const bool& Resize = true ); bool isSubMenu( Node* Ctrl ); - void setItemSelected( UINode* Item ); + void setItemSelected( UIWidget* Item ); virtual Uint32 onKeyDown( const KeyEvent& Event ); @@ -135,9 +127,7 @@ class EE_API UIMenu : public UIWidget { void nextSel(); - void trySelect( UINode* Ctrl, bool Up ); - - void setMinSpaceForIcons( const Uint32& minSpaceForIcons ); + void trySelect( UIWidget* Ctrl, bool Up ); }; }} // namespace EE::UI diff --git a/include/eepp/ui/uimenusubmenu.hpp b/include/eepp/ui/uimenusubmenu.hpp index d284a1199..6988aecc5 100644 --- a/include/eepp/ui/uimenusubmenu.hpp +++ b/include/eepp/ui/uimenusubmenu.hpp @@ -37,7 +37,7 @@ class EE_API UIMenuSubMenu : public UIMenuItem { protected: UIMenu* mSubMenu; - UINode* mArrow; + UIWidget* mArrow; Time mMaxTime; Uint32 mCbId; Uint32 mCbId2; @@ -53,6 +53,8 @@ class EE_API UIMenuSubMenu : public UIMenuItem { virtual void onAlphaChange(); + virtual UIWidget* getExtraInnerWidget(); + void onSubMenuFocusLoss( const Event* Event ); void onHideByClick( const Event* Event ); diff --git a/include/eepp/ui/uinode.hpp b/include/eepp/ui/uinode.hpp index 34f7a1d6e..d11196af7 100644 --- a/include/eepp/ui/uinode.hpp +++ b/include/eepp/ui/uinode.hpp @@ -192,7 +192,7 @@ class EE_API UINode : public Node { virtual void popState( const Uint32& State, bool emitEvent = true ); - Sizef getSkinSize() const; + Sizef getSkinSize( const Uint32& state = UIState::StateFlagNormal ) const; void applyDefaultTheme(); diff --git a/include/eepp/ui/uiprogressbar.hpp b/include/eepp/ui/uiprogressbar.hpp index 4d02fdcef..12933a06f 100644 --- a/include/eepp/ui/uiprogressbar.hpp +++ b/include/eepp/ui/uiprogressbar.hpp @@ -13,7 +13,7 @@ class EE_API UIProgressBar : public UIWidget { public: bool DisplayPercent = false; bool VerticalExpand = true; - Vector2f MovementSpeed = Vector2f( 64.f, 0 ); + Vector2f MovementSpeed = Vector2f( 0.f, 0 ); }; static UIProgressBar* New(); diff --git a/include/eepp/ui/uipushbutton.hpp b/include/eepp/ui/uipushbutton.hpp index 616e769bf..4f0df8af2 100644 --- a/include/eepp/ui/uipushbutton.hpp +++ b/include/eepp/ui/uipushbutton.hpp @@ -9,13 +9,6 @@ namespace EE { namespace UI { class EE_API UIPushButton : public UIWidget { public: - class StyleConfig { - public: - Int32 IconHorizontalMargin = 4; - bool IconAutoMargin = true; - Sizei IconMinSize; - }; - static UIPushButton* New(); UIPushButton(); @@ -36,17 +29,11 @@ class EE_API UIPushButton : public UIWidget { virtual const String& getText(); - void setIconHorizontalMargin( Int32 margin ); - - const Int32& getIconHorizontalMargin() const; - UITextView* getTextBox() const; - const StyleConfig& getStyleConfig() const; - void setIconMinimumSize( const Sizei& minIconSize ); - void setStyleConfig( const StyleConfig& styleConfig ); + const Sizei& getIconMinimumSize() const; virtual bool applyProperty( const StyleSheetProperty& attribute ); @@ -54,9 +41,9 @@ class EE_API UIPushButton : public UIWidget { const Uint32& propertyIndex = 0 ); protected: - StyleConfig mStyleConfig; UIImage* mIcon; UITextView* mTextBox; + Sizei mIconMinSize; explicit UIPushButton( const std::string& tag ); @@ -78,7 +65,7 @@ class EE_API UIPushButton : public UIWidget { virtual Uint32 onKeyUp( const KeyEvent& Event ); - void autoIconHorizontalMargin(); + virtual UIWidget* getExtraInnerWidget(); }; }} // namespace EE::UI diff --git a/include/eepp/ui/uiwidget.hpp b/include/eepp/ui/uiwidget.hpp index 2a76d49a0..5ee6cb6ef 100644 --- a/include/eepp/ui/uiwidget.hpp +++ b/include/eepp/ui/uiwidget.hpp @@ -207,6 +207,8 @@ class EE_API UIWidget : public UINode { 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; @@ -215,6 +217,8 @@ class EE_API UIWidget : public UINode { 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; diff --git a/projects/linux/ee.creator.user b/projects/linux/ee.creator.user index d5ef5b3dc..5c654d724 100644 --- a/projects/linux/ee.creator.user +++ b/projects/linux/ee.creator.user @@ -1,6 +1,6 @@ - + EnvironmentId @@ -1455,7 +1455,7 @@ eepp-MapEditor-debug ProjectExplorer.CustomExecutableRunConfiguration - + -x assets/layouts/test.xml -c assets/layouts/test.css -u false true diff --git a/src/eepp/maps/mapeditor/mapeditor.cpp b/src/eepp/maps/mapeditor/mapeditor.cpp index 1f7d6b655..4fb28f080 100644 --- a/src/eepp/maps/mapeditor/mapeditor.cpp +++ b/src/eepp/maps/mapeditor/mapeditor.cpp @@ -300,7 +300,7 @@ void MapEditor::createTextureRegionContainer( Int32 Width ) { mGOTypeList = UIDropDownList::New(); mGOTypeList->setFontStyle( Text::Shadow ) ->setParent( mTextureRegionCont ) - ->setSize( Width - 26, 0 ) + ->setSize( Width - 30, 0 ) ->setPosition( TAB_CONT_X_DIST, Txt->getPosition().y + Txt->getSize().getHeight() + 4 ); mGOTypeList->addEventListener( Event::OnItemSelected, diff --git a/src/eepp/ui/css/stylesheetspecification.cpp b/src/eepp/ui/css/stylesheetspecification.cpp index 6c2cb561f..19cc5ee46 100644 --- a/src/eepp/ui/css/stylesheetspecification.cpp +++ b/src/eepp/ui/css/stylesheetspecification.cpp @@ -261,9 +261,6 @@ void StyleSheetSpecification::registerDefaultProperties() { .setType( PropertyType::NumberLength ) .setRelativeTarget( PropertyRelativeTarget::ContainingBlockHeight ); - registerProperty( "min-margin-right", "" ).setType( PropertyType::NumberLength ); - registerProperty( "min-icon-space", "" ).setType( PropertyType::NumberLength ); - registerProperty( "total-steps", "" ).setType( PropertyType::NumberInt ); registerProperty( "vertical-expand", "" ).setType( PropertyType::Bool ); registerProperty( "display-percent", "" ).setType( PropertyType::Bool ); @@ -276,12 +273,11 @@ void StyleSheetSpecification::registerDefaultProperties() { registerProperty( "background-expand", "" ).setType( PropertyType::Bool ); registerProperty( "scrollbar-mode", "" ); registerProperty( "half-slider", "" ).setType( PropertyType::Bool ); - registerProperty( "name", "" ).setType( PropertyType::String ); registerProperty( "owns", "" ).setType( PropertyType::String ); registerProperty( "allow-editing", "" ).setType( PropertyType::Bool ); registerProperty( "max-length", "" ).setType( PropertyType::NumberInt ); registerProperty( "free-editing", "" ).setType( PropertyType::Bool ); - registerProperty( "only-numbers", "" ).setType( PropertyType::Bool ); + registerProperty( "numeric", "" ).setType( PropertyType::Bool ); registerProperty( "allow-float", "" ).setType( PropertyType::Bool ); registerProperty( "touch-drag", "" ).setType( PropertyType::Bool ); registerProperty( "touch-drag-deceleration", "" ).setType( PropertyType::NumberFloat ); diff --git a/src/eepp/ui/tools/textureatlaseditor.cpp b/src/eepp/ui/tools/textureatlaseditor.cpp index ed028108b..09befdf70 100644 --- a/src/eepp/ui/tools/textureatlaseditor.cpp +++ b/src/eepp/ui/tools/textureatlaseditor.cpp @@ -77,8 +77,8 @@ TextureAtlasEditor::TextureAtlasEditor( UIWindow* attachTo, const TGEditorCloseC - - + + diff --git a/src/eepp/ui/uidropdownlist.cpp b/src/eepp/ui/uidropdownlist.cpp index a229fbcf5..f8e23cbe7 100644 --- a/src/eepp/ui/uidropdownlist.cpp +++ b/src/eepp/ui/uidropdownlist.cpp @@ -82,7 +82,7 @@ void UIDropDownList::onAutoSize() { if ( mLayoutHeightRule == LayoutSizeRule::WrapContent ) { setInternalPixelsHeight( PixelDensity::dpToPxI( getSkinSize().getHeight() ) + mRealPadding.Top + mRealPadding.Bottom ); - } else if ( ( mFlags & UI_AUTO_SIZE || 0 == getSize().getHeight() ) && + } else if ( ( ( mFlags & UI_AUTO_SIZE ) || 0 == getSize().getHeight() ) && 0 != getSkinSize().getHeight() ) { setInternalHeight( getSkinSize().getHeight() ); } diff --git a/src/eepp/ui/uimenu.cpp b/src/eepp/ui/uimenu.cpp index 27fc4185a..db674ebfd 100644 --- a/src/eepp/ui/uimenu.cpp +++ b/src/eepp/ui/uimenu.cpp @@ -55,12 +55,15 @@ void UIMenu::onThemeLoaded() { onSizeChange(); } +void UIMenu::onPaddingChange() { + widgetsSetPos(); +} + UIMenuItem* UIMenu::createMenuItem( const String& Text, Drawable* Icon ) { UIMenuItem* tCtrl = UIMenuItem::New(); tCtrl->setHorizontalAlign( UI_HALIGN_LEFT ); tCtrl->setParent( this ); - tCtrl->setIconMinimumSize( - Sizei( mStyleConfig.MinSpaceForIcons, mStyleConfig.MinSpaceForIcons ) ); + tCtrl->setIconMinimumSize( mIconMinSize ); tCtrl->setIcon( Icon ); tCtrl->setText( Text ); @@ -75,8 +78,7 @@ UIMenuCheckBox* UIMenu::createMenuCheckBox( const String& Text, const bool& Acti UIMenuCheckBox* tCtrl = UIMenuCheckBox::New(); tCtrl->setHorizontalAlign( UI_HALIGN_LEFT ); tCtrl->setParent( this ); - tCtrl->setIconMinimumSize( - Sizei( mStyleConfig.MinSpaceForIcons, mStyleConfig.MinSpaceForIcons ) ); + tCtrl->setIconMinimumSize( mIconMinSize ); tCtrl->setText( Text ); if ( Active ) @@ -93,8 +95,7 @@ UIMenuSubMenu* UIMenu::createSubMenu( const String& Text, Drawable* Icon, UIMenu UIMenuSubMenu* tCtrl = UIMenuSubMenu::New(); tCtrl->setHorizontalAlign( UI_HALIGN_LEFT ); tCtrl->setParent( this ); - tCtrl->setIconMinimumSize( - Sizei( mStyleConfig.MinSpaceForIcons, mStyleConfig.MinSpaceForIcons ) ); + tCtrl->setIconMinimumSize( mIconMinSize ); tCtrl->setIcon( Icon ); tCtrl->setText( Text ); tCtrl->setSubMenu( SubMenu ); @@ -106,47 +107,27 @@ Uint32 UIMenu::addSubMenu( const String& Text, Drawable* Icon, UIMenu* SubMenu ) return add( createSubMenu( Text, Icon, SubMenu ) ); } -bool UIMenu::checkControlSize( UINode* Control, const bool& Resize ) { - if ( Control->isType( UI_TYPE_MENUITEM ) ) { - UIMenuItem* tItem = Control->asType(); +bool UIMenu::widgetCheckSize( UIWidget* widget, const bool& Resize ) { + if ( widget->isType( UI_TYPE_MENUITEM ) ) { + UIMenuItem* tItem = widget->asType(); - if ( NULL != tItem->getIcon() && - tItem->getIconHorizontalMargin() + tItem->getIcon()->getSize().getWidth() > - (Int32)mBiggestIcon ) { - mBiggestIcon = - tItem->getIconHorizontalMargin() + tItem->getIcon()->getSize().getWidth(); + if ( NULL != tItem->getIcon() && tItem->getIcon()->getLayoutMargin().Left + + tItem->getIcon()->getLayoutMargin().Right + + tItem->getIcon()->getSize().getWidth() > + (Int32)mBiggestIcon ) { + mBiggestIcon = tItem->getIcon()->getLayoutMargin().Left + + tItem->getIcon()->getLayoutMargin().Right + + tItem->getIcon()->getSize().getWidth(); } if ( mFlags & UI_AUTO_SIZE ) { - if ( Control->isType( UI_TYPE_MENUSUBMENU ) ) { - Int32 textWidth = tItem->getTextBox()->getTextWidth(); + if ( widget->getPixelsSize().getWidth() > (Int32)mMaxWidth ) { + mMaxWidth = widget->getPixelsSize().getWidth(); - UIMenuSubMenu* tMenu = tItem->asType(); + if ( Resize ) { + widgetsResize(); - if ( textWidth + PixelDensity::dpToPxI( mBiggestIcon ) + - tMenu->getArrow()->getPixelsSize().getWidth() + - PixelDensity::dpToPxI( mStyleConfig.MinRightMargin ) > - (Int32)mMaxWidth ) { - mMaxWidth = - textWidth + mRealPadding.Left + mRealPadding.Right + - PixelDensity::dpToPxI( mBiggestIcon + mStyleConfig.MinRightMargin ) + - tMenu->getArrow()->getPixelsSize().getWidth(); - - if ( Resize ) { - resizeControls(); - - return true; - } - } - } else { - if ( Control->getPixelsSize().getWidth() > (Int32)mMaxWidth ) { - mMaxWidth = Control->getPixelsSize().getWidth(); - - if ( Resize ) { - resizeControls(); - - return true; - } + return true; } } } @@ -155,27 +136,27 @@ bool UIMenu::checkControlSize( UINode* Control, const bool& Resize ) { return false; } -Uint32 UIMenu::add( UINode* Control ) { - if ( this != Control->getParent() ) - Control->setParent( this ); +Uint32 UIMenu::add( UIWidget* widget ) { + if ( this != widget->getParent() ) + widget->setParent( this ); - checkControlSize( Control ); + widgetCheckSize( widget ); - setControlSize( Control, getCount() ); + setWidgetSize( widget ); - Control->setPixelsPosition( mRealPadding.Left, mRealPadding.Top + mNextPosY ); + widget->setPixelsPosition( mRealPadding.Left, mRealPadding.Top + mNextPosY ); - mNextPosY += Control->getPixelsSize().getHeight(); + mNextPosY += widget->getPixelsSize().getHeight(); - mItems.push_back( Control ); + mItems.push_back( widget ); resizeMe(); return mItems.size() - 1; } -void UIMenu::setControlSize( UINode* Control, const Uint32& ) { - Control->setPixelsSize( mSize.getWidth(), Control->getPixelsSize().getHeight() ); +void UIMenu::setWidgetSize( UIWidget* widget ) { + widget->setPixelsSize( mSize.getWidth(), widget->getPixelsSize().getHeight() ); } Uint32 UIMenu::addSeparator() { @@ -194,12 +175,12 @@ Uint32 UIMenu::addSeparator() { return mItems.size() - 1; } -UINode* UIMenu::getItem( const Uint32& Index ) { +UIWidget* UIMenu::getItem( const Uint32& Index ) { eeASSERT( Index < mItems.size() ); return mItems[Index]; } -UINode* UIMenu::getItem( const String& Text ) { +UIWidget* UIMenu::getItem( const String& Text ) { for ( Uint32 i = 0; i < mItems.size(); i++ ) { if ( mItems[i]->isType( UI_TYPE_MENUITEM ) ) { UIMenuItem* tMenuItem = mItems[i]->asType(); @@ -212,7 +193,7 @@ UINode* UIMenu::getItem( const String& Text ) { return NULL; } -Uint32 UIMenu::getItemIndex( UINode* Item ) { +Uint32 UIMenu::getItemIndex( UIWidget* Item ) { for ( Uint32 i = 0; i < mItems.size(); i++ ) { if ( mItems[i] == Item ) return i; @@ -232,11 +213,11 @@ void UIMenu::remove( const Uint32& Index ) { mItems.erase( mItems.begin() + Index ); - rePosControls(); - resizeControls(); + widgetsSetPos(); + widgetsResize(); } -void UIMenu::remove( UINode* Ctrl ) { +void UIMenu::remove( UIWidget* Ctrl ) { for ( Uint32 i = 0; i < mItems.size(); i++ ) { if ( mItems[i] == Ctrl ) { remove( i ); @@ -261,13 +242,13 @@ void UIMenu::insert( const String& Text, Drawable* Icon, const Uint32& Index ) { insert( createMenuItem( Text, Icon ), Index ); } -void UIMenu::insert( UINode* Control, const Uint32& Index ) { +void UIMenu::insert( UIWidget* Control, const Uint32& Index ) { mItems.insert( mItems.begin() + Index, Control ); childAddAt( Control, Index ); - rePosControls(); - resizeControls(); + widgetsSetPos(); + widgetsResize(); } bool UIMenu::isSubMenu( Node* Ctrl ) { @@ -313,9 +294,13 @@ Uint32 UIMenu::onMessage( const NodeMessage* Msg ) { } void UIMenu::onSizeChange() { - if ( 0 != mStyleConfig.MinWidth && getSize().getWidth() < (Int32)mStyleConfig.MinWidth ) { - setSize( mStyleConfig.MinWidth, - PixelDensity::pxToDpI( mNextPosY ) + mPadding.Top + mPadding.Bottom ); + Float minWidth = 0; + if ( !mMinWidthEq.empty() ) { + minWidth = lengthFromValueAsDp( mMinWidthEq, CSS::PropertyRelativeTarget::None ); + } + + if ( 0 != minWidth && getSize().getWidth() < (Int32)minWidth ) { + setSize( minWidth, PixelDensity::pxToDpI( mNextPosY ) + mPadding.Top + mPadding.Bottom ); } UIWidget::onSizeChange(); @@ -323,37 +308,37 @@ void UIMenu::onSizeChange() { void UIMenu::autoPadding() { if ( mFlags & UI_AUTO_PADDING ) { - mPadding = makePadding(); + setPadding( makePadding() ); } } -void UIMenu::resizeControls() { +void UIMenu::widgetsResize() { resizeMe(); for ( Uint32 i = 0; i < mItems.size(); i++ ) { - setControlSize( mItems[i], i ); + setWidgetSize( mItems[i] ); } } -void UIMenu::rePosControls() { +void UIMenu::widgetsSetPos() { Uint32 i; mNextPosY = 0; - mBiggestIcon = mStyleConfig.MinSpaceForIcons; + mBiggestIcon = mIconMinSize.getWidth(); if ( mFlags & UI_AUTO_SIZE ) { mMaxWidth = 0; for ( i = 0; i < mItems.size(); i++ ) { - checkControlSize( mItems[i], false ); + widgetCheckSize( mItems[i], false ); } } for ( i = 0; i < mItems.size(); i++ ) { - UINode* ctrl = mItems[i]; + UIWidget* widget = mItems[i]; - ctrl->setPixelsPosition( mRealPadding.Left, mRealPadding.Top + mNextPosY ); + widget->setPixelsPosition( mRealPadding.Left, mRealPadding.Top + mNextPosY ); - mNextPosY += ctrl->getPixelsSize().getHeight(); + mNextPosY += widget->getPixelsSize().getHeight(); } resizeMe(); @@ -387,7 +372,7 @@ bool UIMenu::hide() { return true; } -void UIMenu::setItemSelected( UINode* Item ) { +void UIMenu::setItemSelected( UIWidget* Item ) { if ( NULL != mItemSelected ) { if ( mItemSelected->isType( UI_TYPE_MENUSUBMENU ) ) { UIMenuSubMenu* tMenu = mItemSelected->asType(); @@ -408,7 +393,7 @@ void UIMenu::setItemSelected( UINode* Item ) { } } -void UIMenu::trySelect( UINode* Ctrl, bool Up ) { +void UIMenu::trySelect( UIWidget* Ctrl, bool Up ) { if ( mItems.size() ) { if ( !Ctrl->isType( UI_TYPE_MENU_SEPARATOR ) ) { setItemSelected( Ctrl ); @@ -515,19 +500,6 @@ Uint32 UIMenu::onKeyDown( const KeyEvent& Event ) { return UIWidget::onKeyDown( Event ); } -Uint32 UIMenu::getMinRightMargin() const { - return mStyleConfig.MinRightMargin; -} - -void UIMenu::setMinRightMargin( const Uint32& minRightMargin ) { - mStyleConfig.MinRightMargin = minRightMargin; - rePosControls(); -} - -const UIMenu::StyleConfig& UIMenu::getStyleConfig() const { - return mStyleConfig; -} - static Drawable* getIconDrawable( const std::string& name, UITheme* theme ) { Drawable* iconDrawable = NULL; @@ -594,12 +566,9 @@ std::string UIMenu::getPropertyString( const PropertyDefinition* propertyDef, return ""; switch ( propertyDef->getPropertyId() ) { - case PropertyId::MinWidth: - return String::format( "%udp", mStyleConfig.MinWidth ); - case PropertyId::MinMarginRight: - return String::format( "%udp", getMinRightMargin() ); - case PropertyId::MinIconSpace: - return String::format( "%udp", mStyleConfig.MinSpaceForIcons ); + case PropertyId::MinIconSize: + return String::format( "%ddp", mIconMinSize.getWidth() ) + " " + + String::format( "%ddp", mIconMinSize.getHeight() ); default: return UIWidget::getPropertyString( propertyDef, propertyIndex ); } @@ -610,15 +579,8 @@ bool UIMenu::applyProperty( const StyleSheetProperty& attribute ) { return false; switch ( attribute.getPropertyDefinition()->getPropertyId() ) { - case PropertyId::MinWidth: - mStyleConfig.MinWidth = attribute.asDpDimensionI(); - onSizeChange(); - break; - case PropertyId::MinMarginRight: - setMinRightMargin( attribute.asDpDimensionUint() ); - break; - case PropertyId::MinIconSpace: - setMinSpaceForIcons( attribute.asDpDimensionUint() ); + case PropertyId::MinIconSize: + setIconMinimumSize( attribute.asSizei() ); break; default: return UIWidget::applyProperty( attribute ); @@ -635,23 +597,24 @@ void UIMenu::setOwnerNode( UINode* ownerNode ) { mOwnerNode = ownerNode; } -void UIMenu::setMinSpaceForIcons( const Uint32& minSpaceForIcons ) { - // if ( minSpaceForIcons != mStyleConfig.MinSpaceForIcons ) - { - mStyleConfig.MinSpaceForIcons = minSpaceForIcons; - mBiggestIcon = eemax( mBiggestIcon, mStyleConfig.MinSpaceForIcons ); +void UIMenu::setIconMinimumSize( const Sizei& minIconSize ) { + mIconMinSize = minIconSize; + mBiggestIcon = eemax( mBiggestIcon, mIconMinSize.getWidth() ); - for ( Uint32 i = 0; i < mItems.size(); i++ ) { - if ( mItems[i]->isType( UI_TYPE_MENUITEM ) ) { - UIMenuItem* menuItem = static_cast( mItems[i] ); + for ( Uint32 i = 0; i < mItems.size(); i++ ) { + if ( mItems[i]->isType( UI_TYPE_MENUITEM ) ) { + UIMenuItem* menuItem = static_cast( mItems[i] ); - menuItem->setIconMinimumSize( Sizei( minSpaceForIcons, minSpaceForIcons ) ); - } + menuItem->setIconMinimumSize( mIconMinSize ); } - - rePosControls(); - resizeControls(); } + + widgetsSetPos(); + widgetsResize(); +} + +const Sizei& UIMenu::getIconMinimumSize() const { + return mIconMinSize; } void UIMenu::fixMenuPos( Vector2f& Pos, UIMenu* Menu, UIMenu* Parent, UIMenuSubMenu* SubMenu ) { diff --git a/src/eepp/ui/uimenucheckbox.cpp b/src/eepp/ui/uimenucheckbox.cpp index c993b4d1d..9cc3ebb5e 100644 --- a/src/eepp/ui/uimenucheckbox.cpp +++ b/src/eepp/ui/uimenucheckbox.cpp @@ -75,7 +75,7 @@ void UIMenuCheckBox::setActive( const bool& active ) { if ( oActive != active ) { UIMenu* Menu = getParent()->asType(); - if ( !Menu->checkControlSize( this ) ) { + if ( !Menu->widgetCheckSize( this ) ) { if ( NULL != getIcon()->getDrawable() ) { setPadding( Rectf( 0, 0, 0, 0 ) ); } diff --git a/src/eepp/ui/uimenuitem.cpp b/src/eepp/ui/uimenuitem.cpp index cc01099da..920323248 100644 --- a/src/eepp/ui/uimenuitem.cpp +++ b/src/eepp/ui/uimenuitem.cpp @@ -8,7 +8,7 @@ UIMenuItem* UIMenuItem::New() { } UIMenuItem::UIMenuItem( const std::string& tag ) : UIPushButton( tag ) { - mIcon->setElementTag( getElementTag() + "::image" ); + mIcon->setElementTag( getElementTag() + "::icon" ); mTextBox->setElementTag( getElementTag() + "::text" ); applyDefaultTheme(); } diff --git a/src/eepp/ui/uimenusubmenu.cpp b/src/eepp/ui/uimenusubmenu.cpp index fa9763216..51928c86c 100644 --- a/src/eepp/ui/uimenusubmenu.cpp +++ b/src/eepp/ui/uimenusubmenu.cpp @@ -16,11 +16,13 @@ UIMenuSubMenu::UIMenuSubMenu() : mCbId( 0 ), mCbId2( 0 ), mCurWait( NULL ) { - mArrow = UINode::New(); + mArrow = UIWidget::NewWithTag( getElementTag() + "::arrow" ); mArrow->setParent( this ); mArrow->setFlags( UI_AUTO_SIZE ); mArrow->setVisible( true ); mArrow->setEnabled( false ); + mArrow->addEventListener( Event::OnMarginChange, + [&]( const Event* event ) { onSizeChange(); } ); applyDefaultTheme(); } @@ -48,9 +50,8 @@ void UIMenuSubMenu::setTheme( UITheme* Theme ) { void UIMenuSubMenu::onSizeChange() { UIMenuItem::onSizeChange(); - - mArrow->setPosition( getParent()->getSize().getWidth() - mArrow->getSize().getWidth() - - PixelDensity::dpToPx( 1 ), + mArrow->setPosition( getSize().getWidth() - mArrow->getSize().getWidth() - + PixelDensity::dpToPx( mArrow->getLayoutMargin().Right ), 0 ); mArrow->centerVertical(); } @@ -61,6 +62,10 @@ void UIMenuSubMenu::onAlphaChange() { mArrow->setAlpha( mAlpha ); } +UIWidget* UIMenuSubMenu::getExtraInnerWidget() { + return mArrow; +} + void UIMenuSubMenu::onStateChange() { UIMenuItem::onStateChange(); diff --git a/src/eepp/ui/uinode.cpp b/src/eepp/ui/uinode.cpp index 66fac1e14..504fb3185 100644 --- a/src/eepp/ui/uinode.cpp +++ b/src/eepp/ui/uinode.cpp @@ -929,9 +929,9 @@ Sizef UINode::getSkinSize( UISkin* Skin, const Uint32& State ) const { return Sizef::Zero; } -Sizef UINode::getSkinSize() const { +Sizef UINode::getSkinSize( const Uint32& state ) const { if ( NULL != getSkin() ) { - return getSkin()->getSize(); + return getSkin()->getSize( state ); } return Sizef::Zero; @@ -1124,6 +1124,7 @@ Float UINode::getPropertyRelativeTargetContainerLength( case PropertyRelativeTarget::LocalBlockRadiusHeight: containerLength = getPixelsSize().getHeight() * 0.5f; break; + case PropertyRelativeTarget::None: default: break; } diff --git a/src/eepp/ui/uiprogressbar.cpp b/src/eepp/ui/uiprogressbar.cpp index 13340c43d..82c13903a 100644 --- a/src/eepp/ui/uiprogressbar.cpp +++ b/src/eepp/ui/uiprogressbar.cpp @@ -211,8 +211,8 @@ std::string UIProgressBar::getPropertyString( const PropertyDefinition* property case PropertyId::DisplayPercent: return mStyleConfig.DisplayPercent ? "true" : "false"; case PropertyId::MovementSpeed: - return String::fromFloat( getMovementSpeed().x ) + " " + - String::fromFloat( getMovementSpeed().y ); + return String::fromFloat( getMovementSpeed().x, "px" ) + " " + + String::fromFloat( getMovementSpeed().y, "px" ); default: return UIWidget::getPropertyString( propertyDef, propertyIndex ); } @@ -236,7 +236,7 @@ bool UIProgressBar::applyProperty( const StyleSheetProperty& attribute ) { setDisplayPercent( attribute.asBool() ); break; case PropertyId::MovementSpeed: - setMovementSpeed( attribute.asVector2f() ); + setMovementSpeed( attribute.asVector2f( this ) ); break; default: return UIWidget::applyProperty( attribute ); diff --git a/src/eepp/ui/uipushbutton.cpp b/src/eepp/ui/uipushbutton.cpp index c918a8f6c..3e829fabd 100644 --- a/src/eepp/ui/uipushbutton.cpp +++ b/src/eepp/ui/uipushbutton.cpp @@ -15,7 +15,7 @@ UIPushButton::UIPushButton( const std::string& tag ) : UIWidget( tag ), mIcon( NULL ), mTextBox( NULL ) { mFlags |= ( UI_AUTO_SIZE | UI_VALIGN_CENTER | UI_HALIGN_CENTER ); - mIcon = UIImage::NewWithTag( "pushbutton::image" ); + mIcon = UIImage::NewWithTag( "pushbutton::icon" ); mIcon->setScaleType( UIScaleType::FitInside ) ->setLayoutSizeRules( LayoutSizeRule::Fixed, LayoutSizeRule::Fixed ) ->setFlags( UI_VALIGN_CENTER | UI_HALIGN_CENTER ) @@ -23,21 +23,31 @@ UIPushButton::UIPushButton( const std::string& tag ) : ->setVisible( true ) ->setEnabled( false ); - mTextBox = UITextView::NewWithTag( "pushbutton::text" ); - mTextBox->setLayoutSizeRules( LayoutSizeRule::WrapContent, LayoutSizeRule::WrapContent ) - ->setFlags( UI_VALIGN_CENTER | UI_HALIGN_CENTER ) - ->setParent( this ) - ->setVisible( true ) - ->setEnabled( false ); - auto cb = [&]( const Event* event ) { onSizeChange(); notifyLayoutAttrChange(); }; + + mIcon->addEventListener( Event::OnPaddingChange, cb ); + mIcon->addEventListener( Event::OnMarginChange, cb ); + mIcon->addEventListener( Event::OnSizeChange, cb ); + + mTextBox = UITextView::NewWithTag( "pushbutton::text" ); + mTextBox->setLayoutSizeRules( LayoutSizeRule::WrapContent, LayoutSizeRule::WrapContent ) + ->setFlags( UI_VALIGN_CENTER | UI_HALIGN_CENTER ) + ->setParent( this ) + ->setVisible( true ) + ->setEnabled( false ); mTextBox->addEventListener( Event::OnFontChanged, cb ); mTextBox->addEventListener( Event::OnFontStyleChanged, cb ); mTextBox->addEventListener( Event::OnTextChanged, cb ); + if ( NULL != getExtraInnerWidget() ) { + getExtraInnerWidget()->addEventListener( Event::OnPaddingChange, cb ); + getExtraInnerWidget()->addEventListener( Event::OnMarginChange, cb ); + getExtraInnerWidget()->addEventListener( Event::OnSizeChange, cb ); + } + onSizeChange(); applyDefaultTheme(); @@ -56,25 +66,36 @@ bool UIPushButton::isType( const Uint32& type ) const { } void UIPushButton::onAutoSize() { - if ( ( mFlags & UI_AUTO_SIZE ) && NULL != getSkin() ) { + if ( ( ( mFlags & UI_AUTO_SIZE ) && 0 == getSize().getHeight() ) || + mLayoutHeightRule == LayoutSizeRule::WrapContent ) { + Float sH = getSkinSize().getHeight(); + Float sHS = getSkinSize( UIState::StateFlagSelected ).getHeight(); + Float tH = mTextBox->getPixelsSize().getHeight(); + Float eH = + NULL != getExtraInnerWidget() ? getExtraInnerWidget()->getPixelsSize().getHeight() : 0; + Float h = eemax( eemax( PixelDensity::dpToPx( eemax( sH, sHS ) ), tH ), eH ); + setInternalPixelsHeight( h + mRealPadding.Top + mRealPadding.Bottom ); + } else if ( ( mFlags & UI_AUTO_SIZE ) && NULL != getSkin() ) { setInternalHeight( getSkinSize().getHeight() ); } - if ( ( mFlags & UI_AUTO_SIZE ) && - ( 0 == getSize().getHeight() || mLayoutHeightRule == LayoutSizeRule::WrapContent ) ) { - Float h = eemax( PixelDensity::dpToPx( getSkinSize().getHeight() ), - mTextBox->getTextHeight() ); - - setInternalPixelsHeight( h + mRealPadding.Top + mRealPadding.Bottom ); - } - if ( ( mFlags & UI_AUTO_SIZE ) || mLayoutWidthRule == LayoutSizeRule::WrapContent ) { - Int32 txtW = NULL != mTextBox ? mTextBox->getTextWidth() : 0; + Int32 txtW = mTextBox->getPixelsSize().getWidth(); + Int32 iconSize = mIcon->getPixelsSize().getWidth() > 0 + ? mIcon->getPixelsSize().getWidth() + + PixelDensity::dpToPxI( mIcon->getLayoutMargin().Left + + mIcon->getLayoutMargin().Right ) + : 0; + + UIWidget* eWidget = getExtraInnerWidget(); + Int32 eWidgetSize = NULL != eWidget + ? PixelDensity::dpToPxI( eWidget->getSize().getWidth() + + eWidget->getLayoutMargin().Left + + eWidget->getLayoutMargin().Right ) + : 0; Int32 minSize = - txtW + ( NULL != mIcon ? mIcon->getPixelsSize().getWidth() : 0 ) + - PixelDensity::dpToPxI( mStyleConfig.IconHorizontalMargin ) + mRealPadding.Left + - mRealPadding.Right + + txtW + iconSize + eWidgetSize + mRealPadding.Left + mRealPadding.Right + ( NULL != getSkin() ? PixelDensity::dpToPxI( getSkin()->getBorderSize().Left + getSkin()->getBorderSize().Right ) : 0 ); @@ -109,54 +130,90 @@ void UIPushButton::onSizeChange() { if ( mRealPadding.Right > autoPadding.Right ) autoPadding.Right = mRealPadding.Right; - mIcon->setPixelsPosition( autoPadding.Left + mStyleConfig.IconHorizontalMargin, 0 ); - mIcon->centerVertical(); + Vector2f position; + Vector2f iconPos; + Vector2f ePos; + UIWidget* eWidget = getExtraInnerWidget(); - if ( NULL != mTextBox ) { - Vector2f position; + Float iconWidth = mIcon->getPixelsSize().getWidth() > 0 + ? mIcon->getPixelsSize().getWidth() + + PixelDensity::dpToPxI( mIcon->getLayoutMargin().Left + + mIcon->getLayoutMargin().Right ) + : 0; + Float eWidth = NULL != eWidget && eWidget->getPixelsSize().getWidth() > 0 + ? eWidget->getPixelsSize().getWidth() + + PixelDensity::dpToPxI( eWidget->getLayoutMargin().Left + + eWidget->getLayoutMargin().Right ) + : 0; + Float textBoxWidth = mTextBox->getPixelsSize().getWidth(); + Float totalWidth = textBoxWidth + iconWidth + eWidth; - switch ( Font::getVerticalAlign( getFlags() ) ) { - case UI_VALIGN_CENTER: - position.y = ( mSize.getHeight() - mTextBox->getPixelsSize().getHeight() ) / 2; - break; - case UI_VALIGN_BOTTOM: - position.y = mSize.y - mTextBox->getPixelsSize().getHeight() - autoPadding.Bottom; - break; - case UI_VALIGN_TOP: - position.y = autoPadding.Top; - break; - } - - switch ( Font::getHorizontalAlign( getFlags() ) ) { - case UI_HALIGN_RIGHT: - position.x = - mSize.getWidth() - mTextBox->getPixelsSize().getWidth() - autoPadding.Right; - break; - case UI_HALIGN_CENTER: - position.x = ( mSize.getWidth() - mTextBox->getPixelsSize().getWidth() ) / 2; - - if ( NULL != mIcon->getDrawable() ) { - Uint32 iconPos = - mIcon->getPixelsPosition().x + mIcon->getPixelsSize().getWidth(); - - if ( iconPos >= position.x ) { - Float px = PixelDensity::dpToPx( 1 ); - - position.x = iconPos + px; - } - } - - break; - case UI_HALIGN_LEFT: - position.x = mIcon->getPixelsPosition().x + mIcon->getPixelsSize().getWidth(); - break; - } - - mTextBox->setPixelsPosition( position ); + switch ( Font::getVerticalAlign( getFlags() ) ) { + case UI_VALIGN_CENTER: + iconPos.y = + eefloor( ( mSize.getHeight() - mIcon->getPixelsSize().getHeight() ) * 0.5f ); + position.y = + eefloor( ( mSize.getHeight() - mTextBox->getPixelsSize().getHeight() ) * 0.5f ); + ePos.y = + NULL != eWidget + ? eefloor( ( mSize.getHeight() - eWidget->getPixelsSize().getHeight() ) * 0.5f ) + : 0; + break; + case UI_VALIGN_BOTTOM: + iconPos.y = mSize.y - mIcon->getPixelsSize().getHeight() - autoPadding.Bottom; + position.y = mSize.y - mTextBox->getPixelsSize().getHeight() - autoPadding.Bottom; + ePos.y = NULL != eWidget + ? mSize.y - eWidget->getPixelsSize().getHeight() - autoPadding.Bottom + : 0; + break; + case UI_VALIGN_TOP: + iconPos.y = autoPadding.Top; + position.y = autoPadding.Top; + ePos.y = autoPadding.Top; + break; } - if ( NULL != mTextBox && mTextBox->getText().empty() ) { - mIcon->center(); + switch ( Font::getHorizontalAlign( getFlags() ) ) { + case UI_HALIGN_RIGHT: + position.x = mSize.getWidth() - autoPadding.Right; + ePos.x = position.x; + + if ( NULL != eWidget ) { + ePos.x = position.x - PixelDensity::dpToPx( eWidget->getLayoutMargin().Right ) - + eWidget->getPixelsSize().getWidth(); + position.x = ePos.x - PixelDensity::dpToPx( eWidget->getLayoutMargin().Left ); + } + + position.x -= textBoxWidth; + + iconPos.x = position.x - PixelDensity::dpToPxI( mIcon->getLayoutMargin().Right ) - + mIcon->getPixelsSize().getWidth(); + break; + case UI_HALIGN_CENTER: + position.x = ( mSize.getWidth() - totalWidth ) / 2 + iconWidth; + iconPos.x = ( mSize.getWidth() - totalWidth ) / 2 + + PixelDensity::dpToPxI( mIcon->getLayoutMargin().Left ); + + if ( NULL != eWidget ) { + ePos.x = position.x + textBoxWidth + + PixelDensity::dpToPx( eWidget->getLayoutMargin().Left ); + } + break; + case UI_HALIGN_LEFT: + position.x = autoPadding.Left + iconWidth; + iconPos.x = autoPadding.Left + PixelDensity::dpToPxI( mIcon->getLayoutMargin().Left ); + + if ( NULL != eWidget ) { + ePos.x = position.x + textBoxWidth + + PixelDensity::dpToPx( eWidget->getLayoutMargin().Left ); + } + break; + } + + mTextBox->setPixelsPosition( position ); + mIcon->setPixelsPosition( iconPos ); + if ( NULL != eWidget ) { + eWidget->setPixelsPosition( ePos ); } } @@ -168,9 +225,7 @@ void UIPushButton::setTheme( UITheme* Theme ) { } void UIPushButton::onThemeLoaded() { - autoIconHorizontalMargin(); - - onAutoSize(); + onSizeChange(); UIWidget::onThemeLoaded(); } @@ -195,15 +250,6 @@ const String& UIPushButton::getText() { return mTextBox->getText(); } -void UIPushButton::setIconHorizontalMargin( Int32 margin ) { - mStyleConfig.IconHorizontalMargin = margin; - onSizeChange(); -} - -const Int32& UIPushButton::getIconHorizontalMargin() const { - return mStyleConfig.IconHorizontalMargin; -} - UITextView* UIPushButton::getTextBox() const { return mTextBox; } @@ -213,6 +259,10 @@ void UIPushButton::onAlphaChange() { mIcon->setAlpha( mAlpha ); mTextBox->setAlpha( mAlpha ); + + if ( NULL != getExtraInnerWidget() ) { + getExtraInnerWidget()->setAlpha( mAlpha ); + } } void UIPushButton::onStateChange() { @@ -233,7 +283,6 @@ Uint32 UIPushButton::onKeyDown( const KeyEvent& Event ) { NodeMessage Msg( this, NodeMessage::Click, EE_BUTTON_LMASK ); messagePost( &Msg ); onMouseClick( Vector2i( 0, 0 ), EE_BUTTON_LMASK ); - pushState( UIState::StatePressed ); } @@ -248,37 +297,23 @@ Uint32 UIPushButton::onKeyUp( const KeyEvent& Event ) { return UIWidget::onKeyUp( Event ); } -void UIPushButton::autoIconHorizontalMargin() { - if ( mStyleConfig.IconAutoMargin ) { - Rectf RMargin = makePadding( true, false, false, false, true ); - setIconHorizontalMargin( RMargin.Left ); - } -} - -const UIPushButton::StyleConfig& UIPushButton::getStyleConfig() const { - return mStyleConfig; -} - void UIPushButton::setIconMinimumSize( const Sizei& minIconSize ) { - if ( minIconSize != mStyleConfig.IconMinSize ) { - mStyleConfig.IconMinSize = minIconSize; + if ( minIconSize != mIconMinSize ) { + mIconMinSize = minIconSize; - if ( mStyleConfig.IconMinSize.x != 0 && mStyleConfig.IconMinSize.y != 0 ) { - Sizef minSize( eemax( getSize().getWidth(), (Float)mStyleConfig.IconMinSize.x ), - eemax( getSize().getHeight(), (Float)mStyleConfig.IconMinSize.y ) ); - - if ( minSize != getSize() ) { - mIcon->setSize( minSize ); - onSizeChange(); - } + if ( mIconMinSize.x != 0 && mIconMinSize.y != 0 ) { + mIcon->setMinSizeEq( String::fromFloat( mIconMinSize.x, "dp" ), + String::fromFloat( mIconMinSize.y, "dp" ) ); } } } -void UIPushButton::setStyleConfig( const StyleConfig& styleConfig ) { - setIconMinimumSize( styleConfig.IconMinSize ); - mStyleConfig = styleConfig; - onStateChange(); +const Sizei& UIPushButton::getIconMinimumSize() const { + return mIconMinSize; +} + +UIWidget* UIPushButton::getExtraInnerWidget() { + return NULL; } std::string UIPushButton::getPropertyString( const PropertyDefinition* propertyDef, @@ -293,12 +328,8 @@ std::string UIPushButton::getPropertyString( const PropertyDefinition* propertyD // TODO: Implement icon return ""; case PropertyId::MinIconSize: - return String::format( "%ddp", mStyleConfig.IconMinSize.getWidth() ) + " " + - String::format( "%ddp", mStyleConfig.IconMinSize.getHeight() ); - case PropertyId::IconHorizontalMargin: - return String::format( "%ddp", mStyleConfig.IconHorizontalMargin ); - case PropertyId::IconAutoMargin: - return mStyleConfig.IconAutoMargin ? "true" : "false"; + return String::format( "%ddp", mIconMinSize.getWidth() ) + " " + + String::format( "%ddp", mIconMinSize.getHeight() ); case PropertyId::Color: case PropertyId::ShadowColor: case PropertyId::SelectedColor: @@ -344,12 +375,6 @@ bool UIPushButton::applyProperty( const StyleSheetProperty& attribute ) { case PropertyId::MinIconSize: setIconMinimumSize( attribute.asSizei() ); break; - case PropertyId::IconHorizontalMargin: - setIconHorizontalMargin( attribute.asDpDimensionI( this ) ); - break; - case PropertyId::IconAutoMargin: - mStyleConfig.IconAutoMargin = attribute.asBool(); - break; case PropertyId::Color: case PropertyId::ShadowColor: case PropertyId::SelectedColor: diff --git a/src/eepp/ui/uitab.cpp b/src/eepp/ui/uitab.cpp index 4655959b2..615c45859 100644 --- a/src/eepp/ui/uitab.cpp +++ b/src/eepp/ui/uitab.cpp @@ -116,9 +116,11 @@ UIPushButton* UITab::setText( const String& text ) { void UITab::onAutoSize() { if ( mFlags & UI_AUTO_SIZE ) { - Uint32 w = PixelDensity::pxToDpI( mTextBox->getTextWidth() ) + - mStyleConfig.IconHorizontalMargin + - ( NULL != mIcon ? mIcon->getSize().getWidth() : 0 ) + getSkinSize().getWidth(); + Uint32 w = mTextBox->getSize().getWidth() + + ( NULL != mIcon ? mIcon->getSize().getWidth() + mIcon->getLayoutMargin().Left + + mIcon->getLayoutMargin().Right + : 0 ) + + getSkinSize().getWidth(); UITabWidget* tTabW = getTabWidget(); @@ -138,7 +140,6 @@ std::string UITab::getPropertyString( const PropertyDefinition* propertyDef, switch ( propertyDef->getPropertyId() ) { case PropertyId::Text: - case PropertyId::Name: return getText().toUtf8(); case PropertyId::Owns: return mOwnedName; @@ -153,7 +154,6 @@ bool UITab::applyProperty( const StyleSheetProperty& attribute ) { switch ( attribute.getPropertyDefinition()->getPropertyId() ) { case PropertyId::Text: - case PropertyId::Name: if ( NULL != mSceneNode && mSceneNode->isUISceneNode() ) setText( static_cast( mSceneNode ) ->getTranslatorString( attribute.asString() ) ); diff --git a/src/eepp/ui/uitabwidget.cpp b/src/eepp/ui/uitabwidget.cpp index 24e27a4da..dbad77a6e 100644 --- a/src/eepp/ui/uitabwidget.cpp +++ b/src/eepp/ui/uitabwidget.cpp @@ -14,7 +14,11 @@ UITabWidget* UITabWidget::New() { } UITabWidget::UITabWidget() : - UIWidget( "tabwidget" ), mTabSelected( NULL ), mTabSelectedIndex( eeINDEX_NOT_FOUND ) { + UIWidget( "tabwidget" ), + mCtrlContainer( NULL ), + mTabContainer( NULL ), + mTabSelected( NULL ), + mTabSelectedIndex( eeINDEX_NOT_FOUND ) { setHorizontalAlign( UI_HALIGN_CENTER ); mTabContainer = UIWidget::NewWithTag( "tabwidget::tabcontainer" ); @@ -172,7 +176,7 @@ bool UITabWidget::applyProperty( const StyleSheetProperty& attribute ) { setSpecialBorderTabs( attribute.asBool() ); break; case PropertyId::TabSeparation: - setTabSeparation( attribute.asDpDimensionI() ); + setTabSeparation( attribute.asDpDimensionI( this ) ); break; default: return UIWidget::applyProperty( attribute ); diff --git a/src/eepp/ui/uitextinput.cpp b/src/eepp/ui/uitextinput.cpp index 845d41169..7765db02b 100644 --- a/src/eepp/ui/uitextinput.cpp +++ b/src/eepp/ui/uitextinput.cpp @@ -459,7 +459,7 @@ std::string UITextInput::getPropertyString( const PropertyDefinition* propertyDe return String::toStr( getMaxLength() ); case PropertyId::FreeEditing: return isFreeEditingEnabled() ? "true" : "false"; - case PropertyId::OnlyNumbers: + case PropertyId::Numeric: return getInputTextBuffer()->onlyNumbersAllowed() ? "true" : "false"; case PropertyId::AllowFloat: return getInputTextBuffer()->dotsInNumbersAllowed() ? "true" : "false"; @@ -502,7 +502,7 @@ bool UITextInput::applyProperty( const StyleSheetProperty& attribute ) { case PropertyId::FreeEditing: setFreeEditing( attribute.asBool() ); break; - case PropertyId::OnlyNumbers: + case PropertyId::Numeric: getInputTextBuffer()->setAllowOnlyNumbers( attribute.asBool(), getInputTextBuffer()->dotsInNumbersAllowed() ); break; diff --git a/src/eepp/ui/uiwidget.cpp b/src/eepp/ui/uiwidget.cpp index cda1542c1..606292a08 100644 --- a/src/eepp/ui/uiwidget.cpp +++ b/src/eepp/ui/uiwidget.cpp @@ -338,9 +338,6 @@ String UIWidget::getTooltipText() { } void UIWidget::tooltipRemove() { - if ( NULL != mTooltip ) { - mTooltip->close(); - } mTooltip = NULL; } @@ -576,6 +573,14 @@ 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; + setSize( mSize ); + } +} + void UIWidget::setMinWidthEq( const std::string& minWidthEq ) { if ( mMinWidthEq != minWidthEq ) { mMinWidthEq = minWidthEq; @@ -598,6 +603,14 @@ 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( mSize ); + } +} + void UIWidget::setMaxWidthEq( const std::string& maxWidthEq ) { if ( mMaxWidthEq != maxWidthEq ) { mMaxWidthEq = maxWidthEq; @@ -1674,7 +1687,7 @@ std::string UIWidget::getFlagsString() const { if ( mFlags & UI_AUTO_SIZE ) flagvec.push_back( "autosize" ); if ( mFlags & UI_MULTI_SELECT ) - flagvec.push_back( "multi" ); + flagvec.push_back( "multiselect" ); if ( mFlags & UI_AUTO_PADDING ) flagvec.push_back( "autopadding" ); if ( reportSizeChangeToChilds() ) diff --git a/src/eepp/ui/uiwinmenu.cpp b/src/eepp/ui/uiwinmenu.cpp index 62aceb844..c423920dc 100644 --- a/src/eepp/ui/uiwinmenu.cpp +++ b/src/eepp/ui/uiwinmenu.cpp @@ -41,12 +41,8 @@ void UIWinMenu::addMenuButton( const String& ButtonText, UIPopUpMenu* Menu ) { Button->setText( ButtonText ); Button->setVisible( true ); Button->setEnabled( true ); - Button->addEventListener( Event::OnSizeChange, [&]( const Event* event) { - refreshButtons(); - } ); - - if ( NULL != mTheme ) - Button->setThemeSkin( mTheme, "winmenubutton" ); + Button->addEventListener( Event::OnSizeChange, + [&]( const Event* event ) { refreshButtons(); } ); Menu->setVisible( false ); Menu->setEnabled( false ); @@ -57,6 +53,9 @@ void UIWinMenu::addMenuButton( const String& ButtonText, UIPopUpMenu* Menu ) { mButtons.push_back( std::make_pair( Button, Menu ) ); + if ( NULL != mTheme ) + Button->setThemeSkin( mTheme, "winmenubutton" ); + refreshButtons(); } @@ -125,33 +124,22 @@ void UIWinMenu::setMenuHeight( const Uint32& menuHeight ) { } void UIWinMenu::refreshButtons() { - Int32 h = 0, th = 0, ycenter = 0; + Int32 ycenter = 0; - UISkin* skin = getSkin(); - - if ( NULL != skin ) { - h = getSize().getHeight(); - - if ( !mButtons.empty() ) { - UISelectButton* tbut = mButtons.begin()->first; - - skin = tbut->getSkin(); - - if ( NULL != skin ) { - th = skin->getSize( UIState::StateFlagSelected ).getHeight(); - - switch ( Font::getVerticalAlign( getFlags() ) ) { - case UI_VALIGN_CENTER: - ycenter = ( h - th ) / 2; - break; - case UI_VALIGN_BOTTOM: - ycenter = ( h - th ); - break; - case UI_VALIGN_TOP: - ycenter = 0; - break; - } - } + if ( !mButtons.empty() ) { + UISelectButton* tbut = mButtons.begin()->first; + Float h = mSize.getHeight(); + Float th = tbut->getPixelsSize().getHeight(); + switch ( Font::getVerticalAlign( getFlags() ) ) { + case UI_VALIGN_CENTER: + ycenter = eefloor( ( h - th ) / 2 ); + break; + case UI_VALIGN_BOTTOM: + ycenter = ( h - th ); + break; + case UI_VALIGN_TOP: + ycenter = 0; + break; } }