@@ -514,11 +514,71 @@ void tst_layoutnode_vertical_grid()
514
514
root->destroy ();
515
515
}
516
516
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
+
517
576
int main (int argc, char **argv)
518
577
{
519
578
tst_layoutnode_properties ();
520
579
tst_layoutnode_horizontal_grid ();
521
580
tst_layoutnode_vertical_grid ();
581
+ tst_layoutnode_horizontal_flow ();
522
582
523
583
return 0 ;
524
584
}
0 commit comments