Fixed a bug on StyleSheet::addStyle. Now a unique selector can be declared more

than one time without overriding the old one.
UINodes now are only drawn when intersect the viewport ( discard draw if not visible ).
Added a scrolling test.

--HG--
branch : dev
This commit is contained in:
Martín Lucas Golini
2019-06-20 18:21:52 -03:00
parent 9db34b27fd
commit efe79e929a
4 changed files with 39 additions and 10 deletions

View File

@@ -32,7 +32,7 @@ PopUpMenu {
minRightMargin: 8dp;
}
Menu:hover,
Menu:hover,
PopUpMenu:hover,
Menu::Item:hover,
Menu::CheckBox:hover,
@@ -44,7 +44,7 @@ Tab:pressed {
textColor: #FFF;
}
Slider {
Slider {
halfSlider: true;
backgroundColor: #555;
}
@@ -328,3 +328,7 @@ TabWidget {
padding: 16dp;
layout_marginBottom: 140dp;
}
#test_5 TextView {
padding: 8dp;
}

View File

@@ -38,13 +38,13 @@
<PushButton layout_width="wrap_content" layout_height="wrap_content" text="testing padding" layout_gravity="bottom|right" gravity="center" padding="8dp" layout_to_top_of="tmp" />
<PushButton id="pbut" text="OK!" textSize="16dp" icon="ok" layout_gravity="left|bottom" gravity="center" layout_width="wrap_content" layout_height="wrap_content" layout_marginBottom="8dp" padding="8dp" layout_to_top_of="tm" />
<Slider id="slider" orientation="horizontal" halfslider="true" layout_width="200dp" layout_height="wrap_content" layout_to_bottom_of="el1" />
<ScrollBar id="scrollbar" orientation="horizontal" layout_width="200dp" layout_height="wrap_content" layout_to_bottom_of="slider" />
<SpinBox id="spinbox" layout_width="200dp" layout_height="wrap_content" layout_to_bottom_of="scrollbar" />
<TextEdit layout_width="200dp" layout_height="50dp" layout_gravity="bottom|center_horizontal" />
</RelativeLayout>
</vbox>
@@ -68,10 +68,19 @@
<RelativeLayout layout_width="match_parent" layout_height="32dp"><TextView layout_width="wrap_content" layout_height="wrap_content" text="FAQ" /></RelativeLayout>
<RelativeLayout layout_width="match_parent" layout_height="32dp"><TextView layout_width="wrap_content" layout_height="wrap_content" text="About Us" /></RelativeLayout>
</vbox>
<ScrollView id="test_5" layout_width="match_parent" layout_height="match_parent" touchdrag="true">
<vbox layout_width="match_parent" layout_height="wrap_content">
<TextView text="Test" /><TextView text="Test" /><TextView text="Test" /><TextView text="Test" /><TextView text="Test" /><TextView text="Test" />
<TextView text="Test" /><TextView text="Test" /><TextView text="Test" /><TextView text="Test" /><TextView text="Test" /><TextView text="Test" />
<TextView text="Test" /><TextView text="Test" /><TextView text="Test" /><TextView text="Test" /><TextView text="Test" /><TextView text="Test" />
<TextView text="Test" /><TextView text="Test" /><TextView text="Test" /><TextView text="Test" /><TextView text="Test" /><TextView text="Test" />
<TextView text="Test" /><TextView text="Test" /><TextView text="Test" /><TextView text="Test" /><TextView text="Test" /><TextView text="Test" />
</vbox>
</ScrollView>
<Tab name="Padding Test" owns="test_1" />
<Tab name="Tabs Test" owns="test_2" />
<Tab name="Cascade Test" owns="test_3" />
<Tab name="Hover Test" owns="test_4" />
<Tab name="Scroll Test" owns="test_5" />
</TabWidget>
</vbox>

View File

@@ -9,7 +9,16 @@ namespace EE { namespace UI { namespace CSS {
StyleSheet::StyleSheet() {}
void StyleSheet::addStyle( const StyleSheetStyle& node ) {
mNodes[ node.getSelector().getName() ] = node;
auto nodeIt = mNodes.find( node.getSelector().getName() );
if ( nodeIt == mNodes.end() ) {
mNodes[ node.getSelector().getName() ] = node;
} else {
StyleSheetStyle& currentNode = nodeIt->second;
for ( auto& pit : node.getProperties() )
currentNode.setProperty( pit.second );
}
}
void StyleSheet::combineStyle( const StyleSheetStyle& node ) {
@@ -18,7 +27,7 @@ void StyleSheet::combineStyle( const StyleSheetStyle& node ) {
if ( nodeIt == mNodes.end() ) {
addStyle( node );
} else {
auto currentNode = nodeIt->second;
auto& currentNode = nodeIt->second;
if ( node.getSelector().getSpecificity() > currentNode.getSelector().getSpecificity() ) {
for ( auto& pit : node.getProperties() )

View File

@@ -620,13 +620,20 @@ void UINode::internalDraw() {
if ( mNodeFlags & NODE_FLAG_POSITION_DIRTY )
updateScreenPos();
if ( mNodeFlags & NODE_FLAG_POLYGON_DIRTY )
updateWorldPolygon();
matrixSet();
clipStart();
draw();
if ( mWorldBounds.intersect( mSceneNode->getWorldBounds() ) ) {
draw();
drawChilds();
drawChilds();
} else if ( !isClipped() ) {
drawChilds();
}
clipEnd();