static void place_quantity_widgets(home_screen_t* s) { int i; rect_t rect = widget_get_rect(s->stage_widget); sensor_info_t* active_sensors[NUM_SENSORS]; int num_active_sensors = 0; for (i = 0; i < NUM_SENSORS; ++i) { if (s->sensors[i].enabled) { widget_show(s->sensors[i].quantity_widget); active_sensors[num_active_sensors++] = &s->sensors[i]; } else widget_hide(s->sensors[i].quantity_widget); } if (num_active_sensors == 0) { widget_show(s->sensors[SENSOR_1].quantity_widget); active_sensors[num_active_sensors++] = &s->sensors[SENSOR_1]; } for (i = 0; i < num_active_sensors; ++i) { rect_t wrect = widget_get_rect(active_sensors[i]->quantity_widget); int spacing = (rect.height - (num_active_sensors * wrect.height)) / (num_active_sensors + 1); wrect.y = (spacing * (i + 1)) + (wrect.height * i); widget_set_rect(active_sensors[i]->quantity_widget, wrect); } }
void listbox_add_item(widget_t* lb, widget_t* item) { listbox_t* l = widget_get_instance_data(lb); widget_add_child(l->item_container, item); rect_t container_rect = widget_get_rect(l->item_container); rect_t rect = widget_get_rect(item); rect.x = 0; rect.y = 0; rect.width = MIN(rect.width, container_rect.width); rect.height = MIN(rect.height, l->item_height); widget_set_rect(item, rect); widget_invalidate(lb); }
static void listbox_layout(widget_t* w) { int i; listbox_t* l = widget_get_instance_data(w); int visible_items = num_visible_items(w); for (i = 0; i < widget_num_children(w); ++i) { int visible_index = i - l->pos; widget_t* child = widget_get_child(w, i); if (visible_index >= 0 && visible_index < visible_items) { rect_t child_rect = widget_get_rect(child); child_rect.y = (visible_index * l->item_height) + ((l->item_height - child_rect.height) / 2); widget_set_rect(child, child_rect); widget_show(child); } else { widget_hide(child); } } widget_enable(l->up_button, (l->pos > 0)); widget_enable(l->dn_button, (l->pos < (widget_num_children(w) - visible_items))); }
static int num_visible_items(widget_t* lb) { listbox_t* l = widget_get_instance_data(lb); rect_t rect = widget_get_rect(lb); return rect.height / l->item_height; }
static void icon_paint(paint_event_t* event) { icon_t* i = widget_get_instance_data(event->widget); rect_t rect = widget_get_rect(event->widget); point_t center = rect_center(rect); if (!widget_is_enabled(event->widget)) { gfx_set_bg_color(DARK_GRAY); gfx_clear_rect(rect); } /* draw icon */ if (i->image != NULL) { gfx_set_fg_color(i->icon_color); gfx_draw_bitmap( center.x - (i->image->width / 2), center.y - (i->image->height / 2), i->image); } }