Some minor optimizations.

This commit is contained in:
Martín Lucas Golini
2024-10-26 01:21:39 -03:00
parent 9ef654929c
commit 9ccd774bb0
6 changed files with 29 additions and 10 deletions

View File

@@ -5,6 +5,8 @@
#include <eepp/ui/uitextview.hpp>
#include <eepp/ui/uiwidget.hpp>
#include <array>
namespace EE { namespace UI {
enum class InnerWidgetOrientation {
@@ -117,9 +119,9 @@ class EE_API UIPushButton : public UIWidget {
void updateTextBox();
Vector2f packLayout( const std::vector<UIWidget*>& widgets, const Rectf& padding );
Vector2f packLayout( const std::array<UIWidget*, 3>& widgets, const Rectf& padding );
Vector2f calcLayoutSize( const std::vector<UIWidget*>& widgets, const Rectf& padding ) const;
Vector2f calcLayoutSize( const std::array<UIWidget*, 3>& widgets, const Rectf& padding ) const;
};
}} // namespace EE::UI

View File

@@ -548,6 +548,8 @@ UIWidget* UIAbstractTableView::createCell( UIWidget* rowWidget, const ModelIndex
UIWidget* UIAbstractTableView::setupCell( UITableCell* widget, UIWidget* rowWidget,
const ModelIndex& index ) {
mUISceneNode->invalidateStyle( this );
mUISceneNode->invalidateStyleState( this, true );
widget->setParent( rowWidget );
widget->unsetFlags( UI_AUTO_SIZE );
widget->setClipType( ClipType::ContentBox );

View File

@@ -160,7 +160,7 @@ void UIPushButton::onAutoSize() {
}
}
Vector2f UIPushButton::calcLayoutSize( const std::vector<UIWidget*>& widgets,
Vector2f UIPushButton::calcLayoutSize( const std::array<UIWidget*, 3>& widgets,
const Rectf& padding ) const {
Vector2f totSize{ padding.Left, padding.Top + padding.Bottom };
UIWidget* widget;
@@ -182,8 +182,8 @@ Vector2f UIPushButton::calcLayoutSize( const std::vector<UIWidget*>& widgets,
return totSize;
}
Vector2f UIPushButton::packLayout( const std::vector<UIWidget*>& widgets, const Rectf& padding ) {
std::vector<Vector2f> pos( widgets.size() );
Vector2f UIPushButton::packLayout( const std::array<UIWidget*, 3>& widgets, const Rectf& padding ) {
std::array<Vector2f, 3> pos;
Vector2f totSize{ padding.Left, padding.Top + padding.Bottom };
UIWidget* widget;
for ( size_t i = 0; i < widgets.size(); i++ ) {

View File

@@ -672,6 +672,7 @@ void UISceneNode::invalidateStyle( UIWidget* node, bool tryReinsert ) {
if ( node->isClosing() )
return;
// Already invalidated?
if ( mDirtyStyle.count( node ) > 0 ) {
if ( !tryReinsert )
return;
@@ -679,12 +680,17 @@ void UISceneNode::invalidateStyle( UIWidget* node, bool tryReinsert ) {
mDirtyStyle.erase( node );
}
for ( auto& dirtyNode : mDirtyStyle )
if ( NULL != dirtyNode && dirtyNode->isParentOf( node ) )
// Any parent dirty?
Node* parent = node->getParent();
while ( parent != nullptr ) {
if ( parent->isWidget() && mDirtyStyle.count( parent->asType<UIWidget>() ) > 0 )
return;
parent = parent->getParent();
}
std::vector<UIWidget*> eraseList;
// Any child in list? remove it
for ( auto widget : mDirtyStyle )
if ( NULL == widget || node->isParentOf( widget ) )
eraseList.push_back( widget );
@@ -702,6 +708,7 @@ void UISceneNode::invalidateStyleState( UIWidget* node, bool disableCSSAnimation
if ( node->isClosing() )
return;
// Already invalidated?
if ( mDirtyStyleState.count( node ) > 0 ) {
if ( !tryReinsert )
return;
@@ -709,12 +716,17 @@ void UISceneNode::invalidateStyleState( UIWidget* node, bool disableCSSAnimation
mDirtyStyleState.erase( node );
}
for ( auto& dirtyNode : mDirtyStyleState )
if ( NULL != dirtyNode && dirtyNode->isParentOf( node ) )
// Any parent dirty?
Node* parent = node->getParent();
while ( parent != nullptr ) {
if ( parent->isWidget() && mDirtyStyleState.count( parent->asType<UIWidget>() ) > 0 )
return;
parent = parent->getParent();
}
std::vector<UIWidget*> eraseList;
// Any child in list? remove it
for ( auto widget : mDirtyStyleState )
if ( NULL == widget || node->isParentOf( widget ) )
eraseList.push_back( widget );

View File

@@ -177,6 +177,8 @@ bool UITreeView::tryOpenModelIndex( const ModelIndex& index, bool forceUpdate )
UIWidget* UITreeView::setupCell( UITableCell* widget, UIWidget* rowWidget,
const ModelIndex& index ) {
mUISceneNode->invalidateStyle( this );
mUISceneNode->invalidateStyleState( this, true );
widget->setParent( rowWidget );
widget->unsetFlags( UI_AUTO_SIZE );
widget->setClipType( mDisableCellClipping ? ClipType::None : ClipType::ContentBox );

View File

@@ -3,7 +3,7 @@
// Referece https://eugenkiss.github.io/7guis/tasks/#cells
EE_MAIN_FUNC int main( int, char** ) {
UIApplication app( { 1024, 768, "eepp - 7GUIs - Cells" } );
UIApplication app( { 1280, 768, "eepp - 7GUIs - Cells" } );
UIWidget* rlay = app.getUI()->loadLayoutFromString( R"xml(
<style>
.font_theme_normal { color: var(--font); }
@@ -15,6 +15,7 @@ EE_MAIN_FUNC int main( int, char** ) {
border-right: 1dprd solid var(--button-border);
border-bottom: 1dprd solid var(--button-border);
}
#sheet tableview::header::column { text-align: center; }
</style>
<RelativeLayout layout_width="match_parent" layout_height="match_parent">
<TableView id="sheet" layout_width="match_parent" layout_height="match_parent" />