Skip to content

Commit a2b826d

Browse files
committed
[layout] began tests for horizontal flow..
1 parent 381dd2e commit a2b826d

File tree

3 files changed

+72
-5
lines changed

3 files changed

+72
-5
lines changed

README.md

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ Optional dependences include:
2727

2828
- Qt: for the Qt based backend, the default
2929
- SDL2: for the SDL 2 based backend, enable using 'cmake -DRENGINE_USE_SDL=on'
30-
- SfHwc: Sailfish, running directly on the HWC API
30+
3131

3232
todo
3333
----
@@ -50,6 +50,12 @@ lots and lots...
5050
- input, both keyboard, touch and mouse
5151
- keyboard input missing
5252
- basic pointer support in place, but lacking multitouch
53+
- property api needs to improve
54+
- Property<float> takes up 32 bytes: 4 from float, 24 from std::vector, 4 bytes of padding
55+
- both signal and property's disconnect are broken, as the id is an integer
56+
removing one in the middle will invalidate all ids after that position... doh!
57+
58+
5359

5460
overview of the dependencies between source directories
5561
-------------------------------------------------------
@@ -78,9 +84,11 @@ include/backend/
7884
-> qt/qtbackend.h: for qt one
7985
-> sdl/sdlbackend.h: for the sdl one
8086

87+
src/sailfish
88+
- Implementation of a Sailfish system (todo :)
89+
8190
3rdparty
82-
- stb headers for reading and writing images
83-
- picojson.h for parsing json
91+
- stb headers for reading and writing
8492

8593
tests
8694
- tst_keyframes: tests for the animation system
@@ -92,7 +100,6 @@ tests
92100

93101
examples - The examples are simple snippets meant to illustrate how a concept works
94102
- ex_benchmark_rectangles: benchmark on creating/destroying 1000 rects per frame, including rendering
95-
- ex_benchmark_blend: benchmark to test overdraw performance of a GPUs
96103
- ex_blur: shows the blurring
97104
- ex_filters: shows how color filtering works
98105
- ex_layeredopacity: shows layered opacity

include/scenegraph/layoutnode.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ void LayoutEngine::updateLayout(Node *parentNode)
292292
if (rectNode) {
293293
float dim = layoutType == Flow_Horizontal ? rectNode->width() : rectNode->height();
294294
float end = flow + flowSign * dim;
295-
if (index == 0 || (flowSign * end < flowSign * sizeLimit && index < itemLimit)) {
295+
if (index == 0 || (flowSign * end <= flowSign * sizeLimit && index < itemLimit)) {
296296
index++;
297297
if (layoutType == Flow_Horizontal) {
298298
stepIncrement = std::max(stepIncrement, rectNode->height());

tests/tst_layout.cpp

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -514,11 +514,71 @@ void tst_layoutnode_vertical_grid()
514514
root->destroy();
515515
}
516516

517+
static void apply_w_h_r_c_m_s(LayoutNode *node, float width, float height, int rowCount, int columnCount, float margin, float spacing)
518+
{
519+
node->setWidth(width);
520+
node->setHeight(height);
521+
node->setRowCount(rowCount);
522+
node->setColumnCount(columnCount);
523+
node->setSpacing(spacing);
524+
node->setMargin(margin);
525+
node->updateLayout();
526+
}
527+
528+
529+
static void tst_layoutnode_horizontal_flow()
530+
{
531+
LayoutNode *root = LayoutNode::create();
532+
root->setActivationMode(LayoutNode::Explicit);
533+
root->setLayoutType(LayoutEngine::Flow_Horizontal);
534+
535+
RectangleNode *r[4]; // sizes: 10, 20, 40, 80
536+
for (int i=0; i<4; ++i) {
537+
float s = std::pow(2, (float)i) * 10;
538+
r[i] = RectangleNode::create(rect2d(0, 0, s, s));
539+
root->append(r[i]);
540+
}
541+
542+
apply_w_h_r_c_m_s(root, 0, 0, 0, 0, 0, 0);
543+
check_equal(r[0]->geometry(), rect2d::fromXywh( 0, 0, 10, 10));
544+
check_equal(r[1]->geometry(), rect2d::fromXywh(10, 0, 20, 20));
545+
check_equal(r[2]->geometry(), rect2d::fromXywh(30, 0, 40, 40));
546+
check_equal(r[3]->geometry(), rect2d::fromXywh(70, 0, 80, 80));
547+
apply_w_h_r_c_m_s(root, 0, 0, 0, 0, 2, 1);
548+
check_equal(r[0]->geometry(), rect2d::fromXywh( 2, 2, 10, 10));
549+
check_equal(r[1]->geometry(), rect2d::fromXywh(13, 2, 20, 20));
550+
check_equal(r[2]->geometry(), rect2d::fromXywh(34, 2, 40, 40));
551+
check_equal(r[3]->geometry(), rect2d::fromXywh(75, 2, 80, 80));
552+
apply_w_h_r_c_m_s(root, 76, 0, 0, 0, 2, 1); // r[2] ends on 74, +2 margin
553+
check_equal(r[0]->geometry(), rect2d::fromXywh( 2, 2, 10, 10));
554+
check_equal(r[1]->geometry(), rect2d::fromXywh(13, 2, 20, 20));
555+
check_equal(r[2]->geometry(), rect2d::fromXywh(34, 2, 40, 40));
556+
check_equal(r[3]->geometry(), rect2d::fromXywh( 2, 43, 80, 80));
557+
apply_w_h_r_c_m_s(root, 75, 0, 0, 0, 2, 1); // will not fit the margin, so r[2] wraps
558+
check_equal(r[0]->geometry(), rect2d::fromXywh( 2, 2, 10, 10));
559+
check_equal(r[1]->geometry(), rect2d::fromXywh(13, 2, 20, 20));
560+
check_equal(r[2]->geometry(), rect2d::fromXywh( 2, 23, 40, 40));
561+
check_equal(r[3]->geometry(), rect2d::fromXywh(43, 23, 80, 80));
562+
apply_w_h_r_c_m_s(root, 3, 0, 0, 0, 2, 1); // too narrow width, but we always have one per row
563+
check_equal(r[0]->geometry(), rect2d::fromXywh(2, 2, 10, 10));
564+
check_equal(r[1]->geometry(), rect2d::fromXywh(2, 13, 20, 20));
565+
check_equal(r[2]->geometry(), rect2d::fromXywh(2, 34, 40, 40));
566+
check_equal(r[3]->geometry(), rect2d::fromXywh(2, 75, 80, 80));
567+
568+
569+
// test wrapping by width and columns..
570+
571+
572+
573+
cout << __PRETTY_FUNCTION__ << ": ok" << endl;
574+
}
575+
517576
int main(int argc, char **argv)
518577
{
519578
tst_layoutnode_properties();
520579
tst_layoutnode_horizontal_grid();
521580
tst_layoutnode_vertical_grid();
581+
tst_layoutnode_horizontal_flow();
522582

523583
return 0;
524584
}

0 commit comments

Comments
 (0)