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;
70 if (event->type == SDL_EVENT_MOUSE_MOTION && (event->motion.state & SDL_BUTTON_LMASK)) {
73 SDL_Point offset = this->contentOffset;
75 offset.x +=
event->motion.xrel;
76 offset.y +=
event->motion.yrel;
78 $(
this, scrollToOffset, &offset);
80 }
else if (event->type == SDL_EVENT_MOUSE_WHEEL) {
81 SDL_Point offset = this->contentOffset;
83 offset.x -=
event->wheel.x * this->step;
84 offset.y +=
event->wheel.y * this->step;
86 $(
this, scrollToOffset, &offset);
88 }
else if (event->type == SDL_EVENT_MOUSE_BUTTON_UP && (event->button.button & SDL_BUTTON_LMASK)) {
91 self->
state &= ~ControlStateHighlighted;
99#pragma mark - ScrollView
128 self->contentOffset.x = 0;
134 self->contentOffset.y = 0;
155 self->contentView = release(self->contentView);
161 self->contentView = retain(contentView);
164 $(self, scrollToOffset, &MakePoint(0, 0));
168#pragma mark - Class lifecycle
175 ((ObjectInterface *) clazz->interface)->dealloc =
dealloc;
177 ((ViewInterface *) clazz->interface)->layoutSubviews =
layoutSubviews;
179 ((ControlInterface *) clazz->interface)->captureEvent =
captureEvent;
181 ((ScrollViewInterface *) clazz->interface)->initWithFrame =
initWithFrame;
182 ((ScrollViewInterface *) clazz->interface)->
scrollToOffset = scrollToOffset;
183 ((ScrollViewInterface *) clazz->interface)->setContentView =
setContentView;
195 clazz = _initialize(&(
const ClassDef) {
196 .name =
"ScrollView",
199 .interfaceOffset = offsetof(
ScrollView, interface),
200 .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)
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.
Views are the fundamental building blocks of ObjectivelyMVC user interfaces.
bool needsLayout
If true, this View will layout its subviews before it is drawn.
SDL_Rect frame
The frame, relative to the superview.