28#define _Class _ScrollView
39 release(this->contentView);
55 if (this->contentView) {
56 this->contentView->
frame.x = this->contentOffset.x;
57 this->contentView->frame.y = this->contentOffset.y;
72 if (event->type == SDL_MOUSEMOTION && (event->motion.state & SDL_BUTTON_LMASK)) {
75 SDL_Point offset = this->contentOffset;
77 offset.x +=
event->motion.xrel;
78 offset.y +=
event->motion.yrel;
82 }
else if (event->type == SDL_MOUSEWHEEL) {
83 SDL_Point offset = this->contentOffset;
85 offset.x -=
event->wheel.x * this->step;
86 offset.y +=
event->wheel.y * this->step;
90 }
else if (event->type == SDL_MOUSEBUTTONUP && (event->button.button & SDL_BUTTON_LMASK)) {
93 self->
state &= ~ControlStateHighlighted;
101#pragma mark - ScrollView
130 self->contentOffset.x = 0;
136 self->contentOffset.y = 0;
157 self->contentView = release(self->contentView);
163 self->contentView = retain(contentView);
170#pragma mark - Class lifecycle
177 ((ObjectInterface *) clazz->interface)->dealloc =
dealloc;
179 ((ViewInterface *) clazz->interface)->layoutSubviews =
layoutSubviews;
181 ((ControlInterface *) clazz->interface)->captureEvent =
captureEvent;
183 ((ScrollViewInterface *) clazz->interface)->initWithFrame =
initWithFrame;
184 ((ScrollViewInterface *) clazz->interface)->scrollToOffset =
scrollToOffset;
185 ((ScrollViewInterface *) clazz->interface)->setContentView =
setContentView;
197 clazz = _initialize(&(
const ClassDef) {
198 .name =
"ScrollView",
201 .interfaceOffset = offsetof(
ScrollView, interface),
202 .interfaceSize =
sizeof(ScrollViewInterface),
@ ControlStateHighlighted
#define MakePoint(x, y)
Creates an SDL_Point with the given coordinates.
Box * initWithFrame(Box *self, const SDL_Rect *frame)
Initializes this Box with the given frame.
Controls are Views which capture events and dispatch Actions.
_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)
SDL_Size size(const Image *self)
SDL_Size contentSize(const Panel *self)
Views are the fundamental building blocks of ObjectivelyMVC user interfaces.
SDL_Rect bounds(const View *self)
_Bool needsLayout
If true, this View will layout its subviews before it is 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.
layoutSubviews(View *self)
Performs layout for this View's immediate subviews.
SDL_Rect frame
The frame, relative to the superview.
void sizeToContain(View *self)
Resizes this View to contain 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.