示例#1
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;
}
示例#2
0
int gg_ticker_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 cur_x = widget->width_a - GG_TICKER(widget)->offset;

	box->sel = -1;
	GG_TICKER(widget)->focus_x = x;

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

		if (x >= cur_x && cur_x + child->width_a > x) {
			if (!child->input || !child->enabled)
				box->sel = -1;
			return 1;
		}
		cur_x += child->width_a + box->spacing;
	}

	box->sel = -1;
	return 0;
}