42 release(this->handle);
45 free(this->labelFormat);
61 double value = this->value;
74 $(self,
bind, inlets, dictionary);
95 if (this->max > this->min) {
97 if (((
View *) this->label)->hidden ==
false) {
98 int minWidth, maxWidth;
103 snprintf(text,
sizeof(text), this->labelFormat, this->min);
106 snprintf(text,
sizeof(text), this->labelFormat, this->max);
109 this->bar->frame.w -= max(minWidth, maxWidth) + label->
view.
padding.
left;
112 const double fraction = clamp((this->value - this->min) / (this->max - this->min), 0.0, 1.0);
115 View *handle = (
View *) this->handle;
133 const SDL_Point points[] = {
134 { frame.x, frame.y + frame.h * 0.5 },
135 { frame.x + frame.w, frame.y + frame.h * 0.5 }
141#pragma mark - Control
150 if (event->type == SDL_MOUSEBUTTONDOWN) {
156 else if (event->type == SDL_MOUSEBUTTONUP) {
158 self->
state &= ~ControlStateHighlighted;
162 else if (event->type == SDL_MOUSEMOTION) {
167 const double fraction = (
event->motion.x - frame.x) / (
double) frame.w;
168 double value = this->min + (this->max - this->min) * clamp(fraction, 0.0, 1.0);
170 if (this->snapToStep && this->step) {
171 value = clamp(round(value / this->step) * this->step, this->min, this->max);
174 const double delta = fabs(this->value - value);
175 if (delta > __DBL_EPSILON__) {
178 if (this->delegate.didSetValue) {
179 this->delegate.didSetValue(
this, this->value);
222 assert(self->handle);
261 value = clamp(value, self->
min, self->
max);
263 const double delta = fabs(self->
value - value);
264 if (delta > __DBL_EPSILON__) {
272#pragma mark - Class lifecycle
279 ((ObjectInterface *) clazz->interface)->dealloc =
dealloc;
282 ((ViewInterface *) clazz->interface)->init =
init;
284 ((ViewInterface *) clazz->interface)->render =
render;
286 ((ControlInterface *) clazz->interface)->captureEvent =
captureEvent;
288 ((SliderInterface *) clazz->interface)->formatLabel =
formatLabel;
289 ((SliderInterface *) clazz->interface)->initWithFrame =
initWithFrame;
290 ((SliderInterface *) clazz->interface)->setValue =
setValue;
291 ((SliderInterface *) clazz->interface)->setLabelFormat =
setLabelFormat;
303 clazz = _initialize(&(
const ClassDef) {
306 .instanceSize =
sizeof(
Slider),
307 .interfaceOffset = offsetof(
Slider, interface),
308 .interfaceSize =
sizeof(SliderInterface),
@ ControlStateHighlighted
View logging facilities via SDL_Log.
#define MVC_LogWarn(fmt,...)
static void dealloc(Object *self)
static void initialize(Class *clazz)
A Control allowing users to drag a handle to select a numeric value.
#define MakeInlets(...)
Creates a null-termianted array of Inlets.
#define MakeInlet(name, type, dest, data)
Creates an Inlet with the specified parameters.
Box * initWithFrame(Box *self, const SDL_Rect *frame)
Initializes this Box with the given frame.
CollectionView * init(CollectionView *self, const SDL_Rect *frame)
Initializes this CollectionView with the specified frame and style.
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.
void sizeCharacters(const Font *self, const char *chars, int *w, int *h)
Inlets enable inbound data binding of View attributes through JSON.
Label * initWithText(Label *self, const char *text, Font *font)
Initializes this Label with the given text and Font.
void setLabelFormat(ProgressBar *self, const char *labelFormat)
Changes this ProgressBar's label format and calls appropriate update functions.
void formatLabel(ProgressBar *self)
Forces an update on this ProgressBar's label.
void setValue(const ProgressBar *self, double value)
Sets the value, which is clamped to min and max.
The Renderer is responsible for rasterizing the View hierarchy of a WindowController.
void drawLine(const Renderer *self, const SDL_Point *points)
Draws a line segment between two points using GL_LINE_STRIP.
A Control allowing users to drag a handle to select a numeric value.
double min
The slider bounds.
Class * _Slider(void)
The Slider archetype.
View * bar
The slider bar.
Text * label
The Text displaying the current value.
char * labelFormat
The label format, e.g. "%0.01f".
double value
The slider value.
Control control
The superclass.
Text rendered with TrueType fonts.
void setText(Text *self, const char *text)
Sets this Text's text.
Views are the fundamental building blocks of ObjectivelyMVC user interfaces.
SDL_Rect bounds(const View *self)
_Bool bind(View *self, const Inlet *inlets, const Dictionary *dictionary)
Performs data binding for the Inlets described in dictionary.
_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.
_Bool didReceiveEvent(const View *self, const SDL_Event *event)
ViewPadding padding
The padding.
void awakeWithDictionary(View *self, const Dictionary *dictionary)
Wakes this View with the specified Dictionary.
SDL_Rect renderFrame(const View *self)
layoutSubviews(View *self)
Performs layout for this View's immediate subviews.
SDL_Rect frame
The frame, relative to the superview.
void render(View *self, Renderer *renderer)
Renders this View using the given renderer.