コード例 #1
0
ファイル: gui_component.cpp プロジェクト: Cassie90/ClanLib
GUIComponent *GUIComponent::get_next_component_in_tree()
{
	if (has_child_components())
		return get_first_child();

	if (impl->next_sibling)
		return impl->next_sibling;

	GUIComponent *parent = impl->parent;
	while (parent)
	{
		if (parent->get_next_sibling())
			return parent->get_next_sibling();
		parent = parent->get_parent_component();
	}

	// Reached end of tree. Return first item.
	return get_top_level_component();
}
コード例 #2
0
void GUIFindPreferredHeight::flex_vertical_node(GUIComponent_Impl *node)
{
    node->css_used_values.height = node->component->get_preferred_content_height(node->css_used_values.width);

    CSSUsedValue preferred_height = 0.0f;
    for (GUIComponent *child = node->first_child; child != 0; child = child->get_next_sibling())
    {
        if (is_normal_flow(child->impl.get()))
        {
            GUICSSUsedValues &child_used_values = child->impl->css_used_values;

            // If the height of the box cannot be determined from CSS, then ask the component:
            if (child_used_values.height_undetermined)
            {
                GUICSSDisplayVisitor::node(child->impl.get());
            }

            preferred_height += get_used_noncontent_height(child_used_values) + child_used_values.height;
        }
    }

    node->css_used_values.height = std::max(node->css_used_values.height, preferred_height);
    GUICSSApplyMinMaxConstraints::visit(node->css_used_values, node->element.get_css_values().get_box(), node->parent->impl->css_used_values);
}
コード例 #3
0
void RadioButton_Impl::on_process_message(std::shared_ptr<GUIMessage> &msg)
{
	if (!radio->is_enabled())
		return;

	std::shared_ptr<GUIMessage_Input> input_msg = std::dynamic_pointer_cast<GUIMessage_Input>(msg);
	if (input_msg)
	{
		
		const InputEvent &e = input_msg->input_event;

		if (e.type == InputEvent::pressed && e.id == mouse_left)
		{
			part_checker.set_pseudo_class(CssStr::pressed, true);
			radio->request_repaint();
			msg->consumed = true;
		}
		else if (e.type == InputEvent::released && e.id == mouse_left)
		{
			if ((part_checker.get_pseudo_class(CssStr::checked) == false))
			{
				Callback_v1<RadioButton*> cb = uncheck_radio_buttons(radio->get_parent_component());

				part_checker.set_pseudo_class(CssStr::pressed, false);
				radio->set_selected(true);

				if (!cb.is_null())
					cb.invoke(radio);
				if (!func_selected.is_null())
					func_selected.invoke();
			}
			else
			{
				part_checker.set_pseudo_class(CssStr::pressed, false);
				radio->request_repaint();
			}

			radio->set_focus(true);
			msg->consumed = true;
		}
		else if (e.type == InputEvent::pressed && (e.id == keycode_left || e.id == keycode_up))
		{
			std::vector<GUIComponent*> group = radio->get_parent_component()->get_child_component_group(radio->get_component_group_name());

			// find previous visible & enabled radiobutton in the same group:
			GUIComponent *comp = radio->get_previous_sibling();
			if (comp == 0)
				comp = group.back();

			while (comp != radio)
			{
				if (comp->is_visible() && comp->is_enabled() && comp->get_component_group_name() == radio->get_component_group_name())
				{
					RadioButton *focus_comp = dynamic_cast<RadioButton*>(comp);
					if (focus_comp)
					{
						Callback_v1<RadioButton*> cb = uncheck_radio_buttons(radio->get_parent_component());
						focus_comp->set_selected(true);
						if (!cb.is_null())
							cb.invoke(focus_comp);
						if (!focus_comp->func_selected().is_null())
							focus_comp->func_selected().invoke();
						focus_comp->set_focus();
						break;
					}
				}

				if (!comp->get_previous_sibling() || comp->get_previous_sibling()->get_component_group_name() != radio->get_component_group_name())
				{
					// reach first item in group, loop around from the last:
					comp = group.back();
				}
				else
					comp = comp->get_previous_sibling();
			}

			msg->consumed = true;
		}
		else if (e.type == InputEvent::pressed && (e.id == keycode_right || e.id == keycode_down))
		{
			std::vector<GUIComponent*> group = radio->get_parent_component()->get_child_component_group(radio->get_component_group_name());

			// find next visible & enabled radiobutton in the same group:
			GUIComponent *comp = radio->get_next_sibling();
			if (comp == 0 || comp->get_component_group_name() != radio->get_component_group_name())
				comp = group.front();

			while (comp != radio)
			{
				if (comp->is_visible() && comp->is_enabled() && comp->get_component_group_name() == radio->get_component_group_name())
				{
					RadioButton *focus_comp = dynamic_cast<RadioButton*>(comp);
					if (focus_comp)
					{
						Callback_v1<RadioButton*> cb = uncheck_radio_buttons(radio->get_parent_component());
						focus_comp->set_selected(true);
						if (!cb.is_null())
							cb.invoke(focus_comp);
						if (!focus_comp->func_selected().is_null())
							focus_comp->func_selected().invoke();
						focus_comp->set_focus();
						break;
					}
				}

				if (!comp->get_previous_sibling() || comp->get_previous_sibling()->get_component_group_name() != radio->get_component_group_name())
				{
					// reach first item in group, loop around from the last:
					comp = group.back();
				}
				else
					comp = comp->get_next_sibling();
			}
			msg->consumed = true;
		}

	}
	std::shared_ptr<GUIMessage_Pointer> pointer = std::dynamic_pointer_cast<GUIMessage_Pointer>(msg);
	if (pointer)
	{
		
		if (pointer->pointer_type == GUIMessage_Pointer::pointer_enter)
		{
			part_checker.set_pseudo_class(CssStr::hover, true);
			radio->request_repaint();
		}
		else
		{
			part_checker.set_pseudo_class(CssStr::hover, false);
			radio->request_repaint();
		}
	}
	std::shared_ptr<GUIMessage_FocusChange> focus_change_msg = std::dynamic_pointer_cast<GUIMessage_FocusChange>(msg);
	if (focus_change_msg)
	{
		
		if (focus_change_msg->focus_type == GUIMessage_FocusChange::gained_focus)
		{
			radio->set_pseudo_class(CssStr::focused, true);
			if (!radio->is_selected())
			{
				Callback_v1<RadioButton*> cb = uncheck_radio_buttons(radio->get_parent_component());
				radio->set_selected(true);
				if (!cb.is_null())
					cb.invoke(radio);
				if (!func_selected.is_null())
					func_selected.invoke();
			}
			radio->request_repaint();
		}
		else 
		{
			radio->set_pseudo_class(CssStr::focused, false);
			radio->request_repaint();
		}
		msg->consumed = true;
	}
}