lullaby/tests/layout_system_test.cc
// Test that LayoutSystem will resize weighted elements and does not infinite
// loop.
Test that LayoutSystem will resize weighted elements and does not infinite
loop.
Test that LayoutSystem will resize weighted elements and does not infinite loop .
TEST_F(LayoutSystemTest, CreateLayout_WeightedElements) {
  const mathfu::vec2 expectations[] = {
      mathfu::vec2(-0.5f, 1.f), mathfu::vec2(0.5f, 1.f),
      mathfu::vec2(-0.5f, 1.f), mathfu::vec2(0.5f, 1.f),
  };
  const mathfu::vec2 size_expectations[] = {
      mathfu::vec2(1.f, 0.f), mathfu::vec2(1.f, 0.f),
      mathfu::vec2(1.f, 0.f), mathfu::vec2(1.f, 0.f),
  };
  const Entity parent = CreateParent();
  int parent_layout_times = 0;
  dispatcher_system_->Connect(parent, this, [&parent_layout_times](
      const LayoutChangedEvent& event) {
    ++parent_layout_times;
  });
  const int num_children = 4;
  Entity children[num_children];
  for (int i = 0; i < num_children; ++i) {
    children[i] = CreateChild(parent, 1.0f, true);
  }
  AssertTranslationsAndSizes(num_children, children, expectations,
                             size_expectations);
  EXPECT_EQ(24, parent_layout_times);
}
TEST_F ( LayoutSystemTest , CreateLayout_WeightedElements ) { const mathfu :: vec2 expectations [ ] = { mathfu :: vec2 ( -0.5f , 1.f ) , mathfu :: vec2 ( 0.5f , 1.f ) , mathfu :: vec2 ( -0.5f , 1.f ) , mathfu :: vec2 ( 0.5f , 1.f ) , } ; const mathfu :: vec2 size_expectations [ ] = { mathfu :: vec2 ( 1.f , 0.f ) , mathfu :: vec2 ( 1.f , 0.f ) , mathfu :: vec2 ( 1.f , 0.f ) , mathfu :: vec2 ( 1.f , 0.f ) , } ; const Entity parent = CreateParent ( ) ; int parent_layout_times = 0 ; dispatcher_system_ -> Connect ( parent , this , [ & parent_layout_times ] ( const LayoutChangedEvent & event ) { ++ parent_layout_times ; } ) ; const int num_children = 4 ; Entity children [ num_children ] ; for ( int i = 0 ; i < num_children ; ++ i ) { children [ i ] = CreateChild ( parent , 1.0f , true ) ; } AssertTranslationsAndSizes ( num_children , children , expectations , size_expectations ) ; EXPECT_EQ ( 24 , parent_layout_times ) ; }
Test that LayoutSystem will resize weighted elements and does not infinite
loop.
Test that LayoutSystem will resize weighted elements and does not infinite loop .
// Canvas_size = (2,2) and elements_per_wrap = 2, so all the weighted children // will be 1 wide into 2 columns. // They should be arranged in the following manner. //  0/2 1/3  (no height) //   -   - // Give all children weight. // The LayoutDef will change the child's size. // Resulting children will be all 1 wide into 2 columns. // The total number of times parent will re-layout, due to non-queued // dispatcher: // 1: Add child 0. // 2x1: Respond to child 0 resize twice, set Aabb & ActualBox. // 1: Add child 1. // 2x2: Respond to child 0,1 resize twice, set Aabb & ActualBox. // 1: Add child 2. // 3x2: Respond to child 0,1,2 resize twice, set Aabb & ActualBox. // 1: Add child 3. // 4x2: Respond to child 0,1,2,3 resize twice, set Aabb & ActualBox. // Queued dispatcher will be much fewer, down to 1 + 1, since // all children are added on the same frame, and then hopefully resized on the // same frame.  However, if resizing requires complex operations, such as text // rendering, that may result in re-layout on multiple frames.