From 19310bb976400a809b4547de35f9198b5f9dd838 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADn=20Lucas=20Golini?= Date: Thu, 10 Aug 2017 01:12:29 -0300 Subject: [PATCH] Added ScrollBarType. --HG-- branch : dev --- include/eepp/ui/uiscrollbar.hpp | 11 +++++ include/eepp/ui/uitable.hpp | 2 + projects/linux/ee.creator.user | 10 +---- src/eepp/ui/uilistbox.cpp | 11 +++++ src/eepp/ui/uiscrollbar.cpp | 71 ++++++++++++++++++++++++++------- src/eepp/ui/uiscrollview.cpp | 11 +++++ src/eepp/ui/uitable.cpp | 46 +++++++++++++++++++++ src/test/eetest.cpp | 4 +- 8 files changed, 140 insertions(+), 26 deletions(-) diff --git a/include/eepp/ui/uiscrollbar.hpp b/include/eepp/ui/uiscrollbar.hpp index 2c66288c7..8d304961e 100644 --- a/include/eepp/ui/uiscrollbar.hpp +++ b/include/eepp/ui/uiscrollbar.hpp @@ -8,6 +8,11 @@ namespace EE { namespace UI { class EE_API UIScrollBar : public UIWidget { public: + enum ScrollBarType { + TwoButtons, + NoButtons + }; + static UIScrollBar * New( const UI_ORIENTATION & orientation = UI_VERTICAL ); UIScrollBar( const UI_ORIENTATION& orientation = UI_VERTICAL ); @@ -54,12 +59,18 @@ class EE_API UIScrollBar : public UIWidget { UIControl * setOrientation( const UI_ORIENTATION & orientation ); + ScrollBarType getScrollBarType() const; + + void setScrollBarType(const ScrollBarType & scrollBarType); + bool getExpandBackground() const; void setExpandBackground( bool expandBackground ); virtual void loadFromXmlNode( const pugi::xml_node& node ); + protected: + ScrollBarType mScrollBarType; UISlider * mSlider; UIControlAnim * mBtnUp; UIControlAnim * mBtnDown; diff --git a/include/eepp/ui/uitable.hpp b/include/eepp/ui/uitable.hpp index d1f6742e9..8cedb105b 100644 --- a/include/eepp/ui/uitable.hpp +++ b/include/eepp/ui/uitable.hpp @@ -78,6 +78,8 @@ class EE_API UITable : public UITouchDragableWidget { Rect getContainerPadding() const; void setContainerPadding( const Rect & containerPadding); + + void loadFromXmlNode(const pugi::xml_node & node); protected: friend class UIItemContainer; friend class UITableCell; diff --git a/projects/linux/ee.creator.user b/projects/linux/ee.creator.user index d0a7cabc3..37554de41 100644 --- a/projects/linux/ee.creator.user +++ b/projects/linux/ee.creator.user @@ -1,6 +1,6 @@ - + EnvironmentId @@ -28,13 +28,7 @@ QmlJSGlobal - - Nim - - NimGlobal - - - 3 + 2 UTF-8 false 4 diff --git a/src/eepp/ui/uilistbox.cpp b/src/eepp/ui/uilistbox.cpp index cf1fce01c..01a903ecb 100644 --- a/src/eepp/ui/uilistbox.cpp +++ b/src/eepp/ui/uilistbox.cpp @@ -1032,6 +1032,17 @@ void UIListBox::loadFromXmlNode(const pugi::xml_node & node) { setSelected( ait->as_uint() ); } else if ( "selectedtext" == name ) { setSelected( ait->as_string() ); + } else if ( "scrollbartype" == name ) { + std::string val( ait->as_string() ); + String::toLowerInPlace( val ); + + if ( "nobuttons" == val ) { + mVScrollBar->setScrollBarType( UIScrollBar::NoButtons ); + mHScrollBar->setScrollBarType( UIScrollBar::NoButtons ); + } else if ( "twobuttons" == val ) { + mVScrollBar->setScrollBarType( UIScrollBar::TwoButtons ); + mHScrollBar->setScrollBarType( UIScrollBar::NoButtons ); + } } } } diff --git a/src/eepp/ui/uiscrollbar.cpp b/src/eepp/ui/uiscrollbar.cpp index c7a4a02ef..143291f96 100644 --- a/src/eepp/ui/uiscrollbar.cpp +++ b/src/eepp/ui/uiscrollbar.cpp @@ -9,7 +9,12 @@ UIScrollBar * UIScrollBar::New( const UI_ORIENTATION& orientation ) { } UIScrollBar::UIScrollBar( const UI_ORIENTATION& orientation ) : - UIWidget() + UIWidget(), +#ifdef EE_PLATFORM_TOUCH + mScrollBarType( NoButtons ) +#else + mScrollBarType( TwoButtons ) +#endif { mFlags |= UI_AUTO_SIZE; @@ -115,22 +120,46 @@ void UIScrollBar::adjustChilds() { mBtnUp->setPosition( 0, 0 ); - if ( !isVertical() ) { - mBtnDown->setPosition( mSize.getWidth() - mBtnDown->getSize().getWidth(), 0 ); - mSlider->setSize( mSize.getWidth() - mBtnDown->getSize().getWidth() - mBtnUp->getSize().getWidth(), mSize.getHeight() ); - mSlider->setPosition( mBtnUp->getSize().getWidth(), 0 ); + switch ( mScrollBarType ) { + case NoButtons: + { + mBtnDown->setVisible( false )->setEnabled( false ); + mBtnUp->setVisible( false )->setEnabled( false ); - mBtnDown->centerVertical(); - mBtnUp->centerVertical(); - mSlider->centerVertical(); - } else { - mBtnDown->setPosition( 0, mSize.getHeight() - mBtnDown->getSize().getHeight() ); - mSlider->setSize( mSize.getWidth(), mSize.getHeight() - mBtnDown->getSize().getHeight() - mBtnUp->getSize().getHeight() ); - mSlider->setPosition( 0, mBtnUp->getSize().getHeight() ); + if ( !isVertical() ) { + mSlider->setSize( mSize )->setPosition( 0, 0 )->centerVertical(); + } else { + mSlider->setSize( mSize )->setPosition( 0, 0 )->centerHorizontal(); + } - mBtnDown->centerHorizontal(); - mBtnUp->centerHorizontal(); - mSlider->centerHorizontal(); + break; + } + case TwoButtons: + default: + { + mBtnDown->setVisible( true )->setEnabled( true ); + mBtnUp->setVisible( true )->setEnabled( true ); + + if ( !isVertical() ) { + mBtnDown->setPosition( mSize.getWidth() - mBtnDown->getSize().getWidth(), 0 ); + mSlider->setSize( mSize.getWidth() - mBtnDown->getSize().getWidth() - mBtnUp->getSize().getWidth(), mSize.getHeight() ); + mSlider->setPosition( mBtnUp->getSize().getWidth(), 0 ); + + mBtnDown->centerVertical(); + mBtnUp->centerVertical(); + mSlider->centerVertical(); + } else { + mBtnDown->setPosition( 0, mSize.getHeight() - mBtnDown->getSize().getHeight() ); + mSlider->setSize( mSize.getWidth(), mSize.getHeight() - mBtnDown->getSize().getHeight() - mBtnUp->getSize().getHeight() ); + mSlider->setPosition( 0, mBtnUp->getSize().getHeight() ); + + mBtnDown->centerHorizontal(); + mBtnUp->centerHorizontal(); + mSlider->centerHorizontal(); + } + + break; + } } } @@ -246,6 +275,18 @@ void UIScrollBar::loadFromXmlNode(const pugi::xml_node & node) { mSlider->loadFromXmlNode( node ); } +UIScrollBar::ScrollBarType UIScrollBar::getScrollBarType() const { + return mScrollBarType; +} + +void UIScrollBar::setScrollBarType( const ScrollBarType & scrollBarType ) { + if ( mScrollBarType != scrollBarType ) { + mScrollBarType = scrollBarType; + + adjustChilds(); + } +} + UI_ORIENTATION UIScrollBar::getOrientation() const { return mSlider->getOrientation(); } diff --git a/src/eepp/ui/uiscrollview.cpp b/src/eepp/ui/uiscrollview.cpp index 25fd18c75..36a93c8d7 100644 --- a/src/eepp/ui/uiscrollview.cpp +++ b/src/eepp/ui/uiscrollview.cpp @@ -242,6 +242,17 @@ void UIScrollView::loadFromXmlNode( const pugi::xml_node& node ) { if ( "on" == val ) setHorizontalScrollMode( UI_SCROLLBAR_ALWAYS_ON ); else if ( "off" == val ) setHorizontalScrollMode( UI_SCROLLBAR_ALWAYS_ON ); else if ( "auto" == val ) setHorizontalScrollMode( UI_SCROLLBAR_AUTO ); + } else if ( "scrollbartype" == name ) { + std::string val( ait->as_string() ); + String::toLowerInPlace( val ); + + if ( "nobuttons" == val ) { + mVScroll->setScrollBarType( UIScrollBar::NoButtons ); + mHScroll->setScrollBarType( UIScrollBar::NoButtons ); + } else if ( "twobuttons" == val ) { + mVScroll->setScrollBarType( UIScrollBar::TwoButtons ); + mHScroll->setScrollBarType( UIScrollBar::NoButtons ); + } } } } diff --git a/src/eepp/ui/uitable.cpp b/src/eepp/ui/uitable.cpp index c7be6d461..4bfd4457d 100644 --- a/src/eepp/ui/uitable.cpp +++ b/src/eepp/ui/uitable.cpp @@ -1,5 +1,6 @@ #include #include +#include namespace EE { namespace UI { @@ -616,4 +617,49 @@ bool UITable::isTouchOverAllowedChilds() { return isMouseOverMeOrChilds() && !mVScrollBar->isMouseOverMeOrChilds() && !mHScrollBar->isMouseOverMeOrChilds(); } +void UITable::loadFromXmlNode(const pugi::xml_node & node) { + UITouchDragableWidget::loadFromXmlNode( node ); + + for (pugi::xml_attribute_iterator ait = node.attributes_begin(); ait != node.attributes_end(); ++ait) { + std::string name = ait->name(); + String::toLowerInPlace( name ); + + if ( "rowheight" == name ) { + setRowHeight( ait->as_int() ); + } else if ( "padding" == name ) { + int val = ait->as_int(); + setContainerPadding( Rect( val, val, val, val ) ); + } else if ( "paddingleft" == name ) { + setContainerPadding( Rect( ait->as_int(), mContainerPadding.Top, mContainerPadding.Right, mContainerPadding.Bottom ) ); + } else if ( "paddingright" == name ) { + setContainerPadding( Rect( mContainerPadding.Left, mContainerPadding.Top, ait->as_int(), mContainerPadding.Bottom ) ); + } else if ( "paddingtop" == name ) { + setContainerPadding( Rect( mContainerPadding.Left, ait->as_int(), mContainerPadding.Right, mContainerPadding.Bottom ) ); + } else if ( "paddingbottom" == name ) { + setContainerPadding( Rect( mContainerPadding.Left, mContainerPadding.Top, mContainerPadding.Right, ait->as_int() ) ); + } else if ( "verticalscrollmode" == name || "vscrollmode" == name ) { + std::string val = ait->as_string(); + if ( "auto" == val ) setVerticalScrollMode( UI_SCROLLBAR_AUTO ); + else if ( "on" == val ) setVerticalScrollMode( UI_SCROLLBAR_ALWAYS_ON ); + else if ( "off" == val ) setVerticalScrollMode( UI_SCROLLBAR_ALWAYS_OFF ); + } else if ( "horizontalscrollmode" == name || "hscrollmode" == name ) { + std::string val = ait->as_string(); + if ( "auto" == val ) setHorizontalScrollMode( UI_SCROLLBAR_AUTO ); + else if ( "on" == val ) setHorizontalScrollMode( UI_SCROLLBAR_ALWAYS_ON ); + else if ( "off" == val ) setHorizontalScrollMode( UI_SCROLLBAR_ALWAYS_OFF ); + } else if ( "scrollbartype" == name ) { + std::string val( ait->as_string() ); + String::toLowerInPlace( val ); + + if ( "nobuttons" == val ) { + mVScrollBar->setScrollBarType( UIScrollBar::NoButtons ); + mHScrollBar->setScrollBarType( UIScrollBar::NoButtons ); + } else if ( "twobuttons" == val ) { + mVScrollBar->setScrollBarType( UIScrollBar::TwoButtons ); + mHScrollBar->setScrollBarType( UIScrollBar::NoButtons ); + } + } + } +} + }} diff --git a/src/test/eetest.cpp b/src/test/eetest.cpp index 320219cef..c40aa5bc8 100644 --- a/src/test/eetest.cpp +++ b/src/test/eetest.cpp @@ -278,10 +278,8 @@ void EETest::createUI() { mThemeName = "uitheme"; - if ( PixelDensity::getPixelDensity() >= 2 ) { + if ( PixelDensity::getPixelDensity() >= 1.1 ) { mThemeName += "2x"; - } else if ( PixelDensity::getPixelDensity() >= 1.1 ) { - //mThemeName += "1.5x"; } createUIThemeTextureAtlas();