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);
89#pragma mark - ProgressBar
119 assert(self->foreground);
144 if (self->
max <= self->
min) {
148 return 100.0 * (self->
value - self->
min) / (self->
max - self->
min);
171 value = clamp(value, self->
min, self->
max);
173 const double delta = fabs(self->
value - value);
174 if (delta > __DBL_EPSILON__) {
178 const double frac = $(self,
progress) / 100.0;
185 if (self->delegate.didSetValue) {
186 self->delegate.didSetValue(self, self->value);
191#pragma mark - Class lifecycle
198 ((ObjectInterface *) clazz->interface)->dealloc =
dealloc;
201 ((ViewInterface *) clazz->interface)->init =
init;
203 ((ProgressBarInterface *) clazz->interface)->formatLabel =
formatLabel;
206 ((ProgressBarInterface *) clazz->interface)->setLabelFormat =
setLabelFormat;
207 ((ProgressBarInterface *) clazz->interface)->setValue =
setValue;
219 clazz = _initialize(&(
const ClassDef) {
220 .name =
"ProgressBar",
221 .superclass =
_View(),
223 .interfaceSize =
sizeof(ProgressBarInterface),
static Label * initWithText(Label *self, const char *text, Font *font)
static void addSubview(View *self, View *subview)
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 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 addClassName(View *self, const char *className)
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.
double progress(const ProgressBar *self)
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 awakeWithDictionary(View *, const Dictionary *)
Wakes this View with the specified Dictionary.
SDL_Rect frame
The frame, relative to the superview.
View * initWithFrame(View *self, const SDL_Rect *frame)
Initializes this View with the specified frame.