Jump to content

Wrong tooltip displaying


photo

Recommended Posts

I've made a modification to the ui_02.ui file in the 2.6.1 data/samples/widgets directory to demonstrate a problem we're seeing: I kept the first sprite as-is, but enclosed the label, button and second sprite in a <vbox align="expand, overlap"> and removed their individual alignment tags. Then I added tooltips to everything.

No matter where I hover my mouse, I can only see the background sprite's tooltip, never the tooltips for the other four widgets. There is one exception to this: sometimes when I click on one of the buttons, move the mouse away and then back again, that button alone will show its tooltip in preference to the background sprite's. This lasts until I click anywhere else, at which point that button's tooltip will no longer show and I just see the background sprite's tooltip.

 

Link to comment

Hi Glen,

I've noticed a whitespace in your alignment tag between expand and overlap. Do you have any error messages in the Console?

Try modifying your ui_02.ui file as follows:

<?xml version="1.0" encoding="utf-8"?>
<ui version="1.0">

<vbox name="Window::vbox" export="1">

	<sprite name="Window::sprite" export="1" align="overlap,background" texture="samples/widgets/textures/window_01.png">
		<callback type="pressed" instance="Window::instance" string="pressed">Window::callback_redirector</callback>
	</sprite>
	<align align="expand,overlap">
		<label name="Window::label" export="1"  pos_x="32" pos_y="32">
			<text size="32" color="#000000">Window</text>
		</label>
		<button name="Window::button2" export="1" pos_x="80" pos_y="110">
			<text>Press me</text>
			<callback type="clicked" instance="Window::instance" string="clicked">Window::callback_redirector</callback>
		</button>
		<sprite name="Window::button" export="1" pos_x="80" pos_y="150" scale_y="0.25" texcoord_w="0.25" texture="samples/widgets/textures/button_01.png">
			<callback type="clicked" instance="Window::instance" string="clicked">Window::callback_redirector</callback>
			<callback type="enter" instance="Window::instance" string="enter">Window::callback_redirector</callback>
			<callback type="leave" instance="Window::instance" string="leave">Window::callback_redirector</callback>
		</sprite>
	</align>
</vbox>

</ui>

Everything should work fine for a script modified like this (suppose you did something alike):

// ...

class Window {
	
	Window instance;		// current instance
	WidgetVBox vbox;		// window vbox
	WidgetSprite sprite;		// window sprite
	WidgetLabel label;		// window label 	<--
	WidgetButton button2;		// window button2 	<--
	WidgetSprite button;		// window button

	
	// constructor
	Window(vec4 color) {
		instance = this;
		new UserInterface(engine.getGui(),fullPath("samples/widgets/ui_02.ui"));
		sprite.setColor(color);
      	
      	// setting tooltips for widgets
		vbox.setToolTip("vbox"); 		//	<--
		sprite.setToolTip("SPRITE"); 		//	<--
		button.setToolTip("BUTTON"); 		//	<--
		label.setToolTip("LABEL"); 		//	<--
		button2.setToolTip("BUTTON2"); 		//	<--
	}
  
  	// ...

Hope this helps!

Thank you!

Link to comment

There was indeed an extra space there. But that's not the underlying cause - the problem originally appeared in code which didn't even use a .UI file, I just chose this sample as the easiest way to reproduce it on a small scale for you.

As far as I can tell, adding that <align/> tag has changed the behaviour of the inner widgets to act like _they_ have align="expand,overlap" attributes? Although that restores the original behaviour, it's not behaviour I want. I need the vbox to be there, and I need the inner widgets not to overlap the vbox.

What I'm ultimately trying to do is remove the manual positioning and just let them align themselves normally (align="top" or something) within the vbox, but let the whole vbox overlap on top of the background sprite.

Link to comment

Oh, I think it's clearer now. So, you want your widgets to be aligned within the vbox automatically and behave as shown on the gif attached (please, correct me if I'm wrong).

If so, you could rearrange them like this (e.g., using the UI file):

<?xml version="1.0" encoding="utf-8"?>
<ui version="1.0">

<vbox name="Window::vbox" export="1">

	<vbox align="overlap,background">
		<sprite name="Window::sprite" export="1" texture="samples/widgets/textures/window_01.png">
			<callback type="pressed" instance="Window::instance" string="pressed">Window::callback_redirector</callback>
		</sprite>
	</vbox>
	<vbox align="top">
		<label name="Window::label" export="1">
			<text size="32" color="#000000">Window</text>
		</label>
		<button name="Window::button2" export="1">
			<text>Press me</text>
			<callback type="clicked" instance="Window::instance" string="clicked">Window::callback_redirector</callback>
		</button>
		<sprite name="Window::button" export="1" scale_y="0.25" texcoord_w="0.25" texture="samples/widgets/textures/button_01.png">
			<callback type="clicked" instance="Window::instance" string="clicked">Window::callback_redirector</callback>
			<callback type="enter" instance="Window::instance" string="enter">Window::callback_redirector</callback>
			<callback type="leave" instance="Window::instance" string="leave">Window::callback_redirector</callback>
		</sprite>
	</vbox>
</vbox>
</ui>

Thank you!

tooltips.gif

  • Like 1
Link to comment

The task is a bit tricky considering the way things currently work.  As a quick workaround maybe you could use "focus follows mouse" (setting focus on a widget under mouse cursor), if it is acceptable in your case. It preserves the behavior described above and registers all clicks before and after moving the box.

Thank you!

Link to comment

Or this https://developer.unigine.com/forum/topic/2738-solved-interfacewindow-focus-problem/?tab=comments#comment-15830 in which case is it worth trying to combine your approach above with the removeFocus() hack?

(Edit: I should clarify that we tried something kinda like that without success, but perhaps you will know how to do it properly)

Edit 2: I threw a sprite.removeFocus() in at the end of pressed() in the sample and it seems to work, haven't tried it on our real codebase yet. But when we've done that in the past we've found that double-clicks no longer register. Is there a way to have both working?

Edited by Greg.Mildenhall
Link to comment
×
×
  • Create New...