39#define _Class _StackView
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 const View *subview = $(subviews, objectAtIndex, i);
101 requestedSize +=
size.
h;
104 requestedSize +=
size.
w;
111 const float scale = requestedSize ? availableSize / (float) requestedSize : 1.0;
113 for (
size_t i = 0; i < subviews->count; i++) {
115 View *subview = $(subviews, objectAtIndex, i);
117 switch (this->axis) {
119 subview->
frame.y = pos;
122 subview->
frame.x = pos;
128 switch (this->distribution) {
133 switch (this->axis) {
135 subviewSize.
h *= scale;
138 subviewSize.
w *= scale;
144 switch (this->axis) {
146 subviewSize.
h = availableSize / (float) subviews->count;
149 subviewSize.
w = availableSize / (
float) subviews->count;
155 $(subview,
resize, &subviewSize);
157 switch (this->axis) {
159 pos += subviewSize.
h;
162 pos += subviewSize.
w;
166 pos += this->spacing;
184 switch (this->axis) {
194 for (
size_t i = 0; i < subviews->count; i++) {
196 const View *subview = $(subviews, objectAtIndex, i);
199 switch (this->axis) {
209 if (subviews->count) {
210 switch (this->axis) {
212 size.
h += this->spacing * (subviews->count - 1);
215 size.
w += this->spacing * (subviews->count - 1);
226#pragma mark - StackView
242#pragma mark - Class lifecycle
249 ((ViewInterface *) clazz->interface)->applyStyle =
applyStyle;
250 ((ViewInterface *) clazz->interface)->init =
init;
253 ((ViewInterface *) clazz->interface)->sizeThatFits =
sizeThatFits;
255 ((StackViewInterface *) clazz->interface)->initWithFrame =
initWithFrame;
267 clazz = _initialize(&(
const ClassDef) {
269 .superclass =
_View(),
271 .interfaceOffset = offsetof(
StackView, interface),
272 .interfaceSize =
sizeof(StackViewInterface),
const EnumName StackViewAxisNames[]
const EnumName StackViewDistributionNames[]
static void initialize(Class *clazz)
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.
@ ViewAutoresizingContain
Box * initWithFrame(Box *self, const SDL_Rect *frame)
Initializes this Box with the given frame.
CollectionView * init(CollectionView *self, const SDL_Rect *frame)
Initializes this CollectionView with the specified frame and style.
SDL_Size size(const Image *self)
Inlets enable inbound data binding of View attributes through JSON.
StackViews are containers that manage the arrangement of their subviews.
Class * _StackView(void)
The StackView archetype.
Views are the fundamental building blocks of ObjectivelyMVC user interfaces.
SDL_Rect bounds(const View *self)
_Bool bind(View *self, const Inlet *inlets, const Dictionary *dictionary)
Performs data binding for the Inlets described in dictionary.
Class * _View(void)
The View archetype.
Array * visibleSubviews(const View *self)
void applyStyle(View *self, const Style *style)
Applies the given Style to this View.
void resize(View *self, const SDL_Size *size)
Resizes this View to the specified size.
int autoresizingMask
The ViewAutoresizing bitmask.
void sizeThatFits(const View *self)
ViewPadding padding
The padding.
layoutSubviews(View *self)
Performs layout for this View's immediate subviews.
SDL_Size sizeThatContains(const View *self)
_Bool isContainer(const View *self)
SDL_Rect frame
The frame, relative to the superview.