-
December 12th, 2017, 00:18 #1
Window Controls with sub-elements.
Is there a way to access sub-elements within a window control?
In the toolbar template, it utilizes the toolbar_30 template which is a frame. Nested within this frame are several buttons (paint/unmask/erase) whose controls I want to access. Frames as far as the ruleset documentation states, isn't a unique kind of window control, therefore it's working off the base WindowControl. Unlike window I can't Window.getControls() to get at their sub-elements, unless I'm missing something here.
The fact that CoreRPG is stuffing buttons inside of a frame definition tells me that it's a container of some kind, and a way to get at them, but I can't find any concrete definition to proceed here.
For reference:
Code:<toolbar_30 name="toolbar_draw"> <anchored to="toolbar_anchor"> <top /> <left anchor="right" relation="relative" /> </anchored> <button name="unmask_button"> <id>unmask</id> <icon>tool_mask_30</icon> <tooltipres>image_tooltip_toolbarmask</tooltipres> </button> ... </toolbar_30>
Code:<framedef name="toolbar_30"> <bitmap file="graphics/toolbar/toolbar_30.png"/> <topleft rect="0,0,4,3" /> <top rect="4,0,32,3" /> <topright rect="62,0,4,3" /> <left rect="0,3,4,28" /> <middle rect="4,3,32,28" /> <right rect="62,3,4,28" /> <bottomleft rect="0,31,4,3" /> <bottom rect="4,31,32,3" /> <bottomright rect="62,31,4,3" /> </framedef>
-
December 12th, 2017, 01:31 #2
I'm not an expert, but one thing you might be missing is that when you insert your <toolbar_30 /> control into your windowclass, you aren't referencing the <framedef> defined in on line 51 of template_toolbar.xml of the Core RPG ruleset, instead you are referencing a template with the same name defined on line 78 of the same file.
Code:<template name="toolbar_30"> <genericcontrol> <parameters> <horzmargin>2</horzmargin> <vertmargin>2</vertmargin> <buttonsize>30</buttonsize> </parameters> <frame name="toolbar_30" /> <button mergerule="resetandadd" /> <script file="common/scripts/toolbar.lua" /> </genericcontrol> </template>
As to your original question, are you trying to get a script reference to a control contained in a windowinstance? This would basically be a property of the windowinstance object, for example window.toolbar_draw.
EDIT: As for the buttons beneath your toolbar_draw control, what you're seeing in the control definition isn't actually a sub control, it's just a set of properties of the control itself. You can access them as properties of the control, although the properties themselves are stored as tables, even if there's only one tag. For example:
Code:if window.toolbar_draw.button and window.toolbar_draw.button[1] then local button1 = window.toolbar_draw.button[1]; --doStuff with button1. end
Code:if button and type(button[1]) == "table" then for k, v in ipairs(button) do if v.id and v.icon then local sID = v.id[1]; local sIcon = v.icon[1]; local sTooltip = ""; if v.tooltipres then sTooltip = Interface.getString(v.tooltipres[1]); elseif v.tooltip then sTooltip = v.tooltip[1]; end addButton(sID, sIcon, sTooltip); end end end
Code:function addButton(sID, sIcon, sTooltip) local bToggle = false; if toggle then bToggle = true; end local button = window.createControl("toolbar_button", ""); if button then local x = nButtonHorzMargin + (nButtons * (nButtonSize + nButtonHorzMargin)); nButtons = nButtons + 1; local nBarWidth = x + nButtonSize + nButtonHorzMargin; setAnchoredWidth(nBarWidth); setAnchoredHeight(nButtonSize + (2 * nButtonVertMargin)); local w,h = getSize(); button.setAnchor("left", getName(), "left", "absolute", x); button.setAnchor("top", getName(), "top", "absolute", nButtonVertMargin); button.setAnchoredWidth(nButtonSize); button.setAnchoredHeight(nButtonSize); button.configure(self, sID, sIcon, sTooltip, bToggle); aButtons[sID] = button; if isVisible() then button.setVisible(true); end end end
Sorry I can't be more specific but maybe this will get you on the right track.Last edited by ElementalAjah; December 12th, 2017 at 02:22. Reason: Further explanation of accessing buttons in a toolbar
-
December 12th, 2017, 02:13 #3
-
December 12th, 2017, 02:16 #4
Sorry, I did a ninja edit with more information above at about the same time you posted your response. Let me know if there's anything useful in there.
I don't think window.toolbar_30 is going to be correct though. toolbar_30 is the name of the template your control references, but not the control instance. I do mention trying window.toolbar_draw.unmask or window.toolbar_draw["unmask"] in my edited example above, give that a try.Last edited by ElementalAjah; December 12th, 2017 at 02:23.
-
December 12th, 2017, 02:27 #5
That's a big edit there.
The play off the window.toolbar_30's table entries is interesting, reminds me of java reflection hacks.
The addButton I believe to be a dynamic option as the buttons I reference are actually built into the window definition (campaign/record_image.xml to be exact).
-
December 12th, 2017, 02:44 #6
type(window.toobar_draw["unmask_button"]) is nil which I kinda expected from a WindowControl which toolbar_draw is. It's a container with no access to its elements which is a kinda weird framework design.
-
December 12th, 2017, 02:50 #7
Okay, I just noticed something strange. The definition of toolbar_draw that I'm seeing in my version of the coreRPG ruleset looks different from what you posted above — I'd been assuming they were the same and was working off of what I had on my own machine, which may explain why it sounds like we're talking about two different things.. Mine looks like this:
Code:<toolbar_30 name="toolbar_draw"> <anchored to="toolbar_anchor"> <top /> <left anchor="right" relation="relative" /> </anchored> <button> <id>unmask</id> <icon>tool_mask_30</icon> <tooltipres>image_tooltip_toolbarmask</tooltipres> </button> <button> <id>paint</id> <icon>tool_paint_30</icon> <tooltipres>image_tooltip_toolbardraw</tooltipres> </button> <button> <id>erase</id> <icon>tool_erase_30</icon> <tooltipres>image_tooltip_toolbarerase</tooltipres> </button> [...a few more tags] </toolbar_30>
Last edited by ElementalAjah; December 12th, 2017 at 02:53.
-
December 12th, 2017, 03:00 #8It's a container with no access to its elements
-
December 12th, 2017, 03:02 #9
-
December 12th, 2017, 03:05 #10
Do a find in files in CoreRPG for toolbar_draw - you'll see the toolbar can be reached with window.toolbar.subwindow.toolbar_draw
Now that you have button names in your extension, try window.toolbar.subwindow.toolbar_draw.unmask_butto nPrivate Messages: My inbox is forever filling up with PMs. Please don't send me PMs unless they are actually private/personal messages. General FG questions should be asked in the forums - don't be afraid, the FG community don't bite and you're giving everyone the chance to respond and learn!
Thread Information
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks