Example #1
0
int gg_vbox_set_focus_pos(gg_widget_t *widget, int x , int y)
{
    gg_box_t *box = GG_BOX(widget);
    gg_container_t *container = GG_CONTAINER(widget);
    int size = gg_container_get_size(container);
    int cur_y = box->height_a - box->height;
    int prev = box->sel;

    box->sel = size;

    while (gg_select_prev(GG_SELECT(widget), 0, 0))
    {
        gg_widget_t *child = gg_container_get_child(container, box->sel);

        cur_y += child->height_a;
        if (cur_y > y)
        {
            if (!child->input || !child->enabled || !
                child->set_focus_pos(child, x, child->height_a - (cur_y - y)))
                break;
            else
                return 1;
        }
        cur_y += box->spacing;
    }

    box->sel = prev;
    return 0;
}
Example #2
0
int gg_vbox_input(gg_widget_t *widget, gg_event_t event) {
	gg_select_t *select = GG_SELECT(widget);
	gg_box_t *box = GG_BOX(widget);
	gg_widget_t *child;
	gg_rect_t focus;
	int retval = 0, x, y;

	if (select->sel == -1)
		return 0;

	if (event.type == GG_EVENT_MOUSE) {
		int nr = gg_container_get_size(GG_CONTAINER(widget));

		event.mouse.y -= box->height_a - box->height;
		while (--nr > select->sel) {
			gg_widget_t *child = gg_container_get_child(GG_CONTAINER(widget), nr);

			event.mouse.y -= child->height_a;
			event.mouse.y -= box->spacing;
		}
	}

	child = gg_container_get_child(GG_CONTAINER(widget), select->sel);

	if (event.type == GG_EVENT_MOUSE) {
		if (event.mouse.x < 0 || event.mouse.x >= child->width_a || event.mouse.y < 0 ||
			event.mouse.y >= child->height_a)
			return 0;
	}

	if (child->input(child, event))
		return 1;

	focus = child->get_focus_pos(child);
	x = focus.x + focus.width / 2;

	if (event.type == GG_EVENT_KEY && event.key == GG_KEY_UP) {
		retval = gg_select_prev(select, 1, 1);
		child = gg_container_get_child(GG_CONTAINER(widget), select->sel);
		y = 0;
	}

	if (event.type == GG_EVENT_KEY && event.key == GG_KEY_DOWN) {
		retval = gg_select_next(select, 1, 1);
		child = gg_container_get_child(GG_CONTAINER(widget), select->sel);
		y = child->height_a - 1;
	}

	if (retval) {
		child->set_focus_pos(child, x, y);
		return retval;
	}

	return 0;
}