* 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 "GroupView.h"
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
#include <LayoutUtils.h>
|
#include <LayoutUtils.h>
|
||||||
|
|
||||||
|
|
||||||
@@ -36,7 +38,7 @@ struct GroupView::LayoutInfo {
|
|||||||
|
|
||||||
void Normalize()
|
void Normalize()
|
||||||
{
|
{
|
||||||
if (max > min)
|
if (max < min)
|
||||||
max = min;
|
max = min;
|
||||||
if (preferred < min)
|
if (preferred < min)
|
||||||
preferred = min;
|
preferred = min;
|
||||||
@@ -126,9 +128,18 @@ GroupView::Alignment()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
GroupView::InvalidateLayout()
|
||||||
|
{
|
||||||
|
fMinMaxValid = false;
|
||||||
|
View::InvalidateLayout();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
GroupView::Layout()
|
GroupView::Layout()
|
||||||
{
|
{
|
||||||
|
//printf("%p->GroupView::Layout()\n", this);
|
||||||
_ValidateMinMax();
|
_ValidateMinMax();
|
||||||
// actually a little late already
|
// actually a little late already
|
||||||
|
|
||||||
@@ -162,6 +173,7 @@ GroupView::Layout()
|
|||||||
|
|
||||||
location.x += columnInfo.size + fColumnSpacing;
|
location.x += columnInfo.size + fColumnSpacing;
|
||||||
}
|
}
|
||||||
|
//printf("%p->GroupView::Layout() done\n", this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -171,6 +183,7 @@ GroupView::_ValidateMinMax()
|
|||||||
if (fMinMaxValid)
|
if (fMinMaxValid)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
//printf("%p->GroupView::_ValidateMinMax()\n", this);
|
||||||
delete fColumnInfos;
|
delete fColumnInfos;
|
||||||
delete fRowInfos;
|
delete fRowInfos;
|
||||||
|
|
||||||
@@ -215,6 +228,7 @@ GroupView::_ValidateMinMax()
|
|||||||
fColumnInfos[column].max);
|
fColumnInfos[column].max);
|
||||||
fPreferredWidth = BLayoutUtils::AddSizesInt32(fPreferredWidth,
|
fPreferredWidth = BLayoutUtils::AddSizesInt32(fPreferredWidth,
|
||||||
fColumnInfos[column].preferred);
|
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++) {
|
for (int32 row = 0; row < fRowCount; row++) {
|
||||||
@@ -225,9 +239,11 @@ GroupView::_ValidateMinMax()
|
|||||||
fRowInfos[row].max);
|
fRowInfos[row].max);
|
||||||
fPreferredHeight = BLayoutUtils::AddSizesInt32(fPreferredHeight,
|
fPreferredHeight = BLayoutUtils::AddSizesInt32(fPreferredHeight,
|
||||||
fRowInfos[row].preferred);
|
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;
|
fMinMaxValid = true;
|
||||||
|
//printf("%p->GroupView::_ValidateMinMax() done\n", this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ public:
|
|||||||
virtual BSize PreferredSize();
|
virtual BSize PreferredSize();
|
||||||
virtual BAlignment Alignment();
|
virtual BAlignment Alignment();
|
||||||
|
|
||||||
|
virtual void InvalidateLayout();
|
||||||
virtual void Layout();
|
virtual void Layout();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|||||||
@@ -5,9 +5,11 @@ SetSubDirSupportedPlatforms haiku libbe_test ;
|
|||||||
SimpleTest WidgetLayoutTest :
|
SimpleTest WidgetLayoutTest :
|
||||||
WidgetLayoutTest.cpp
|
WidgetLayoutTest.cpp
|
||||||
|
|
||||||
|
ButtonTest.cpp
|
||||||
CheckBox.cpp
|
CheckBox.cpp
|
||||||
GroupView.cpp
|
GroupView.cpp
|
||||||
StringView.cpp
|
StringView.cpp
|
||||||
|
Test.cpp
|
||||||
TwoDimensionalSliderView.cpp
|
TwoDimensionalSliderView.cpp
|
||||||
View.cpp
|
View.cpp
|
||||||
ViewContainer.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
|
void
|
||||||
View::InvalidateLayout()
|
View::InvalidateLayout()
|
||||||
{
|
{
|
||||||
|
//printf("%p->View::InvalidateLayout(): %d\n", this, fLayoutValid);
|
||||||
if (fLayoutValid) {
|
if (fLayoutValid) {
|
||||||
fLayoutValid = false;
|
fLayoutValid = false;
|
||||||
if (fParent)
|
if (fParent)
|
||||||
|
|||||||
@@ -6,12 +6,13 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
#include <Application.h>
|
#include <Application.h>
|
||||||
#include <Button.h>
|
|
||||||
#include <Window.h>
|
#include <Window.h>
|
||||||
|
|
||||||
|
#include "ButtonTest.h"
|
||||||
#include "CheckBox.h"
|
#include "CheckBox.h"
|
||||||
#include "GroupView.h"
|
#include "GroupView.h"
|
||||||
#include "StringView.h"
|
#include "StringView.h"
|
||||||
|
#include "Test.h"
|
||||||
#include "TwoDimensionalSliderView.h"
|
#include "TwoDimensionalSliderView.h"
|
||||||
#include "View.h"
|
#include "View.h"
|
||||||
#include "ViewContainer.h"
|
#include "ViewContainer.h"
|
||||||
@@ -36,25 +37,29 @@ operator+(const BPoint& p, const BSize& size)
|
|||||||
// TestWindow
|
// TestWindow
|
||||||
class TestWindow : public BWindow {
|
class TestWindow : public BWindow {
|
||||||
public:
|
public:
|
||||||
TestWindow()
|
TestWindow(Test* test)
|
||||||
: BWindow(BRect(100, 100, 700, 500), "Widget Layout",
|
: BWindow(BRect(50, 50, 750, 550), "Widget Layout",
|
||||||
B_TITLED_WINDOW,
|
B_TITLED_WINDOW,
|
||||||
B_ASYNCHRONOUS_CONTROLS | B_QUIT_ON_WINDOW_CLOSE | B_NOT_RESIZABLE
|
B_ASYNCHRONOUS_CONTROLS | B_QUIT_ON_WINDOW_CLOSE | B_NOT_RESIZABLE
|
||||||
| B_NOT_ZOOMABLE)
|
| B_NOT_ZOOMABLE),
|
||||||
|
fTest(test)
|
||||||
{
|
{
|
||||||
fViewContainer = new ViewContainer(Bounds());
|
fViewContainer = new ViewContainer(Bounds());
|
||||||
fViewContainer->View::SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
|
fViewContainer->View::SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
|
||||||
AddChild(fViewContainer);
|
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);
|
View* view = new View(rect);
|
||||||
fViewContainer->View::AddChild(view);
|
fViewContainer->View::AddChild(view);
|
||||||
view->SetViewColor((rgb_color){200, 200, 240, 255});
|
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
|
// wrapper view
|
||||||
fWrapperView = new WrapperView(
|
fWrapperView = new WrapperView(fTest->GetView());
|
||||||
new BButton(BRect(0, 0, 9, 9), "test button", "Ooh, press me!",
|
|
||||||
(BMessage*)NULL, B_FOLLOW_NONE));
|
|
||||||
fWrapperView->SetLocation(BPoint(10, 10));
|
fWrapperView->SetLocation(BPoint(10, 10));
|
||||||
view->AddChild(fWrapperView);
|
view->AddChild(fWrapperView);
|
||||||
fWrapperView->SetSize(fWrapperView->PreferredSize());
|
fWrapperView->SetSize(fWrapperView->PreferredSize());
|
||||||
@@ -98,6 +103,10 @@ public:
|
|||||||
sizeViewsGroup->PreferredSize()));
|
sizeViewsGroup->PreferredSize()));
|
||||||
|
|
||||||
_UpdateSizeViews();
|
_UpdateSizeViews();
|
||||||
|
|
||||||
|
// activate test
|
||||||
|
AddHandler(fTest);
|
||||||
|
fTest->ActivateTest(fTestControlsView);
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void DispatchMessage(BMessage* message, BHandler* handler)
|
virtual void DispatchMessage(BMessage* message, BHandler* handler)
|
||||||
@@ -231,7 +240,9 @@ private:
|
|||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
Test* fTest;
|
||||||
ViewContainer* fViewContainer;
|
ViewContainer* fViewContainer;
|
||||||
|
View* fTestControlsView;
|
||||||
WrapperView* fWrapperView;
|
WrapperView* fWrapperView;
|
||||||
TwoDimensionalSliderView* fSliderView;
|
TwoDimensionalSliderView* fSliderView;
|
||||||
StringView* fMinWidthView;
|
StringView* fMinWidthView;
|
||||||
@@ -251,7 +262,9 @@ main()
|
|||||||
{
|
{
|
||||||
BApplication app("application/x-vnd.haiku.widget-layout-test");
|
BApplication app("application/x-vnd.haiku.widget-layout-test");
|
||||||
|
|
||||||
BWindow* window = new TestWindow;
|
Test* test = new ButtonTest;
|
||||||
|
|
||||||
|
BWindow* window = new TestWindow(test);
|
||||||
window->Show();
|
window->Show();
|
||||||
|
|
||||||
app.Run();
|
app.Run();
|
||||||
|
|||||||
Reference in New Issue
Block a user