39#define _Class _StackView
58 $(self, bind, inlets, (Dictionary *) style->
attributes);
76 if (subviews->count) {
82 int availableSize, requestedSize = 0;
92 availableSize -= this->spacing * (subviews->count - 1);
94 for (
size_t i = 0; i < subviews->count; i++) {
96 View *subview = $(subviews, objectAtIndex, i);
98 const SDL_Size subviewSize = $(subview,
size);
100 switch (this->axis) {
102 requestedSize += subviewSize.h;
105 requestedSize += subviewSize.w;
112 const float scale = requestedSize ? availableSize / (float) requestedSize : 1.f;
114 for (
size_t i = 0; i < subviews->count; i++) {
116 View *subview = $(subviews, objectAtIndex, i);
118 switch (this->axis) {
120 subview->
frame.y = pos;
123 subview->
frame.x = pos;
127 SDL_Size subviewSize = $(subview,
size);
129 switch (this->axis) {
142 switch (this->distribution) {
147 switch (this->axis) {
149 subviewSize.h *= scale;
152 subviewSize.w *= scale;
158 switch (this->axis) {
160 subviewSize.h = availableSize / (float) subviews->count;
163 subviewSize.w = availableSize / (float) subviews->count;
169 $(subview,
resize, &subviewSize);
172 switch (this->axis) {
174 pos += subviewSize.h;
177 pos += subviewSize.w;
181 pos += this->spacing;
195 SDL_Size
size = MakeSize(0, 0);
197 switch (this->axis) {
207 for (
size_t i = 0; i < subviews->count; i++) {
209 const View *subview = $(subviews, objectAtIndex, i);
211 SDL_Size subviewSize;
217 subviewSize = $(subview,
size);
220 switch (this->axis) {
222 size.w = max(
size.w, subviewSize.w);
223 size.h += subviewSize.h;
226 size.w += subviewSize.w;
227 size.h = max(
size.h, subviewSize.h);
232 if (subviews->count) {
233 switch (this->axis) {
235 size.h += this->spacing * (subviews->count - 1);
238 size.w += this->spacing * (subviews->count - 1);
251#pragma mark - StackView
267#pragma mark - Class lifecycle
275 ((ViewInterface *) clazz->interface)->init =
init;
278 ((ViewInterface *) clazz->interface)->sizeThatFits =
sizeThatFits;
280 ((StackViewInterface *) clazz->interface)->initWithFrame =
initWithFrame;
292 clazz = _initialize(&(
const ClassDef) {
294 .superclass =
_View(),
296 .interfaceOffset = offsetof(
StackView, interface),
297 .interfaceSize =
sizeof(StackViewInterface),
static SDL_Size size(const Image *self)
static Array * visibleSubviews(const View *self)
const EnumName StackViewAxisNames[]
static View * init(View *self)
static void applyStyle(View *self, const Style *style)
static SDL_Size sizeThatFits(const View *self)
static StackView * initWithFrame(StackView *self, const SDL_Rect *frame)
const EnumName StackViewDistributionNames[]
static void initialize(Class *clazz)
static void layoutSubviews(View *self)
StackViews are containers that manage the arrangement of their subviews.
@ StackViewDistributionDefault
@ StackViewDistributionFillEqually
@ StackViewDistributionFill
@ StackViewAxisHorizontal
#define MakeInlets(...)
Creates a null-termianted array of Inlets.
#define MakeInlet(name, type, dest, data)
Creates an Inlet with the specified parameters.
static void resize(View *self, const SDL_Size *size)
static void layoutIfNeeded(View *self)
static SDL_Size sizeThatContains(const View *self)
static SDL_Rect bounds(const View *self)
@ ViewAutoresizingContain
Inlets enable inbound data binding of View attributes through JSON.
StackViews are containers that manage the arrangement of their subviews.
Views are the fundamental building blocks of ObjectivelyMVC user interfaces.
void applyStyle(View *self, const Style *style)
Applies the given Style to this View.
int autoresizingMask
The ViewAutoresizing bitmask.
ViewPadding padding
The padding.
SDL_Size minSize
The minimum size this View may be resized to during layout.
layoutSubviews(View *self)
Performs layout for this View's immediate subviews.
SDL_Size maxSize
The maximum size this View may be resized to during layout.
SDL_Rect frame
The frame, relative to the superview.