32#define _Class _ProgressBar
43 memset(&this->delegate, 0,
sizeof(this->delegate));
45 release(this->background);
46 release(this->foreground);
49 free(this->labelFormat);
65 double value = this->value;
77 $(self, bind, inlets, dictionary);
100 const double frac = clamp($(
this,
progress) / 100.0, 0.0, 1.0);
102 this->foreground->view.frame.w =
bounds.w * frac;
107#pragma mark - ProgressBar
137 assert(self->foreground);
162 if (self->
max <= self->
min) {
166 return 100.0 * (self->
value - self->
min) / (self->
max - self->
min);
189 value = clamp(value, self->
min, self->
max);
191 const double delta = fabs(self->
value - value);
192 if (delta > __DBL_EPSILON__) {
196 const double frac = $(self,
progress) / 100.0;
203 if (self->delegate.didSetValue) {
204 self->delegate.didSetValue(self, self->value);
209#pragma mark - Class lifecycle
216 ((ObjectInterface *) clazz->interface)->dealloc =
dealloc;
218 ((ViewInterface *) clazz->interface)->layoutSubviews =
layoutSubviews;
221 ((ViewInterface *) clazz->interface)->init =
init;
223 ((ProgressBarInterface *) clazz->interface)->formatLabel =
formatLabel;
224 ((ProgressBarInterface *) clazz->interface)->initWithFrame =
initWithFrame;
225 ((ProgressBarInterface *) clazz->interface)->progress =
progress;
226 ((ProgressBarInterface *) clazz->interface)->setLabelFormat =
setLabelFormat;
227 ((ProgressBarInterface *) clazz->interface)->setValue =
setValue;
239 clazz = _initialize(&(
const ClassDef) {
240 .name =
"ProgressBar",
241 .superclass =
_View(),
243 .interfaceSize =
sizeof(ProgressBarInterface),
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 Label * initWithText(Label *self, const char *text, Font *font)
static View * init(View *self)
static void awakeWithDictionary(View *self, const Dictionary *dictionary)
static void setValue(ProgressBar *self, double value)
Class * _ProgressBar(void)
static void dealloc(Object *self)
static double progress(const ProgressBar *self)
static void setLabelFormat(ProgressBar *self, const char *labelFormat)
static void initialize(Class *clazz)
static void layoutSubviews(View *self)
static ProgressBar * initWithFrame(ProgressBar *self, const SDL_Rect *frame)
static void formatLabel(ProgressBar *self)
static void setText(Text *self, const char *text)
#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 SDL_Rect bounds(const View *self)
ImageViews render an Image in the context of a View hierarchy.
Inlets enable inbound data binding of View attributes through JSON.
double min
The progress bounds.
double value
The progress value.
Text * label
The progress Text.
ImageView * background
The background ImageView.
ProgressBar * initWithFrame(ProgressBar *self, const SDL_Rect *frame)
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.
char * labelFormat
The Label format, e.g. "%0.0lf".
Text rendered with TrueType fonts.
Views are the fundamental building blocks of ObjectivelyMVC user interfaces.
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_Rect frame
The frame, relative to the superview.