BLayoutBuilder: Add support for BCardLayout

Signed-off-by: Augustin Cavalier <waddlesplash@gmail.com>
This commit is contained in:
Markus Himmel 2015-12-27 00:12:01 +01:00 committed by Augustin Cavalier
parent 5f2db70ffb
commit 52c0749723

View File

@ -8,6 +8,8 @@
#include <new>
#include <CardLayout.h>
#include <CardView.h>
#include <GridLayout.h>
#include <GridView.h>
#include <GroupLayout.h>
@ -27,6 +29,7 @@ template<typename ParentBuilder> class Base;
template<typename ParentBuilder = void*> class Group;
template<typename ParentBuilder = void*> class Grid;
template<typename ParentBuilder = void*> class Split;
template<typename ParentBuilder = void*> class Cards;
template<typename ParentBuilder = void*> class Menu;
template<typename ParentBuilder = void*> class MenuItem;
@ -53,6 +56,7 @@ public:
typedef Group<ThisBuilder> GroupBuilder;
typedef Grid<ThisBuilder> GridBuilder;
typedef Split<ThisBuilder> SplitBuilder;
typedef Cards<ThisBuilder> CardBuilder;
public:
inline Group(orientation orientation = B_HORIZONTAL,
@ -99,6 +103,12 @@ public:
inline SplitBuilder AddSplit(BSplitView* splitView,
float weight = 1.0f);
inline CardBuilder AddCards(float weight = 1.0f);
inline CardBuilder AddCards(BCardLayout* cardLayout,
float weight = 1.0f);
inline CardBuilder AddCards(BCardView* cardView,
float weight = 1.0f);
inline ThisBuilder& AddGlue(float weight = 1.0f);
inline ThisBuilder& AddStrut(float size);
@ -126,6 +136,7 @@ public:
typedef Group<ThisBuilder> GroupBuilder;
typedef Grid<ThisBuilder> GridBuilder;
typedef Split<ThisBuilder> SplitBuilder;
typedef Cards<ThisBuilder> CardBuilder;
public:
inline Grid(float horizontal
@ -192,6 +203,15 @@ public:
int32 row, int32 columnCount = 1,
int32 rowCount = 1);
inline CardBuilder AddCards(int32 column, int32 row,
int32 columnCount = 1, int32 rowCount = 1);
inline CardBuilder AddCards(BCardLayout* cardLayout, int32 column,
int32 row, int32 columnCount = 1,
int32 rowCount = 1);
inline CardBuilder AddCards(BCardView* cardView, int32 column,
int32 row, int32 columnCount = 1,
int32 rowCount = 1);
inline ThisBuilder& AddGlue(int32 column, int32 row,
int32 columnCount = 1, int32 rowCount = 1);
@ -226,6 +246,7 @@ public:
typedef Group<ThisBuilder> GroupBuilder;
typedef Grid<ThisBuilder> GridBuilder;
typedef Split<ThisBuilder> SplitBuilder;
typedef Cards<ThisBuilder> CardBuilder;
public:
inline Split(orientation orientation = B_HORIZONTAL,
@ -264,6 +285,12 @@ public:
inline SplitBuilder AddSplit(BSplitView* splitView,
float weight = 1.0f);
inline CardBuilder AddCards(float weight = 1.0f);
inline CardBuilder AddCards(BCardLayout* cardLayout,
float weight = 1.0f);
inline CardBuilder AddCards(BCardView* cardView,
float weight = 1.0f);
inline ThisBuilder& SetCollapsible(bool collapsible);
inline ThisBuilder& SetCollapsible(int32 index, bool collapsible);
inline ThisBuilder& SetCollapsible(int32 first, int32 last,
@ -280,6 +307,62 @@ private:
BSplitView* fView;
};
template<typename ParentBuilder>
class Cards : public Base<ParentBuilder> {
public:
typedef Cards<ParentBuilder> ThisBuilder;
typedef Group<ThisBuilder> GroupBuilder;
typedef Grid<ThisBuilder> GridBuilder;
typedef Split<ThisBuilder> SplitBuilder;
typedef Cards<ThisBuilder> CardBuilder;
public:
inline Cards();
inline Cards(BWindow* window);
inline Cards(BView* view);
inline Cards(BCardLayout* layout);
inline Cards(BCardView* view);
inline BCardLayout* Layout() const;
inline BView* View() const;
inline ThisBuilder& GetLayout(BCardLayout** _layout);
inline ThisBuilder& GetView(BView** _view);
inline ThisBuilder& Add(BView* view);
inline ThisBuilder& Add(BLayoutItem* item);
inline GroupBuilder AddGroup(orientation orientation,
float spacing = B_USE_DEFAULT_SPACING);
inline GroupBuilder AddGroup(BGroupView* groupView);
inline GroupBuilder AddGroup(BGroupLayout* groupLayout);
inline GridBuilder AddGrid(float horizontal
= B_USE_DEFAULT_SPACING,
float vertical = B_USE_DEFAULT_SPACING);
inline GridBuilder AddGrid(BGridLayout* gridLayout);
inline GridBuilder AddGrid(BGridView* gridView);
inline SplitBuilder AddSplit(orientation orientation,
float spacing = B_USE_DEFAULT_SPACING);
inline SplitBuilder AddSplit(BSplitView* splitView);
inline CardBuilder AddCards();
inline CardBuilder AddCards(BCardLayout* cardLayout);
inline CardBuilder AddCards(BCardView* cardView);
inline ThisBuilder& SetExplicitMinSize(BSize size);
inline ThisBuilder& SetExplicitMaxSize(BSize size);
inline ThisBuilder& SetExplicitPreferredSize(BSize size);
inline ThisBuilder& SetExplicitAlignment(BAlignment alignment);
inline ThisBuilder& SetVisibleItem(int32 index);
inline operator BCardLayout*();
private:
BCardLayout* fLayout;
};
template<typename ParentBuilder>
class Menu : public Base<ParentBuilder> {
@ -569,6 +652,39 @@ Group<ParentBuilder>::AddSplit(BSplitView* splitView, float weight)
}
template<typename ParentBuilder>
typename Group<ParentBuilder>::CardBuilder
Group<ParentBuilder>::AddCards(float weight)
{
CardBuilder builder;
builder.SetParent(this);
fLayout->AddView(builder.View(), weight);
return builder;
}
template<typename ParentBuilder>
typename Group<ParentBuilder>::CardBuilder
Group<ParentBuilder>::AddCards(BCardLayout* cardLayout, float weight)
{
CardBuilder builder(cardLayout);
builder.SetParent(this);
fLayout->AddView(builder.View(), weight);
return builder;
}
template<typename ParentBuilder>
typename Group<ParentBuilder>::CardBuilder
Group<ParentBuilder>::AddCards(BCardView* cardView, float weight)
{
CardBuilder builder(cardView);
builder.SetParent(this);
fLayout->AddView(builder.View(), weight);
return builder;
}
template<typename ParentBuilder>
typename Group<ParentBuilder>::ThisBuilder&
Group<ParentBuilder>::AddGlue(float weight)
@ -884,6 +1000,42 @@ Grid<ParentBuilder>::AddSplit(BSplitView* splitView, int32 column, int32 row,
}
template<typename ParentBuilder>
typename Grid<ParentBuilder>::CardBuilder
Grid<ParentBuilder>::AddCards(int32 column, int32 row, int32 columnCount,
int32 rowCount)
{
CardBuilder builder;
builder.SetParent(this);
fLayout->AddView(builder.View(), column, row, columnCount, rowCount);
return builder;
}
template<typename ParentBuilder>
typename Grid<ParentBuilder>::CardBuilder
Grid<ParentBuilder>::AddCards(BCardLayout* cardLayout, int32 column, int32 row,
int32 columnCount, int32 rowCount)
{
CardBuilder builder(cardLayout);
builder.SetParent(this);
fLayout->AddView(builder.View(), column, row, columnCount, rowCount);
return builder;
}
template<typename ParentBuilder>
typename Grid<ParentBuilder>::CardBuilder
Grid<ParentBuilder>::AddCards(BCardView* cardView, int32 column, int32 row,
int32 columnCount, int32 rowCount)
{
CardBuilder builder(cardView);
builder.SetParent(this);
fLayout->AddView(builder.View(), column, row, columnCount, rowCount);
return builder;
}
template<typename ParentBuilder>
typename Grid<ParentBuilder>::ThisBuilder&
Grid<ParentBuilder>::AddGlue(int32 column, int32 row, int32 columnCount,
@ -1172,6 +1324,39 @@ Split<ParentBuilder>::AddSplit(orientation orientation, float spacing,
}
template<typename ParentBuilder>
typename Split<ParentBuilder>::CardBuilder
Split<ParentBuilder>::AddCards(float weight)
{
CardBuilder builder;
builder.SetParent(this);
fView->AddChild(builder.View(), weight);
return builder;
}
template<typename ParentBuilder>
typename Split<ParentBuilder>::CardBuilder
Split<ParentBuilder>::AddCards(BCardLayout* cardLayout, float weight)
{
CardBuilder builder(cardLayout);
builder.SetParent(this);
fView->AddChild(builder.View(), weight);
return builder;
}
template<typename ParentBuilder>
typename Split<ParentBuilder>::CardBuilder
Split<ParentBuilder>::AddCards(BCardView* cardView, float weight)
{
CardBuilder builder(cardView);
builder.SetParent(this);
fView->AddChild(builder.View(), weight);
return builder;
}
template<typename ParentBuilder>
typename Split<ParentBuilder>::ThisBuilder&
Split<ParentBuilder>::SetCollapsible(bool collapsible)
@ -1234,6 +1419,278 @@ Split<ParentBuilder>::operator BSplitView*()
}
// #pragma mark - Cards
template<typename ParentBuilder>
Cards<ParentBuilder>::Cards()
:
fLayout((new BCardView())->CardLayout())
{
}
template<typename ParentBuilder>
Cards<ParentBuilder>::Cards(BWindow* window)
:
fLayout(new BCardLayout())
{
window->SetLayout(fLayout);
fLayout->Owner()->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
}
template<typename ParentBuilder>
Cards<ParentBuilder>::Cards(BView* view)
:
fLayout(new BCardLayout())
{
view->SetLayout(fLayout);
view->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
}
template<typename ParentBuilder>
Cards<ParentBuilder>::Cards(BCardLayout* layout)
:
fLayout(layout)
{
}
template<typename ParentBuilder>
Cards<ParentBuilder>::Cards(BCardView* view)
:
fLayout(view->CardLayout())
{
}
template<typename ParentBuilder>
BCardLayout*
Cards<ParentBuilder>::Layout() const
{
return fLayout;
}
template<typename ParentBuilder>
BView*
Cards<ParentBuilder>::View() const
{
return fLayout->Owner();
}
template<typename ParentBuilder>
typename Cards<ParentBuilder>::ThisBuilder&
Cards<ParentBuilder>::GetLayout(BCardLayout** _layout)
{
*_layout = fLayout;
return *this;
}
template<typename ParentBuilder>
typename Cards<ParentBuilder>::ThisBuilder&
Cards<ParentBuilder>::GetView(BView** _view)
{
*_view = fLayout->Owner();
return *this;
}
template<typename ParentBuilder>
typename Cards<ParentBuilder>::ThisBuilder&
Cards<ParentBuilder>::Add(BView* view)
{
fLayout->AddView(view);
return *this;
}
template<typename ParentBuilder>
typename Cards<ParentBuilder>::ThisBuilder&
Cards<ParentBuilder>::Add(BLayoutItem* item)
{
fLayout->AddItem(item);
return *this;
}
template<typename ParentBuilder>
typename Cards<ParentBuilder>::GroupBuilder
Cards<ParentBuilder>::AddGroup(orientation orientation, float spacing)
{
GroupBuilder builder(new BGroupLayout(orientation, spacing));
builder.SetParent(this);
fLayout->AddItem(builder.Layout());
return builder;
}
template<typename ParentBuilder>
typename Cards<ParentBuilder>::GroupBuilder
Cards<ParentBuilder>::AddGroup(BGroupView* groupView)
{
GroupBuilder builder(groupView);
builder.SetParent(this);
fLayout->AddItem(builder.Layout());
return builder;
}
template<typename ParentBuilder>
typename Cards<ParentBuilder>::GroupBuilder
Cards<ParentBuilder>::AddGroup(BGroupLayout* groupLayout)
{
GroupBuilder builder(groupLayout);
builder.SetParent(this);
fLayout->AddItem(builder.Layout());
return builder;
}
template<typename ParentBuilder>
typename Cards<ParentBuilder>::GridBuilder
Cards<ParentBuilder>::AddGrid(float horizontal, float vertical)
{
GridBuilder builder(horizontal, vertical);
builder.SetParent(this);
fLayout->AddItem(builder.Layout());
return builder;
}
template<typename ParentBuilder>
typename Cards<ParentBuilder>::GridBuilder
Cards<ParentBuilder>::AddGrid(BGridLayout* gridLayout)
{
GridBuilder builder(gridLayout);
builder.SetParent(this);
fLayout->AddItem(builder.Layout());
return builder;
}
template<typename ParentBuilder>
typename Cards<ParentBuilder>::GridBuilder
Cards<ParentBuilder>::AddGrid(BGridView* gridView)
{
GridBuilder builder(gridView);
builder.SetParent(this);
fLayout->AddItem(builder.Layout());
return builder;
}
template<typename ParentBuilder>
typename Cards<ParentBuilder>::SplitBuilder
Cards<ParentBuilder>::AddSplit(orientation orientation, float spacing)
{
SplitBuilder builder(orientation, spacing);
builder.SetParent(this);
fLayout->AddView(builder.View());
return builder;
}
template<typename ParentBuilder>
typename Cards<ParentBuilder>::SplitBuilder
Cards<ParentBuilder>::AddSplit(BSplitView* splitView)
{
SplitBuilder builder(splitView);
builder.SetParent(this);
fLayout->AddView(builder.View());
return builder;
}
template<typename ParentBuilder>
typename Cards<ParentBuilder>::CardBuilder
Cards<ParentBuilder>::AddCards()
{
CardBuilder builder;
builder.SetParent(this);
fLayout->AddView(builder.View());
return builder;
}
template<typename ParentBuilder>
typename Cards<ParentBuilder>::CardBuilder
Cards<ParentBuilder>::AddCards(BCardLayout* cardLayout)
{
CardBuilder builder(cardLayout);
builder.SetParent(this);
fLayout->AddView(builder.View());
return builder;
}
template<typename ParentBuilder>
typename Cards<ParentBuilder>::CardBuilder
Cards<ParentBuilder>::AddCards(BCardView* cardView)
{
CardBuilder builder(cardView);
builder.SetParent(this);
fLayout->AddView(builder.View());
return builder;
}
template<typename ParentBuilder>
typename Cards<ParentBuilder>::ThisBuilder&
Cards<ParentBuilder>::SetExplicitMinSize(BSize size)
{
fLayout->SetExplicitMinSize(size);
return *this;
}
template<typename ParentBuilder>
typename Cards<ParentBuilder>::ThisBuilder&
Cards<ParentBuilder>::SetExplicitMaxSize(BSize size)
{
fLayout->SetExplicitMaxSize(size);
return *this;
}
template<typename ParentBuilder>
typename Cards<ParentBuilder>::ThisBuilder&
Cards<ParentBuilder>::SetExplicitPreferredSize(BSize size)
{
fLayout->SetExplicitPreferredSize(size);
return *this;
}
template<typename ParentBuilder>
typename Cards<ParentBuilder>::ThisBuilder&
Cards<ParentBuilder>::SetExplicitAlignment(BAlignment alignment)
{
fLayout->SetExplicitAlignment(alignment);
return *this;
}
template<typename ParentBuilder>
typename Cards<ParentBuilder>::ThisBuilder&
Cards<ParentBuilder>::SetVisibleItem(int32 item)
{
fLayout->SetVisibleItem(item);
return *this;
}
template<typename ParentBuilder>
Cards<ParentBuilder>::operator BCardLayout*()
{
return fLayout;
}
// #pragma mark - Menu