PDA

View Full Version : Is it possible to know if a widget has been clicked?



meathome
February 18th, 2014, 20:42
So as the thread title suggests, is it possible, or do I have to do manual calculations in the mouse event of the parent control? Maybe it is a better idea to use full blown controls when I want them to do something more than just display things?
Oh and I wan to use radial positioning for the widgets...

Moon Wizard
February 19th, 2014, 03:18
I believe that you have to manually calculate the click position and compare to widget position, since widget objects do not support onClick events.

You are probably better off using controls, since clicks outside of the control generating the widgets are not captured.

Regards,
JPG

meathome
February 19th, 2014, 08:28
After switching to actual controls I have a strange problem. All the generated controls throw a console error message namely: no vertical anchor defined for control controlname in window windowname.
But setting those is the first thing I do after creating them:



for i = 1, vitality do
local control=nil;
control=window.createControl("genericcontrol",track.." "..i);
control.setAnchor( "top", "damageframe", "top" ,"absolute",pos[i].y*size.y+offsety) ;
control.setAnchor( "left", "damageframe", "left" ,"absolute",pos[i].x*size.x+offsetx ) ;
control.setAnchoredWidth(size.x);
control.setAnchoredHeight(size.y);

control.setIcon(boxicon);

container[track][i]=control;
end


On top of that all the custom controls are displayed just fine, but everyone of them throws the mentioned error message.
What is causing this, what am I doing wrong?

Trenloe
February 19th, 2014, 10:23
After switching to actual controls I have a strange problem. All the generated controls throw a console error message namely: no vertical anchor defined for control controlname in window windowname.
But setting those is the first thing I do after creating them:



for i = 1, vitality do
local control=nil;
control=window.createControl("genericcontrol",track.." "..i);
control.setAnchor( "top", "damageframe", "top" ,"absolute",pos[i].y*size.y+offsety) ;
control.setAnchor( "left", "damageframe", "left" ,"absolute",pos[i].x*size.x+offsetx ) ;
control.setAnchoredWidth(size.x);
control.setAnchoredHeight(size.y);

control.setIcon(boxicon);

container[track][i]=control;
end


On top of that all the custom controls are displayed just fine, but everyone of them throws the mentioned error message.
What is causing this, what am I doing wrong?
Is the error being raised immediately after your window.createcontrol command? Put a "Debug.console("Window Created");" line in your code to see where the error appears in your code.

I would imagine that the error is occurring at the window.createControl stage - before you set the anchors.

To get around this you can use a control template instead of an actual control name to create the control - include an <anchored> tag in the control template to avoid the error on creation and then change the anchor parameters immediately after as you are doing above.

For an example, see the addButton function in the CoreRPG ruleset: \common\script\toolbar.lua. This uses the following code to create a new button control:

local button = window.createControl("toolbar_button", "");
After creation of the control the script goes on to set anchors etc.. "toolbar_button" is a template not a base control and is defined in \common\template_toolbar.xml and this has an <anchored> position:

<template name="toolbar_button">
<buttoncontrol>
<anchored position="insidetopleft" />
<invisible/>
<script file="common/scripts/toolbar_button.lua" />
</buttoncontrol>
</template>

meathome
February 19th, 2014, 18:25
That fixed it! After using a template that simply adds <bounds>0,0,0,0</bounds> the error disappeared. Thank you very much!