From 4e1ff1f28ee14fc7c844cdcc8d0fd8008c005a1e Mon Sep 17 00:00:00 2001 From: Liu Chao Date: Sat, 23 Dec 2017 22:40:16 +0800 Subject: [PATCH] Add test for flex layout in absolute position --- test/test_widget_flex_layout.c | 37 +++++++++++++++++++++++++++----- test/test_widget_flex_layout.css | 22 ++++++++++++++++++- test/test_widget_flex_layout.xml | 26 +++++++++++++++++++--- 3 files changed, 76 insertions(+), 9 deletions(-) diff --git a/test/test_widget_flex_layout.c b/test/test_widget_flex_layout.c index c86a6c31..dd985af0 100644 --- a/test/test_widget_flex_layout.c +++ b/test/test_widget_flex_layout.c @@ -27,7 +27,7 @@ static int check_flex_box_1( void ) }; box = LCUIWidget_GetById( "flex-box-1" ); CHECK( box->x == 0 && box->y == 0 ); - CHECK( box->height == BLOCK_SIZE * 3 ); + CHECK( box->height == BLOCK_SIZE * 3 + 1 ); for( LinkedList_Each( node, &box->children ) ) { child = node->data; sprintf( str, "[%d] (%g, %g) == (%g, %g)", child->index, @@ -56,8 +56,8 @@ static int check_flex_box_2( void ) { offset_x2 + BLOCK_SIZE, BLOCK_SIZE * 2 } }; box = LCUIWidget_GetById( "flex-box-2" ); - CHECK( box->x == 0 && box->y == BLOCK_SIZE * 3 ); - CHECK( box->height == BLOCK_SIZE * 3 ); + CHECK( box->x == 0 && box->y == BLOCK_SIZE * 3 + 1 ); + CHECK( box->height == BLOCK_SIZE * 3 + 1 ); for( LinkedList_Each( node, &box->children ) ) { child = node->data; sprintf( str, "[%d] (%g, %g) == (%g, %g)", child->index, @@ -86,8 +86,34 @@ static int check_flex_box_3( void ) { offset_x2 + BLOCK_SIZE, BLOCK_SIZE * 2 } }; box = LCUIWidget_GetById( "flex-box-3" ); - CHECK( box->x == 0 && box->y == BLOCK_SIZE * 3 * 2 ); - CHECK( box->height == BLOCK_SIZE * 3 ); + CHECK( box->x == 0 && box->y == BLOCK_SIZE * 3 * 2 + 2 ); + CHECK( box->height == BLOCK_SIZE * 3 + 1 ); + for( LinkedList_Each( node, &box->children ) ) { + child = node->data; + sprintf( str, "[%d] (%g, %g) == (%g, %g)", child->index, + child->x, child->y, simples[i][0], simples[i][1] ); + CHECK_WITH_TEXT( str, child->x == simples[i][0] && + child->y == simples[i][1] ); + i += 1; + } + return ret; +} + +static int check_flex_box_4( void ) +{ + char str[256]; + int ret = 0, i = 0; + LinkedListNode *node; + LCUI_Widget child, box; + const float offset_x = 480 - BLOCK_SIZE * 3; + float simples[][2] = { + { 0, 0 }, + { offset_x, BLOCK_SIZE }, + { offset_x + BLOCK_SIZE, BLOCK_SIZE }, + { offset_x + BLOCK_SIZE * 2, BLOCK_SIZE } + }; + box = LCUIWidget_GetById( "flex-box-4" ); + CHECK( box->height == BLOCK_SIZE * 2 ); for( LinkedList_Each( node, &box->children ) ) { child = node->data; sprintf( str, "[%d] (%g, %g) == (%g, %g)", child->index, @@ -105,6 +131,7 @@ static int check_layout( void ) ret += check_flex_box_1(); ret += check_flex_box_2(); ret += check_flex_box_3(); + ret += check_flex_box_4(); return ret; } diff --git a/test/test_widget_flex_layout.css b/test/test_widget_flex_layout.css index c3eaa7b5..01957b2d 100644 --- a/test/test_widget_flex_layout.css +++ b/test/test_widget_flex_layout.css @@ -10,6 +10,9 @@ display: flex; justify-content: flex-end; } +.flex-box { + border-bottom: 1px solid #ddd; +} .inline-block { padding: 5px; display: inline-block; @@ -26,4 +29,21 @@ .box-2 { height: 64px; background-color: #957bbe; -} \ No newline at end of file +} +.bottom { + bottom: 0; + left: 0; + width: 100%; + position: absolute; + background-color: rgba(0,0,0,0.5); +} +.bottom-box { + width: auto; + max-width: 480px; + margin: 20px auto; +} +.bottom-content { + width: 100%; + position: relative; + background-color: #f0f0f0; +} diff --git a/test/test_widget_flex_layout.xml b/test/test_widget_flex_layout.xml index eb2453e2..ee04de08 100644 --- a/test/test_widget_flex_layout.xml +++ b/test/test_widget_flex_layout.xml @@ -2,7 +2,7 @@ - + @@ -22,7 +22,7 @@ - + @@ -42,7 +42,7 @@ - + @@ -62,5 +62,25 @@ + + + + + + + + + + + + + + + + + + + +