* Applied a patch by Christof Lutteroth that updates ALM, and brings new test

apps.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@33805 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler 2009-10-28 09:00:14 +00:00
parent dcfdc8374a
commit ea607d6f7f
14 changed files with 541 additions and 512 deletions

View File

@ -7,22 +7,23 @@
#ifndef AREA_H
#define AREA_H
#include "Constraint.h"
#include <Alignment.h>
#include <List.h>
#include <Size.h>
#include <SupportDefs.h>
#include <View.h>
#include "XTab.h"
#include "YTab.h"
#include "Area.h"
#include "Row.h"
#include "Column.h"
#include "Constraint.h"
namespace BALM {
class Column;
class BALMLayout;
class Row;
class XTab;
class YTab;
/**
* Rectangular area in the GUI, defined by a tab on each side.
@ -30,9 +31,6 @@ class YTab;
class Area {
public:
bool AutoPrefContentSize() const;
void SetAutoPrefContentSize(bool value);
XTab* Left() const;
void SetLeft(XTab* left);
XTab* Right() const;
@ -57,18 +55,21 @@ public:
void SetMinContentSize(BSize min);
BSize MaxContentSize() const;
void SetMaxContentSize(BSize max);
BSize PrefContentSize() const;
void SetPrefContentSize(BSize pref);
BSize ShrinkRigidity() const;
void SetShrinkRigidity(BSize shrink);
BSize ExpandRigidity() const;
void SetExpandRigidity(BSize expand);
BSize PreferredContentSize() const;
void SetPreferredContentSize(BSize preferred);
double ContentAspectRatio() const;
void SetContentAspectRatio(double ratio);
BSize ShrinkPenalties() const;
void SetShrinkPenalties(BSize shrink);
BSize GrowPenalties() const;
void SetGrowPenalties(BSize grow);
BAlignment Alignment() const;
void SetAlignment(BAlignment alignment);
void SetHAlignment(alignment horizontal);
void SetVAlignment(vertical_alignment vertical);
void SetHorizontalAlignment(alignment horizontal);
void SetVerticalAlignment(vertical_alignment vertical);
int32 LeftInset() const;
void SetLeftInset(int32 left);
int32 TopInset() const;
@ -77,12 +78,18 @@ public:
void SetRightInset(int32 right);
int32 BottomInset() const;
void SetBottomInset(int32 bottom);
void SetDefaultPrefContentSize();
//~ string ToString();
void SetDefaultBehavior();
bool AutoPreferredContentSize() const;
void SetAutoPreferredContentSize(bool value);
BString* ToBString();
const char* ToString();
Constraint* HasSameWidthAs(Area* area);
Constraint* HasSameHeightAs(Area* area);
BList* HasSameSizetAs(Area* area);
BList* HasSameSizeAs(Area* area);
~Area();
protected:
@ -127,14 +134,14 @@ private:
Constraint* fMaxContentWidth;
Constraint* fMinContentHeight;
Constraint* fMaxContentHeight;
BSize fPrefContentSize;
BSize fShrinkRigidity;
BSize fExpandRigidity;
BSize fPreferredContentSize;
BSize fShrinkPenalties;
BSize fGrowPenalties;
double fContentAspectRatio;
Constraint* fContentAspectRatioC;
bool fAutoPrefContentSize;
Constraint* fPrefContentWidth;
Constraint* fPrefContentHeight;
bool fAutoPreferredContentSize;
Constraint* fPreferredContentWidth;
Constraint* fPreferredContentHeight;
Area* fChildArea;
BAlignment fAlignment;
int32 fLeftInset;
@ -147,7 +154,7 @@ private:
Constraint* fBottomConstraint;
public:
friend class BALMLayout;
friend class BALMLayout;
};

View File

@ -15,16 +15,16 @@
#include <View.h>
#include "LayoutStyleType.h"
#include "XTab.h"
#include "YTab.h"
#include "Area.h"
#include "Row.h"
#include "Column.h"
#include "Constraint.h"
#include "LinearSpec.h"
namespace BALM {
class Area;
class Column;
class Row;
class XTab;
class YTab;
/**
* A GUI layout engine using the ALM.

View File

@ -34,9 +34,9 @@ BSize Area::kUndefinedSize(-1, -1);
* @return the auto preferred content size
*/
bool
Area::AutoPrefContentSize() const
Area::AutoPreferredContentSize() const
{
return fAutoPrefContentSize;
return fAutoPreferredContentSize;
}
@ -46,9 +46,9 @@ Area::AutoPrefContentSize() const
* @param value the auto preferred content size
*/
void
Area::SetAutoPrefContentSize(bool value)
Area::SetAutoPreferredContentSize(bool value)
{
fAutoPrefContentSize = value;
fAutoPreferredContentSize = value;
}
@ -360,38 +360,42 @@ Area::SetMaxContentSize(BSize max)
* Gets Preferred size of the area's content.
*/
BSize
Area::PrefContentSize() const
Area::PreferredContentSize() const
{
return (fChildArea == NULL) ? fPrefContentSize : fChildArea->fPrefContentSize;
return (fChildArea == NULL) ? fPreferredContentSize
: fChildArea->fPreferredContentSize;
}
/**
* Sets Preferred size of the area's content.
* May be different from the preferred size of the area.
* Manual changes of PrefContentSize are ignored unless autoPrefContentSize is set to false.
* Manual changes of PreferredContentSize are ignored unless
* autoPreferredContentSize is set to false.
*/
void
Area::SetPrefContentSize(BSize pref)
Area::SetPreferredContentSize(BSize preferred)
{
if (fChildArea == NULL) {
fPrefContentSize = pref;
if (fPrefContentWidth == NULL) {
fPrefContentWidth = fLS->AddConstraint(-1.0, fLeft, 1.0, fRight, OperatorType(EQ),
fPrefContentSize.Width(), fShrinkRigidity.Width(),
fExpandRigidity.Width());
fConstraints->AddItem(fPrefContentWidth);
fPreferredContentSize = preferred;
if (fPreferredContentWidth == NULL) {
fPreferredContentWidth = fLS->AddConstraint(
-1.0, fLeft, 1.0, fRight, OperatorType(EQ),
fPreferredContentSize.Width(), fShrinkPenalties.Width(),
fGrowPenalties.Width());
fConstraints->AddItem(fPreferredContentWidth);
fPrefContentHeight = fLS->AddConstraint(-1.0, fTop, 1.0, fBottom, OperatorType(EQ),
fPrefContentSize.Height(), fShrinkRigidity.Height(),
fExpandRigidity.Height());
fConstraints->AddItem(fPrefContentHeight);
fPreferredContentHeight = fLS->AddConstraint(
-1.0, fTop, 1.0, fBottom, OperatorType(EQ),
fPreferredContentSize.Height(), fShrinkPenalties.Height(),
fGrowPenalties.Height());
fConstraints->AddItem(fPreferredContentHeight);
} else {
fPrefContentWidth->SetRightSide(pref.Width());
fPrefContentHeight->SetRightSide(pref.Height());
fPreferredContentWidth->SetRightSide(preferred.Width());
fPreferredContentHeight->SetRightSide(preferred.Height());
}
} else
fChildArea->SetPrefContentSize(pref);
fChildArea->SetPreferredContentSize(preferred);
fLS->InvalidateLayout();
}
@ -401,47 +405,47 @@ Area::SetPrefContentSize(BSize pref)
* The bigger the less likely is such shrinking.
*/
BSize
Area::ShrinkRigidity() const
Area::ShrinkPenalties() const
{
return (fChildArea == NULL) ? fShrinkRigidity : fChildArea->fShrinkRigidity;
return (fChildArea == NULL) ? fShrinkPenalties : fChildArea->fShrinkPenalties;
}
void Area::SetShrinkRigidity(BSize shrink) {
void Area::SetShrinkPenalties(BSize shrink) {
if (fChildArea == NULL) {
fShrinkRigidity = shrink;
if (fPrefContentWidth != NULL) {
fPrefContentWidth->SetPenaltyNeg(shrink.Width());
fPrefContentHeight->SetPenaltyNeg(shrink.Height());
fShrinkPenalties = shrink;
if (fPreferredContentWidth != NULL) {
fPreferredContentWidth->SetPenaltyNeg(shrink.Width());
fPreferredContentHeight->SetPenaltyNeg(shrink.Height());
}
} else
fChildArea->SetShrinkRigidity(shrink);
fChildArea->SetShrinkPenalties(shrink);
fLS->InvalidateLayout();
}
/**
* The reluctance with which the area's content expands over its preferred size.
* The bigger the less likely is such expansion.
* The reluctance with which the area's content grows over its preferred size.
* The bigger the less likely is such growth.
*/
BSize
Area::ExpandRigidity() const
Area::GrowPenalties() const
{
return (fChildArea == NULL) ? fExpandRigidity : fChildArea->fExpandRigidity;
return (fChildArea == NULL) ? fGrowPenalties : fChildArea->fGrowPenalties;
}
void
Area::SetExpandRigidity(BSize expand)
Area::SetGrowPenalties(BSize grow)
{
if (fChildArea == NULL) {
fExpandRigidity = expand;
if (fPrefContentWidth != NULL) {
fPrefContentWidth->SetPenaltyPos(expand.Width());
fPrefContentHeight->SetPenaltyPos(expand.Height());
fGrowPenalties = grow;
if (fPreferredContentWidth != NULL) {
fPreferredContentWidth->SetPenaltyPos(grow.Width());
fPreferredContentHeight->SetPenaltyPos(grow.Height());
}
} else
fChildArea->SetExpandRigidity(expand);
fChildArea->SetGrowPenalties(grow);
fLS->InvalidateLayout();
}
@ -506,7 +510,7 @@ Area::SetAlignment(BAlignment alignment)
/**
* Sets horizontal alignment of the content in its area.
*/
void Area::SetHAlignment(alignment horizontal) {
void Area::SetHorizontalAlignment(alignment horizontal) {
fAlignment.SetHorizontal(horizontal);
UpdateHorizontal();
fLS->InvalidateLayout();
@ -517,7 +521,7 @@ void Area::SetHAlignment(alignment horizontal) {
* Sets vertical alignment of the content in its area.
*/
void
Area::SetVAlignment(vertical_alignment vertical)
Area::SetVerticalAlignment(vertical_alignment vertical)
{
fAlignment.SetVertical(vertical);
UpdateVertical();
@ -613,20 +617,20 @@ Area::SetBottomInset(int32 bottom)
/**
* Sets the preferred size according to the content's PreferredSize method,
* and the rigidities according to heuristics.
* and the penalties according to heuristics.
*/
void
Area::SetDefaultPrefContentSize()
Area::SetDefaultBehavior()
{
if (Content() == NULL) {
SetPrefContentSize(BSize(0, 0));
SetShrinkRigidity(BSize(0, 0));
SetExpandRigidity(BSize(0, 0));
SetPreferredContentSize(BSize(0, 0));
SetShrinkPenalties(BSize(0, 0));
SetGrowPenalties(BSize(0, 0));
return;
}
if (PrefContentSize() != Content()->PreferredSize()){
SetPrefContentSize(Content()->PreferredSize());
if (PreferredContentSize() != Content()->PreferredSize()){
SetPreferredContentSize(Content()->PreferredSize());
fLS->InvalidateLayout();
}
@ -636,21 +640,44 @@ Area::SetDefaultPrefContentSize()
|| dynamic_cast<BStringView*>(Content()) != NULL
|| dynamic_cast<BPictureButton*>(Content()) != NULL
|| dynamic_cast<BStatusBar*>(Content()) != NULL) {
//~ || Content is LinkLabel
//~ || Content is NumericUpDown) {
fShrinkRigidity = BSize(4, 4);
fExpandRigidity = BSize(3, 3);
fShrinkPenalties = BSize(4, 4);
fGrowPenalties = BSize(3, 3);
} else {
fShrinkRigidity = BSize(2, 2);
fExpandRigidity = BSize(1, 1);
fShrinkPenalties = BSize(2, 2);
fGrowPenalties = BSize(1, 1);
}
}
//~ string Area::ToString() {
//~ return "Area(" + fLeft->ToString() + "," + fTop->ToString() + ","
//~ + fRight->ToString() + "," + fBottom->ToString() + ")";
//~ }
BString*
Area::ToBString()
{
BString* str = new BString();
BString* leftStr = fLeft->ToBString();
BString* topStr = fTop->ToBString();
BString* rightStr = fRight->ToBString();
BString* bottomStr = fBottom->ToBString();
*str << "Area(" << *leftStr << ", "
<< *topStr << ", "
<< *rightStr << ", "
<< *bottomStr << ")";
delete leftStr;
delete topStr;
delete rightStr;
delete bottomStr;
return str;
}
const char*
Area::ToString()
{
BString* str = new BString();
char* result = (char*) malloc(str->Length() + 1);
str->CopyInto(result, 0, str->Length());
delete str;
return result;
}
/**
@ -690,7 +717,7 @@ Area::HasSameHeightAs(Area* area)
* @return a list containing a same-width and same-height constraint
*/
BList*
Area::HasSameSizetAs(Area* area)
Area::HasSameSizeAs(Area* area)
{
BList* constraints = new BList(2);
constraints->AddItem(this->HasSameWidthAs(area));
@ -752,16 +779,16 @@ Area::Init(BALMLayout* ls, XTab* left, YTab* top, XTab* right, YTab* bottom,
fMaxContentWidth = NULL;
fMaxContentHeight = NULL;
fPrefContentSize = kUndefinedSize;
fShrinkRigidity = BSize(2, 2);
fExpandRigidity = BSize(1, 1);
fPreferredContentSize = kUndefinedSize;
fShrinkPenalties = BSize(2, 2);
fGrowPenalties = BSize(1, 1);
fContentAspectRatio = 0;
fContentAspectRatioC = NULL;
fAutoPrefContentSize = false;
fAutoPreferredContentSize = false;
fPrefContentWidth = NULL;
fPrefContentHeight = NULL;
fPreferredContentWidth = NULL;
fPreferredContentHeight = NULL;
fChildArea = NULL;
@ -855,25 +882,29 @@ Area::InitChildArea()
fChildArea->fMaxContentSize = fMaxContentSize;
fChildArea->fMaxContentWidth = fMaxContentWidth;
fMaxContentWidth->SetLeftSide(-1.0, fChildArea->Left(), 1.0, fChildArea->Right());
fMaxContentWidth->SetLeftSide(
-1.0, fChildArea->Left(), 1.0, fChildArea->Right());
fChildArea->fMaxContentHeight = fMaxContentHeight;
fMaxContentHeight->SetLeftSide(-1.0, fChildArea->Top(), 1.0, fChildArea->Bottom());
fMaxContentHeight->SetLeftSide(
-1.0, fChildArea->Top(), 1.0, fChildArea->Bottom());
}
// if there are preferred content size constraints on this area,
// change them so that they refer to the tabs of the childArea
// and copy the preferred content size settings to the childArea
if (fPrefContentHeight != NULL) {
fChildArea->fPrefContentSize = fPrefContentSize;
fChildArea->fShrinkRigidity = fShrinkRigidity;
fChildArea->fExpandRigidity = fExpandRigidity;
if (fPreferredContentHeight != NULL) {
fChildArea->fPreferredContentSize = fPreferredContentSize;
fChildArea->fShrinkPenalties = fShrinkPenalties;
fChildArea->fGrowPenalties = fGrowPenalties;
fChildArea->fPrefContentWidth = fPrefContentWidth;
fPrefContentWidth->SetLeftSide(-1.0, fChildArea->Left(), 1.0, fChildArea->Right());
fChildArea->fPreferredContentWidth = fPreferredContentWidth;
fPreferredContentWidth->SetLeftSide(
-1.0, fChildArea->Left(), 1.0, fChildArea->Right());
fChildArea->fPrefContentHeight = fPrefContentHeight;
fPrefContentHeight->SetLeftSide(-1.0, fChildArea->Top(), 1.0, fChildArea->Bottom());
fChildArea->fPreferredContentHeight = fPreferredContentHeight;
fPreferredContentHeight->SetLeftSide(
-1.0, fChildArea->Top(), 1.0, fChildArea->Bottom());
}
}

View File

@ -52,14 +52,14 @@ BALMLayout::BALMLayout()
void
BALMLayout::SolveLayout()
{
// if autoPrefContentSize is set on an area, readjust its prefContentSize and
// rigidity settings
// if autoPreferredContentSize is set on an area,
// readjust its preferredContentSize and penalties settings
int32 sizeAreas = fAreas->CountItems();
Area* currentArea;
for (int32 i = 0; i < sizeAreas; i++) {
currentArea = (Area*)fAreas->ItemAt(i);
if (currentArea->AutoPrefContentSize())
currentArea->SetDefaultPrefContentSize();
if (currentArea->AutoPreferredContentSize())
currentArea->SetDefaultBehavior();
}
// try to solve the layout until the result is OPTIMAL or INFEASIBLE, maximally
@ -229,8 +229,8 @@ BALMLayout::AddArea(XTab* left, YTab* top, XTab* right, YTab* bottom,
if (content != NULL)
View()->AddChild(content);
Area* area = new Area(this, left, top, right, bottom, content, BSize(0, 0));
area->SetDefaultPrefContentSize();
area->SetAutoPrefContentSize(false);
area->SetDefaultBehavior();
area->SetAutoPreferredContentSize(false);
fAreas->AddItem(area);
return area;
}
@ -251,8 +251,8 @@ BALMLayout::AddArea(Row* row, Column* column, BView* content)
if (content != NULL)
View()->AddChild(content);
Area* area = new Area(this, row, column, content, BSize(0, 0));
area->SetDefaultPrefContentSize();
area->SetAutoPrefContentSize(false);
area->SetDefaultBehavior();
area->SetAutoPreferredContentSize(false);
fAreas->AddItem(area);
return area;
}

View File

@ -0,0 +1,85 @@
#include <Application.h>
#include <Button.h>
#include <List.h>
#include <Window.h>
#include "BALMLayout.h"
class AreasWindow : public BWindow {
public:
AreasWindow(BRect frame)
: BWindow(frame, "ALM Areas",
B_TITLED_WINDOW, B_QUIT_ON_WINDOW_CLOSE)
{
button1 = new BButton("1");
button2 = new BButton("2");
button3 = new BButton("3");
button4 = new BButton("4");
// create a new BALMLayout and use it for this window
BALMLayout* layout = new BALMLayout();
SetLayout(layout);
// create extra tabs
YTab* y1 = layout->AddYTab();
YTab* y2 = layout->AddYTab();
YTab* y3 = layout->AddYTab();
Area* a1 = layout->AddArea(
layout->Left(), layout->Top(),
layout->Right(), y1,
button1);
a1->SetTopInset(10);
a1->SetLeftInset(10);
a1->SetRightInset(10);
Area* a2 = layout->AddArea(
layout->Left(), y1,
layout->Right(), y2,
button2);
a2->SetHorizontalAlignment(B_ALIGN_LEFT);
Area* a3 = layout->AddArea(
layout->Left(), y2,
layout->Right(), y3,
button3);
a3->SetHorizontalAlignment(B_ALIGN_HORIZONTAL_CENTER);
a3->HasSameHeightAs(a1);
Area* a4 = layout->AddArea(
layout->Left(), y3,
layout->Right(), layout->Bottom(),
button4);
a4->SetHorizontalAlignment(B_ALIGN_RIGHT);
}
private:
BButton* button1;
BButton* button2;
BButton* button3;
BButton* button4;
};
class Areas : public BApplication {
public:
Areas()
: BApplication("application/x-vnd.haiku.Areas")
{
BRect frameRect;
frameRect.Set(100, 100, 300, 300);
AreasWindow* window = new AreasWindow(frameRect);
window->Show();
}
};
int
main()
{
Areas app;
app.Run();
return 0;
}

View File

@ -0,0 +1,58 @@
#include <Application.h>
#include <Button.h>
#include <List.h>
#include <Window.h>
// include this for ALM
#include "XTab.h"
#include "YTab.h"
#include "Area.h"
#include "BALMLayout.h"
class HelloWorldWindow : public BWindow {
public:
HelloWorldWindow(BRect frame)
: BWindow(frame, "ALM Hello World",
B_TITLED_WINDOW, B_QUIT_ON_WINDOW_CLOSE)
{
button1 = new BButton("Hello World!");
// create a new BALMLayout and use it for this window
fLayout = new BALMLayout();
SetLayout(fLayout);
// add an area containing the button
// use the borders of the layout as the borders for the area
Area* a = fLayout->AddArea(
fLayout->Left(), fLayout->Top(),
fLayout->Right(), fLayout->Bottom(),
button1);
}
private:
BALMLayout* fLayout;
BButton* button1;
};
class HelloWorld : public BApplication {
public:
HelloWorld()
: BApplication("application/x-vnd.haiku.HelloWorld")
{
BRect frameRect;
frameRect.Set(100, 100, 300, 300);
HelloWorldWindow* window = new HelloWorldWindow(frameRect);
window->Show();
}
};
int
main()
{
HelloWorld app;
app.Run();
return 0;
}

View File

@ -4,26 +4,32 @@ SetSubDirSupportedPlatformsBeOSCompatible ;
UseLibraryHeaders lp_solve linprog alm ;
Application ALMTableTest :
TableTest.cpp
Application ALMHelloWorld :
HelloWorld.cpp
:
be liblpsolve55.so liblinprog.so libalm.so $(TARGET_LIBSUPC++)
;
Application ALMTest1 :
Test1.cpp
Application ALMTwoViews :
TwoViews.cpp
:
be liblpsolve55.so be liblinprog.so libalm.so $(TARGET_LIBSUPC++)
;
Application ALMTest2 :
Test2.cpp
Application ALMPinwheel :
Pinwheel.cpp
:
be liblpsolve55.so be liblinprog.so libalm.so $(TARGET_LIBSUPC++)
;
Application ALMSimpleTest :
SimpleTest.cpp
Application ALMAreas :
Areas.cpp
:
be liblpsolve55.so be liblinprog.so libalm.so $(TARGET_LIBSUPC++)
;
Application ALMTableDemo :
TableDemo.cpp
:
be liblpsolve55.so be liblinprog.so libalm.so $(TARGET_LIBSUPC++)
;

View File

@ -0,0 +1,90 @@
#include <Application.h>
#include <Button.h>
#include <TextView.h>
#include <List.h>
#include <Window.h>
// include this for ALM
#include "XTab.h"
#include "YTab.h"
#include "Area.h"
#include "BALMLayout.h"
class PinwheelWindow : public BWindow {
public:
PinwheelWindow(BRect frame)
: BWindow(frame, "ALM Pinwheel",
B_TITLED_WINDOW, B_QUIT_ON_WINDOW_CLOSE)
{
button1 = new BButton("1");
button2 = new BButton("2");
button3 = new BButton("3");
button4 = new BButton("4");
textView1 = new BTextView("textView1");
textView1->SetText("5");
// create a new BALMLayout and use it for this window
BALMLayout* layout = new BALMLayout();
SetLayout(layout);
// create extra tabs
XTab* x1 = layout->AddXTab();
XTab* x2 = layout->AddXTab();
YTab* y1 = layout->AddYTab();
YTab* y2 = layout->AddYTab();
Area* a1 = layout->AddArea(
layout->Left(), layout->Top(),
x2, y1,
button1);
Area* a2 = layout->AddArea(
x2, layout->Top(),
layout->Right(), y2,
button2);
Area* a3 = layout->AddArea(
x1, y2,
layout->Right(), layout->Bottom(),
button3);
Area* a4 = layout->AddArea(
layout->Left(), y1,
x1, layout->Bottom(),
button4);
Area* a5 = layout->AddArea(
x1, y1,
x2, y2,
textView1);
a1->HasSameSizeAs(a3);
}
private:
BButton* button1;
BButton* button2;
BButton* button3;
BButton* button4;
BTextView* textView1;
};
class Pinwheel : public BApplication {
public:
Pinwheel()
: BApplication("application/x-vnd.haiku.Pinwheel")
{
BRect frameRect;
frameRect.Set(100, 100, 300, 300);
PinwheelWindow* window = new PinwheelWindow(frameRect);
window->Show();
}
};
int
main()
{
Pinwheel app;
app.Run();
return 0;
}

View File

@ -1,74 +0,0 @@
/*
* Copyright 2007-2008, Christof Lutteroth, lutteroth@cs.auckland.ac.nz
* Copyright 2007-2008, James Kim, jkim202@ec.auckland.ac.nz
* Distributed under the terms of the MIT License.
*/
#include <Application.h>
#include <Button.h>
#include <List.h>
#include <Window.h>
#include "Area.h"
#include "BALMLayout.h"
#include "OperatorType.h"
#include "XTab.h"
#include "YTab.h"
using namespace BALM;
class SimpleTestWindow : public BWindow {
public:
SimpleTestWindow(BRect frame)
: BWindow(frame, "SimpleTest", B_TITLED_WINDOW, B_QUIT_ON_WINDOW_CLOSE)
{
fLS = new BALMLayout();
SetLayout(fLS);
button1 = new BButton("button1");
SetBALMLayout();
Show();
}
void
SetBALMLayout()
{
Area* a = fLS->AddArea(fLS->Left(), fLS->Top(), fLS->Right(), fLS->Bottom(), button1);
a->SetLeftInset(10);
fLS->Save("/boot/home/Desktop/test1_ls.txt");
// fLS->AddConstraint(2.0, x1, -1.0, fLS->Right(), OperatorType(EQ), 0.0);
// fLS->AddConstraint(2.0, y1, -1.0, fLS->Bottom(), OperatorType(EQ), 0.0);
}
private:
BALMLayout* fLS;
BButton* button1;
};
class SimpleTest : public BApplication {
public:
SimpleTest()
: BApplication("application/x-vnd.haiku.simpletest")
{
BRect frameRect;
frameRect.Set(100, 100, 392, 366);
SimpleTestWindow* theWindow = new SimpleTestWindow(frameRect);
}
};
int
main()
{
SimpleTest test;
test.Run();
return 0;
}

View File

@ -0,0 +1,72 @@
/*
* Copyright 2007-2008, Christof Lutteroth, lutteroth@cs.auckland.ac.nz
* Copyright 2007-2008, James Kim, jkim202@ec.auckland.ac.nz
* Distributed under the terms of the MIT License.
*/
#include <Application.h>
#include <File.h>
#include <Button.h>
#include <Window.h>
#include "BALMLayout.h"
class TableDemoWindow : public BWindow {
public:
TableDemoWindow(BRect frame)
: BWindow(frame, "ALM Table Demo", B_TITLED_WINDOW, B_QUIT_ON_WINDOW_CLOSE)
{
// create a new BALMLayout and use it for this window
BALMLayout* layout = new BALMLayout();
SetLayout(layout);
Column* c1 = layout->AddColumn(layout->Left(), layout->Right());
Row* r1 = layout->AddRow(layout->Top(), NULL);
Row* r3 = layout->AddRow(NULL, layout->Bottom());
r1->SetNext(r3);
Row* r2 = layout->AddRow();
r2->InsertAfter(r1);
BButton* b1 = new BButton("A1");
Area* a1 = layout->AddArea(r1, c1, b1);
a1->SetHorizontalAlignment(B_ALIGN_LEFT);
a1->SetVerticalAlignment(B_ALIGN_TOP);
BButton* b2 = new BButton("A2");
Area* a2 = layout->AddArea(r2, c1, b2);
a2->SetHorizontalAlignment(B_ALIGN_HORIZONTAL_CENTER);
a2->SetVerticalAlignment(B_ALIGN_VERTICAL_CENTER);
BButton* b3 = new BButton("A3");
Area* a3 = layout->AddArea(r3, c1, b3);
a3->SetHorizontalAlignment(B_ALIGN_RIGHT);
a3->SetVerticalAlignment(B_ALIGN_BOTTOM);
r2->HasSameHeightAs(r1);
r3->HasSameHeightAs(r1);
}
};
class TableDemo : public BApplication {
public:
TableDemo()
: BApplication("application/x-vnd.haiku.table-demo")
{
BRect frameRect;
frameRect.Set(100, 100, 400, 400);
TableDemoWindow* window = new TableDemoWindow(frameRect);
window->Show();
}
};
int
main()
{
TableDemo app;
app.Run();
return 0;
}

View File

@ -1,80 +0,0 @@
/*
* Copyright 2007-2008, Christof Lutteroth, lutteroth@cs.auckland.ac.nz
* Copyright 2007-2008, James Kim, jkim202@ec.auckland.ac.nz
* Distributed under the terms of the MIT License.
*/
#include <Application.h>
#include <File.h>
#include <Button.h>
#include <Window.h>
#include "Area.h"
#include "Column.h"
#include "BALMLayout.h"
#include "Row.h"
using namespace BALM;
class TableTestWindow : public BWindow {
public:
TableTestWindow(BRect frame)
: BWindow(frame, "TableTest", B_TITLED_WINDOW, B_QUIT_ON_WINDOW_CLOSE)
{
BALMLayout* fLS = new BALMLayout();
SetLayout(fLS);
fLS->SetPerformancePath("/boot/home/Desktop/table_test_performance.txt");
Column* c1 = fLS->AddColumn(fLS->Left(), fLS->Right());
Row* r1 = fLS->AddRow(fLS->Top(), NULL);
Row* r3 = fLS->AddRow(NULL, fLS->Bottom());
r1->SetNext(r3);
Row* r2 = fLS->AddRow();
r2->InsertAfter(r1);
BButton* b1 = new BButton("A1");
Area* a1 = fLS->AddArea(r1, c1, b1);
a1->SetHAlignment(B_ALIGN_LEFT);
a1->SetVAlignment(B_ALIGN_TOP);
BButton* b2 = new BButton("A2");
Area* a2 = fLS->AddArea(r2, c1, b2);
a2->SetHAlignment(B_ALIGN_HORIZONTAL_CENTER);
a2->SetVAlignment(B_ALIGN_VERTICAL_CENTER);
BButton* b3 = new BButton("A3");
Area* a3 = fLS->AddArea(r3, c1, b3);
a3->SetHAlignment(B_ALIGN_RIGHT);
a3->SetVAlignment(B_ALIGN_BOTTOM);
r2->HasSameHeightAs(r1);
r3->HasSameHeightAs(r1);
Show();
}
};
class TableTest : public BApplication {
public:
TableTest()
: BApplication("application/x-vnd.haiku.table-test")
{
BRect frameRect;
frameRect.Set(100, 100, 400, 400);
TableTestWindow* theWindow = new TableTestWindow(frameRect);
}
};
int
main()
{
TableTest test;
test.Run();
return 0;
}

View File

@ -1,84 +0,0 @@
/*
* Copyright 2007-2008, Christof Lutteroth, lutteroth@cs.auckland.ac.nz
* Copyright 2007-2008, James Kim, jkim202@ec.auckland.ac.nz
* Distributed under the terms of the MIT License.
*/
#include <Application.h>
#include <Button.h>
#include <List.h>
#include <Window.h>
#include "Area.h"
#include "BALMLayout.h"
#include "OperatorType.h"
#include "XTab.h"
#include "YTab.h"
using namespace BALM;
class Test1Window : public BWindow {
public:
Test1Window(BRect frame)
: BWindow(frame, "Test1", B_TITLED_WINDOW, B_QUIT_ON_WINDOW_CLOSE)
{
fLS = new BALMLayout();
SetLayout(fLS);
button1 = new BButton("button1");
button2 = new BButton("button2");
button3 = new BButton("button3");
fLS->SetPerformancePath("/boot/home/Desktop/test1_performance.txt");
SetBALMLayout();
Show();
}
void
SetBALMLayout()
{
XTab* x1 = fLS->AddXTab();
YTab* y1 = fLS->AddYTab();
fLS->AddArea(fLS->Left(), fLS->Top(), x1, y1, button1);
fLS->AddArea(x1, fLS->Top(), fLS->Right(), y1, button2);
fLS->AddArea(fLS->Left(), y1, fLS->Right(), fLS->Bottom(), button3);
fLS->AddConstraint(2.0, x1, -1.0, fLS->Right(), OperatorType(EQ), 0.0);
fLS->AddConstraint(2.0, y1, -1.0, fLS->Bottom(), OperatorType(EQ), 0.0);
}
private:
BALMLayout* fLS;
BButton* button1;
BButton* button2;
BButton* button3;
};
class Test1 : public BApplication {
public:
Test1()
: BApplication("application/x-vnd.haiku.test1")
{
BRect frameRect;
frameRect.Set(100, 100, 392, 366);
Test1Window* theWindow = new Test1Window(frameRect);
}
};
int
main()
{
Test1 test;
test.Run();
return 0;
}

View File

@ -1,150 +0,0 @@
/*
* Copyright 2007-2008, Christof Lutteroth, lutteroth@cs.auckland.ac.nz
* Copyright 2007-2008, James Kim, jkim202@ec.auckland.ac.nz
* Distributed under the terms of the MIT License.
*/
#include <Application.h>
#include <Button.h>
#include <List.h>
#include <StringView.h>
#include <TextControl.h>
#include <TextView.h>
#include <Window.h>
#include "Area.h"
#include "BALMLayout.h"
#include "OperatorType.h"
#include "XTab.h"
#include "YTab.h"
using namespace BALM;
class Test2Window : public BWindow {
public:
Test2Window(BRect frame)
: BWindow(frame, "Test2", B_TITLED_WINDOW, B_QUIT_ON_WINDOW_CLOSE)
{
fLS = new BALMLayout();
SetLayout(fLS);
button1 = new BButton("button1");
button2 = new BButton("button2");
button3 = new BButton("button3");
button4 = new BButton("button4");
button5 = new BButton("button5");
button6 = new BButton("button6");
checkedListBox1 = new BButton("checkedListBox1");
textBox1 = new BButton("textBox1");
textBox2 = new BButton("textBox2");
richTextBox1 = new BButton("richTextBox1");
//~ textBox1 = new BTextView(frame, "textBox1", NULL, NULL);
//~ textBox2 = new BTextView(frame, "textBox2", NULL, NULL);
//~ richTextBox1 = new BTextControl(NULL, "richTextBox1", NULL);
listView1 = new BButton("listView1");
label1 = new BStringView(frame, "label1", "label1");
label2 = new BStringView(frame, "label2", "label2");
label3 = new BStringView(frame, "label3", "label3");
fLS->SetPerformancePath("/boot/home/Desktop/test2_performance.txt");
SetBALMLayout();
Show();
}
void
SetBALMLayout()
{
XTab* x1 = fLS->AddXTab();
XTab* x2 = fLS->AddXTab();
XTab* x3 = fLS->AddXTab();
YTab* y1 = fLS->AddYTab();
YTab* y2 = fLS->AddYTab();
YTab* y3 = fLS->AddYTab();
YTab* y4 = fLS->AddYTab();
YTab* y5 = fLS->AddYTab();
fLS->AddArea(fLS->Left(), fLS->Top(), x1, y1, button1);
fLS->AddArea(x1, fLS->Top(), x2, y1, button2);
fLS->AddArea(fLS->Left(), y1, x1, y2, button3);
fLS->AddArea(x1, y1, x2, y2, button4);
fLS->AddArea(fLS->Left(), y2, x1, y3, button5);
fLS->AddArea(x1, y2, x2, y3, button6);
fLS->AddConstraint(2.0, x1, -1.0, x2, OperatorType(EQ), 0.0);
fLS->AddConstraint(2.0, y1, -1.0, y2, OperatorType(EQ), 0.0);
fLS->AddConstraint(1.0, y1, 1.0, y2, -1.0, y3, OperatorType(EQ), 0.0);
fLS->AddArea(fLS->Left(), y3, x2, y4, checkedListBox1);
fLS->AddArea(x2, fLS->Top(), fLS->Right(), y2, textBox1);
fLS->AddArea(fLS->Left(), y4, x3, y5, listView1);
fLS->AddArea(x3, y2, fLS->Right(), y5, textBox2);
Area* richTextBox1Area = fLS->AddArea(x2, y2, x3, y4, richTextBox1);
richTextBox1Area->SetLeftInset(10);
richTextBox1Area->SetTopInset(10);
richTextBox1Area->SetRightInset(10);
richTextBox1Area->SetBottomInset(10);
Area* label1Area = fLS->AddArea(fLS->Left(), y5, x2, fLS->Bottom(), label1);
label1Area->SetHAlignment(B_ALIGN_LEFT);
label1Area->SetTopInset(4);
label1Area->SetBottomInset(4);
Area* label2Area = fLS->AddArea(x2, y5, x3, fLS->Bottom(), label2);
label2Area->SetHAlignment(B_ALIGN_HORIZONTAL_CENTER);
label2Area->SetTopInset(4);
label2Area->SetBottomInset(4);
Area* label3Area = fLS->AddArea(x3, y5, fLS->Right(), fLS->Bottom(), label3);
label3Area->SetHAlignment(B_ALIGN_RIGHT);
label3Area->SetTopInset(4);
label3Area->SetBottomInset(4);
}
private:
BALMLayout* fLS;
BButton* button1;
BButton* button2;
BButton* button3;
BButton* button4;
BButton* button5;
BButton* button6;
BButton* checkedListBox1;
BButton* textBox1;
BButton* textBox2;
BButton* richTextBox1;
//~ BTextView* textBox1;
//~ BTextView* textBox2;
//~ BTextControl* richTextBox1;
BButton* listView1;
BStringView* label1;
BStringView* label2;
BStringView* label3;
};
class Test2 : public BApplication {
public:
Test2()
: BApplication("application/x-vnd.haiku.test2")
{
BRect frameRect;
frameRect.Set(100, 100, 610, 456);
Test2Window* theWindow = new Test2Window(frameRect);
}
};
int
main()
{
Test2 test;
test.Run();
return 0;
}

View File

@ -0,0 +1,68 @@
#include <Application.h>
#include <Button.h>
#include <TextView.h>
#include <List.h>
#include <Window.h>
#include "BALMLayout.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");
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();
Area* a1 = layout->AddArea(
layout->Left(), layout->Top(),
x1, layout->Bottom(),
button1);
Area* a2 = layout->AddArea(
x1, layout->Top(),
layout->Right(), layout->Bottom(),
textView1);
// add a constraint: 2*x1 == right
// i.e. x1 is in the middle of the layout
layout->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;
}