xref: /haiku/src/kits/interface/SpaceLayoutItem.cpp (revision 1acbe440b8dd798953bec31d18ee589aa3f71b73)
1 /*
2  * Copyright 2006, Ingo Weinhold <bonefish@cs.tu-berlin.de>.
3  * All rights reserved. Distributed under the terms of the MIT License.
4  */
5 
6 #include <SpaceLayoutItem.h>
7 
8 
9 // constructor
10 BSpaceLayoutItem::BSpaceLayoutItem(BSize minSize, BSize maxSize,
11 	BSize preferredSize, BAlignment alignment)
12 	: fFrame(),
13 	  fMinSize(minSize),
14 	  fMaxSize(maxSize),
15 	  fPreferredSize(preferredSize),
16 	  fAlignment(alignment),
17 	  fVisible(true)
18 {
19 }
20 
21 // destructor
22 BSpaceLayoutItem::~BSpaceLayoutItem()
23 {
24 }
25 
26 // CreateGlue
27 BSpaceLayoutItem*
28 BSpaceLayoutItem::CreateGlue() {
29 	return new BSpaceLayoutItem(
30 		BSize(-1, -1),
31 		BSize(B_SIZE_UNLIMITED, B_SIZE_UNLIMITED),
32 		BSize(-1, -1),
33 		BAlignment(B_ALIGN_HORIZONTAL_CENTER, B_ALIGN_VERTICAL_CENTER));
34 }
35 
36 // CreateHorizontalStrut
37 BSpaceLayoutItem*
38 BSpaceLayoutItem::CreateHorizontalStrut(float width) {
39 	return new BSpaceLayoutItem(
40 		BSize(width, -1),
41 		BSize(width, B_SIZE_UNLIMITED),
42 		BSize(width, -1),
43 		BAlignment(B_ALIGN_HORIZONTAL_CENTER, B_ALIGN_VERTICAL_CENTER));
44 }
45 
46 // CreateVerticalStrut
47 BSpaceLayoutItem*
48 BSpaceLayoutItem::CreateVerticalStrut(float height) {
49 	return new BSpaceLayoutItem(
50 		BSize(-1, height),
51 		BSize(B_SIZE_UNLIMITED, height),
52 		BSize(-1, height),
53 		BAlignment(B_ALIGN_HORIZONTAL_CENTER, B_ALIGN_VERTICAL_CENTER));
54 }
55 
56 // MinSize
57 BSize
58 BSpaceLayoutItem::MinSize()
59 {
60 	return fMinSize;
61 }
62 
63 // MaxSize
64 BSize
65 BSpaceLayoutItem::MaxSize()
66 {
67 	return fMaxSize;
68 }
69 
70 // PreferredSize
71 BSize
72 BSpaceLayoutItem::PreferredSize()
73 {
74 	return fPreferredSize;
75 }
76 
77 // Alignment
78 BAlignment
79 BSpaceLayoutItem::Alignment()
80 {
81 	return fAlignment;
82 }
83 
84 // SetExplicitMinSize
85 void
86 BSpaceLayoutItem::SetExplicitMinSize(BSize size)
87 {
88 	if (size.IsWidthSet())
89 		fMinSize.width = size.width;
90 	if (size.IsHeightSet())
91 		fMinSize.height = size.height;
92 
93 	InvalidateLayout();
94 }
95 
96 // SetExplicitMaxSize
97 void
98 BSpaceLayoutItem::SetExplicitMaxSize(BSize size)
99 {
100 	if (size.IsWidthSet())
101 		fMaxSize.width = size.width;
102 	if (size.IsHeightSet())
103 		fMaxSize.height = size.height;
104 
105 	InvalidateLayout();
106 }
107 
108 // SetExplicitPreferredSize
109 void
110 BSpaceLayoutItem::SetExplicitPreferredSize(BSize size)
111 {
112 	if (size.IsWidthSet())
113 		fPreferredSize.width = size.width;
114 	if (size.IsHeightSet())
115 		fPreferredSize.height = size.height;
116 
117 	InvalidateLayout();
118 }
119 
120 // SetExplicitAlignment
121 void
122 BSpaceLayoutItem::SetExplicitAlignment(BAlignment alignment)
123 {
124 	if (alignment.IsHorizontalSet())
125 		fAlignment.horizontal = alignment.horizontal;
126 	if (alignment.IsVerticalSet())
127 		fAlignment.vertical = alignment.vertical;
128 
129 	InvalidateLayout();
130 }
131 
132 // IsVisible
133 bool
134 BSpaceLayoutItem::IsVisible()
135 {
136 	return fVisible;
137 }
138 
139 // SetVisible
140 void
141 BSpaceLayoutItem::SetVisible(bool visible)
142 {
143 	fVisible = visible;
144 }
145 
146 // Frame
147 BRect
148 BSpaceLayoutItem::Frame()
149 {
150 	return fFrame;
151 }
152 
153 // SetFrame
154 void
155 BSpaceLayoutItem::SetFrame(BRect frame)
156 {
157 	fFrame = frame;
158 }
159