Пример #1
0
 void BoxLayout::Layout(View* host)
 {
     gfx::Rect childArea(gfx::Rect(host->size()));
     childArea.Inset(host->GetInsets());
     childArea.Inset(inside_border_horizontal_spacing_,
         inside_border_vertical_spacing_);
     int x = childArea.x();
     int y = childArea.y();
     for(int i=0; i<host->GetChildViewCount(); ++i)
     {
         View* child = host->GetChildViewAt(i);
         if(child->IsVisible())
         {
             gfx::Rect bounds(x, y, childArea.width(), childArea.height());
             gfx::Size size(child->GetPreferredSize());
             if(orientation_ == kHorizontal)
             {
                 bounds.set_width(size.width());
                 x += size.width() + between_child_spacing_;
             }
             else
             {
                 bounds.set_height(size.height());
                 y += size.height() + between_child_spacing_;
             }
             // Clamp child view bounds to |childArea|.
             child->SetBounds(bounds.Intersect(childArea));
         }
     }
 }
Пример #2
0
void AppLayout::Layout(views::View* host)
{
    gfx::Rect childArea(gfx::Rect(host->size()));
    childArea.Inset(host->GetInsets());
    childArea.Inset(inside_border_horizontal_spacing_,
        inside_border_vertical_spacing_);
    int x = childArea.x();
    int y = childArea.y();
    for(int i=0; i<host->child_count(); ++i)
    {
        views::View* child = host->child_at(i);
        if(child->visible())
        {
            gfx::Size size(child->GetPreferredSize());
            gfx::Rect bounds(x, y, 0, size.height());
            if(x + size.width() <= childArea.right())
            {
                bounds.set_width(size.width());
                x += size.width() + between_child_spacing_;
            }
            else
            {
                x = childArea.x();
                y += size.height() + between_child_spacing_;
                bounds.SetRect(x, y, size.width(), size.height());

                x += size.width() + between_child_spacing_;
            }

            // Clamp child view bounds to |childArea|.
			bounds.Intersect(childArea);
            child->SetBoundsRect( bounds );
        }
    }
}