- Add helper functions to get the tabs of a view or a layout item.
- AddView only require the top, left tabs now. - Remove the TwoViews test and replace it with a slightly more complex test. - Merge XTab and YTab files into one header file. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@38860 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -17,8 +17,7 @@
|
||||
#include "Column.h"
|
||||
#include "LinearSpec.h"
|
||||
#include "Row.h"
|
||||
#include "XTab.h"
|
||||
#include "YTab.h"
|
||||
#include "Tab.h"
|
||||
|
||||
|
||||
namespace BALM {
|
||||
@@ -54,17 +53,26 @@ public:
|
||||
void SetSpacing(float spacing);
|
||||
float Spacing() const;
|
||||
|
||||
Area* AreaFor(const BView* control) const;
|
||||
Area* AreaFor(const BView* view) const;
|
||||
Area* AreaFor(const BLayoutItem* item) const;
|
||||
Area* CurrentArea() const;
|
||||
void SetCurrentArea(const Area* area);
|
||||
void SetCurrentArea(const BView* control);
|
||||
void SetCurrentArea(const BView* view);
|
||||
void SetCurrentArea(const BLayoutItem* item);
|
||||
|
||||
XTab* LeftOf(const BView* view) const;
|
||||
XTab* LeftOf(const BLayoutItem* item) const;
|
||||
XTab* RightOf(const BView* view) const;
|
||||
XTab* RightOf(const BLayoutItem* item) const;
|
||||
YTab* TopOf(const BView* view) const;
|
||||
YTab* TopOf(const BLayoutItem* item) const;
|
||||
YTab* BottomOf(const BView* view) const;
|
||||
YTab* BottomOf(const BLayoutItem* item) const;
|
||||
|
||||
virtual BLayoutItem* AddView(BView* child);
|
||||
virtual BLayoutItem* AddView(int32 index, BView* child);
|
||||
virtual Area* AddView(BView* view, XTab* left, YTab* top,
|
||||
XTab* right, YTab* bottom);
|
||||
XTab* right = NULL, YTab* bottom = NULL);
|
||||
virtual Area* AddView(BView* view, Row* row, Column* column);
|
||||
virtual Area* AddViewToRight(BView* view, XTab* right = NULL,
|
||||
YTab* top = NULL, YTab* bottom = NULL);
|
||||
@@ -79,7 +87,8 @@ public:
|
||||
virtual bool AddItem(BLayoutItem* item);
|
||||
virtual bool AddItem(int32 index, BLayoutItem* item);
|
||||
virtual Area* AddItem(BLayoutItem* item, XTab* left,
|
||||
YTab* top, XTab* right, YTab* bottom);
|
||||
YTab* top, XTab* right = NULL,
|
||||
YTab* bottom = NULL);
|
||||
virtual Area* AddItem(BLayoutItem* item, Row* row,
|
||||
Column* column);
|
||||
virtual Area* AddItemToRight(BLayoutItem* item,
|
||||
|
||||
@@ -15,8 +15,7 @@
|
||||
#include "Column.h"
|
||||
#include "LinearSpec.h"
|
||||
#include "Row.h"
|
||||
#include "XTab.h"
|
||||
#include "YTab.h"
|
||||
#include "Tab.h"
|
||||
|
||||
|
||||
class Constraint;
|
||||
|
||||
@@ -18,25 +18,37 @@ namespace BALM {
|
||||
*/
|
||||
class XTab : public Variable {
|
||||
protected:
|
||||
XTab(LinearSpec* ls);
|
||||
|
||||
protected:
|
||||
/**
|
||||
* Property signifying if there is a constraint which relates
|
||||
* this tab to a different tab that is further to the left.
|
||||
* Only used for reverse engineering.
|
||||
*/
|
||||
bool fLeftLink;
|
||||
XTab(LinearSpec* ls)
|
||||
:
|
||||
Variable(ls)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public:
|
||||
friend class Area;
|
||||
friend class Column;
|
||||
friend class BALMLayout;
|
||||
|
||||
friend class BALMLayout;
|
||||
friend class Column;
|
||||
};
|
||||
|
||||
|
||||
class YTab : public Variable {
|
||||
protected:
|
||||
YTab(LinearSpec* ls)
|
||||
:
|
||||
Variable(ls)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public:
|
||||
friend class BALMLayout;
|
||||
friend class Row;
|
||||
};
|
||||
|
||||
|
||||
} // namespace BALM
|
||||
|
||||
using BALM::XTab;
|
||||
using BALM::YTab;
|
||||
|
||||
#endif // X_TAB_H
|
||||
@@ -1,42 +0,0 @@
|
||||
/*
|
||||
* Copyright 2006 - 2010, Haiku, Inc. All rights reserved.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
#ifndef Y_TAB_H
|
||||
#define Y_TAB_H
|
||||
|
||||
|
||||
#include "LinearSpec.h"
|
||||
#include "Variable.h"
|
||||
|
||||
|
||||
namespace BALM {
|
||||
|
||||
|
||||
/**
|
||||
* Horizontal grid line (y-tab).
|
||||
*/
|
||||
class YTab : public Variable {
|
||||
protected:
|
||||
YTab(LinearSpec* ls);
|
||||
|
||||
protected:
|
||||
/**
|
||||
* Property signifying if there is a constraint which relates
|
||||
* this tab to a different tab that is further to the top.
|
||||
* Only used for reverse engineering.
|
||||
*/
|
||||
bool fTopLink;
|
||||
|
||||
public:
|
||||
friend class Area;
|
||||
friend class Row;
|
||||
friend class BALMLayout;
|
||||
|
||||
};
|
||||
|
||||
} // namespace BALM
|
||||
|
||||
using BALM::YTab;
|
||||
|
||||
#endif // Y_TAB_H
|
||||
@@ -13,12 +13,7 @@
|
||||
|
||||
#include "ViewLayoutItem.h"
|
||||
|
||||
#include "Area.h"
|
||||
#include "Column.h"
|
||||
#include "ResultType.h"
|
||||
#include "Row.h"
|
||||
#include "XTab.h"
|
||||
#include "YTab.h"
|
||||
|
||||
|
||||
const BSize kUnsetSize(B_SIZE_UNSET, B_SIZE_UNSET);
|
||||
@@ -197,6 +192,62 @@ BALMLayout::SetCurrentArea(const BLayoutItem* item)
|
||||
}
|
||||
|
||||
|
||||
XTab*
|
||||
BALMLayout::LeftOf(const BView* view) const
|
||||
{
|
||||
return AreaFor(view)->Left();
|
||||
}
|
||||
|
||||
|
||||
XTab*
|
||||
BALMLayout::LeftOf(const BLayoutItem* item) const
|
||||
{
|
||||
return AreaFor(item)->Left();
|
||||
}
|
||||
|
||||
|
||||
XTab*
|
||||
BALMLayout::RightOf(const BView* view) const
|
||||
{
|
||||
return AreaFor(view)->Right();
|
||||
}
|
||||
|
||||
|
||||
XTab*
|
||||
BALMLayout::RightOf(const BLayoutItem* item) const
|
||||
{
|
||||
return AreaFor(item)->Right();
|
||||
}
|
||||
|
||||
|
||||
YTab*
|
||||
BALMLayout::TopOf(const BView* view) const
|
||||
{
|
||||
return AreaFor(view)->Top();
|
||||
}
|
||||
|
||||
|
||||
YTab*
|
||||
BALMLayout::TopOf(const BLayoutItem* item) const
|
||||
{
|
||||
return AreaFor(item)->Top();
|
||||
}
|
||||
|
||||
|
||||
YTab*
|
||||
BALMLayout::BottomOf(const BView* view) const
|
||||
{
|
||||
return AreaFor(view)->Bottom();
|
||||
}
|
||||
|
||||
|
||||
YTab*
|
||||
BALMLayout::BottomOf(const BLayoutItem* item) const
|
||||
{
|
||||
return AreaFor(item)->Bottom();
|
||||
}
|
||||
|
||||
|
||||
BLayoutItem*
|
||||
BALMLayout::AddView(BView* child)
|
||||
{
|
||||
@@ -325,8 +376,6 @@ BALMLayout::AddItem(int32 index, BLayoutItem* item)
|
||||
// TODO maybe find a more elegant solution
|
||||
XTab* left = Left();
|
||||
YTab* top = Top();
|
||||
XTab* right = AddXTab();
|
||||
YTab* bottom = AddYTab();
|
||||
|
||||
// check range
|
||||
if (index < 0 || index > CountItems())
|
||||
@@ -341,7 +390,7 @@ BALMLayout::AddItem(int32 index, BLayoutItem* item)
|
||||
top = area->Top();
|
||||
}
|
||||
}
|
||||
Area* area = AddItem(item, left, top, right, bottom);
|
||||
Area* area = AddItem(item, left, top);
|
||||
return area ? true : false;
|
||||
}
|
||||
|
||||
@@ -350,6 +399,11 @@ Area*
|
||||
BALMLayout::AddItem(BLayoutItem* item, XTab* left, YTab* top, XTab* right,
|
||||
YTab* bottom)
|
||||
{
|
||||
if (!right)
|
||||
right = AddXTab();
|
||||
if (!bottom)
|
||||
bottom = AddYTab();
|
||||
|
||||
if (!BAbstractLayout::AddItem(-1, item))
|
||||
return NULL;
|
||||
Area* area = AreaFor(item);
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
|
||||
#include "ALMLayout.h"
|
||||
#include "OperatorType.h"
|
||||
#include "XTab.h"
|
||||
#include "Tab.h"
|
||||
|
||||
#include <SupportDefs.h>
|
||||
|
||||
|
||||
@@ -12,8 +12,6 @@ SharedLibrary libalm.so :
|
||||
Column.cpp
|
||||
ALMLayout.cpp
|
||||
Row.cpp
|
||||
XTab.cpp
|
||||
YTab.cpp
|
||||
:
|
||||
be liblpsolve55.so liblinprog.so $(TARGET_LIBSUPC++)
|
||||
;
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
|
||||
#include "ALMLayout.h"
|
||||
#include "OperatorType.h"
|
||||
#include "YTab.h"
|
||||
#include "Tab.h"
|
||||
|
||||
#include <SupportDefs.h>
|
||||
|
||||
|
||||
@@ -1,19 +0,0 @@
|
||||
/*
|
||||
* Copyright 2007-2008, Christof Lutteroth, [email protected]
|
||||
* Copyright 2007-2008, James Kim, [email protected]
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
|
||||
|
||||
#include "XTab.h"
|
||||
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
XTab::XTab(LinearSpec* ls)
|
||||
: Variable(ls)
|
||||
{
|
||||
fLeftLink = false;
|
||||
}
|
||||
|
||||
@@ -1,18 +0,0 @@
|
||||
/*
|
||||
* Copyright 2007-2008, Christof Lutteroth, [email protected]
|
||||
* Copyright 2007-2008, James Kim, [email protected]
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
|
||||
#include "YTab.h"
|
||||
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
YTab::YTab(LinearSpec* ls)
|
||||
: Variable(ls)
|
||||
{
|
||||
fTopLink = false;
|
||||
}
|
||||
|
||||
@@ -12,8 +12,8 @@ Application ALMHelloWorld :
|
||||
be liblpsolve55.so liblinprog.so libalm.so $(TARGET_LIBSUPC++)
|
||||
;
|
||||
|
||||
Application ALMTwoViews :
|
||||
TwoViews.cpp
|
||||
Application ALMViews :
|
||||
Views.cpp
|
||||
:
|
||||
be liblpsolve55.so be liblinprog.so libalm.so $(TARGET_LIBSUPC++)
|
||||
;
|
||||
|
||||
@@ -1,75 +0,0 @@
|
||||
/*
|
||||
* Copyright 2007-2008, Christof Lutteroth, [email protected]
|
||||
* Copyright 2007-2008, James Kim, [email protected]
|
||||
* Copyright 2010, Clemens Zeidler <[email protected]>
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
|
||||
#include <Application.h>
|
||||
#include <Button.h>
|
||||
#include <TextView.h>
|
||||
#include <List.h>
|
||||
#include <Window.h>
|
||||
|
||||
#include "ALMLayout.h"
|
||||
|
||||
|
||||
class TwoViewsWindow : public BWindow {
|
||||
public:
|
||||
TwoViewsWindow(BRect frame)
|
||||
:
|
||||
BWindow(frame, "ALM Two Views", B_TITLED_WINDOW, B_QUIT_ON_WINDOW_CLOSE)
|
||||
{
|
||||
button1 = new BButton("View 1");
|
||||
button1->SetExplicitMinSize(BSize(0, 0));
|
||||
button1->SetExplicitMaxSize(BSize(B_SIZE_UNLIMITED, B_SIZE_UNLIMITED));
|
||||
|
||||
textView1 = new BTextView("textView1");
|
||||
textView1->SetText("View 2");
|
||||
|
||||
// create a new BALMLayout and use it for this window
|
||||
BALMLayout* layout = new BALMLayout();
|
||||
SetLayout(layout);
|
||||
|
||||
// create an extra tab
|
||||
XTab* x1 = layout->AddXTab();
|
||||
|
||||
layout->AddView(button1, layout->Left(), layout->Top(), x1,
|
||||
layout->Bottom());
|
||||
layout->AddView(textView1, x1, layout->Top(), layout->Right(),
|
||||
layout->Bottom());
|
||||
|
||||
// add a constraint: 2*x1 == right
|
||||
// i.e. x1 is in the middle of the layout
|
||||
layout->Solver()->AddConstraint(2, x1, -1, layout->Right(),
|
||||
OperatorType(EQ), 0);
|
||||
}
|
||||
|
||||
private:
|
||||
BButton* button1;
|
||||
BTextView* textView1;
|
||||
};
|
||||
|
||||
|
||||
class TwoViews : public BApplication {
|
||||
public:
|
||||
TwoViews()
|
||||
:
|
||||
BApplication("application/x-vnd.haiku.TwoViews")
|
||||
{
|
||||
BRect frameRect;
|
||||
frameRect.Set(100, 100, 300, 300);
|
||||
TwoViewsWindow* window = new TwoViewsWindow(frameRect);
|
||||
window->Show();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
int
|
||||
main()
|
||||
{
|
||||
TwoViews app;
|
||||
app.Run();
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,113 @@
|
||||
/*
|
||||
* Copyright 2007-2008, Christof Lutteroth, [email protected]
|
||||
* Copyright 2007-2008, James Kim, [email protected]
|
||||
* Copyright 2010, Clemens Zeidler <[email protected]>
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
|
||||
|
||||
#include <Application.h>
|
||||
#include <Button.h>
|
||||
#include <MenuField.h>
|
||||
#include <PopUpMenu.h>
|
||||
#include <RadioButton.h>
|
||||
#include <SpaceLayoutItem.h>
|
||||
#include <StatusBar.h>
|
||||
#include <StringView.h>
|
||||
#include <TextView.h>
|
||||
#include <Window.h>
|
||||
|
||||
#include "ALMLayout.h"
|
||||
|
||||
|
||||
class ViewsWindow : public BWindow {
|
||||
public:
|
||||
ViewsWindow(BRect frame)
|
||||
:
|
||||
BWindow(frame, "ALM Two Views", B_TITLED_WINDOW, B_QUIT_ON_WINDOW_CLOSE)
|
||||
{
|
||||
BButton* button1 = new BButton("BButton");
|
||||
BRadioButton* radioButton = new BRadioButton("BRadioButton", NULL);
|
||||
BButton* button3 = new BButton("3");
|
||||
BButton* button4 = new BButton("4");
|
||||
button4->SetExplicitAlignment(BAlignment(B_ALIGN_LEFT,
|
||||
B_ALIGN_VERTICAL_CENTER));
|
||||
BButton* button5 = new BButton("5");
|
||||
BButton* button6 = new BButton("6");
|
||||
BTextView* textView1 = new BTextView("textView1");
|
||||
textView1->SetText("BTextView");
|
||||
BStatusBar* statusBar = new BStatusBar("BStatusBar", "label",
|
||||
"trailing label");
|
||||
statusBar->Update(50);
|
||||
|
||||
BMenu* menu = new BMenu("Menu 1");
|
||||
BMenuField* menu1 = new BMenuField("MenuField 1", menu);
|
||||
menu->AddItem(new BPopUpMenu("Menu 1"));
|
||||
BStringView* stringView1 = new BStringView("string 1", "string 1");
|
||||
|
||||
menu = new BMenu("Menu 2 + long text");
|
||||
BMenuField* menu2 = new BMenuField("MenuField 2", menu);
|
||||
menu->AddItem(new BPopUpMenu("Menu 2"));
|
||||
BStringView* stringView2 = new BStringView("string 2", "string 2");
|
||||
|
||||
// create a new BALMLayout and use it for this window
|
||||
BALMLayout* layout = new BALMLayout(10);
|
||||
SetLayout(layout);
|
||||
layout->SetInset(10.);
|
||||
|
||||
layout->AddView(button1);
|
||||
layout->AddViewToRight(radioButton);
|
||||
layout->AddItemToRight(BSpaceLayoutItem::CreateGlue());
|
||||
Area* a3 = layout->AddViewToRight(button3);
|
||||
layout->SetCurrentArea(radioButton);
|
||||
layout->AddViewToBottom(textView1, NULL, NULL, a3->Right());
|
||||
layout->AddViewToBottom(button4);
|
||||
layout->AddViewToRight(button5, layout->Right());
|
||||
layout->AddViewToBottom(button6);
|
||||
|
||||
layout->AddView(menu1, layout->Left(), layout->BottomOf(button6));
|
||||
layout->AddViewToRight(stringView1);
|
||||
layout->AddItemToRight(BSpaceLayoutItem::CreateGlue(), layout->Right());
|
||||
|
||||
layout->AddViewToBottom(statusBar, NULL, layout->Left(),
|
||||
layout->Right());
|
||||
|
||||
layout->AddView(menu2, layout->Left(), layout->BottomOf(statusBar),
|
||||
layout->RightOf(menu1), layout->Bottom());
|
||||
layout->AddViewToRight(stringView2);
|
||||
layout->AddItemToRight(BSpaceLayoutItem::CreateGlue(), layout->Right());
|
||||
|
||||
layout->Solver()->AddConstraint(2, layout->TopOf(menu1), -1,
|
||||
layout->Bottom(), OperatorType(EQ), 0);
|
||||
|
||||
// test size limits
|
||||
BSize min = layout->MinSize();
|
||||
BSize max = layout->MaxSize();
|
||||
SetSizeLimits(min.Width(), max.Width(), min.Height(), max.Height());
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
class Views : public BApplication {
|
||||
public:
|
||||
Views()
|
||||
:
|
||||
BApplication("application/x-vnd.haiku.Views")
|
||||
{
|
||||
BRect frameRect;
|
||||
frameRect.Set(100, 100, 300, 300);
|
||||
ViewsWindow* window = new ViewsWindow(frameRect);
|
||||
window->Show();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
int
|
||||
main()
|
||||
{
|
||||
Views app;
|
||||
app.Run();
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user