Add default spacing for Layouts (#5614)
* introduce B_USE_DEFAULT_SPACING, which works somewhat like B_SIZE_UNSET and B_ALIGN_HORIZONTAL_UNSET * introduce static float BControlLook::ComposeItemSpacing(float spacing), which checks uses be_control_look->DefaultItemSpacing(). * modify layouts to use BControlLook::ComposeItemSpacing() in SetInsets and SetSpacing methods. * default insets are still 0, 0, 0, 0, but can be set to default spacing by passing B_USE_DEFAULT_SPACING * I've found two regressions, patches incoming, please report others on #5614. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@38512 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
743d974099
commit
82ab316723
@ -79,6 +79,7 @@ public:
|
||||
|
||||
/* TODO: virtual*/
|
||||
float DefaultItemSpacing() const;
|
||||
static float ComposeItemSpacing(float spacing);
|
||||
|
||||
uint32 Flags(BControl* control) const;
|
||||
|
||||
|
@ -10,8 +10,9 @@
|
||||
|
||||
class BGridLayout : public BTwoDimensionalLayout {
|
||||
public:
|
||||
BGridLayout(float horizontal = 0.0f,
|
||||
float vertical = 0.0f);
|
||||
BGridLayout(float horizontal
|
||||
= B_USE_DEFAULT_SPACING,
|
||||
float vertical = B_USE_DEFAULT_SPACING);
|
||||
BGridLayout(BMessage* from);
|
||||
virtual ~BGridLayout();
|
||||
|
||||
|
@ -9,9 +9,9 @@
|
||||
|
||||
class BGridLayoutBuilder {
|
||||
public:
|
||||
BGridLayoutBuilder(
|
||||
float horizontalSpacing = 0.0f,
|
||||
float verticalSpacing = 0.0f);
|
||||
BGridLayoutBuilder(float horizontal
|
||||
= B_USE_DEFAULT_SPACING,
|
||||
float vertical = B_USE_DEFAULT_SPACING);
|
||||
BGridLayoutBuilder(BGridLayout* layout);
|
||||
BGridLayoutBuilder(BGridView* view);
|
||||
|
||||
|
@ -11,8 +11,12 @@
|
||||
|
||||
class BGridView : public BView {
|
||||
public:
|
||||
BGridView(float horizontalSpacing = 0.0f,
|
||||
float verticalSpacing = 0.0f);
|
||||
BGridView(float horizontal
|
||||
= B_USE_DEFAULT_SPACING,
|
||||
float vertical = B_USE_DEFAULT_SPACING);
|
||||
BGridView(const char* name,
|
||||
float horizontal = B_USE_DEFAULT_SPACING,
|
||||
float vertical = B_USE_DEFAULT_SPACING);
|
||||
BGridView(BMessage* from);
|
||||
virtual ~BGridView();
|
||||
|
||||
|
@ -10,7 +10,7 @@
|
||||
class BGroupLayout : public BTwoDimensionalLayout {
|
||||
public:
|
||||
BGroupLayout(enum orientation orientation,
|
||||
float spacing = 0.0f);
|
||||
float spacing = B_USE_DEFAULT_SPACING);
|
||||
BGroupLayout(BMessage* from);
|
||||
virtual ~BGroupLayout();
|
||||
|
||||
|
@ -13,7 +13,7 @@ class BGroupLayoutBuilder {
|
||||
public:
|
||||
BGroupLayoutBuilder(
|
||||
enum orientation orientation = B_HORIZONTAL,
|
||||
float spacing = 0.0f);
|
||||
float spacing = B_USE_DEFAULT_SPACING);
|
||||
BGroupLayoutBuilder(BGroupLayout* layout);
|
||||
BGroupLayoutBuilder(BGroupView* view);
|
||||
|
||||
@ -29,7 +29,8 @@ public:
|
||||
BGroupLayoutBuilder& Add(BLayoutItem* item, float weight);
|
||||
|
||||
BGroupLayoutBuilder& AddGroup(enum orientation orientation,
|
||||
float spacing = 0.0f, float weight = 1.0f);
|
||||
float spacing = B_USE_DEFAULT_SPACING,
|
||||
float weight = 1.0f);
|
||||
BGroupLayoutBuilder& End();
|
||||
|
||||
BGroupLayoutBuilder& AddGlue(float weight = 1.0f);
|
||||
|
@ -14,10 +14,10 @@ class BGroupView : public BView {
|
||||
public:
|
||||
BGroupView(
|
||||
enum orientation orientation = B_HORIZONTAL,
|
||||
float spacing = 0.0f);
|
||||
float spacing = B_USE_DEFAULT_SPACING);
|
||||
BGroupView(const char* name,
|
||||
enum orientation orientation = B_HORIZONTAL,
|
||||
float spacing = 0.0f);
|
||||
float spacing = B_USE_DEFAULT_SPACING);
|
||||
BGroupView(BMessage* from);
|
||||
virtual ~BGroupView();
|
||||
|
||||
|
@ -223,6 +223,8 @@ enum vertical_alignment {
|
||||
B_ALIGN_USE_FULL_HEIGHT = -2L
|
||||
};
|
||||
|
||||
const float B_USE_DEFAULT_SPACING = -2.0f;
|
||||
|
||||
|
||||
// Line join and cap modes
|
||||
|
||||
|
@ -51,10 +51,10 @@ public:
|
||||
public:
|
||||
inline Group(enum orientation orientation
|
||||
= B_HORIZONTAL,
|
||||
float spacing = 0.0f);
|
||||
float spacing = B_USE_DEFAULT_SPACING);
|
||||
inline Group(BWindow* window,
|
||||
enum orientation orientation = B_HORIZONTAL,
|
||||
float spacing = 0.0f);
|
||||
float spacing = B_USE_DEFAULT_SPACING);
|
||||
inline Group(BGroupLayout* layout);
|
||||
inline Group(BGroupView* view);
|
||||
|
||||
@ -69,14 +69,16 @@ public:
|
||||
inline ThisBuilder& Add(BLayoutItem* item, float weight);
|
||||
|
||||
inline GroupBuilder AddGroup(enum orientation orientation,
|
||||
float spacing = 0.0f, float weight = 1.0f);
|
||||
float spacing = B_USE_DEFAULT_SPACING,
|
||||
float weight = 1.0f);
|
||||
inline GroupBuilder AddGroup(BGroupView* groupView,
|
||||
float weight = 1.0f);
|
||||
inline GroupBuilder AddGroup(BGroupLayout* groupLayout,
|
||||
float weight = 1.0f);
|
||||
|
||||
inline GridBuilder AddGrid(float horizontalSpacing = 0.0f,
|
||||
float verticalSpacing = 0.0f,
|
||||
inline GridBuilder AddGrid(float horizontal
|
||||
= B_USE_DEFAULT_SPACING,
|
||||
float vertical = B_USE_DEFAULT_SPACING,
|
||||
float weight = 1.0f);
|
||||
inline GridBuilder AddGrid(BGridLayout* gridLayout,
|
||||
float weight = 1.0f);
|
||||
@ -84,7 +86,8 @@ public:
|
||||
float weight = 1.0f);
|
||||
|
||||
inline SplitBuilder AddSplit(enum orientation orientation,
|
||||
float spacing = 0.0f, float weight = 1.0f);
|
||||
float spacing = B_USE_DEFAULT_SPACING,
|
||||
float weight = 1.0f);
|
||||
inline SplitBuilder AddSplit(BSplitView* splitView,
|
||||
float weight = 1.0f);
|
||||
|
||||
@ -110,11 +113,12 @@ public:
|
||||
typedef Split<ThisBuilder> SplitBuilder;
|
||||
|
||||
public:
|
||||
inline Grid(float horizontalSpacing = 0.0f,
|
||||
float verticalSpacing = 0.0f);
|
||||
inline Grid(float horizontal
|
||||
= B_USE_DEFAULT_SPACING,
|
||||
float vertical = B_USE_DEFAULT_SPACING);
|
||||
inline Grid(BWindow* window,
|
||||
float horizontalSpacing = 0.0f,
|
||||
float verticalSpacing = 0.0f);
|
||||
float horizontal = B_USE_DEFAULT_SPACING,
|
||||
float vertical = B_USE_DEFAULT_SPACING);
|
||||
inline Grid(BGridLayout* layout);
|
||||
inline Grid(BGridView* view);
|
||||
|
||||
@ -190,7 +194,7 @@ public:
|
||||
public:
|
||||
inline Split(enum orientation orientation
|
||||
= B_HORIZONTAL,
|
||||
float spacing = 0.0f);
|
||||
float spacing = B_USE_DEFAULT_SPACING);
|
||||
inline Split(BSplitView* view);
|
||||
|
||||
inline BSplitView* View() const;
|
||||
@ -203,14 +207,16 @@ public:
|
||||
inline ThisBuilder& Add(BLayoutItem* item, float weight);
|
||||
|
||||
inline GroupBuilder AddGroup(enum orientation orientation,
|
||||
float spacing = 0.0f, float weight = 1.0f);
|
||||
float spacing = B_USE_DEFAULT_SPACING,
|
||||
float weight = 1.0f);
|
||||
inline GroupBuilder AddGroup(BGroupView* groupView,
|
||||
float weight = 1.0f);
|
||||
inline GroupBuilder AddGroup(BGroupLayout* groupLayout,
|
||||
float weight = 1.0f);
|
||||
|
||||
inline GridBuilder AddGrid(float horizontalSpacing = 0.0f,
|
||||
float verticalSpacing = 0.0f,
|
||||
inline GridBuilder AddGrid(float horizontal
|
||||
= B_USE_DEFAULT_SPACING,
|
||||
float vertical = B_USE_DEFAULT_SPACING,
|
||||
float weight = 1.0f);
|
||||
inline GridBuilder AddGrid(BGridView* gridView,
|
||||
float weight = 1.0f);
|
||||
@ -218,7 +224,8 @@ public:
|
||||
float weight = 1.0f);
|
||||
|
||||
inline SplitBuilder AddSplit(enum orientation orientation,
|
||||
float spacing = 0.0f, float weight = 1.0f);
|
||||
float spacing = B_USE_DEFAULT_SPACING,
|
||||
float weight = 1.0f);
|
||||
inline SplitBuilder AddSplit(BSplitView* splitView,
|
||||
float weight = 1.0f);
|
||||
|
||||
|
@ -11,7 +11,7 @@ class BSplitLayoutBuilder {
|
||||
public:
|
||||
BSplitLayoutBuilder(
|
||||
enum orientation orientation = B_HORIZONTAL,
|
||||
float spacing = 0.0f);
|
||||
float spacing = B_USE_DEFAULT_SPACING);
|
||||
BSplitLayoutBuilder(BSplitView* view);
|
||||
|
||||
BSplitView* SplitView() const;
|
||||
|
@ -15,7 +15,7 @@ public:
|
||||
BSplitView(
|
||||
enum orientation orientation
|
||||
= B_HORIZONTAL,
|
||||
float spacing = 0.0f);
|
||||
float spacing = B_USE_DEFAULT_SPACING);
|
||||
BSplitView(BMessage* from);
|
||||
virtual ~BSplitView();
|
||||
|
||||
|
@ -50,6 +50,18 @@ BControlLook::DefaultItemSpacing() const
|
||||
}
|
||||
|
||||
|
||||
float
|
||||
BControlLook::ComposeItemSpacing(float spacing)
|
||||
{
|
||||
if (spacing != B_USE_DEFAULT_SPACING)
|
||||
return spacing;
|
||||
|
||||
if (be_control_look)
|
||||
return be_control_look->DefaultItemSpacing();
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
uint32
|
||||
BControlLook::Flags(BControl* control) const
|
||||
{
|
||||
|
@ -11,6 +11,7 @@
|
||||
#include <new>
|
||||
#include <string.h>
|
||||
|
||||
#include <ControlLook.h>
|
||||
#include <LayoutItem.h>
|
||||
#include <List.h>
|
||||
#include <Message.h>
|
||||
@ -252,6 +253,7 @@ BGridLayout::VerticalSpacing() const
|
||||
void
|
||||
BGridLayout::SetHorizontalSpacing(float spacing)
|
||||
{
|
||||
spacing = BControlLook::ComposeItemSpacing(spacing);
|
||||
if (spacing != fHSpacing) {
|
||||
fHSpacing = spacing;
|
||||
|
||||
@ -263,6 +265,7 @@ BGridLayout::SetHorizontalSpacing(float spacing)
|
||||
void
|
||||
BGridLayout::SetVerticalSpacing(float spacing)
|
||||
{
|
||||
spacing = BControlLook::ComposeItemSpacing(spacing);
|
||||
if (spacing != fVSpacing) {
|
||||
fVSpacing = spacing;
|
||||
|
||||
@ -274,6 +277,8 @@ BGridLayout::SetVerticalSpacing(float spacing)
|
||||
void
|
||||
BGridLayout::SetSpacing(float horizontal, float vertical)
|
||||
{
|
||||
horizontal = BControlLook::ComposeItemSpacing(horizontal);
|
||||
vertical = BControlLook::ComposeItemSpacing(vertical);
|
||||
if (horizontal != fHSpacing || vertical != fVSpacing) {
|
||||
fHSpacing = horizontal;
|
||||
fVSpacing = vertical;
|
||||
|
@ -16,6 +16,15 @@ BGridView::BGridView(float horizontalSpacing, float verticalSpacing)
|
||||
}
|
||||
|
||||
|
||||
BGridView::BGridView(const char* name, float horizontalSpacing,
|
||||
float verticalSpacing)
|
||||
:
|
||||
BView(name, 0, new BGridLayout(horizontalSpacing, verticalSpacing))
|
||||
{
|
||||
SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
|
||||
}
|
||||
|
||||
|
||||
BGridView::BGridView(BMessage* from)
|
||||
:
|
||||
BView(from)
|
||||
|
@ -7,6 +7,7 @@
|
||||
|
||||
#include <GroupLayout.h>
|
||||
|
||||
#include <ControlLook.h>
|
||||
#include <LayoutItem.h>
|
||||
#include <Message.h>
|
||||
|
||||
@ -67,6 +68,7 @@ BGroupLayout::Spacing() const
|
||||
void
|
||||
BGroupLayout::SetSpacing(float spacing)
|
||||
{
|
||||
spacing = BControlLook::ComposeItemSpacing(spacing);
|
||||
if (spacing != fHSpacing) {
|
||||
fHSpacing = spacing;
|
||||
fVSpacing = spacing;
|
||||
|
@ -9,6 +9,7 @@
|
||||
#include <new>
|
||||
#include <stdio.h>
|
||||
|
||||
#include <ControlLook.h>
|
||||
#include <LayoutItem.h>
|
||||
#include <LayoutUtils.h>
|
||||
#include <Message.h>
|
||||
@ -161,7 +162,7 @@ BSplitLayout::BSplitLayout(enum orientation orientation,
|
||||
fTopInset(0),
|
||||
fBottomInset(0),
|
||||
fSplitterSize(6),
|
||||
fSpacing(spacing),
|
||||
fSpacing(BControlLook::ComposeItemSpacing(spacing)),
|
||||
|
||||
fSplitterItems(),
|
||||
fVisibleItems(),
|
||||
@ -259,10 +260,10 @@ BSplitLayout::~BSplitLayout()
|
||||
void
|
||||
BSplitLayout::SetInsets(float left, float top, float right, float bottom)
|
||||
{
|
||||
fLeftInset = left;
|
||||
fTopInset = top;
|
||||
fRightInset = right;
|
||||
fBottomInset = bottom;
|
||||
fLeftInset = BControlLook::ComposeItemSpacing(left);
|
||||
fTopInset = BControlLook::ComposeItemSpacing(top);
|
||||
fRightInset = BControlLook::ComposeItemSpacing(right);
|
||||
fBottomInset = BControlLook::ComposeItemSpacing(bottom);
|
||||
|
||||
InvalidateLayout();
|
||||
}
|
||||
@ -293,6 +294,7 @@ BSplitLayout::Spacing() const
|
||||
void
|
||||
BSplitLayout::SetSpacing(float spacing)
|
||||
{
|
||||
spacing = BControlLook::ComposeItemSpacing(spacing);
|
||||
if (spacing != fSpacing) {
|
||||
fSpacing = spacing;
|
||||
|
||||
|
@ -8,6 +8,7 @@
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include <ControlLook.h>
|
||||
#include <LayoutContext.h>
|
||||
#include <LayoutItem.h>
|
||||
#include <LayoutUtils.h>
|
||||
@ -286,10 +287,10 @@ void
|
||||
BTwoDimensionalLayout::SetInsets(float left, float top, float right,
|
||||
float bottom)
|
||||
{
|
||||
fLeftInset = left;
|
||||
fTopInset = top;
|
||||
fRightInset = right;
|
||||
fBottomInset = bottom;
|
||||
fLeftInset = BControlLook::ComposeItemSpacing(left);
|
||||
fTopInset = BControlLook::ComposeItemSpacing(top);
|
||||
fRightInset = BControlLook::ComposeItemSpacing(right);
|
||||
fBottomInset = BControlLook::ComposeItemSpacing(bottom);
|
||||
|
||||
InvalidateLayout();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user