Haiku API Bindings
LayoutAPI
Not logged in

Documentation | InterfaceKit | LayoutAPI

SYNOPSIS

Perl

# if you want a layout like this:

#          A             B             C
#   |-------------|-------------|-------------|
#   |             |             |             |
# 1 |             |             |             |
#   |             |             |             |
#   |-------------|             |             |
#   |             |             |             |
# 2 |             |             |             |
#   |             |             |             |
#   |-------------|             |             |
#   |             |             |             |
# 3 |             |             |             |
#   |             |             |             |
#   |-------------|-------------|-------------|

# first set a horizontal GroupLayout to the Window

my $layoutH = GroupLayout->new(B_HORIZONTAL);
$window->SetLayout($layoutH);

# then add a vertical GroupLayout as a child to the Window, followed by two Views

my $layoutV = GroupLayout->new(B_VERTICAL);
$window->AddChild($layoutV);

$window->AddChild($viewB);
$window->AddChild($viewC);

# finally, add three Views to the vertical TwoDimensionalLayout

$layoutV->AddView($viewA1);
$layoutV->AddView($viewA2);
$layoutV->AddView($viewA3);

Python

# if you want a layout like this:

#          A             B             C
#   |-------------|-------------|-------------|
#   |             |             |             |
# 1 |             |             |             |
#   |             |             |             |
#   |-------------|             |             |
#   |             |             |             |
# 2 |             |             |             |
#   |             |             |             |
#   |-------------|             |             |
#   |             |             |             |
# 3 |             |             |             |
#   |             |             |             |
#   |-------------|-------------|-------------|

# first set a horizontal GroupLayout to the Window

layoutH = GroupLayout(B_HORIZONTAL)
window.SetLayout(layoutH)

# then add a vertical GroupLayout as a child to the Window, followed by two Views

layoutV = GroupLayout(B_VERTICAL)
window.AddChild(layoutV)

window.AddChild(viewB)
window.AddChild(viewC)

# finally, add three Views to the vertical TwoDimensionalLayout

layoutV.AddView(viewA1)
layoutV.AddView(viewA2)
layoutV.AddView(viewA3)

DESCRIPTION

The old BeOS API handle location and size of Views using frame rectangles and resizing flags. While Haiku still supports this, it also has a layout system that allows for more complex layouts.

For more information on the Layout API, see the Haiku Book Layout API description. (As of this writing, this page does not contain very much information.)

In addition to the various objects that are part of this API, there are a number of Layout-related methods in Window and View.

OBJECTS

WINDOW METHODS

AddChild

Under the BeOS API, AddChild took a View. It still does under Haiku, but it can also take a LayoutItem instead. This version does not take a sibling argument.

LayoutItem is a base class whose only only API-defined descendant class is Layout, so the main purpose of this method is to create more complex layout patterns by adding sub-layouts to a Window.

Perl

$window->AddChild($layout_item);

Python

window.AddChild(layout_item)

InvalidateLayout

Invalidates the layout, so it will be recalculated.

Perl

$window->InvalidateLayout($descendants);

Python

window.InvalidateLayout(descendants)

GetLayout

SetLayout

These methods do what you expect.

Perl

$window->GetLayout();
$window->SetLayout($layout);

Python

window.GetLayout()
window.SetLayout(layout)

Layout

Layout redoes the Window layout, if the layout is no longer valid.

Perl

$window->Layout($force);

Python

window.Layout(force)

VIEW METHODS

Constructor

The constructors for View and its descendants have a version that does not take a frame rectangle or resizing flags. This version is meant for use with the Layout API.

Many of these constructors also take an optional Layout object; this is used when the View will have child Views of its own.

AddChild

As with Window.AddChild above, View has a version of AddChild that takes a LayoutItem instead of a View.

Perl

$view->AddChild($layout_item);

Python

view.AddChild(layout_item)

HeightForWidth

HasHeightForWidth

GetHeightForWidth

HasHeightForWidth returns true if the height constraints are dependent on the width; GetHeightForWidth returns the height for a given width.

These can also be called as hooks.

Perl

$view->HasHeightForWidth();
$view->GetHeightForWidth($width);

Python

view.HasHeightForWidth()
view.GetHeightForWidth(width)

InvalidateLayout

IsLayoutValid

EnableLayoutInvalidation

DisableLayoutInvalidation

IsLayoutInvalidationDisabled

ResetLayoutInvalidation

Invalidates the layout.

TODO: finish this

Perl

$view->InvalidateLayout($descendants);
$view->IsLayoutValid();
$view->EnableLayoutInvalidation();
$view->DisableLayoutInvalidation();
$view->IsLayoutInvalidationDisabled();
$view->ResetLayoutInvalidation();

Python

view.InvalidateLayout(descendants)
view.IsLayoutValid()
view.EnableLayoutInvalidation()
view.DisableLayoutInvalidation()
view.IsLayoutInvalidationDisabled()
view.ResetLayoutInvalidation()

Layout

Relayout

Lays out the View.

Perl

$view->Layout($force);
$view->Relayout();

Python

view.Layout(force)
view.Relayout()

Layout object

GetLayout

SetLayout

Gets or sets the Layout object.

SetLayout can also be called as a hook.

Perl

$view->GetLayout();
$view->SetLayout($layout);

Python

view.GetLayout()
view.SetLayout(layout)

LayoutContext

Gets the LayoutContext object.

Perl

$view->LayoutContext();

Python

view.LayoutContext()

Size and Alignment

SetExplicitSize

MinSize

ExplicitMinSize

SetExplicitMinSize

MaxSize

ExplicitMaxSize

SetExplicitMaxSize

PreferredSize

ExplicitPreferredSize

SetExplicitPreferredSize

LayoutAlignment

ExplicitAlignment

SetExplicitAlignment

THese limits are used when for calculating the size of the View. The Explicit getters and setters allow you to override the calculated sizes and alignment; the other methods report which size is actually being used.

MinSize, MaxSize, PreferredSize, and LayoutAlignment can also be called as hooks.

Perl

$view->SetExplicitSize($size);
$view->MinSize();
$view->ExplicitMinSize();
$view->SetExplicitMinSize($size);
$view->MaxSize();
$view->ExplicitMaxSize();
$view->SetExplicitMaxSize($size);
$view->PreferredSize();
$view->ExplicitPreferredSize();
$view->SetExplicitPreferredSize($size);
$view->LayoutAlignment();
$view->ExplicitAlignment();
$view->SetExplicitAlignment($alignment);

Python

view.SetExplicitSize(size)
view.MinSize()
view.ExplicitMinSize()
view.SetExplicitMinSize(size)
view.MaxSize()
view.ExplicitMaxSize()
view.SetExplicitMaxSize(size)
view.PreferredSize()
view.ExplicitPreferredSize()
view.SetExplicitPreferredSize(size)
view.LayoutAlignment()
view.ExplicitAlignment()
view.SetExplicitAlignment(alignment)

VIEW HOOKS

DoLayout

Called when the View needs to recalculate its layout.

Perl

$view->DoLayout();

Python

view.DoLayout()

LayoutChanged

Called when the Layout changes.

Perl

$view->LayoutChanged();

Python

view.LayoutChanged()

LayoutInvalidated

Called when the layout is invalidated.

Perl

$view->LayoutInvalidated($descendants);

Python

view.LayoutInvalidated(descendants)