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);
143 return 100.0 * self->
value / (self->
max - self->
min);
166 value = clamp(value, self->
min, self->
max);
168 const double delta = fabs(self->
value - value);
169 if (delta > __DBL_EPSILON__) {
173 const double frac = self->value / (self->max - self->min);
180 if (self->delegate.didSetValue) {
181 self->delegate.didSetValue(self, self->value);
186#pragma mark - Class lifecycle
193 ((ObjectInterface *) clazz->interface)->dealloc =
dealloc;
196 ((ViewInterface *) clazz->interface)->init =
init;
198 ((ProgressBarInterface *) clazz->interface)->formatLabel =
formatLabel;
201 ((ProgressBarInterface *) clazz->interface)->setLabelFormat =
setLabelFormat;
202 ((ProgressBarInterface *) clazz->interface)->setValue =
setValue;
214 clazz = _initialize(&(
const ClassDef) {
215 .name =
"ProgressBar",
216 .superclass =
_View(),
218 .interfaceOffset = offsetof(
ProgressBar, interface),
219 .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 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.
bool needsLayout
If true, this View will layout its subviews before it is drawn.
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.