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)) {
173#pragma mark - ScrollView
210 self->contentOffset.x = 0;
216 self->contentOffset.y = 0;
238 self->contentView = release(self->contentView);
266#pragma mark - Class lifecycle
273 ((ObjectInterface *) clazz->interface)->dealloc =
dealloc;
275 ((ViewInterface *) clazz->interface)->applyStyle =
applyStyle;
277 ((ViewInterface *) clazz->interface)->init =
init;
278 ((ViewInterface *) clazz->interface)->layoutSubviews =
layoutSubviews;
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 void initialize(Class *clazz)
static View * init(View *self)
static void awakeWithDictionary(View *self, const Dictionary *dictionary)
static void dealloc(Object *self)
static Box * initWithFrame(Box *self, const SDL_Rect *frame)
static void layoutSubviews(View *self)
static void applyStyle(View *self, const Style *style)
static bool isHighlighted(const Control *self)
@ ControlStateHighlighted
static SDL_Size size(const Image *self)
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 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.
SDL_Rect bounds(const View *self)
void invalidateStyle(View *self)
Invalidates the computed Style for this View and its descendants.
void setVisibility(View *self, ViewVisibility visibility)
Sets this View's visibility.
Style * style
The element-level Style of this View.
void setNeedsLayout(View *self)
Marks this View as needing layout before it is next 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.
SDL_Size size(const View *self)
ViewVisibility visibility
Whether this View is drawn, and contributes to its superview's size.
SDL_Rect frame
The frame, relative to the superview.
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.