Jump to content

Getting GUI elements by name


megamagas
 Share

Recommended Posts

Hiya M!  Welcome to the forum. Sorry for the slow replies.

I think... no, not possible (yet)... but that is a pretty good feature idea.

Generally, only "nodes" can be gathered from the scene object.  Lights, cameras, and mesh... all ancestry of BabylonJS Node class.

But putting a searcher onto AdvancedDynamicTexture... would seem possible and plausible.  Perhaps you would like to code it for us?  ;)  Or, code your own.

Take a quick sniff at this...

https://github.com/BabylonJS/Babylon.js/blob/master/gui/src/advancedDynamicTexture.ts#L198

.executeOnAllControls()  Nice.  Recursion.  Scary.  Remove the Typescript debris, and it looks like this...

https://github.com/BabylonJS/Babylon.js/blob/master/dist/gui/babylon.gui.js#L191

Shove it into the top of a playground full-of named and un-named GUI crap.  (lines 3-16)

http://playground.babylonjs.com/#HETZDX#1

Create lines 276-278, ready to call our "do-it-to-every-control" engine... sending some function to be executed.  I think, for now, sending it

function() {console.log("name: ")}

...is a safe little function... to execute on each control.  There are 3 advancedDynamicTextures (ADT) active in this playground, so I made a line for each one.  :)

Now I'm too scared to activate any of those lines.  Maybe one of our "pros" would like to?  I don't have health coverage, so I don't activate recursive functions... ever.  heh.  Tree-walking is serious business.

(Hey WINGNUT... the guy simply asked a basic YES/NO question!  He didn't ask for a course in getting brain tumors!)  :D

Link to comment
Share on other sites

Hey, cheers for the in-depth answer :).

I sort of half-solved by writing a helper class for creating grids with two dimensional arrays, which I needed anyway. So I can at least know which column/row something is in. Having unique identifies would still be useful though :P.

I haven't looked at your playground example in depth yet, but I'm getting an "_a is undefined error" on run.

Link to comment
Share on other sites

Cool.

Yeah, that's the error I was getting, too (coming from line 8, I suspect).   Likely, a problem in the way I'm calling.

http://playground.babylonjs.com/#HETZDX#2

See line 286.  I am now calling... using advancedTexture._rootContainer

I also added .name's to all the controls within the first advanced[dynamic]Texture.  We needed some data to go fishing-for.  :)

I have also done some adjusting to the "sent function" in line 285.  I believe the 'this' is not working well.

Console now reports 10 occurrences-of name:   ... without any _a errors.  (yay!)  But, our "drill bit" function (line 285) is failing to drill data, it seems.

My dog has run under the refrigerator and hid, yet again.  How does he DO that?  ;)  (he fears recursion, too)

FindControlByRowAndColumn()... yeah, that's a good work-around, MM.  You're coding-up 3D Scrabble, aren't ya?  :) 

I bet you could use a GUI Stackpanel that is both vertical and horizontal, simultaneously, eh?  ;)  Well forget it... not gonna happen.  :D  (Just kidding around)

All in all, glad to hear you are rolling.  Party on!

Possible helpful hint:  Those who do heavy mods of GUI textBlocks... sometimes/often find that it is easier/better to dispose previous textBlock and create NEW textBlock... instead-of trying to change the text on an already-existing textBlock.  This is due to some performed-at-creation-time measuring of things... that happens to GUI controls... when text is involved.  At least that's how I understand it. 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...