diff --git a/bin/assets/ui/uitheme.eta b/bin/assets/ui/uitheme.eta index fde209ad9..362d007d1 100644 Binary files a/bin/assets/ui/uitheme.eta and b/bin/assets/ui/uitheme.eta differ diff --git a/bin/assets/ui/uitheme.png b/bin/assets/ui/uitheme.png index a3de374ce..5b2d00aa3 100644 Binary files a/bin/assets/ui/uitheme.png and b/bin/assets/ui/uitheme.png differ diff --git a/bin/assets/ui/uitheme/uitheme_gridcell_hover.png b/bin/assets/ui/uitheme/uitheme_tablerow_hover.png similarity index 100% rename from bin/assets/ui/uitheme/uitheme_gridcell_hover.png rename to bin/assets/ui/uitheme/uitheme_tablerow_hover.png diff --git a/bin/assets/ui/uitheme/uitheme_gridcell_selected.png b/bin/assets/ui/uitheme/uitheme_tablerow_selected.png similarity index 100% rename from bin/assets/ui/uitheme/uitheme_gridcell_selected.png rename to bin/assets/ui/uitheme/uitheme_tablerow_selected.png diff --git a/bin/assets/ui/uitheme1.5x.eta b/bin/assets/ui/uitheme1.5x.eta index 91b954f4e..671f5ab6f 100644 Binary files a/bin/assets/ui/uitheme1.5x.eta and b/bin/assets/ui/uitheme1.5x.eta differ diff --git a/bin/assets/ui/uitheme1.5x.png b/bin/assets/ui/uitheme1.5x.png index 3f759c97a..6be3cc27e 100644 Binary files a/bin/assets/ui/uitheme1.5x.png and b/bin/assets/ui/uitheme1.5x.png differ diff --git a/bin/assets/ui/uitheme1.5x/uitheme1.5x_gridcell_hover.png b/bin/assets/ui/uitheme1.5x/uitheme1.5x_tablerow_hover.png similarity index 100% rename from bin/assets/ui/uitheme1.5x/uitheme1.5x_gridcell_hover.png rename to bin/assets/ui/uitheme1.5x/uitheme1.5x_tablerow_hover.png diff --git a/bin/assets/ui/uitheme1.5x/uitheme1.5x_gridcell_selected.png b/bin/assets/ui/uitheme1.5x/uitheme1.5x_tablerow_selected.png similarity index 100% rename from bin/assets/ui/uitheme1.5x/uitheme1.5x_gridcell_selected.png rename to bin/assets/ui/uitheme1.5x/uitheme1.5x_tablerow_selected.png diff --git a/bin/assets/ui/uitheme2x.eta b/bin/assets/ui/uitheme2x.eta index 30219ea8a..e09ecc807 100644 Binary files a/bin/assets/ui/uitheme2x.eta and b/bin/assets/ui/uitheme2x.eta differ diff --git a/bin/assets/ui/uitheme2x.png b/bin/assets/ui/uitheme2x.png index c7a5f0963..57e335f82 100644 Binary files a/bin/assets/ui/uitheme2x.png and b/bin/assets/ui/uitheme2x.png differ diff --git a/bin/assets/ui/uitheme2x/uitheme2x_gridcell_hover.png b/bin/assets/ui/uitheme2x/uitheme2x_tablerow_hover.png similarity index 100% rename from bin/assets/ui/uitheme2x/uitheme2x_gridcell_hover.png rename to bin/assets/ui/uitheme2x/uitheme2x_tablerow_hover.png diff --git a/bin/assets/ui/uitheme2x/uitheme2x_gridcell_selected.png b/bin/assets/ui/uitheme2x/uitheme2x_tablerow_selected.png similarity index 100% rename from bin/assets/ui/uitheme2x/uitheme2x_gridcell_selected.png rename to bin/assets/ui/uitheme2x/uitheme2x_tablerow_selected.png diff --git a/docs/articles/cssspecification.md b/docs/articles/cssspecification.md index f4fd18eda..1aab38424 100644 --- a/docs/articles/cssspecification.md +++ b/docs/articles/cssspecification.md @@ -745,7 +745,7 @@ Sets the horizontal scroll mode to any scrollable element. The mode defines the visibility of the horizontal scroll. * Applicable to: EE::UI::DropDownList (DropDownList), EE::UI::UIListBox (ListBox), - EE::UI::UIScrollView (ScrollView), EE::UI::UITable (Table), EE::UI::UITextEdit (TextEdit). + EE::UI::UIScrollView (ScrollView), EE::UI::UIWidgetTable (WidgetTable), EE::UI::UITextEdit (TextEdit). * Data Type: [string-list](#string-list-data-type) * Value List: * `auto`: The horizontal scrollbar will be visible only when needed. @@ -1282,7 +1282,7 @@ rotation-origin-point-y: 100%; Sets the row height in any element that contains fixed size rows. -* Applicable to: EE::UI::UIListBox (ListBox), EE::UI::UIDropDownList (DropDownList), EE::UI::UITable (Table), EE::UI::UIGridLayout (GridLayout) +* Applicable to: EE::UI::UIListBox (ListBox), EE::UI::UIDropDownList (DropDownList), EE::UI::UIWidgetTable (WidgetTable), EE::UI::UIGridLayout (GridLayout) * Data Type: [length](#length-data-type) * Default value: Varies on each case. ListBox and DropDownList will guess the value based on the [font-size](#font-size). Table requires this value to be manually set in order to work. GridLayout will require the value only if [row-mode](#row-mode) is `size`. @@ -1403,7 +1403,7 @@ Defines how the scrollbar should fit inside an scrollable element. Sets the scrollbar style (for the moment defines if it contains buttons at its edge or it's simply a bar). * Applicable to: EE::UI::UIScrollBar (ScrollBar), EE::UI::UIListBox (ListBox), EE::UI::UIDropDownList - (DropDownList), EE::UI::UITable (Table), EE::UI::UIScrollView (ScrollView) + (DropDownList), EE::UI::UIWidgetTable (WidgetTable), EE::UI::UIScrollView (ScrollView) * Data Type: [string-list](#string-list-data-type) * Value List: * `no-buttons`: It's just a scroll bar. @@ -1760,7 +1760,7 @@ Sets the total steps required to complete a progress bar (the maximum value a pr Enables/disables the element as draggable. When enabled the element will be able to be dragged. * Applicable to: EE::UI::UITouchDraggable (TouchDraggable), (EE::UI::UIListBox (ListBox), - EE::UI::UIScrollView (ScrollView), EE::UI::UITable (Table) + EE::UI::UIScrollView (ScrollView), EE::UI::UIWidgetTable (WidgetTable) * Data Type: [boolean](#boolean-data-type) * Default value: `false` @@ -1771,7 +1771,7 @@ Enables/disables the element as draggable. When enabled the element will be able Sets a acceleration value that defines how much will accelerate the drag when the mouse or touch is released. * Applicable to: EE::UI::UITouchDraggable (TouchDraggable), (EE::UI::UIListBox (ListBox), - EE::UI::UIScrollView (ScrollView), EE::UI::UITable (Table) + EE::UI::UIScrollView (ScrollView), EE::UI::UIWidgetTable (WidgetTable) * Data Type: [vector2-number](#vector2-number-data-type) * Default value: `5 5` @@ -1843,7 +1843,7 @@ Sets the vertical scroll mode to any scrollable element. The mode defines the visibility of the vertical scroll. * Applicable to: EE::UI::DropDownList (DropDownList), EE::UI::UIListBox (ListBox), - EE::UI::UIScrollView (ScrollView), EE::UI::UITable (Table), EE::UI::UITextEdit (TextEdit). + EE::UI::UIScrollView (ScrollView), EE::UI::UIWidgetTable (WidgetTable), EE::UI::UITextEdit (TextEdit). * Data Type: [string-list](#string-list-data-type) * Value List: * `auto`: The vertical scrollbar will be visible only when needed. diff --git a/include/eepp/scene/eventdispatcher.hpp b/include/eepp/scene/eventdispatcher.hpp index 18ad5afc7..3ea9e1ca6 100644 --- a/include/eepp/scene/eventdispatcher.hpp +++ b/include/eepp/scene/eventdispatcher.hpp @@ -44,6 +44,8 @@ class EE_API EventDispatcher { Node* getMouseDownNode() const; + void resetMouseDownNode(); + Node* getLossFocusNode() const; void sendMsg( Node* node, const Uint32& Msg, const Uint32& Flags = 0 ); diff --git a/include/eepp/ui.hpp b/include/eepp/ui.hpp index fa8dd947e..98ceed37c 100644 --- a/include/eepp/ui.hpp +++ b/include/eepp/ui.hpp @@ -37,8 +37,8 @@ #include #include #include -#include -#include +#include +#include #include #include #include diff --git a/include/eepp/ui/abstract/uiabstracttableview.hpp b/include/eepp/ui/abstract/uiabstracttableview.hpp index ef3696fd5..3b9f8724a 100644 --- a/include/eepp/ui/abstract/uiabstracttableview.hpp +++ b/include/eepp/ui/abstract/uiabstracttableview.hpp @@ -3,6 +3,7 @@ #include #include +#include #include #include diff --git a/include/eepp/ui/css/stylesheetspecification.hpp b/include/eepp/ui/css/stylesheetspecification.hpp index c1e55ceac..4f263e33f 100644 --- a/include/eepp/ui/css/stylesheetspecification.hpp +++ b/include/eepp/ui/css/stylesheetspecification.hpp @@ -16,12 +16,12 @@ namespace EE { namespace UI { namespace CSS { class PropertySpecification; -typedef std::function +typedef std::function StyleSheetNodeSelector; struct StructuralSelector { StructuralSelector( StyleSheetNodeSelector selector, int a = 0, int b = 0, - FunctionString data = FunctionString::parse( "" ) ) : + const FunctionString& data = FunctionString::parse( "" ) ) : selector( selector ), a( a ), b( b ), data( data ) {} StyleSheetNodeSelector selector; int a; diff --git a/include/eepp/ui/uifiledialog.hpp b/include/eepp/ui/uifiledialog.hpp index fbad249a2..3c82276c0 100644 --- a/include/eepp/ui/uifiledialog.hpp +++ b/include/eepp/ui/uifiledialog.hpp @@ -18,10 +18,12 @@ class EE_API UIFileDialog : public UIWindow { SaveDialog = ( 1 << 0 ), FoldersFirst = ( 1 << 1 ), SortAlphabetically = ( 1 << 2 ), - AllowFolderSelect = ( 1 << 3 ) + AllowFolderSelect = ( 1 << 3 ), + ShowOnlyFolders = ( 1 << 4 ), + ShowHidden = ( 1 << 5 ) }; - static const Uint32 DefaultFlags = FoldersFirst | SortAlphabetically; + static const Uint32 DefaultFlags = FoldersFirst | SortAlphabetically | UIFileDialog::ShowHidden; static UIFileDialog* New( Uint32 dialogFlags = DefaultFlags, const std::string& defaultFilePattern = "*", @@ -74,6 +76,10 @@ class EE_API UIFileDialog : public UIWindow { bool getFoldersFirst(); + bool getShowOnlyFolders(); + + bool getShowHidden(); + bool getAllowFolderSelect(); void setSortAlphabetically( const bool& sortAlphabetically ); @@ -82,6 +88,10 @@ class EE_API UIFileDialog : public UIWindow { void setAllowFolderSelect( const bool& allowFolderSelect ); + void setShowOnlyFolders( const bool& showOnlyFolders ); + + void setShowHidden( const bool& showHidden ); + const KeyBindings::Shortcut& getCloseShortcut() const; void setFileName( const std::string& name ); diff --git a/include/eepp/ui/uihelper.hpp b/include/eepp/ui/uihelper.hpp index 0a502eb3c..ea4bc080f 100644 --- a/include/eepp/ui/uihelper.hpp +++ b/include/eepp/ui/uihelper.hpp @@ -71,7 +71,8 @@ enum UINodeType { UI_TYPE_MENUSUBMENU, UI_TYPE_TEXTEDIT, UI_TYPE_TOOLTIP, - UI_TYPE_TABLE, + UI_TYPE_WIDGETTABLE, + UI_TYPE_WIDGETTABLEROW, UI_TYPE_WINDOW, UI_TYPE_MENUBAR, UI_TYPE_SELECTBUTTON, @@ -95,6 +96,7 @@ enum UINodeType { UI_TYPE_SCROLLABLEWIDGET, UI_TYPE_TREEVIEW_CELL, UI_TYPE_TABLEVIEW, + UI_TYPE_TABLECELL, UI_TYPE_USER = 10000 }; diff --git a/include/eepp/ui/uitablecell.hpp b/include/eepp/ui/uitablecell.hpp index 4ae55b267..33450d524 100644 --- a/include/eepp/ui/uitablecell.hpp +++ b/include/eepp/ui/uitablecell.hpp @@ -1,56 +1,37 @@ -#ifndef EE_UICUIGRIDCELL_HPP -#define EE_UICUIGRIDCELL_HPP +#ifndef EE_UI_UITABLECELL_HPP +#define EE_UI_UITABLECELL_HPP -#include -#include +#include +#include + +using namespace EE::UI::Models; namespace EE { namespace UI { -class UITable; - -class EE_API UITableCell : public UIWidget { +class EE_API UITableCell : public UIPushButton { public: - static UITableCell* New(); + static UITableCell* New() { return eeNew( UITableCell, () ); } - UITableCell(); + static UITableCell* New( const std::string& tag ) { return eeNew( UITableCell, ( tag ) ); } - virtual ~UITableCell(); + Uint32 getType() const { return UI_TYPE_TABLECELL; } - virtual void setTheme( UITheme* Theme ); + bool isType( const Uint32& type ) const { + return UITableCell::getType() == type ? true : UIPushButton::isType( type ); + } - void setCell( const Uint32& ColumnIndex, UINode* node ); + ModelIndex getCurIndex() const { return mCurIndex; } - UINode* getCell( const Uint32& ColumnIndex ) const; - - bool isSelected() const; - - void unselect(); - - void select(); - - virtual Uint32 onMessage( const NodeMessage* Msg ); + void setCurIndex( const ModelIndex& curIndex ) { mCurIndex = curIndex; } protected: - friend class UIItemContainer; - friend class UITable; + ModelIndex mCurIndex; - std::vector mCells; + UITableCell() : UIPushButton( "table::cell" ) {} - UITable* gridParent() const; - - void fixCell(); - - virtual Uint32 onMouseLeave( const Vector2i& position, const Uint32& flags ); - - virtual void onStateChange(); - - virtual void onParentChange(); - - virtual void onAlphaChange(); - - virtual void onAutoSize(); + UITableCell( const std::string& tag ) : UIPushButton( tag ) {} }; }} // namespace EE::UI -#endif +#endif // EE_UI_UITABLECELL_HPP diff --git a/include/eepp/ui/uitablerow.hpp b/include/eepp/ui/uitablerow.hpp index 37b15c630..63c7897fd 100644 --- a/include/eepp/ui/uitablerow.hpp +++ b/include/eepp/ui/uitablerow.hpp @@ -12,6 +12,8 @@ class EE_API UITableRow : public UIWidget { public: static UITableRow* New( const std::string& tag ) { return eeNew( UITableRow, ( tag ) ); } + static UITableRow* New() { return eeNew( UITableRow, () ); } + ModelIndex getCurIndex() const { return mCurIndex; } void setCurIndex( const ModelIndex& curIndex ) { mCurIndex = curIndex; } @@ -19,6 +21,8 @@ class EE_API UITableRow : public UIWidget { protected: UITableRow( const std::string& tag ) : UIWidget( tag ) {} + UITableRow() : UIWidget( "table::row" ) {} + virtual Uint32 onMessage( const NodeMessage* msg ) { if ( msg->getMsg() == NodeMessage::MouseDown && ( msg->getFlags() & EE_BUTTON_LMASK ) && ( !getEventDispatcher()->getMouseDownNode() || diff --git a/include/eepp/ui/uitable.hpp b/include/eepp/ui/uiwidgettable.hpp similarity index 64% rename from include/eepp/ui/uitable.hpp rename to include/eepp/ui/uiwidgettable.hpp index 1a48a124b..817fca5b5 100644 --- a/include/eepp/ui/uitable.hpp +++ b/include/eepp/ui/uiwidgettable.hpp @@ -4,18 +4,16 @@ #include #include #include -#include #include +#include namespace EE { namespace UI { -class EE_API UITable : public UITouchDraggableWidget { +class EE_API UIWidgetTable : public UITouchDraggableWidget { public: - static UITable* New(); + static UIWidgetTable* New(); - UITable(); - - ~UITable(); + ~UIWidgetTable(); virtual Uint32 getType() const; @@ -23,57 +21,57 @@ class EE_API UITable : public UITouchDraggableWidget { virtual void setTheme( UITheme* Theme ); - void add( UITableCell* Cell ); + void add( UIWidgetTableRow* row ); - void remove( UITableCell* Cell ); + void remove( UIWidgetTableRow* row ); - void remove( std::vector ItemsIndex ); + void remove( std::vector itemsIndex ); - void remove( Uint32 ItemIndex ); + void remove( Uint32 itemIndex ); - UITable* setColumnWidth( const Uint32& ColumnIndex, const Uint32& columnWidth ); + UIWidgetTable* setColumnWidth( const Uint32& columnIndex, const Uint32& columnWidth ); - const Uint32& getColumnWidth( const Uint32& ColumnIndex ) const; + const Uint32& getColumnWidth( const Uint32& columnIndex ) const; Uint32 getCount() const; - UITable* setColumnsCount( const Uint32& columnsCount ); + UIWidgetTable* setColumnsCount( const Uint32& columnsCount ); const Uint32& getColumnsCount() const; - UITable* setRowHeight( const Uint32& height ); + UIWidgetTable* setRowHeight( const Uint32& height ); const Uint32& getRowHeight() const; - UITableCell* getCell( const Uint32& CellIndex ) const; + UIWidgetTableRow* getRow( const Uint32& rowIndex ) const; - void setVerticalScrollMode( const ScrollBarMode& Mode ); + void setVerticalScrollMode( const ScrollBarMode& mode ); const ScrollBarMode& getVerticalScrollMode(); - void setHorizontalScrollMode( const ScrollBarMode& Mode ); + void setHorizontalScrollMode( const ScrollBarMode& mode ); const ScrollBarMode& getHorizontalScrollMode(); - Uint32 getCellPosition( const Uint32& ColumnIndex ); + Uint32 getColumnPosition( const Uint32& columnIndex ); UIScrollBar* getVerticalScrollBar() const; UIScrollBar* getHorizontalScrollBar() const; - Uint32 getItemIndex( UITableCell* Item ); + Uint32 getItemIndex( UIWidgetTableRow* item ); - UITableCell* getItemSelected(); + UIWidgetTableRow* getItemSelected(); Uint32 getItemSelectedIndex() const; Uint32 onMessage( const NodeMessage* Msg ); - UIItemContainer* getContainer() const; + UIItemContainer* getContainer() const; bool getSmoothScroll() const; - UITable* setSmoothScroll( bool smoothScroll ); + UIWidgetTable* setSmoothScroll( bool smoothScroll ); Rectf getContainerPadding() const; @@ -83,16 +81,16 @@ class EE_API UITable : public UITouchDraggableWidget { const Uint32& propertyIndex = 0 ); protected: - friend class UIItemContainer; - friend class UITableCell; + friend class UIItemContainer; + friend class UIWidgetTableRow; Rectf mContainerPadding; - UIItemContainer* mContainer; + UIItemContainer* mContainer; UIScrollBar* mVScrollBar; UIScrollBar* mHScrollBar; ScrollBarMode mVScrollMode; ScrollBarMode mHScrollMode; - std::vector mItems; + std::vector mItems; Uint32 mColumnsCount; Uint32 mRowHeight; std::vector mColumnsWidth; @@ -108,6 +106,8 @@ class EE_API UITable : public UITouchDraggableWidget { bool mSmoothScroll; bool mCollWidthAssigned; + UIWidgetTable(); + void updateCells(); void updateColumnsPos(); diff --git a/include/eepp/ui/uiwidgettablerow.hpp b/include/eepp/ui/uiwidgettablerow.hpp new file mode 100644 index 000000000..d8bb58633 --- /dev/null +++ b/include/eepp/ui/uiwidgettablerow.hpp @@ -0,0 +1,60 @@ +#ifndef EE_UI_UIWIDGETTABLEROW_HPP +#define EE_UI_UIWIDGETTABLEROW_HPP + +#include +#include + +namespace EE { namespace UI { + +class UIWidgetTable; + +class EE_API UIWidgetTableRow : public UIWidget { + public: + static UIWidgetTableRow* New(); + + Uint32 getType() const; + + bool isType( const Uint32& type ) const; + + virtual ~UIWidgetTableRow(); + + virtual void setTheme( UITheme* Theme ); + + void setColumn( const Uint32& columnIndex, UINode* node ); + + UINode* getColumn( const Uint32& columnIndex ) const; + + bool isSelected() const; + + void unselect(); + + void select(); + + virtual Uint32 onMessage( const NodeMessage* Msg ); + + protected: + friend class UIItemContainer; + friend class UIWidgetTable; + + std::vector mCells; + + UIWidgetTableRow(); + + UIWidgetTable* gridParent() const; + + void updateRow(); + + virtual Uint32 onMouseLeave( const Vector2i& position, const Uint32& flags ); + + virtual void onStateChange(); + + virtual void onParentChange(); + + virtual void onAlphaChange(); + + virtual void onAutoSize(); +}; + +}} // namespace EE::UI + +#endif diff --git a/projects/linux/ee.files b/projects/linux/ee.files index abb79976f..68ab3e6cb 100644 --- a/projects/linux/ee.files +++ b/projects/linux/ee.files @@ -398,7 +398,6 @@ ../../include/eepp/ui/uistyle.hpp ../../include/eepp/ui/uitab.hpp ../../include/eepp/ui/uitablecell.hpp -../../include/eepp/ui/uitable.hpp ../../include/eepp/ui/uitableheadercolumn.hpp ../../include/eepp/ui/uitablerow.hpp ../../include/eepp/ui/uitableview.hpp @@ -416,6 +415,8 @@ ../../include/eepp/ui/uiviewpager.hpp ../../include/eepp/ui/uiwidgetcreator.hpp ../../include/eepp/ui/uiwidget.hpp +../../include/eepp/ui/uiwidgettable.hpp +../../include/eepp/ui/uiwidgettablerow.hpp ../../include/eepp/ui/uiwindow.hpp ../../include/eepp/version.hpp ../../include/eepp/window/base.hpp @@ -866,8 +867,6 @@ ../../src/eepp/ui/uistate.cpp ../../src/eepp/ui/uistyle.cpp ../../src/eepp/ui/uitab.cpp -../../src/eepp/ui/uitablecell.cpp -../../src/eepp/ui/uitable.cpp ../../src/eepp/ui/uitableheadercolumn.cpp ../../src/eepp/ui/uitableview.cpp ../../src/eepp/ui/uitabwidget.cpp @@ -884,6 +883,8 @@ ../../src/eepp/ui/uiviewpager.cpp ../../src/eepp/ui/uiwidget.cpp ../../src/eepp/ui/uiwidgetcreator.cpp +../../src/eepp/ui/uiwidgettable.cpp +../../src/eepp/ui/uiwidgettablerow.cpp ../../src/eepp/ui/uiwindow.cpp ../../src/eepp/window/backend/allegro5/cbackendal.hpp ../../src/eepp/window/backend/allegro5/cclipboardal.cpp diff --git a/src/eepp/maps/mapeditor/maplayerproperties.cpp b/src/eepp/maps/mapeditor/maplayerproperties.cpp index 618a49ddb..67a2b5441 100644 --- a/src/eepp/maps/mapeditor/maplayerproperties.cpp +++ b/src/eepp/maps/mapeditor/maplayerproperties.cpp @@ -87,7 +87,7 @@ MapLayerProperties::MapLayerProperties( MapLayer* Map, RefreshLayerListCb Cb ) : CancelButton->setText( "Cancel" ); CancelButton->setAnchors( UI_ANCHOR_RIGHT | UI_ANCHOR_BOTTOM ); - mGenGrid = UITable::New(); + mGenGrid = UIWidgetTable::New(); mGenGrid->setParent( mUIWindow->getContainer() ); mGenGrid->setSize( 400, 340 ) ->setPosition( 50, TxtBox->getPosition().y + TxtBox->getSize().getHeight() ); @@ -136,10 +136,10 @@ void MapLayerProperties::saveProperties() { mLayer->clearProperties(); for ( Uint32 i = 0; i < mGenGrid->getCount(); i++ ) { - UITableCell* Cell = mGenGrid->getCell( i ); + UIWidgetTableRow* Cell = mGenGrid->getRow( i ); - UITextInput* Input = Cell->getCell( 1 )->asType(); - UITextInput* Input2 = Cell->getCell( 3 )->asType(); + UITextInput* Input = Cell->getColumn( 1 )->asType(); + UITextInput* Input2 = Cell->getColumn( 3 )->asType(); if ( NULL != Cell && Input->getText().size() && Input2->getText().size() ) { mLayer->addProperty( Input->getText(), Input2->getText() ); @@ -151,10 +151,10 @@ void MapLayerProperties::loadProperties() { MapLayer::PropertiesMap& Proper = mLayer->getProperties(); for ( MapLayer::PropertiesMap::iterator it = Proper.begin(); it != Proper.end(); ++it ) { - UITableCell* Cell = createCell(); + UIWidgetTableRow* Cell = createCell(); - UITextInput* Input = Cell->getCell( 1 )->asType(); - UITextInput* Input2 = Cell->getCell( 3 )->asType(); + UITextInput* Input = Cell->getColumn( 1 )->asType(); + UITextInput* Input2 = Cell->getColumn( 3 )->asType(); Input->setText( it->first ); Input2->setText( it->second ); @@ -189,7 +189,7 @@ void MapLayerProperties::onAddCellClick( const Event* ) { Uint32 Index = mGenGrid->getItemSelectedIndex(); if ( eeINDEX_NOT_FOUND == Index ) { - mGenGrid->getCell( 0 )->select(); + mGenGrid->getRow( 0 )->select(); } } @@ -200,11 +200,11 @@ void MapLayerProperties::onRemoveCellClick( const Event* ) { mGenGrid->remove( Index ); if ( Index < mGenGrid->getCount() ) { - mGenGrid->getCell( Index )->select(); + mGenGrid->getRow( Index )->select(); } else { if ( mGenGrid->getCount() ) { if ( Index > 0 ) - mGenGrid->getCell( Index - 1 )->select(); + mGenGrid->getRow( Index - 1 )->select(); } } } @@ -216,12 +216,12 @@ void MapLayerProperties::createGridElems() { if ( 0 == mGenGrid->getCount() ) { onAddCellClick( NULL ); } else { - mGenGrid->getCell( 0 )->select(); + mGenGrid->getRow( 0 )->select(); } } -UITableCell* MapLayerProperties::createCell() { - UITableCell* Cell = UITableCell::New(); +UIWidgetTableRow* MapLayerProperties::createCell() { + UIWidgetTableRow* Cell = UIWidgetTableRow::New(); UITextInput* TxtInput = UITextInput::New(); UITextInput* TxtInput2 = UITextInput::New(); @@ -229,11 +229,11 @@ UITableCell* MapLayerProperties::createCell() { TxtInput->setMaxLength( LAYER_NAME_SIZE ); TxtInput2->setMaxLength( LAYER_NAME_SIZE ); - Cell->setCell( 0, UIWidget::New() ); - Cell->setCell( 1, TxtInput ); - Cell->setCell( 2, UIWidget::New() ); - Cell->setCell( 3, TxtInput2 ); - Cell->setCell( 4, UIWidget::New() ); + Cell->setColumn( 0, UIWidget::New() ); + Cell->setColumn( 1, TxtInput ); + Cell->setColumn( 2, UIWidget::New() ); + Cell->setColumn( 3, TxtInput2 ); + Cell->setColumn( 4, UIWidget::New() ); return Cell; } diff --git a/src/eepp/maps/mapeditor/maplayerproperties.hpp b/src/eepp/maps/mapeditor/maplayerproperties.hpp index 539360c32..77a773954 100644 --- a/src/eepp/maps/mapeditor/maplayerproperties.hpp +++ b/src/eepp/maps/mapeditor/maplayerproperties.hpp @@ -4,7 +4,7 @@ #include #include #include -#include +#include #include #include @@ -25,7 +25,7 @@ class EE_API MapLayerProperties { protected: UITheme* mUITheme; UIWindow* mUIWindow; - UITable* mGenGrid; + UIWidgetTable* mGenGrid; MapLayer* mLayer; UITextInput* mUIInput; RefreshLayerListCb mRefreshCb; @@ -46,7 +46,7 @@ class EE_API MapLayerProperties { void loadProperties(); - UITableCell* createCell(); + UIWidgetTableRow* createCell(); }; }}} // namespace EE::Maps::Private diff --git a/src/eepp/maps/mapeditor/mapobjectproperties.cpp b/src/eepp/maps/mapeditor/mapobjectproperties.cpp index a936e7835..b12983b47 100644 --- a/src/eepp/maps/mapeditor/mapobjectproperties.cpp +++ b/src/eepp/maps/mapeditor/mapobjectproperties.cpp @@ -105,7 +105,7 @@ MapObjectProperties::MapObjectProperties( GameObjectObject* Obj ) : CancelButton->setText( "Cancel" ); CancelButton->setAnchors( UI_ANCHOR_RIGHT | UI_ANCHOR_BOTTOM ); - mGenGrid = UITable::New(); + mGenGrid = UIWidgetTable::New(); mGenGrid->setParent( mUIWindow->getContainer() ); mGenGrid->setSize( 400, 340 ) ->setPosition( 50, TxtBox->getPosition().y + TxtBox->getSize().getHeight() ); @@ -154,10 +154,10 @@ void MapObjectProperties::saveProperties() { mObj->clearProperties(); for ( Uint32 i = 0; i < mGenGrid->getCount(); i++ ) { - UITableCell* Cell = mGenGrid->getCell( i ); + UIWidgetTableRow* Cell = mGenGrid->getRow( i ); - UITextInput* Input = Cell->getCell( 1 )->asType(); - UITextInput* Input2 = Cell->getCell( 3 )->asType(); + UITextInput* Input = Cell->getColumn( 1 )->asType(); + UITextInput* Input2 = Cell->getColumn( 3 )->asType(); if ( NULL != Cell && Input->getText().size() && Input2->getText().size() ) { mObj->addProperty( Input->getText(), Input2->getText() ); @@ -170,10 +170,10 @@ void MapObjectProperties::loadProperties() { for ( GameObjectObject::PropertiesMap::iterator it = Proper.begin(); it != Proper.end(); ++it ) { - UITableCell* Cell = createCell(); + UIWidgetTableRow* Cell = createCell(); - UITextInput* Input = Cell->getCell( 1 )->asType(); - UITextInput* Input2 = Cell->getCell( 3 )->asType(); + UITextInput* Input = Cell->getColumn( 1 )->asType(); + UITextInput* Input2 = Cell->getColumn( 3 )->asType(); Input->setText( it->first ); Input2->setText( it->second ); @@ -205,7 +205,7 @@ void MapObjectProperties::onAddCellClick( const Event* Event ) { Uint32 Index = mGenGrid->getItemSelectedIndex(); if ( eeINDEX_NOT_FOUND == Index ) { - mGenGrid->getCell( 0 )->select(); + mGenGrid->getRow( 0 )->select(); } } @@ -216,11 +216,11 @@ void MapObjectProperties::onRemoveCellClick( const Event* Event ) { mGenGrid->remove( Index ); if ( Index < mGenGrid->getCount() ) { - mGenGrid->getCell( Index )->select(); + mGenGrid->getRow( Index )->select(); } else { if ( mGenGrid->getCount() ) { if ( Index > 0 ) - mGenGrid->getCell( Index - 1 )->select(); + mGenGrid->getRow( Index - 1 )->select(); } } } @@ -232,12 +232,12 @@ void MapObjectProperties::createGridElems() { if ( 0 == mGenGrid->getCount() ) { onAddCellClick( NULL ); } else { - mGenGrid->getCell( 0 )->select(); + mGenGrid->getRow( 0 )->select(); } } -UITableCell* MapObjectProperties::createCell() { - UITableCell* Cell = UITableCell::New(); +UIWidgetTableRow* MapObjectProperties::createCell() { + UIWidgetTableRow* Cell = UIWidgetTableRow::New(); UITextInput* TxtInput = UITextInput::New(); UITextInput* TxtInput2 = UITextInput::New(); @@ -245,11 +245,11 @@ UITableCell* MapObjectProperties::createCell() { TxtInput->setMaxLength( LAYER_NAME_SIZE ); TxtInput2->setMaxLength( LAYER_NAME_SIZE ); - Cell->setCell( 0, UIWidget::New() ); - Cell->setCell( 1, TxtInput ); - Cell->setCell( 2, UIWidget::New() ); - Cell->setCell( 3, TxtInput2 ); - Cell->setCell( 4, UIWidget::New() ); + Cell->setColumn( 0, UIWidget::New() ); + Cell->setColumn( 1, TxtInput ); + Cell->setColumn( 2, UIWidget::New() ); + Cell->setColumn( 3, TxtInput2 ); + Cell->setColumn( 4, UIWidget::New() ); return Cell; } diff --git a/src/eepp/maps/mapeditor/mapobjectproperties.hpp b/src/eepp/maps/mapeditor/mapobjectproperties.hpp index f267045f5..cc5441d89 100644 --- a/src/eepp/maps/mapeditor/mapobjectproperties.hpp +++ b/src/eepp/maps/mapeditor/mapobjectproperties.hpp @@ -4,7 +4,7 @@ #include #include #include -#include +#include #include #include @@ -23,7 +23,7 @@ class MapObjectProperties { protected: UITheme* mUITheme; UIWindow* mUIWindow; - UITable* mGenGrid; + UIWidgetTable* mGenGrid; GameObjectObject* mObj; UITextInput* mUIInput; UITextInput* mUIInput2; @@ -44,7 +44,7 @@ class MapObjectProperties { void loadProperties(); - UITableCell* createCell(); + UIWidgetTableRow* createCell(); }; }}} // namespace EE::Maps::Private diff --git a/src/eepp/maps/mapeditor/tilemapproperties.cpp b/src/eepp/maps/mapeditor/tilemapproperties.cpp index c8a5c1611..a83fb3d91 100644 --- a/src/eepp/maps/mapeditor/tilemapproperties.cpp +++ b/src/eepp/maps/mapeditor/tilemapproperties.cpp @@ -156,7 +156,7 @@ TileMapProperties::TileMapProperties( TileMap* Map ) : CancelButton->setText( "Cancel" ); CancelButton->setAnchors( UI_ANCHOR_RIGHT | UI_ANCHOR_BOTTOM ); - mGenGrid = UITable::New(); + mGenGrid = UIWidgetTable::New(); mGenGrid->setParent( mUIWindow->getContainer() ); mGenGrid->setSize( 400, 310 ) ->setPosition( 50, TxtBox->getPosition().y + TxtBox->getSize().getHeight() ); @@ -238,10 +238,10 @@ void TileMapProperties::saveProperties() { mMap->clearProperties(); for ( Uint32 i = 0; i < mGenGrid->getCount(); i++ ) { - UITableCell* Cell = mGenGrid->getCell( i ); + UIWidgetTableRow* Cell = mGenGrid->getRow( i ); - UITextInput* Input = Cell->getCell( 1 )->asType(); - UITextInput* Input2 = Cell->getCell( 3 )->asType(); + UITextInput* Input = Cell->getColumn( 1 )->asType(); + UITextInput* Input2 = Cell->getColumn( 3 )->asType(); if ( NULL != Cell && Input->getText().size() && Input2->getText().size() ) { mMap->addProperty( Input->getText(), Input2->getText() ); @@ -253,10 +253,10 @@ void TileMapProperties::loadProperties() { TileMap::PropertiesMap& Proper = mMap->getProperties(); for ( TileMap::PropertiesMap::iterator it = Proper.begin(); it != Proper.end(); ++it ) { - UITableCell* Cell = createCell(); + UIWidgetTableRow* Cell = createCell(); - UITextInput* Input = Cell->getCell( 1 )->asType(); - UITextInput* Input2 = Cell->getCell( 3 )->asType(); + UITextInput* Input = Cell->getColumn( 1 )->asType(); + UITextInput* Input2 = Cell->getColumn( 3 )->asType(); Input->setText( it->first ); Input2->setText( it->second ); @@ -285,7 +285,7 @@ void TileMapProperties::onAddCellClick( const Event* ) { Uint32 Index = mGenGrid->getItemSelectedIndex(); if ( eeINDEX_NOT_FOUND == Index ) { - mGenGrid->getCell( 0 )->select(); + mGenGrid->getRow( 0 )->select(); } } @@ -296,11 +296,11 @@ void TileMapProperties::onRemoveCellClick( const Event* ) { mGenGrid->remove( Index ); if ( Index < mGenGrid->getCount() ) { - mGenGrid->getCell( Index )->select(); + mGenGrid->getRow( Index )->select(); } else { if ( mGenGrid->getCount() ) { if ( Index > 0 ) - mGenGrid->getCell( Index - 1 )->select(); + mGenGrid->getRow( Index - 1 )->select(); } } } @@ -312,12 +312,12 @@ void TileMapProperties::createGridElems() { if ( 0 == mGenGrid->getCount() ) { onAddCellClick( NULL ); } else { - mGenGrid->getCell( 0 )->select(); + mGenGrid->getRow( 0 )->select(); } } -UITableCell* TileMapProperties::createCell() { - UITableCell* Cell = UITableCell::New(); +UIWidgetTableRow* TileMapProperties::createCell() { + UIWidgetTableRow* Cell = UIWidgetTableRow::New(); UITextInput* TxtInput = UITextInput::New(); UITextInput* TxtInput2 = UITextInput::New(); @@ -325,11 +325,11 @@ UITableCell* TileMapProperties::createCell() { TxtInput->setMaxLength( LAYER_NAME_SIZE ); TxtInput2->setMaxLength( LAYER_NAME_SIZE ); - Cell->setCell( 0, UIWidget::New() ); - Cell->setCell( 1, TxtInput ); - Cell->setCell( 2, UIWidget::New() ); - Cell->setCell( 3, TxtInput2 ); - Cell->setCell( 4, UIWidget::New() ); + Cell->setColumn( 0, UIWidget::New() ); + Cell->setColumn( 1, TxtInput ); + Cell->setColumn( 2, UIWidget::New() ); + Cell->setColumn( 3, TxtInput2 ); + Cell->setColumn( 4, UIWidget::New() ); return Cell; } diff --git a/src/eepp/maps/mapeditor/tilemapproperties.hpp b/src/eepp/maps/mapeditor/tilemapproperties.hpp index 3175da25c..6682e31f8 100644 --- a/src/eepp/maps/mapeditor/tilemapproperties.hpp +++ b/src/eepp/maps/mapeditor/tilemapproperties.hpp @@ -4,7 +4,7 @@ #include #include #include -#include +#include #include #include @@ -21,7 +21,7 @@ class EE_API TileMapProperties { protected: UITheme* mUITheme; UIWindow* mUIWindow; - UITable* mGenGrid; + UIWidgetTable* mGenGrid; TileMap* mMap; UIWidget* mUIBaseColor; UISlider* mUIRedSlider; @@ -53,7 +53,7 @@ class EE_API TileMapProperties { void loadProperties(); - UITableCell* createCell(); + UIWidgetTableRow* createCell(); }; }}} // namespace EE::Maps::Private diff --git a/src/eepp/scene/eventdispatcher.cpp b/src/eepp/scene/eventdispatcher.cpp index 0e59b56c7..b81ce319a 100644 --- a/src/eepp/scene/eventdispatcher.cpp +++ b/src/eepp/scene/eventdispatcher.cpp @@ -230,6 +230,10 @@ Node* EventDispatcher::getMouseDownNode() const { return mDownNode; } +void EventDispatcher::resetMouseDownNode() { + mDownNode = mSceneNode; +} + Node* EventDispatcher::getMouseOverNode() const { return mOverNode; } diff --git a/src/eepp/scene/node.cpp b/src/eepp/scene/node.cpp index 20937c368..6a37d3607 100644 --- a/src/eepp/scene/node.cpp +++ b/src/eepp/scene/node.cpp @@ -58,6 +58,10 @@ Node::~Node() { if ( eventDispatcher->getMouseOverNode() == this && mSceneNode != this ) { eventDispatcher->setMouseOverNode( mSceneNode ); } + + if ( eventDispatcher->getMouseDownNode() == this ) { + eventDispatcher->resetMouseDownNode(); + } } } diff --git a/src/eepp/ui/abstract/uiabstracttableview.cpp b/src/eepp/ui/abstract/uiabstracttableview.cpp index 6de41efa9..853e8504c 100644 --- a/src/eepp/ui/abstract/uiabstracttableview.cpp +++ b/src/eepp/ui/abstract/uiabstracttableview.cpp @@ -264,7 +264,7 @@ void UIAbstractTableView::setColumnsHidden( const std::vector columns, b UITableRow* UIAbstractTableView::createRow() { mUISceneNode->invalidateStyle( this ); mUISceneNode->invalidateStyleState( this, true ); - UITableRow* rowWidget = UITableRow::New( "table::row" ); + UITableRow* rowWidget = UITableRow::New(); rowWidget->setParent( this ); rowWidget->setLayoutSizePolicy( SizePolicy::Fixed, SizePolicy::Fixed ); rowWidget->reloadStyle( true, true, true ); @@ -305,13 +305,14 @@ void UIAbstractTableView::onScrollChange() { mHeader->setPixelsPosition( -mScrollOffset.x, 0 ); } -UIWidget* UIAbstractTableView::createCell( UIWidget* rowWidget, const ModelIndex& ) { - UIPushButton* widget = UIPushButton::NewWithTag( "table::cell" ); +UIWidget* UIAbstractTableView::createCell( UIWidget* rowWidget, const ModelIndex& index ) { + UITableCell* widget = UITableCell::New(); widget->setParent( rowWidget ); widget->unsetFlags( UI_AUTO_SIZE ); widget->clipEnable(); widget->setLayoutSizePolicy( SizePolicy::Fixed, SizePolicy::Fixed ); widget->setTextAlign( UI_HALIGN_LEFT ); + widget->setCurIndex( index ); widget->addEventListener( Event::MouseDoubleClick, [&]( const Event* event ) { auto mouseEvent = static_cast( event ); auto idx = mouseEvent->getNode()->getParent()->asType()->getCurIndex(); @@ -335,24 +336,25 @@ UIWidget* UIAbstractTableView::updateCell( const int& rowIndex, const ModelIndex } widget->setPixelsSize( columnData( index.column() ).width, getRowHeight() ); widget->setPixelsPosition( {getColumnPosition( index.column() ).x, 0} ); - if ( widget->isType( UI_TYPE_PUSHBUTTON ) ) { - UIPushButton* pushButton = widget->asType(); + if ( widget->isType( UI_TYPE_TABLECELL ) ) { + UITableCell* cell = widget->asType(); + cell->setCurIndex( index ); Variant txt( getModel()->data( index, Model::Role::Display ) ); if ( txt.isValid() ) { if ( txt.is( Variant::Type::String ) ) - pushButton->setText( txt.asString() ); + cell->setText( txt.asString() ); else if ( txt.is( Variant::Type::cstr ) ) - pushButton->setText( txt.asCStr() ); + cell->setText( txt.asCStr() ); } bool isVisible = false; Variant icon( getModel()->data( index, Model::Role::Icon ) ); if ( icon.is( Variant::Type::Drawable ) && icon.asDrawable() ) { isVisible = true; - pushButton->setIcon( icon.asDrawable() ); + cell->setIcon( icon.asDrawable() ); } - pushButton->getIcon()->setVisible( isVisible ); + cell->getIcon()->setVisible( isVisible ); } return widget; diff --git a/src/eepp/ui/css/stylesheetspecification.cpp b/src/eepp/ui/css/stylesheetspecification.cpp index 8f33fc251..252629278 100644 --- a/src/eepp/ui/css/stylesheetspecification.cpp +++ b/src/eepp/ui/css/stylesheetspecification.cpp @@ -424,19 +424,19 @@ static bool isNth( int a, int b, int count ) { void StyleSheetSpecification::registerDefaultNodeSelectors() { mNodeSelectors["empty"] = []( const UIWidget* node, int a, int b, - FunctionString data ) -> bool { + const FunctionString& data ) -> bool { return node->getFirstChild() == NULL; }; mNodeSelectors["first-child"] = []( const UIWidget* node, int a, int b, - FunctionString data ) -> bool { + const FunctionString& data ) -> bool { return NULL != node->getParent() && node->getParent()->getFirstChild() == node; }; mNodeSelectors["enabled"] = []( const UIWidget* node, int a, int b, - FunctionString data ) -> bool { return node->isEnabled(); }; + const FunctionString& data ) -> bool { return node->isEnabled(); }; mNodeSelectors["disabled"] = []( const UIWidget* node, int a, int b, - FunctionString data ) -> bool { return !node->isEnabled(); }; + const FunctionString& data ) -> bool { return !node->isEnabled(); }; mNodeSelectors["first-of-type"] = []( const UIWidget* node, int a, int b, - FunctionString data ) -> bool { + const FunctionString& data ) -> bool { Node* child = NULL != node->getParent() ? node->getParent()->getFirstChild() : NULL; Uint32 type = node->getType(); while ( NULL != child ) { @@ -448,11 +448,11 @@ void StyleSheetSpecification::registerDefaultNodeSelectors() { return false; }; mNodeSelectors["last-child"] = []( const UIWidget* node, int a, int b, - FunctionString data ) -> bool { + const FunctionString& data ) -> bool { return NULL != node->getParent() && node->getParent()->getLastChild() == node; }; mNodeSelectors["last-of-type"] = []( const UIWidget* node, int a, int b, - FunctionString data ) -> bool { + const FunctionString& data ) -> bool { Node* child = NULL != node->getParent() ? node->getParent()->getLastChild() : NULL; Uint32 type = node->getType(); while ( NULL != child ) { @@ -464,11 +464,11 @@ void StyleSheetSpecification::registerDefaultNodeSelectors() { return false; }; mNodeSelectors["only-child"] = []( const UIWidget* node, int a, int b, - FunctionString data ) -> bool { + const FunctionString& data ) -> bool { return NULL != node->getParent() && node->getParent()->getChildCount() == 1; }; mNodeSelectors["only-of-type"] = []( const UIWidget* node, int a, int b, - FunctionString data ) -> bool { + const FunctionString& data ) -> bool { Node* child = NULL != node->getParent() ? node->getParent()->getFirstChild() : NULL; Uint32 type = node->getType(); Uint32 typeCount = 0; @@ -483,19 +483,19 @@ void StyleSheetSpecification::registerDefaultNodeSelectors() { return typeCount == 1; }; mNodeSelectors["nth-child"] = []( const UIWidget* node, int a, int b, - FunctionString data ) -> bool { + const FunctionString& data ) -> bool { return isNth( a, b, node->getNodeIndex() + 1 ); }; mNodeSelectors["nth-last-child"] = []( const UIWidget* node, int a, int b, - FunctionString data ) -> bool { + const FunctionString& data ) -> bool { return isNth( a, b, node->getChildCount() - node->getNodeIndex() ); }; mNodeSelectors["nth-of-type"] = []( const UIWidget* node, int a, int b, - FunctionString data ) -> bool { + const FunctionString& data ) -> bool { return isNth( a, b, node->getNodeOfTypeIndex() + 1 ); }; mNodeSelectors["nth-last-of-type"] = []( const UIWidget* node, int a, int b, - FunctionString data ) -> bool { + const FunctionString& data ) -> bool { return node->getParent() != NULL ? isNth( a, b, node->getParent()->getChildOfTypeCount( node->getType() ) - @@ -503,10 +503,10 @@ void StyleSheetSpecification::registerDefaultNodeSelectors() { : false; }; mNodeSelectors["checked"] = []( const UIWidget* node, int a, int b, - FunctionString data ) -> bool { + const FunctionString& data ) -> bool { return 0 != ( node->getFlags() & UI_CHECKED ); }; - mNodeSelectors["not"] = []( const UIWidget* node, int a, int b, FunctionString data ) -> bool { + mNodeSelectors["not"] = []( const UIWidget* node, int a, int b, const FunctionString& data ) -> bool { if ( !data.isEmpty() && !data.getParameters().empty() && data.getName() == "not" ) { for ( const auto& param : data.getParameters() ) { if ( !param.empty() ) { diff --git a/src/eepp/ui/uifiledialog.cpp b/src/eepp/ui/uifiledialog.cpp index d6bcf7109..bdec6eb7c 100644 --- a/src/eepp/ui/uifiledialog.cpp +++ b/src/eepp/ui/uifiledialog.cpp @@ -199,9 +199,9 @@ void UIFileDialog::setTheme( UITheme* Theme ) { void UIFileDialog::refreshFolder() { FileSystem::dirAddSlashAtEnd( mCurPath ); - std::vector flist = FileSystem::filesGetInPath( String( mCurPath ) ); + std::vector flist = FileSystem::filesGetInPath( + String( mCurPath ), getSortAlphabetically(), getFoldersFirst(), !getShowHidden() ); std::vector files; - std::vector folders; std::vector patterns; bool accepted; Uint32 i, z; @@ -214,9 +214,9 @@ void UIFileDialog::refreshFolder() { } for ( i = 0; i < flist.size(); i++ ) { - if ( getFoldersFirst() && FileSystem::isDirectory( mCurPath + flist[i] ) ) { - folders.push_back( flist[i] ); - } else { + if ( FileSystem::isDirectory( mCurPath + flist[i] ) ) { + files.push_back( flist[i] ); + } else if ( !getShowOnlyFolders() ) { accepted = false; if ( patterns.size() ) { @@ -235,17 +235,8 @@ void UIFileDialog::refreshFolder() { } } - if ( getSortAlphabetically() ) { - std::sort( folders.begin(), folders.end() ); - std::sort( files.begin(), files.end() ); - } - mList->clear(); - if ( getFoldersFirst() ) { - mList->addListBoxItems( folders ); - } - mList->addListBoxItems( files ); updateClickStep(); @@ -420,6 +411,14 @@ bool UIFileDialog::getAllowFolderSelect() { return 0 != ( mDialogFlags & AllowFolderSelect ); } +bool UIFileDialog::getShowOnlyFolders() { + return 0 != ( mDialogFlags & ShowOnlyFolders ); +} + +bool UIFileDialog::getShowHidden() { + return 0 != ( mDialogFlags & ShowHidden ); +} + void UIFileDialog::setSortAlphabetically( const bool& sortAlphabetically ) { BitOp::setBitFlagValue( &mDialogFlags, SortAlphabetically, sortAlphabetically ? 1 : 0 ); refreshFolder(); @@ -434,6 +433,16 @@ void UIFileDialog::setAllowFolderSelect( const bool& allowFolderSelect ) { BitOp::setBitFlagValue( &mDialogFlags, AllowFolderSelect, allowFolderSelect ? 1 : 0 ); } +void UIFileDialog::setShowOnlyFolders( const bool& showOnlyFolders ) { + BitOp::setBitFlagValue( &mDialogFlags, ShowOnlyFolders, showOnlyFolders ? 1 : 0 ); + refreshFolder(); +} + +void UIFileDialog::setShowHidden( const bool& showHidden ) { + BitOp::setBitFlagValue( &mDialogFlags, ShowHidden, showHidden ? 1 : 0 ); + refreshFolder(); +} + std::string UIFileDialog::getFullPath() { std::string tPath = mCurPath; diff --git a/src/eepp/ui/uipushbutton.cpp b/src/eepp/ui/uipushbutton.cpp index 4e5afca13..60930479d 100644 --- a/src/eepp/ui/uipushbutton.cpp +++ b/src/eepp/ui/uipushbutton.cpp @@ -110,12 +110,14 @@ Vector2f UIPushButton::packLayout( const std::vector& widgets, const break; } if ( 0 == i ) - pos[i].x += PixelDensity::dpToPxI( widget->getLayoutMargin().Left ); - totSize.x += widget->getPixelsSize().getWidth() > 0 - ? PixelDensity::dpToPxI( widget->getLayoutMargin().Left + - widget->getLayoutMargin().Right ) + - widget->getPixelsSize().getWidth() - : 0; + pos[i].x += widget->getLayoutPixelsMargin().Left; + if ( widget->getPixelsSize().getWidth() > 0 ) { + totSize.x += widget->getLayoutPixelsMargin().Left + widget->getPixelsSize().getWidth(); + if ( ( i + 1 < widgets.size() && widgets[i + 1] && widgets[i + 1]->isVisible() ) || + ( i + 2 < widgets.size() && widgets[i + 2] && widgets[i + 2]->isVisible() ) ) { + totSize.x += widget->getLayoutPixelsMargin().Right; + } + } totSize.y = eemax( totSize.y, padding.Top + padding.Bottom + widget->getPixelsSize().getHeight() ); } @@ -223,6 +225,7 @@ UIPushButton* UIPushButton::setIcon( Drawable* icon ) { if ( mIcon->getDrawable() != icon ) { mIcon->setPixelsSize( icon->getPixelsSize() ); mIcon->setDrawable( icon ); + mTextBox->setVisible( !getText().empty() ); updateLayout(); } return this; @@ -234,6 +237,7 @@ UIImage* UIPushButton::getIcon() const { UIPushButton* UIPushButton::setText( const String& text ) { if ( text != mTextBox->getText() ) { + mTextBox->setVisible( !text.empty() ); mTextBox->setText( text ); updateLayout(); } diff --git a/src/eepp/ui/uitreeview.cpp b/src/eepp/ui/uitreeview.cpp index 7167e5364..75691c9e4 100644 --- a/src/eepp/ui/uitreeview.cpp +++ b/src/eepp/ui/uitreeview.cpp @@ -106,14 +106,14 @@ void UITreeView::updateContentSize() { onContentSizeChange(); } -class UITreeViewCell : public UIPushButton { +class UITreeViewCell : public UITableCell { public: static UITreeViewCell* New() { return eeNew( UITreeViewCell, () ); } Uint32 getType() const { return UI_TYPE_TREEVIEW_CELL; } bool isType( const Uint32& type ) const { - return UITreeViewCell::getType() == type ? true : UIPushButton::isType( type ); + return UITreeViewCell::getType() == type ? true : UITableCell::isType( type ); } UIImage* getImage() const { return mImage; } @@ -160,7 +160,7 @@ class UITreeViewCell : public UIPushButton { mutable UIImage* mImage{nullptr}; Float mIndent{0}; - UITreeViewCell() : UIPushButton( "treeview::cell" ) { + UITreeViewCell() : UITableCell( "treeview::cell" ) { mTextBox->setElementTag( mTag + "::text" ); mIcon->setElementTag( mTag + "::icon" ); mInnerWidgetOrientation = InnerWidgetOrientation::Left; @@ -182,14 +182,14 @@ class UITreeViewCell : public UIPushButton { }; UIWidget* UITreeView::createCell( UIWidget* rowWidget, const ModelIndex& index ) { - UIPushButton* widget = index.column() == (Int64)getModel()->treeColumn() - ? UITreeViewCell::New() - : UIPushButton::NewWithTag( "table::cell" ); + UITableCell* widget = index.column() == (Int64)getModel()->treeColumn() ? UITreeViewCell::New() + : UITableCell::New(); widget->setParent( rowWidget ); widget->unsetFlags( UI_AUTO_SIZE ); widget->clipEnable(); widget->setLayoutSizePolicy( SizePolicy::Fixed, SizePolicy::Fixed ); widget->setTextAlign( UI_HALIGN_LEFT ); + widget->setCurIndex( index ); if ( index.column() == (Int64)getModel()->treeColumn() ) { widget->addEventListener( Event::MouseDoubleClick, [&]( const Event* event ) { auto mouseEvent = static_cast( event ); @@ -240,15 +240,16 @@ UIWidget* UITreeView::updateCell( const int& rowIndex, const ModelIndex& index, widget->setPixelsSize( columnData( index.column() ).width, getRowHeight() ); widget->setPixelsPosition( {getColumnPosition( index.column() ).x, 0} ); - if ( widget->isType( UI_TYPE_PUSHBUTTON ) ) { - UIPushButton* pushButton = widget->asType(); + if ( widget->isType( UI_TYPE_TABLECELL ) ) { + UITableCell* cell = widget->asType(); + cell->setCurIndex( index ); Variant txt( getModel()->data( index, Model::Role::Display ) ); if ( txt.isValid() ) { if ( txt.is( Variant::Type::String ) ) - pushButton->setText( txt.asString() ); + cell->setText( txt.asString() ); else if ( txt.is( Variant::Type::cstr ) ) - pushButton->setText( txt.asCStr() ); + cell->setText( txt.asCStr() ); } bool hasChilds = false; @@ -285,7 +286,7 @@ UIWidget* UITreeView::updateCell( const int& rowIndex, const ModelIndex& index, } if ( hasChilds && mExpandersAsIcons ) { - pushButton->getIcon()->setVisible( false ); + cell->getIcon()->setVisible( false ); return widget; } @@ -293,9 +294,9 @@ UIWidget* UITreeView::updateCell( const int& rowIndex, const ModelIndex& index, Variant icon( getModel()->data( index, Model::Role::Icon ) ); if ( icon.is( Variant::Type::Drawable ) && icon.asDrawable() ) { isVisible = true; - pushButton->setIcon( icon.asDrawable() ); + cell->setIcon( icon.asDrawable() ); } - pushButton->getIcon()->setVisible( isVisible ); + cell->getIcon()->setVisible( isVisible ); } return widget; diff --git a/src/eepp/ui/uiwidgetcreator.cpp b/src/eepp/ui/uiwidgetcreator.cpp index b75f56118..a9929179c 100644 --- a/src/eepp/ui/uiwidgetcreator.cpp +++ b/src/eepp/ui/uiwidgetcreator.cpp @@ -20,8 +20,8 @@ #include #include #include -#include -#include +#include +#include #include #include #include @@ -65,8 +65,8 @@ void UIWidgetCreator::createBaseWidgetList() { registeredWidget["spinbox"] = UISpinBox::New; registeredWidget["sprite"] = UISprite::New; registeredWidget["tab"] = UITab::New; - registeredWidget["table"] = UITable::New; - registeredWidget["tablecell"] = UITableCell::New; + registeredWidget["widgettable"] = UIWidgetTable::New; + registeredWidget["widgettablerow"] = UIWidgetTableRow::New; registeredWidget["tabwidget"] = UITabWidget::New; registeredWidget["textedit"] = UITextEdit::New; registeredWidget["textinput"] = UITextInput::New; diff --git a/src/eepp/ui/uitable.cpp b/src/eepp/ui/uiwidgettable.cpp similarity index 76% rename from src/eepp/ui/uitable.cpp rename to src/eepp/ui/uiwidgettable.cpp index fe5ff34fe..ebbf0842e 100644 --- a/src/eepp/ui/uitable.cpp +++ b/src/eepp/ui/uiwidgettable.cpp @@ -1,15 +1,15 @@ #include -#include +#include #include namespace EE { namespace UI { -UITable* UITable::New() { - return eeNew( UITable, () ); +UIWidgetTable* UIWidgetTable::New() { + return eeNew( UIWidgetTable, () ); } -UITable::UITable() : - UITouchDraggableWidget( "table" ), +UIWidgetTable::UIWidgetTable() : + UITouchDraggableWidget( "widgettable" ), mContainerPadding(), mContainer( NULL ), mVScrollBar( NULL ), @@ -31,7 +31,7 @@ UITable::UITable() : auto cb = [&]( const Event* ) { containerResize(); }; - mContainer = eeNew( UIItemContainer, () ); + mContainer = eeNew( UIItemContainer, () ); mContainer->setVisible( true ); mContainer->setEnabled( true ); mContainer->setParent( this ); @@ -57,9 +57,9 @@ UITable::UITable() : mVScrollBar->setEnabled( ScrollBarMode::AlwaysOn == mVScrollMode ); mVScrollBar->addEventListener( Event::OnValueChange, - cb::Make1( this, &UITable::onScrollValueChange ) ); + cb::Make1( this, &UIWidgetTable::onScrollValueChange ) ); mHScrollBar->addEventListener( Event::OnValueChange, - cb::Make1( this, &UITable::onScrollValueChange ) ); + cb::Make1( this, &UIWidgetTable::onScrollValueChange ) ); mVScrollBar->addEventListener( Event::OnSizeChange, cb ); mHScrollBar->addEventListener( Event::OnSizeChange, cb ); @@ -67,17 +67,17 @@ UITable::UITable() : applyDefaultTheme(); } -UITable::~UITable() {} +UIWidgetTable::~UIWidgetTable() {} -Uint32 UITable::getType() const { - return UI_TYPE_TABLE; +Uint32 UIWidgetTable::getType() const { + return UI_TYPE_WIDGETTABLE; } -bool UITable::isType( const Uint32& type ) const { - return UITable::getType() == type ? true : UITouchDraggableWidget::isType( type ); +bool UIWidgetTable::isType( const Uint32& type ) const { + return UIWidgetTable::getType() == type ? true : UITouchDraggableWidget::isType( type ); } -void UITable::setDefaultColumnsWidth() { +void UIWidgetTable::setDefaultColumnsWidth() { if ( mCollWidthAssigned || 0 == mColumnsCount || 0 == mRowHeight ) return; @@ -105,11 +105,11 @@ void UITable::setDefaultColumnsWidth() { updateCells(); } -void UITable::onScrollValueChange( const Event* ) { +void UIWidgetTable::onScrollValueChange( const Event* ) { updateScroll( true ); } -void UITable::setTheme( UITheme* Theme ) { +void UIWidgetTable::setTheme( UITheme* Theme ) { UIWidget::setTheme( Theme ); setThemeSkin( Theme, "genericgrid" ); @@ -121,20 +121,20 @@ void UITable::setTheme( UITheme* Theme ) { onThemeLoaded(); } -void UITable::autoPadding() { +void UIWidgetTable::autoPadding() { if ( mFlags & UI_AUTO_PADDING ) { mContainerPadding = PixelDensity::dpToPx( makePadding() ); } } -void UITable::onSizeChange() { +void UIWidgetTable::onSizeChange() { containerResize(); setDefaultColumnsWidth(); updateScroll(); updatePageStep(); } -void UITable::containerResize() { +void UIWidgetTable::containerResize() { Rectf padding = mContainerPadding + mPaddingPx; mContainer->setPosition( padding.Left, padding.Top ); @@ -158,7 +158,7 @@ void UITable::containerResize() { updateScrollBar(); } -void UITable::updateVScroll() { +void UIWidgetTable::updateVScroll() { if ( mItemsNotVisible <= 0 ) { if ( ScrollBarMode::AlwaysOn == mVScrollMode ) { mVScrollBar->setVisible( true ); @@ -180,7 +180,7 @@ void UITable::updateVScroll() { containerResize(); } -void UITable::updateHScroll() { +void UIWidgetTable::updateHScroll() { if ( mContainer->isClipped() && ( ScrollBarMode::Auto == mHScrollMode || ScrollBarMode::AlwaysOn == mHScrollMode ) ) { if ( mContainer->getSize().getWidth() < (Int32)mTotalWidth ) { @@ -207,7 +207,7 @@ void UITable::updateHScroll() { } } -void UITable::setHScrollStep() { +void UIWidgetTable::setHScrollStep() { Float width = (Float)mContainer->getPixelsSize().getWidth(); if ( ( mItemsNotVisible > 0 && ScrollBarMode::Auto == mVScrollMode ) || @@ -229,7 +229,7 @@ void UITable::setHScrollStep() { mHScrollBar->setClickStep( stepVal ); } -void UITable::updateScrollBar() { +void UIWidgetTable::updateScrollBar() { mVScrollBar->setPosition( getSize().getWidth() - mVScrollBar->getSize().getWidth(), 0 ); mVScrollBar->setSize( mVScrollBar->getSize().getWidth(), getSize().getHeight() ); @@ -246,11 +246,11 @@ void UITable::updateScrollBar() { } } -void UITable::updateScroll( bool FromScrollChange ) { +void UIWidgetTable::updateScroll( bool FromScrollChange ) { if ( !mItems.size() ) return; - UITableCell* Item; + UIWidgetTableRow* Item; Uint32 i, RelPos = 0, RelPosMax; Int32 ItemPos, ItemPosMax; Int32 tHLastScroll = mHScrollInit; @@ -356,23 +356,23 @@ void UITable::updateScroll( bool FromScrollChange ) { setHScrollStep(); } -void UITable::updateSize() { +void UIWidgetTable::updateSize() { updateColumnsPos(); mTotalHeight = mItems.size() * mRowHeight; } -void UITable::add( UITableCell* Cell ) { - Cell->setParent( getContainer() ); +void UIWidgetTable::add( UIWidgetTableRow* row ) { + row->setParent( getContainer() ); - mItems.push_back( Cell ); + mItems.push_back( row ); - if ( mContainer != Cell->getParent() ) - Cell->setParent( mContainer ); + if ( mContainer != row->getParent() ) + row->setParent( mContainer ); setDefaultColumnsWidth(); - Cell->onAutoSize(); + row->onAutoSize(); updateSize(); @@ -381,24 +381,24 @@ void UITable::add( UITableCell* Cell ) { updatePageStep(); } -void UITable::remove( UITableCell* Cell ) { - return remove( getItemIndex( Cell ) ); +void UIWidgetTable::remove( UIWidgetTableRow* row ) { + return remove( getItemIndex( row ) ); } -void UITable::remove( std::vector ItemsIndex ) { - if ( ItemsIndex.size() && eeINDEX_NOT_FOUND != ItemsIndex[0] ) { - std::vector ItemsCpy; +void UIWidgetTable::remove( std::vector itemsIndex ) { + if ( itemsIndex.size() && eeINDEX_NOT_FOUND != itemsIndex[0] ) { + std::vector ItemsCpy; bool erase; for ( Uint32 i = 0; i < mItems.size(); i++ ) { erase = false; - for ( Uint32 z = 0; z < ItemsIndex.size(); z++ ) { - if ( ItemsIndex[z] == i ) { - if ( (Int32)ItemsIndex[z] == mSelected ) + for ( Uint32 z = 0; z < itemsIndex.size(); z++ ) { + if ( itemsIndex[z] == i ) { + if ( (Int32)itemsIndex[z] == mSelected ) mSelected = -1; - ItemsIndex.erase( ItemsIndex.begin() + z ); + itemsIndex.erase( itemsIndex.begin() + z ); erase = true; @@ -424,16 +424,17 @@ void UITable::remove( std::vector ItemsIndex ) { } } -void UITable::remove( Uint32 ItemIndex ) { - remove( std::vector( 1, ItemIndex ) ); +void UIWidgetTable::remove( Uint32 itemIndex ) { + remove( std::vector( 1, itemIndex ) ); } -UITable* UITable::setColumnWidth( const Uint32& ColumnIndex, const Uint32& ColumnWidth ) { - eeASSERT( ColumnIndex < mColumnsCount ); +UIWidgetTable* UIWidgetTable::setColumnWidth( const Uint32& columnIndex, + const Uint32& ColumnWidth ) { + eeASSERT( columnIndex < mColumnsCount ); mCollWidthAssigned = true; - mColumnsWidth[ColumnIndex] = ColumnWidth; + mColumnsWidth[columnIndex] = ColumnWidth; updateColumnsPos(); updateCells(); @@ -442,11 +443,11 @@ UITable* UITable::setColumnWidth( const Uint32& ColumnIndex, const Uint32& Colum return this; } -Uint32 UITable::getCount() const { +Uint32 UIWidgetTable::getCount() const { return mItems.size(); } -UITable* UITable::setColumnsCount( const Uint32& columnsCount ) { +UIWidgetTable* UIWidgetTable::setColumnsCount( const Uint32& columnsCount ) { mColumnsCount = columnsCount; mColumnsWidth.resize( mColumnsCount, 0 ); @@ -457,17 +458,17 @@ UITable* UITable::setColumnsCount( const Uint32& columnsCount ) { return this; } -const Uint32& UITable::getColumnsCount() const { +const Uint32& UIWidgetTable::getColumnsCount() const { return mColumnsCount; } -const Uint32& UITable::getColumnWidth( const Uint32& ColumnIndex ) const { - eeASSERT( ColumnIndex < mColumnsCount ); +const Uint32& UIWidgetTable::getColumnWidth( const Uint32& columnIndex ) const { + eeASSERT( columnIndex < mColumnsCount ); - return mColumnsWidth[ColumnIndex]; + return mColumnsWidth[columnIndex]; } -UITable* UITable::setRowHeight( const Uint32& height ) { +UIWidgetTable* UIWidgetTable::setRowHeight( const Uint32& height ) { if ( mRowHeight != height ) { mRowHeight = height; @@ -479,29 +480,29 @@ UITable* UITable::setRowHeight( const Uint32& height ) { return this; } -const Uint32& UITable::getRowHeight() const { +const Uint32& UIWidgetTable::getRowHeight() const { return mRowHeight; } -UITableCell* UITable::getCell( const Uint32& CellIndex ) const { - eeASSERT( CellIndex < mItems.size() ); +UIWidgetTableRow* UIWidgetTable::getRow( const Uint32& rowIndex ) const { + eeASSERT( rowIndex < mItems.size() ); - return mItems[CellIndex]; + return mItems[rowIndex]; } -Uint32 UITable::getCellPosition( const Uint32& ColumnIndex ) { - eeASSERT( ColumnIndex < mColumnsCount ); +Uint32 UIWidgetTable::getColumnPosition( const Uint32& columnIndex ) { + eeASSERT( columnIndex < mColumnsCount ); - return mColumnsPos[ColumnIndex]; + return mColumnsPos[columnIndex]; } -void UITable::updateCells() { +void UIWidgetTable::updateCells() { for ( Uint32 i = 0; i < mItems.size(); i++ ) { - mItems[i]->fixCell(); + mItems[i]->updateRow(); } } -void UITable::updateColumnsPos() { +void UIWidgetTable::updateColumnsPos() { Uint32 Pos = 0; for ( Uint32 i = 0; i < mColumnsCount; i++ ) { @@ -513,28 +514,28 @@ void UITable::updateColumnsPos() { mTotalWidth = Pos; } -void UITable::onAlphaChange() { +void UIWidgetTable::onAlphaChange() { UINode::onAlphaChange(); mVScrollBar->setAlpha( mAlpha ); mHScrollBar->setAlpha( mAlpha ); } -void UITable::setVerticalScrollMode( const ScrollBarMode& Mode ) { - if ( Mode != mVScrollMode ) { - mVScrollMode = Mode; +void UIWidgetTable::setVerticalScrollMode( const ScrollBarMode& mode ) { + if ( mode != mVScrollMode ) { + mVScrollMode = mode; updateScroll(); } } -const ScrollBarMode& UITable::getVerticalScrollMode() { +const ScrollBarMode& UIWidgetTable::getVerticalScrollMode() { return mVScrollMode; } -void UITable::setHorizontalScrollMode( const ScrollBarMode& Mode ) { - if ( Mode != mHScrollMode ) { - mHScrollMode = Mode; +void UIWidgetTable::setHorizontalScrollMode( const ScrollBarMode& mode ) { + if ( mode != mHScrollMode ) { + mHScrollMode = mode; if ( ScrollBarMode::AlwaysOn == mHScrollMode ) { mHScrollBar->setVisible( true ); @@ -550,45 +551,45 @@ void UITable::setHorizontalScrollMode( const ScrollBarMode& Mode ) { } } -const ScrollBarMode& UITable::getHorizontalScrollMode() { +const ScrollBarMode& UIWidgetTable::getHorizontalScrollMode() { return mHScrollMode; } -UIScrollBar* UITable::getVerticalScrollBar() const { +UIScrollBar* UIWidgetTable::getVerticalScrollBar() const { return mVScrollBar; } -UIScrollBar* UITable::getHorizontalScrollBar() const { +UIScrollBar* UIWidgetTable::getHorizontalScrollBar() const { return mHScrollBar; } -Uint32 UITable::getItemIndex( UITableCell* Item ) { +Uint32 UIWidgetTable::getItemIndex( UIWidgetTableRow* item ) { for ( Uint32 i = 0; i < mItems.size(); i++ ) { - if ( Item == mItems[i] ) + if ( item == mItems[i] ) return i; } return eeINDEX_NOT_FOUND; } -Uint32 UITable::onSelected() { +Uint32 UIWidgetTable::onSelected() { sendCommonEvent( Event::OnItemSelected ); return 1; } -UITableCell* UITable::getItemSelected() { +UIWidgetTableRow* UIWidgetTable::getItemSelected() { if ( -1 != mSelected ) return mItems[mSelected]; return NULL; } -Uint32 UITable::getItemSelectedIndex() const { +Uint32 UIWidgetTable::getItemSelectedIndex() const { return mSelected; } -Uint32 UITable::onMessage( const NodeMessage* Msg ) { +Uint32 UIWidgetTable::onMessage( const NodeMessage* Msg ) { switch ( Msg->getMsg() ) { case NodeMessage::FocusLoss: { if ( NULL != getEventDispatcher() ) { @@ -606,15 +607,15 @@ Uint32 UITable::onMessage( const NodeMessage* Msg ) { return 0; } -UIItemContainer* UITable::getContainer() const { +UIItemContainer* UIWidgetTable::getContainer() const { return mContainer; } -bool UITable::getSmoothScroll() const { +bool UIWidgetTable::getSmoothScroll() const { return mSmoothScroll; } -UITable* UITable::setSmoothScroll( bool smoothScroll ) { +UIWidgetTable* UIWidgetTable::setSmoothScroll( bool smoothScroll ) { mSmoothScroll = smoothScroll; if ( mSmoothScroll ) { @@ -626,15 +627,15 @@ UITable* UITable::setSmoothScroll( bool smoothScroll ) { return this; } -Rectf UITable::getContainerPadding() const { +Rectf UIWidgetTable::getContainerPadding() const { return PixelDensity::pxToDp( mContainerPadding + mPaddingPx ); } -void UITable::onPaddingChange() { +void UIWidgetTable::onPaddingChange() { containerResize(); } -void UITable::onTouchDragValueChange( Vector2f diff ) { +void UIWidgetTable::onTouchDragValueChange( Vector2f diff ) { if ( mVScrollBar->isEnabled() ) mVScrollBar->setValue( mVScrollBar->getValue() + ( -diff.y / ( Float )( ( mItems.size() - 1 ) * mRowHeight ) ) ); @@ -643,18 +644,18 @@ void UITable::onTouchDragValueChange( Vector2f diff ) { mHScrollBar->setValue( mHScrollBar->getValue() + ( -diff.x / mTotalWidth ) ); } -bool UITable::isTouchOverAllowedChilds() { +bool UIWidgetTable::isTouchOverAllowedChilds() { return isMouseOverMeOrChilds() && !mVScrollBar->isMouseOverMeOrChilds() && !mHScrollBar->isMouseOverMeOrChilds(); } -void UITable::updatePageStep() { +void UIWidgetTable::updatePageStep() { mVScrollBar->setPageStep( ( (Float)mContainer->getSize().getHeight() / (Float)mRowHeight ) / (Float)mItems.size() ); } -std::string UITable::getPropertyString( const PropertyDefinition* propertyDef, - const Uint32& propertyIndex ) { +std::string UIWidgetTable::getPropertyString( const PropertyDefinition* propertyDef, + const Uint32& propertyIndex ) { if ( NULL == propertyDef ) return ""; @@ -677,7 +678,7 @@ std::string UITable::getPropertyString( const PropertyDefinition* propertyDef, } } -bool UITable::applyProperty( const StyleSheetProperty& attribute ) { +bool UIWidgetTable::applyProperty( const StyleSheetProperty& attribute ) { if ( !checkPropertyDefinition( attribute ) ) return false; diff --git a/src/eepp/ui/uitablecell.cpp b/src/eepp/ui/uiwidgettablerow.cpp similarity index 56% rename from src/eepp/ui/uitablecell.cpp rename to src/eepp/ui/uiwidgettablerow.cpp index 14f042e7d..4e633b3a5 100644 --- a/src/eepp/ui/uitablecell.cpp +++ b/src/eepp/ui/uiwidgettablerow.cpp @@ -1,17 +1,17 @@ -#include -#include +#include +#include namespace EE { namespace UI { -UITableCell* UITableCell::New() { - return eeNew( UITableCell, () ); +UIWidgetTableRow* UIWidgetTableRow::New() { + return eeNew( UIWidgetTableRow, () ); } -UITableCell::UITableCell() : UIWidget( "tablecell" ) { +UIWidgetTableRow::UIWidgetTableRow() : UIWidget( "widgettablerow" ) { applyDefaultTheme(); } -UITableCell::~UITableCell() { +UIWidgetTableRow::~UIWidgetTableRow() { if ( NULL != getEventDispatcher() ) { if ( getEventDispatcher()->getFocusNode() == this ) mParentNode->setFocus(); @@ -21,24 +21,32 @@ UITableCell::~UITableCell() { } } -void UITableCell::setTheme( UITheme* Theme ) { +Uint32 UIWidgetTableRow::getType() const { + return UI_TYPE_WIDGETTABLEROW; +} + +bool UIWidgetTableRow::isType( const Uint32& type ) const { + return UIWidgetTableRow::getType() == type ? true : UIWidget::isType( type ); +} + +void UIWidgetTableRow::setTheme( UITheme* Theme ) { UIWidget::setTheme( Theme ); - setThemeSkin( Theme, "gridcell" ); + setThemeSkin( Theme, "tablerow" ); onThemeLoaded(); } -UITable* UITableCell::gridParent() const { - return mParentNode->getParent()->asType(); +UIWidgetTable* UIWidgetTableRow::gridParent() const { + return mParentNode->getParent()->asType(); } -void UITableCell::setCell( const Uint32& ColumnIndex, UINode* node ) { - eeASSERT( ColumnIndex < gridParent()->getColumnsCount() ); +void UIWidgetTableRow::setColumn( const Uint32& columnIndex, UINode* node ) { + eeASSERT( columnIndex < gridParent()->getColumnsCount() ); - UITable* P = gridParent(); + UIWidgetTable* P = gridParent(); - mCells[ColumnIndex] = node; + mCells[columnIndex] = node; if ( node->getParent() != this ) node->setParent( this ); @@ -46,32 +54,32 @@ void UITableCell::setCell( const Uint32& ColumnIndex, UINode* node ) { if ( node->isWidget() ) static_cast( node )->setLayoutSizePolicy( SizePolicy::Fixed, SizePolicy::Fixed ); - node->setPosition( P->getCellPosition( ColumnIndex ), 0 ); - node->setSize( P->getColumnWidth( ColumnIndex ), P->getRowHeight() ); + node->setPosition( P->getColumnPosition( columnIndex ), 0 ); + node->setSize( P->getColumnWidth( columnIndex ), P->getRowHeight() ); node->setVisible( true ); node->setEnabled( true ); } -UINode* UITableCell::getCell( const Uint32& ColumnIndex ) const { - eeASSERT( ColumnIndex < gridParent()->getColumnsCount() ); +UINode* UIWidgetTableRow::getColumn( const Uint32& columnIndex ) const { + eeASSERT( columnIndex < gridParent()->getColumnsCount() ); - return mCells[ColumnIndex]; + return mCells[columnIndex]; } -void UITableCell::fixCell() { +void UIWidgetTableRow::updateRow() { onAutoSize(); - UITable* P = gridParent(); + UIWidgetTable* P = gridParent(); for ( Uint32 i = 0; i < mCells.size(); i++ ) { - mCells[i]->setPosition( P->getCellPosition( i ), 0 ); + mCells[i]->setPosition( P->getColumnPosition( i ), 0 ); mCells[i]->setSize( P->getColumnWidth( i ), P->getRowHeight() ); } } -void UITableCell::select() { - UITable* MyParent = getParent()->getParent()->asType(); +void UIWidgetTableRow::select() { + UIWidgetTable* MyParent = getParent()->getParent()->asType(); if ( MyParent->getItemSelected() != this ) { if ( NULL != MyParent->getItemSelected() ) @@ -91,18 +99,18 @@ void UITableCell::select() { } } -void UITableCell::unselect() { +void UIWidgetTableRow::unselect() { if ( mNodeFlags & NODE_FLAG_SELECTED ) mNodeFlags &= ~NODE_FLAG_SELECTED; popState( UIState::StateSelected ); } -bool UITableCell::isSelected() const { +bool UIWidgetTableRow::isSelected() const { return 0 != ( mNodeFlags & NODE_FLAG_SELECTED ); } -Uint32 UITableCell::onMouseLeave( const Vector2i& Pos, const Uint32& Flags ) { +Uint32 UIWidgetTableRow::onMouseLeave( const Vector2i& Pos, const Uint32& Flags ) { UIWidget::onMouseLeave( Pos, Flags ); if ( mNodeFlags & NODE_FLAG_SELECTED ) @@ -111,7 +119,7 @@ Uint32 UITableCell::onMouseLeave( const Vector2i& Pos, const Uint32& Flags ) { return 1; } -Uint32 UITableCell::onMessage( const NodeMessage* Msg ) { +Uint32 UIWidgetTableRow::onMessage( const NodeMessage* Msg ) { switch ( Msg->getMsg() ) { case NodeMessage::MouseClick: { if ( Msg->getFlags() & EE_BUTTONS_LRM ) { @@ -127,7 +135,7 @@ Uint32 UITableCell::onMessage( const NodeMessage* Msg ) { break; } case NodeMessage::MouseUp: { - UITable* MyParent = getParent()->getParent()->asType(); + UIWidgetTable* MyParent = getParent()->getParent()->asType(); if ( ( Msg->getFlags() & EE_BUTTONS_WUWD ) && MyParent->getVerticalScrollBar()->isVisible() ) { @@ -141,13 +149,13 @@ Uint32 UITableCell::onMessage( const NodeMessage* Msg ) { return 0; } -void UITableCell::onAutoSize() { - UITable* MyParent = getParent()->getParent()->asType(); +void UIWidgetTableRow::onAutoSize() { + UIWidgetTable* MyParent = getParent()->getParent()->asType(); setInternalSize( Sizef( MyParent->mTotalWidth, MyParent->mRowHeight ) ); } -void UITableCell::onStateChange() { +void UIWidgetTableRow::onStateChange() { UIWidget::onStateChange(); if ( isSelected() && NULL != mSkinState && @@ -156,14 +164,14 @@ void UITableCell::onStateChange() { } } -void UITableCell::onParentChange() { +void UIWidgetTableRow::onParentChange() { if ( NULL != getParent() && NULL != gridParent() ) mCells.resize( gridParent()->getColumnsCount(), NULL ); } -void UITableCell::onAlphaChange() { +void UIWidgetTableRow::onAlphaChange() { if ( mEnabled && mVisible ) { - UITable* MyParent = getParent()->getParent()->asType(); + UIWidgetTable* MyParent = getParent()->getParent()->asType(); if ( NULL != MyParent && MyParent->getAlpha() != mAlpha ) { setAlpha( MyParent->getAlpha() ); diff --git a/src/tests/test_all/test.cpp b/src/tests/test_all/test.cpp index 565be1f48..391697af2 100644 --- a/src/tests/test_all/test.cpp +++ b/src/tests/test_all/test.cpp @@ -476,13 +476,13 @@ void EETest::createBaseUI() { TextEdit->setParent( C )->setPosition( 5, 245 )->setSize( 315, 130 ); TextEdit->setText( mBuda ); - UITable* genGrid = UITable::New(); + UIWidgetTable* genGrid = UIWidgetTable::New(); genGrid->setSmoothScroll( true )->setFlags( UI_TOUCH_DRAG_ENABLED ); genGrid->setParent( C )->setPosition( 325, 245 )->setSize( 200, 130 ); genGrid->setColumnsCount( 3 )->setRowHeight( 24 ); for ( Uint32 i = 0; i < 15; i++ ) { - UITableCell* Cell = UITableCell::New(); + UIWidgetTableRow* Cell = UIWidgetTableRow::New(); UITextView* TxtBox = UITextView::New(); UITextInput* TxtInput = UITextInput::New(); UIImage* TxtGfx = UIImage::New(); @@ -493,9 +493,9 @@ void EETest::createBaseUI() { TxtGfx->setDrawable( mSceneNode->findIcon( "ok" ) ); TxtBox->setText( "Test " + String::toString( i + 1 ) ); - Cell->setCell( 0, TxtBox ); - Cell->setCell( 1, TxtGfx ); - Cell->setCell( 2, TxtInput ); + Cell->setColumn( 0, TxtBox ); + Cell->setColumn( 1, TxtGfx ); + Cell->setColumn( 2, TxtInput ); genGrid->add( Cell ); } @@ -777,7 +777,7 @@ void EETest::createNewUI() { UISpinBox* spinBox = UISpinBox::New(); spinBox->setPosition( 350, 210 )->setSize( 200, 0 )->setParent( container ); - UITable* genGrid = UITable::New(); + UIWidgetTable* genGrid = UIWidgetTable::New(); genGrid->setSmoothScroll( true ); genGrid->setPosition( 350, 250 )->setSize( 200, 130 )->setParent( container ); genGrid->setColumnsCount( 3 )->setRowHeight( 24 ); @@ -786,7 +786,7 @@ void EETest::createNewUI() { genGrid->setColumnWidth( 2, 100 ); for ( Uint32 i = 0; i < 15; i++ ) { - UITableCell* Cell = UITableCell::New(); + UIWidgetTableRow* Cell = UIWidgetTableRow::New(); UITextView* TxtBox = UITextView::New(); UITextInput* TxtInput = UITextInput::New(); UIImage* TxtGfx = UIImage::New(); @@ -794,9 +794,9 @@ void EETest::createNewUI() { Cell->setParent( genGrid->getContainer() ); - Cell->setCell( 0, TxtBox ); - Cell->setCell( 1, TxtGfx ); - Cell->setCell( 2, TxtInput ); + Cell->setColumn( 0, TxtBox ); + Cell->setColumn( 1, TxtGfx ); + Cell->setColumn( 2, TxtInput ); TxtGfx->setDrawable( mSceneNode->findIcon( "ok" ) ); TxtBox->setText( "Test " + String::toString( i + 1 ) ); diff --git a/src/tools/codeeditor/codeeditor.cpp b/src/tools/codeeditor/codeeditor.cpp index 1ee4a488d..eea8d0238 100644 --- a/src/tools/codeeditor/codeeditor.cpp +++ b/src/tools/codeeditor/codeeditor.cpp @@ -87,6 +87,28 @@ void App::openFileDialog() { dialog->show(); } +void App::openFolderDialog() { + UIFileDialog* dialog = + UIFileDialog::New( UIFileDialog::DefaultFlags | UIFileDialog::AllowFolderSelect | + UIFileDialog::ShowOnlyFolders, + "*", "." ); + dialog->setWinFlags( UI_WIN_DEFAULT_FLAGS | UI_WIN_MAXIMIZE_BUTTON | UI_WIN_MODAL ); + dialog->setTitle( "Open Folder" ); + dialog->setCloseShortcut( KEY_ESCAPE ); + dialog->addEventListener( Event::OpenFile, [&]( const Event* event ) { + String path( event->getNode()->asType()->getFullPath() ); + if ( FileSystem::isDirectory( path ) ) + loadFolder( path ); + } ); + dialog->addEventListener( Event::OnWindowClose, [&]( const Event* ) { + if ( mEditorSplitter && mEditorSplitter->getCurEditor() && + !SceneManager::instance()->isShootingDown() ) + mEditorSplitter->getCurEditor()->setFocus(); + } ); + dialog->center(); + dialog->show(); +} + void App::saveFileDialog() { UIFileDialog* dialog = UIFileDialog::New( UIFileDialog::DefaultFlags | UIFileDialog::SaveDialog, "." ); @@ -257,6 +279,8 @@ void App::loadConfig() { mIniState.loadFromFile( mConfigPath + "state.cfg" ); std::string recent = mIniState.getValue( "files", "recentfiles", "" ); mRecentFiles = String::split( recent, ';' ); + std::string recentFolders = mIniState.getValue( "folders", "recentfolders", "" ); + mRecentFolders = String::split( recentFolders, ';' ); mInitColorScheme = mConfig.editor.colorScheme = mIni.getValue( "editor", "colorscheme", "eepp" ); mConfig.editor.fontSize = mIni.getValue( "editor", "font_size", "11dp" ); @@ -312,6 +336,7 @@ void App::saveConfig() { mProjectSplitter ? mProjectSplitter->getSplitPartition().toString() : "15%" ); mIniState.setValue( "files", "recentfiles", String::join( mRecentFiles, ';' ) ); + mIniState.setValue( "folders", "recentfolders", String::join( mRecentFolders, ';' ) ); mIni.setValueB( "editor", "show_line_numbers", mConfig.editor.showLineNumbers ); mIni.setValueB( "editor", "show_white_spaces", mConfig.editor.showWhiteSpaces ); mIni.setValueB( "editor", "highlight_matching_brackets", @@ -374,6 +399,7 @@ void App::initLocateBar() { } ); }; mLocateTable = UITableView::New(); + mLocateTable->setId( "locate_bar_table" ); mLocateTable->setParent( mUISceneNode->getRoot() ); mLocateTable->setHeadersVisible( false ); mLocateTable->setVisible( false ); @@ -657,6 +683,34 @@ void App::updateRecentFiles() { } } +void App::updateRecentFolders() { + UINode* node = nullptr; + if ( mSettingsMenu && ( node = mSettingsMenu->getItem( "Recent Folders" ) ) ) { + UIMenuSubMenu* uiMenuSubMenu = static_cast( node ); + UIMenu* menu = uiMenuSubMenu->getSubMenu(); + uiMenuSubMenu->setEnabled( !mRecentFolders.empty() ); + menu->removeAll(); + menu->removeEventsOfType( Event::OnItemClicked ); + if ( mRecentFolders.empty() ) + return; + for ( auto file : mRecentFolders ) + menu->add( file ); + menu->addSeparator(); + menu->add( "Clear Menu" ); + menu->addEventListener( Event::OnItemClicked, [&]( const Event* event ) { + if ( !event->getNode()->isType( UI_TYPE_MENUITEM ) ) + return; + const String& txt = event->getNode()->asType()->getText(); + if ( txt != "Clear Menu" ) { + loadFolder( txt ); + } else { + mRecentFolders.clear(); + updateRecentFolders(); + } + } ); + } +} + void App::showSidePanel( bool show ) { if ( show == mSidePanel->isVisible() ) return; @@ -1252,8 +1306,8 @@ void App::onCodeEditorCreated( UICodeEditor* editor, TextDocument& doc ) { doc.setBOM( config.writeUnicodeBOM ); editor->addKeyBinds( getLocalKeybindings() ); - editor->addUnlockedCommands( - {"fullscreen-toggle", "open-file", "console-toggle", "close-app", "open-locatebar"} ); + editor->addUnlockedCommands( {"fullscreen-toggle", "open-file", "open-folder", "console-toggle", + "close-app", "open-locatebar"} ); doc.setCommand( "save-doc", [&] { saveDoc(); } ); doc.setCommand( "save-as-doc", [&] { saveFileDialog(); } ); doc.setCommand( "find-replace", [&] { showFindView(); } ); @@ -1267,6 +1321,7 @@ void App::onCodeEditorCreated( UICodeEditor* editor, TextDocument& doc ) { ->setActive( !mWindow->isWindowed() ); } ); doc.setCommand( "open-file", [&] { openFileDialog(); } ); + doc.setCommand( "open-folder", [&] { openFolderDialog(); } ); doc.setCommand( "console-toggle", [&] { mConsole->toggle(); bool lock = mConsole->isActive(); @@ -1344,8 +1399,12 @@ bool App::setAutoComplete( bool enable ) { void App::createSettingsMenu() { mSettingsMenu = UIPopUpMenu::New(); mSettingsMenu->add( "New", findIcon( "document-new" ), getKeybind( "create-new" ) ); - mSettingsMenu->add( "Open...", findIcon( "document-open" ), getKeybind( "open-file" ) ); + mSettingsMenu->add( "Open File...", findIcon( "document-open" ), getKeybind( "open-file" ) ); + mSettingsMenu->add( "Open Folder...", findIcon( "document-open" ), + getKeybind( "open-folder" ) ); mSettingsMenu->addSubMenu( "Recent Files", findIcon( "document-recent" ), UIPopUpMenu::New() ); + mSettingsMenu->addSubMenu( "Recent Folders", findIcon( "document-recent" ), + UIPopUpMenu::New() ); mSettingsMenu->addSeparator(); mSettingsMenu->add( "Save", findIcon( "document-save" ), getKeybind( "save-doc" ) ); mSettingsMenu->add( "Save as...", findIcon( "document-save-as" ), getKeybind( "save-as-doc" ) ); @@ -1379,8 +1438,10 @@ void App::createSettingsMenu() { const String& name = event->getNode()->asType()->getText(); if ( name == "New" ) { runCommand( "create-new" ); - } else if ( name == "Open..." ) { + } else if ( name == "Open File..." ) { runCommand( "open-file" ); + } else if ( name == "Open Folder..." ) { + runCommand( "open-folder" ); } else if ( name == "Save" ) { runCommand( "save-doc" ); } else if ( name == "Save as..." ) { @@ -1511,25 +1572,40 @@ void App::initProjectTreeView( const std::string& path ) { if ( !path.empty() && FileSystem::fileExists( path ) ) { if ( FileSystem::isDirectory( path ) ) { - loadDirTree( FileSystem::getRealPath( path ) ); - mProjectTreeView->setModel( FileSystemModel::New( - path, FileSystemModel::Mode::FilesAndDirectories, {true, true, true} ) ); + loadFolder( path ); } else { std::string rpath( FileSystem::getRealPath( path ) ); + mProjectTreeView->setModel( FileSystemModel::New( FileSystem::fileRemoveFileName( rpath ), FileSystemModel::Mode::FilesAndDirectories, {true, true, true} ) ); + mEditorSplitter->loadFileFromPath( rpath ); } } else { - loadDirTree( FileSystem::getRealPath( "." ) ); - mProjectTreeView->setModel( FileSystemModel::New( - ".", FileSystemModel::Mode::FilesAndDirectories, {true, true, true} ) ); + loadFolder( "." ); } mProjectTreeView->setAutoExpandOnSingleColumn( true ); } +void App::loadFolder( const std::string& path ) { + std::string rpath( FileSystem::getRealPath( path ) ); + loadDirTree( rpath ); + + mProjectTreeView->setModel( FileSystemModel::New( + rpath, FileSystemModel::Mode::FilesAndDirectories, {true, true, true} ) ); + + auto found = std::find( mRecentFolders.begin(), mRecentFolders.end(), rpath ); + if ( found != mRecentFolders.end() ) + mRecentFolders.erase( found ); + mRecentFolders.insert( mRecentFolders.begin(), rpath ); + if ( mRecentFolders.size() > 10 ) + mRecentFolders.resize( 10 ); + + updateRecentFolders(); +} + void App::init( const std::string& file, const Float& pidelDensity ) { DisplayManager* displayManager = Engine::instance()->getDisplayManager(); Display* currentDisplay = displayManager->getDisplayIndex( 0 ); @@ -1661,6 +1737,12 @@ void App::init( const std::string& file, const Float& pidelDensity ) { #search_replace.error { border-color: #ff4040; } + TableView#locate_bar_table > table::row > table::cell:nth-child(2) { + color: var(--font-hint); + } + TableView#locate_bar_table > table::row:selected > table::cell:nth-child(2) { + color: var(--font); + } diff --git a/src/tools/codeeditor/codeeditor.hpp b/src/tools/codeeditor/codeeditor.hpp index cee72c307..f6e003281 100644 --- a/src/tools/codeeditor/codeeditor.hpp +++ b/src/tools/codeeditor/codeeditor.hpp @@ -137,6 +137,8 @@ class App : public UICodeEditorSplitter::Client { void openFileDialog(); + void openFolderDialog(); + void saveFileDialog(); bool findPrevText( SearchState& search ); @@ -184,6 +186,7 @@ class App : public UICodeEditorSplitter::Client { IniFile mIni; IniFile mIniState; std::vector mRecentFiles; + std::vector mRecentFolders; AppConfig mConfig; UIPopUpMenu* mDocMenu{nullptr}; UIPopUpMenu* mViewMenu{nullptr}; @@ -247,6 +250,10 @@ class App : public UICodeEditorSplitter::Client { void updateRecentFiles(); + void updateRecentFolders(); + + void loadFolder( const std::string& path ); + UIMenu* createViewMenu(); UIMenu* createEditMenu();