28#define _Class _ScrollView
39 release(this->contentView);
40 release(this->scrollBar);
61 $(self, bind, inlets, dictionary);
77 $(self, bind, inlets, (Dictionary *) style->
attributes);
90 switch (this->scrollBarVisibility) {
95 showScrollBar =
false;
98 if (this->contentView == NULL) {
99 showScrollBar =
false;
109 ((
View *) this->scrollBar)->hidden = !showScrollBar;
113 if (this->contentView) {
114 this->contentView->frame.x = this->contentOffset.x;
115 this->contentView->frame.y = this->contentOffset.y;
119 ((
View *) this->scrollBar)->needsLayout =
true;
123#pragma mark - Control
132 if (event->type == SDL_EVENT_MOUSE_MOTION && (event->motion.state & SDL_BUTTON_LMASK)) {
135 SDL_Point offset = this->contentOffset;
137 offset.x +=
event->motion.xrel;
138 offset.y +=
event->motion.yrel;
140 $(
this, scrollToOffset, &offset);
142 }
else if (event->type == SDL_EVENT_MOUSE_WHEEL) {
143 SDL_Point offset = this->contentOffset;
145 offset.x -=
event->wheel.x * this->step;
146 offset.y +=
event->wheel.y * this->step;
148 $(
this, scrollToOffset, &offset);
150 }
else if (event->type == SDL_EVENT_MOUSE_BUTTON_UP && (event->button.button & SDL_BUTTON_LMASK)) {
153 self->
state &= ~ControlStateHighlighted;
161#pragma mark - ScrollView
201 self->contentOffset.x = 0;
207 self->contentOffset.y = 0;
229 self->contentView = release(self->contentView);
235 self->contentView = retain(contentView);
240 $(self, scrollToOffset, &MakePoint(0, 0));
254#pragma mark - Class lifecycle
261 ((ObjectInterface *) clazz->interface)->dealloc =
dealloc;
263 ((ViewInterface *) clazz->interface)->applyStyle =
applyStyle;
265 ((ViewInterface *) clazz->interface)->layoutSubviews =
layoutSubviews;
267 ((ControlInterface *) clazz->interface)->captureEvent =
captureEvent;
269 ((ScrollViewInterface *) clazz->interface)->initWithFrame =
initWithFrame;
270 ((ScrollViewInterface *) clazz->interface)->
scrollToOffset = scrollToOffset;
271 ((ScrollViewInterface *) clazz->interface)->setContentView =
setContentView;
284 clazz = _initialize(&(
const ClassDef) {
285 .name =
"ScrollView",
288 .interfaceOffset = offsetof(
ScrollView, interface),
289 .interfaceSize =
sizeof(ScrollViewInterface),
static bool isHighlighted(const Control *self)
@ ControlStateHighlighted
static SDL_Size size(const Image *self)
static void removeSubview(View *self, View *subview)
static void addSubview(View *self, View *subview)
static SDL_Size contentSize(const Panel *self)
#define MakeInlets(...)
Creates a null-termianted array of Inlets.
#define MakeInlet(name, type, dest, data)
Creates an Inlet with the specified parameters.
static void removeClassName(View *self, const char *className)
static void addClassName(View *self, const char *className)
static SDL_Rect bounds(const View *self)
Controls are Views which capture and respond to events.
unsigned int state
The bit mask of ControlState.
Inlets enable inbound data binding of View attributes through JSON.
Views are the fundamental building blocks of ObjectivelyMVC user interfaces.
ViewAlignment alignment
The alignment.
int autoresizingMask
The ViewAutoresizing bitmask.
bool needsLayout
If true, this View will layout its subviews before it is drawn.
bool hidden
If true, this View is not drawn.