PDA

View Full Version : createControl() with windowreferencecontrol



celestian
June 24th, 2019, 06:39
I am attempting to use createControl to create a link button that will open a class/record I setValue() on the control.

Here is the template I use.



<template name="link_inventory_item_ct">
<linkcontrol>
<script>
function onDragStart(button, x, y, draginfo)
local sClass, sRecord = getValue();
local node = DB.findNode(sRecord);
if node then
local sName = DB.getValue(node,"name","");
local sPathToItem = node.getPath();
draginfo.setType("shortcut");
draginfo.setShortcutData( sClass, sRecord );
draginfo.setDescription(sName);
draginfo.setIcon("button_link_down");
return true;
end
end

function onButtonPress()
local sClass, sRecord = getValue();
if sClass and sRecord then
local sPathToItem = node.getPath();
Interface.openWindow(sClass, sRecord);
return true;
end
end
</script>
<anchored >
<top />
<left />
</anchored>
<icon normal="button_link" pressed="button_link_down" empty="button_link_empty" />
</linkcontrol>
</template>


Here is the lua I use to create the control object.



local controlItemLink = createControl("link_inventory_item_ct", sControlItemLink);
controlItemLink.setAnchor("top", sControlItemName,"top","absolute",10);
controlItemLink.setAnchor("left", sControlItemName,"right","absolute",0);
controlItemLink.setAnchor("right", sControlItemName,"right","absolute",-20);
controlItemLink.setValue('item',nodeItem.getPath() );


However, the button/link doesn't seem to allow interaction at all. Neither drag or mouse clicks on them work.

The result of my code is something like this. (I also createControl for the count and name of the items)

https://i.imgur.com/O8L0IuH.png

This item list is generated from a single string, not a list of nodes. My use case is to eliminate the inventorylist objects on npcs while in the CT but also be able to "see" the items and link back to the source NPC record that it came from. So far all this works it's just I can't seem to get the link buttons to interact.

Trenloe
June 24th, 2019, 13:39
I'm guessing it's a problem with the positioning/anchoring. It looks like your setting the right side of your control to be further to the left than the left side.

If your control template has a width, then there's no need to set the right anchor - as you've set the left anchor to the same control. If your template doesn't have a width, try setting the control width using setAnchoredWidth - https://www.fantasygrounds.com/refdoc/windowcontrol.xcp#setAnchoredWidth

celestian
June 24th, 2019, 16:06
I'm guessing it's a problem with the positioning/anchoring. It looks like your setting the right side of your control to be further to the left than the left side.

If your control template has a width, then there's no need to set the right anchor - as you've set the left anchor to the same control. If your template doesn't have a width, try setting the control width using setAnchoredWidth - https://www.fantasygrounds.com/refdoc/windowcontrol.xcp#setAnchoredWidth

That was it, more or less, I was placing the "buttons" underneath the label so clicks went to label, not the "button" that was under. I assumed that since it was AFTER the label it would be on top. Got it functional now, thanks for the tip ;)

What I had to do was "achor" my "left" side of the button to the right side of the "contentanchor" and not the label. Once I did that I was able to use a offset so the button was on the "frame" (shaded/non-shaded variants) and/or on top and the button works.

Bidmaron
June 24th, 2019, 18:05
Thanks for the explanation, Celestian