28#define _Class _ScrollView
39 release(this->contentView);
40 release(this->scrollBar);
56 View *contentView = NULL;
64 $(self, bind, inlets, dictionary);
85 $(self, bind, inlets, (Dictionary *) style->
attributes);
104 bool scrollBarHidden;
105 switch (this->scrollBarVisibility) {
107 scrollBarHidden =
false;
110 scrollBarHidden =
true;
113 if (this->contentView == NULL) {
114 scrollBarHidden =
true;
129 if (this->contentView) {
130 this->contentView->frame.x = this->contentOffset.x;
131 this->contentView->frame.y = this->contentOffset.y;
135#pragma mark - Control
144 if (event->type == SDL_EVENT_MOUSE_MOTION && (event->motion.state & SDL_BUTTON_LMASK)) {
147 SDL_Point offset = this->contentOffset;
149 offset.x +=
event->motion.xrel;
150 offset.y +=
event->motion.yrel;
152 $(
this, scrollToOffset, &offset);
154 }
else if (event->type == SDL_EVENT_MOUSE_WHEEL) {
155 SDL_Point offset = this->contentOffset;
157 offset.x -=
event->wheel.x * this->step;
158 offset.y +=
event->wheel.y * this->step;
160 $(
this, scrollToOffset, &offset);
162 }
else if (event->type == SDL_EVENT_MOUSE_BUTTON_UP && (event->button.button & SDL_BUTTON_LMASK)) {
165 self->
state &= ~ControlStateHighlighted;
173#pragma mark - ScrollView
210 self->contentOffset.x = 0;
216 self->contentOffset.y = 0;
238 self->contentView = release(self->contentView);
244 self->contentView = retain(contentView);
249 $(self, scrollToOffset, &MakePoint(0, 0));
266#pragma mark - Class lifecycle
273 ((ObjectInterface *) clazz->interface)->dealloc =
dealloc;
275 ((ViewInterface *) clazz->interface)->applyStyle =
applyStyle;
277 ((ViewInterface *) clazz->interface)->init =
init;
280 ((ControlInterface *) clazz->interface)->captureEvent =
captureEvent;
282 ((ScrollViewInterface *) clazz->interface)->initWithFrame =
initWithFrame;
283 ((ScrollViewInterface *) clazz->interface)->
scrollToOffset = scrollToOffset;
284 ((ScrollViewInterface *) clazz->interface)->setContentView =
setContentView;
297 clazz = _initialize(&(
const ClassDef) {
298 .name =
"ScrollView",
301 .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 addEnumAttribute(Style *self, const char *attr, const EnumName *names, int value)
#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 void invalidateStyle(View *self)
static void setNeedsLayout(View *self)
static void setVisibility(View *self, ViewVisibility visibility)
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.
layoutSubviews(View *self)
Arranges this View's immediate subviews within its (already final) frame.