26#include <Objectively/Array.h>
41 release(this->options);
42 release(this->stackView);
67 const Array *options = (Array *) this->options;
68 for (
size_t i = 0; i < options->count; i++) {
70 Option *option = $(options, objectAtIndex, i);
95 const Array *options = (Array *) this->options;
96 for (
size_t i = 0; i < options->count; i++) {
98 const View *option = $(options, objectAtIndex, i);
108#pragma mark - Control
117 if (event->type == SDL_MOUSEBUTTONUP) {
119 self->
state &= ~ControlStateHighlighted;
121 const Array *options = (Array *) this->options;
122 for (
size_t i = 0; i < options->count; i++) {
124 Option *option = $(options, objectAtIndex, i);
127 if (this->delegate.didSelectOption) {
128 this->delegate.didSelectOption(
this, option);
151 View *stackView = (
View *) this->stackView;
210 $(self->
options, addObject, option);
242 self->
options = $$(MutableArray, arrayWithCapacity, 8);
258 return ((
Option *) obj)->value == data;
290 if ($((Array *) self->
options, containsObject, option)) {
292 $(self->
options, removeObject, option);
297 Option *first_option = $((Array *) self->
options, firstObject);
362 return ((
Option *) obj)->isSelected;
381#pragma mark - Class lifecycle
388 ((ObjectInterface *) clazz->interface)->dealloc =
dealloc;
390 ((ViewInterface *) clazz->interface)->init =
init;
392 ((ViewInterface *) clazz->interface)->sizeThatFits =
sizeThatFits;
394 ((ControlInterface *) clazz->interface)->captureEvent =
captureEvent;
395 ((ControlInterface *) clazz->interface)->stateDidChange =
stateDidChange;
397 ((SelectInterface *) clazz->interface)->addOption =
addOption;
398 ((SelectInterface *) clazz->interface)->initWithFrame =
initWithFrame;
399 ((SelectInterface *) clazz->interface)->optionWithValue =
optionWithValue;
400 ((SelectInterface *) clazz->interface)->removeAllOptions =
removeAllOptions;
401 ((SelectInterface *) clazz->interface)->removeOption =
removeOption;
403 ((SelectInterface *) clazz->interface)->selectOption =
selectOption;
405 ((SelectInterface *) clazz->interface)->selectedOption =
selectedOption;
406 ((SelectInterface *) clazz->interface)->selectedOptions =
selectedOptions;
418 clazz = _initialize(&(
const ClassDef) {
421 .instanceSize =
sizeof(
Select),
422 .interfaceOffset = offsetof(
Select, interface),
423 .interfaceSize =
sizeof(SelectInterface),
@ ControlStateHighlighted
static void removeAllOptions_enumerate(const Array *array, ident obj, ident data)
ArrayEnumerator for removeAllOptions.
static void selectOption_enumerate(const Array *array, ident obj, ident data)
ArrayEnumerator for enforcing ControlSelectionSingle.
static void addOption_removeSubview(const Array *array, ident obj, ident data)
ArrayEnumerator to remove Options from the stackView.
static _Bool optionWithValue_predicate(ident obj, ident data)
Predicate function for optionWithValue.
static void dealloc(Object *self)
static void addOption_addSubview(const Array *array, ident obj, ident data)
ArrayEnumerator to add Options to the stackView.
static void initialize(Class *clazz)
static _Bool selectedOptions_predicate(ident obj, ident data)
Predicate for selectedOption and selectedOptions.
A Control allowing users to select one or more Options.
Box * initWithFrame(Box *self, const SDL_Rect *frame)
Initializes this Box with the given frame.
void setSelected(CollectionItemView *self, _Bool isSelected)
Sets the selected state of this item.
CollectionView * init(CollectionView *self, const SDL_Rect *frame)
Initializes this CollectionView with the specified frame and style.
Controls are Views which capture events and dispatch Actions.
void stateDidChange(Control *self)
Called when the state of this Control changes.
_Bool captureEvent(Control *self, const SDL_Event *event)
Captures a given event, potentially altering the state of this Control.
Class * _Control(void)
The Control archetype.
unsigned int state
The bit mask of ControlState.
_Bool isHighlighted(const Control *self)
ControlSelection selection
The ControlSelection.
SDL_Size size(const Image *self)
_Bool isSelected
True if this Option is selected, false otherwise.
A Control allowing users to select one or more Options.
Array * selectedOptions(const Select *self)
void removeOptionWithValue(Select *self, ident value)
Removes first the Option with the given value.
void addOption(Select *self, const char *title, ident value)
Creates and adds a new Option to this Select.
MutableArray * options
The Options.
void selectOption(Select *self, Option *option)
Selects the given Option.
Option * selectedOption(const Select *self)
void selectOptionWithValue(Select *self, ident value)
Selects the first Option with the given value.
Comparator comparator
An optional Comparator to sort Options.
void removeOption(Select *self, Option *option)
Removes the specified Option.
StackView * stackView
The StackView for rendering the Options.
Option * optionWithValue(const Select *self, ident value)
Class * _Select(void)
The Select archetype.
void removeAllOptions(Select *self)
Removes all Options from this Select.
Control control
The superclass.
StackViews are containers that manage the arrangement of their subviews.
Views are the fundamental building blocks of ObjectivelyMVC user interfaces.
View * superview
The super View.
_Bool needsLayout
If true, this View will layout its subviews before it is drawn.
_Bool hidden
If true, this View is not drawn.
void addSubview(View *self, View *subview)
Adds a subview to this view, to be drawn above its siblings.
void addClassName(View *self, const char *className)
Adds the given class name to this View.
_Bool didReceiveEvent(const View *self, const SDL_Event *event)
View * nextResponder
The next responder, or event handler, in the chain.
void sizeThatFits(const View *self)
ViewPadding padding
The padding.
SDL_Rect renderFrame(const View *self)
layoutSubviews(View *self)
Performs layout for this View's immediate subviews.
SDL_Rect frame
The frame, relative to the superview.
void sizeToFit(View *self)
Resizes this View to fit its subviews.
void removeClassName(View *self, const char *className)
Removes the given class name to this View.
void removeSubview(View *self, View *subview)
Removes the given subview from this View.