Jump to content

Custom Widgets?


photo

Recommended Posts

Hi,

Is it possible to code our own Widgets, that could be integrated along side the others UnigineWidget. We need some very specific UI, like a rotary knob, a sequencer, an editable curve editor... All could be done or are existing with other UI sdk, but maybe it could be done seamlessly with the other widgets. A quick sample would help greatly.

Thanks!

Link to comment

Hi! 

there are two possible solutions

1. inherit from WidgetExternBase
you can override methods:

update
checkCallbacks
render

you can find a sample in Samples -> C++API -> Widgets -> WidgetExtern

2. use WidgetCanvas, draw on it by its API and interact via the basic Input system
Samples -> UnigineScript -> Widgets -> canvas_02 / canvas_03 (not the best example, but there is interaction with the canvas using the mouse)

Link to comment
34 minutes ago, Amerio.Stephane said:

but how do you manage mouse/keyboard interaction with it?

what kind of manage? Widgets do not have any specific mouse and keyboard controls

you can use Widget::getMouseX/getMouseY for mouse position in widget space. 

you can check click and double click in checkCallbacks Gui::getMouseButtons

void MyButton::checkCallbacks(int x, int y)
{
	check_default_callbacks(x, y);
	auto gui = getGui();

	if (isEnabled() && isFocused())
	{
		// double clicked
		if (gui->getMouseButtons() & Gui::MOUSE_MASK_DCLICK)
		{
			if (x >= 0 && y >= 0 && x < getWidth() && y < getHeight())
			{
				gui->setMouseButtons((gui->getMouseButtons() & ~Gui::MOUSE_MASK_DCLICK) | Gui::MOUSE_MASK_LEFT); // stop propagation
				runCallback(Gui::DOUBLE_CLICKED);
			}
		}
	}
}

the same way with keyPress/textPress

 

  • Like 1
Link to comment
×
×
  • Create New...