* The min/max info was not correctly invalidated in GroupView.
* Tests for individual widgets are encapsulated as Test subclasses. * Added a check box to toggle the button label to the BButton test. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@21189 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -0,0 +1,93 @@
|
||||
/*
|
||||
* Copyright 2007, Ingo Weinhold <[email protected]>.
|
||||
* All rights reserved. Distributed under the terms of the MIT License.
|
||||
*/
|
||||
|
||||
#include "ButtonTest.h"
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include <Button.h>
|
||||
#include <Message.h>
|
||||
|
||||
#include "CheckBox.h"
|
||||
#include "GroupView.h"
|
||||
#include "StringView.h"
|
||||
|
||||
|
||||
enum {
|
||||
MSG_CHANGE_BUTTON_TEXT = 'lgbt'
|
||||
};
|
||||
|
||||
|
||||
// constructor
|
||||
ButtonTest::ButtonTest()
|
||||
: Test("Button", NULL),
|
||||
fButton(new BButton(BRect(0, 0, 9, 9), "test button", "",
|
||||
(BMessage*)NULL, B_FOLLOW_NONE)),
|
||||
fLongTextCheckBox(NULL)
|
||||
|
||||
{
|
||||
_SetButtonText(false);
|
||||
SetView(fButton);
|
||||
}
|
||||
|
||||
|
||||
// destructor
|
||||
ButtonTest::~ButtonTest()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
// ActivateTest
|
||||
void
|
||||
ButtonTest::ActivateTest(View* controls)
|
||||
{
|
||||
GroupView* group = new GroupView(B_VERTICAL);
|
||||
group->SetFrame(controls->Bounds());
|
||||
controls->AddChild(group);
|
||||
|
||||
GroupView* longTextGroup = new GroupView(B_HORIZONTAL);
|
||||
group->AddChild(longTextGroup);
|
||||
fLongTextCheckBox = new CheckBox(new BMessage(MSG_CHANGE_BUTTON_TEXT),
|
||||
this);
|
||||
longTextGroup->AddChild(fLongTextCheckBox);
|
||||
longTextGroup->AddChild(new StringView(" Long Button Text"));
|
||||
|
||||
group->AddChild(new Glue());
|
||||
|
||||
_SetButtonText(false);
|
||||
}
|
||||
|
||||
|
||||
// DectivateTest
|
||||
void
|
||||
ButtonTest::DectivateTest()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
// MessageReceived
|
||||
void
|
||||
ButtonTest::MessageReceived(BMessage* message)
|
||||
{
|
||||
switch (message->what) {
|
||||
case MSG_CHANGE_BUTTON_TEXT:
|
||||
_SetButtonText(fLongTextCheckBox->IsSelected());
|
||||
break;
|
||||
default:
|
||||
Test::MessageReceived(message);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// _SetButtonText
|
||||
void
|
||||
ButtonTest::_SetButtonText(bool longText)
|
||||
{
|
||||
if (fLongTextCheckBox)
|
||||
fLongTextCheckBox->SetSelected(longText);
|
||||
fButton->SetLabel(longText ? "very long text for a simple button"
|
||||
: "Ooh, press me!");
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* Copyright 2007, Ingo Weinhold <[email protected]>.
|
||||
* All rights reserved. Distributed under the terms of the MIT License.
|
||||
*/
|
||||
#ifndef WIDGET_LAYOUT_TEST_BUTTON_TEST_H
|
||||
#define WIDGET_LAYOUT_TEST_BUTTON_TEST_H
|
||||
|
||||
|
||||
#include "Test.h"
|
||||
|
||||
|
||||
class BButton;
|
||||
class CheckBox;
|
||||
class View;
|
||||
|
||||
|
||||
class ButtonTest : public Test {
|
||||
public:
|
||||
ButtonTest();
|
||||
virtual ~ButtonTest();
|
||||
|
||||
virtual void ActivateTest(View* controls);
|
||||
virtual void DectivateTest();
|
||||
|
||||
virtual void MessageReceived(BMessage* message);
|
||||
|
||||
private:
|
||||
void _SetButtonText(bool longText);
|
||||
|
||||
private:
|
||||
BButton* fButton;
|
||||
CheckBox* fLongTextCheckBox;
|
||||
};
|
||||
|
||||
|
||||
#endif // WIDGET_LAYOUT_TEST_BUTTON_TEST_H
|
||||
@@ -5,6 +5,8 @@
|
||||
|
||||
#include "GroupView.h"
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include <LayoutUtils.h>
|
||||
|
||||
|
||||
@@ -36,7 +38,7 @@ struct GroupView::LayoutInfo {
|
||||
|
||||
void Normalize()
|
||||
{
|
||||
if (max > min)
|
||||
if (max < min)
|
||||
max = min;
|
||||
if (preferred < min)
|
||||
preferred = min;
|
||||
@@ -126,9 +128,18 @@ GroupView::Alignment()
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
GroupView::InvalidateLayout()
|
||||
{
|
||||
fMinMaxValid = false;
|
||||
View::InvalidateLayout();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
GroupView::Layout()
|
||||
{
|
||||
//printf("%p->GroupView::Layout()\n", this);
|
||||
_ValidateMinMax();
|
||||
// actually a little late already
|
||||
|
||||
@@ -162,6 +173,7 @@ GroupView::Layout()
|
||||
|
||||
location.x += columnInfo.size + fColumnSpacing;
|
||||
}
|
||||
//printf("%p->GroupView::Layout() done\n", this);
|
||||
}
|
||||
|
||||
|
||||
@@ -171,6 +183,7 @@ GroupView::_ValidateMinMax()
|
||||
if (fMinMaxValid)
|
||||
return;
|
||||
|
||||
//printf("%p->GroupView::_ValidateMinMax()\n", this);
|
||||
delete fColumnInfos;
|
||||
delete fRowInfos;
|
||||
|
||||
@@ -215,6 +228,7 @@ GroupView::_ValidateMinMax()
|
||||
fColumnInfos[column].max);
|
||||
fPreferredWidth = BLayoutUtils::AddSizesInt32(fPreferredWidth,
|
||||
fColumnInfos[column].preferred);
|
||||
//printf(" column %ld: min: %ld, max: %ld, preferred: %ld\n", column, fColumnInfos[column].min, fColumnInfos[column].max, fColumnInfos[column].preferred);
|
||||
}
|
||||
|
||||
for (int32 row = 0; row < fRowCount; row++) {
|
||||
@@ -225,9 +239,11 @@ GroupView::_ValidateMinMax()
|
||||
fRowInfos[row].max);
|
||||
fPreferredHeight = BLayoutUtils::AddSizesInt32(fPreferredHeight,
|
||||
fRowInfos[row].preferred);
|
||||
//printf(" row %ld: min: %ld, max: %ld, preferred: %ld\n", row, fRowInfos[row].min, fRowInfos[row].max, fRowInfos[row].preferred);
|
||||
}
|
||||
|
||||
fMinMaxValid = true;
|
||||
//printf("%p->GroupView::_ValidateMinMax() done\n", this);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -25,6 +25,7 @@ public:
|
||||
virtual BSize PreferredSize();
|
||||
virtual BAlignment Alignment();
|
||||
|
||||
virtual void InvalidateLayout();
|
||||
virtual void Layout();
|
||||
|
||||
private:
|
||||
|
||||
@@ -5,9 +5,11 @@ SetSubDirSupportedPlatforms haiku libbe_test ;
|
||||
SimpleTest WidgetLayoutTest :
|
||||
WidgetLayoutTest.cpp
|
||||
|
||||
ButtonTest.cpp
|
||||
CheckBox.cpp
|
||||
GroupView.cpp
|
||||
StringView.cpp
|
||||
Test.cpp
|
||||
TwoDimensionalSliderView.cpp
|
||||
View.cpp
|
||||
ViewContainer.cpp
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* Copyright 2007, Ingo Weinhold <[email protected]>.
|
||||
* All rights reserved. Distributed under the terms of the MIT License.
|
||||
*/
|
||||
|
||||
#include "Test.h"
|
||||
|
||||
|
||||
Test::Test(const char* name, const char* description, BView* view)
|
||||
: fName(name),
|
||||
fDescription(description),
|
||||
fView(view)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
Test::~Test()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
const char*
|
||||
Test::Name() const
|
||||
{
|
||||
return fName.String();
|
||||
}
|
||||
|
||||
|
||||
const char*
|
||||
Test::Description() const
|
||||
{
|
||||
return fDescription.String();
|
||||
}
|
||||
|
||||
|
||||
BView*
|
||||
Test::GetView() const
|
||||
{
|
||||
return fView;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
Test::SetView(BView* view)
|
||||
{
|
||||
fView = view;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
Test::ActivateTest(View* controls)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
Test::DectivateTest()
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Copyright 2007, Ingo Weinhold <[email protected]>.
|
||||
* All rights reserved. Distributed under the terms of the MIT License.
|
||||
*/
|
||||
#ifndef WIDGET_LAYOUT_TEST_TEST_H
|
||||
#define WIDGET_LAYOUT_TEST_TEST_H
|
||||
|
||||
|
||||
#include <Handler.h>
|
||||
#include <String.h>
|
||||
|
||||
|
||||
class BView;
|
||||
class View;
|
||||
|
||||
|
||||
class Test : public BHandler {
|
||||
public:
|
||||
Test(const char* name, const char* description,
|
||||
BView* view = NULL);
|
||||
virtual ~Test();
|
||||
|
||||
const char* Name() const;
|
||||
const char* Description() const;
|
||||
|
||||
virtual BView* GetView() const;
|
||||
void SetView(BView* view);
|
||||
|
||||
virtual void ActivateTest(View* controls);
|
||||
virtual void DectivateTest();
|
||||
|
||||
private:
|
||||
BString fName;
|
||||
BString fDescription;
|
||||
BView* fView;
|
||||
};
|
||||
|
||||
|
||||
#endif // WIDGET_LAYOUT_TEST_TEST_H
|
||||
@@ -320,6 +320,7 @@ View::Invalidate()
|
||||
void
|
||||
View::InvalidateLayout()
|
||||
{
|
||||
//printf("%p->View::InvalidateLayout(): %d\n", this, fLayoutValid);
|
||||
if (fLayoutValid) {
|
||||
fLayoutValid = false;
|
||||
if (fParent)
|
||||
|
||||
@@ -6,12 +6,13 @@
|
||||
#include <stdio.h>
|
||||
|
||||
#include <Application.h>
|
||||
#include <Button.h>
|
||||
#include <Window.h>
|
||||
|
||||
#include "ButtonTest.h"
|
||||
#include "CheckBox.h"
|
||||
#include "GroupView.h"
|
||||
#include "StringView.h"
|
||||
#include "Test.h"
|
||||
#include "TwoDimensionalSliderView.h"
|
||||
#include "View.h"
|
||||
#include "ViewContainer.h"
|
||||
@@ -36,25 +37,29 @@ operator+(const BPoint& p, const BSize& size)
|
||||
// TestWindow
|
||||
class TestWindow : public BWindow {
|
||||
public:
|
||||
TestWindow()
|
||||
: BWindow(BRect(100, 100, 700, 500), "Widget Layout",
|
||||
TestWindow(Test* test)
|
||||
: BWindow(BRect(50, 50, 750, 550), "Widget Layout",
|
||||
B_TITLED_WINDOW,
|
||||
B_ASYNCHRONOUS_CONTROLS | B_QUIT_ON_WINDOW_CLOSE | B_NOT_RESIZABLE
|
||||
| B_NOT_ZOOMABLE)
|
||||
| B_NOT_ZOOMABLE),
|
||||
fTest(test)
|
||||
{
|
||||
fViewContainer = new ViewContainer(Bounds());
|
||||
fViewContainer->View::SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
|
||||
AddChild(fViewContainer);
|
||||
|
||||
BRect rect(10, 10, 400, 300);
|
||||
// container view for the tested BView
|
||||
BRect rect(10, 10, 400, 400);
|
||||
View* view = new View(rect);
|
||||
fViewContainer->View::AddChild(view);
|
||||
view->SetViewColor((rgb_color){200, 200, 240, 255});
|
||||
|
||||
// container for the test's controls
|
||||
fTestControlsView = new View(BRect(410, 10, 690, 400));
|
||||
fViewContainer->View::AddChild(fTestControlsView);
|
||||
|
||||
// wrapper view
|
||||
fWrapperView = new WrapperView(
|
||||
new BButton(BRect(0, 0, 9, 9), "test button", "Ooh, press me!",
|
||||
(BMessage*)NULL, B_FOLLOW_NONE));
|
||||
fWrapperView = new WrapperView(fTest->GetView());
|
||||
fWrapperView->SetLocation(BPoint(10, 10));
|
||||
view->AddChild(fWrapperView);
|
||||
fWrapperView->SetSize(fWrapperView->PreferredSize());
|
||||
@@ -98,6 +103,10 @@ public:
|
||||
sizeViewsGroup->PreferredSize()));
|
||||
|
||||
_UpdateSizeViews();
|
||||
|
||||
// activate test
|
||||
AddHandler(fTest);
|
||||
fTest->ActivateTest(fTestControlsView);
|
||||
}
|
||||
|
||||
virtual void DispatchMessage(BMessage* message, BHandler* handler)
|
||||
@@ -231,7 +240,9 @@ private:
|
||||
}
|
||||
|
||||
private:
|
||||
Test* fTest;
|
||||
ViewContainer* fViewContainer;
|
||||
View* fTestControlsView;
|
||||
WrapperView* fWrapperView;
|
||||
TwoDimensionalSliderView* fSliderView;
|
||||
StringView* fMinWidthView;
|
||||
@@ -251,7 +262,9 @@ main()
|
||||
{
|
||||
BApplication app("application/x-vnd.haiku.widget-layout-test");
|
||||
|
||||
BWindow* window = new TestWindow;
|
||||
Test* test = new ButtonTest;
|
||||
|
||||
BWindow* window = new TestWindow(test);
|
||||
window->Show();
|
||||
|
||||
app.Run();
|
||||
|
||||
Reference in New Issue
Block a user