Referencing a child gui object

  • 5 Replies
  • 140 Views
*

RobertMeI

  • Novice
  • *
  • 17
Referencing a child gui object
« on: March 17, 2017, 05:23:25 »
Hi,
If I define an gui object such as ...
{ "kind" : "win",
  ......
  "children" :
 [ {
     "kind" : "image",
    "name" : "img1",
    .....
 } ]
} var, guiWin
var gui
.....
 guiWin @ g:new gui !

How do I reference that child image, and how do I load an image from disk into it ?
Thanks
Robert

*

ron

  • Administrator
  • Guru
  • *****
  • 3,238
Re: Referencing a child gui object
« Reply #1 on: March 17, 2017, 05:35:35 »
So to get the child gui, you would do gui @ "img1" g:child

Then the child gui with the name 'img1' would be on TOS.

You load it from disk by using the "img" key:

...
  "kind" : "image",
  "img" : "disk/file/name.png",
...

*

ron

  • Administrator
  • Guru
  • *****
  • 3,238
Re: Referencing a child gui object
« Reply #2 on: March 17, 2017, 05:37:40 »
If you mean, "how do I load an image after the gui has been created", then you would use "g:image"  and "g:setimage" on the child image gui.

*

RobertMeI

  • Novice
  • *
  • 17
Re: Referencing a child gui object
« Reply #3 on: March 17, 2017, 06:45:35 »
Thanks Ron,
found something that worked, but the 'new' image doesn't update on the screen straight away.  Is there an update or refresh that can force a redraw of the gui object ?
eg. I load an image from disk into myImage, then set my child gui object to display this image
: app:main
   "Starting 170315Img1.8thdir" log
   
   guiWin @ g:new gui    !
   gui @ g:show
   
   \  load image from disk into variable
    "image.png" app:asset img:new
    null? if "Image not loaded" . cr bye
          then myImage !
         
   "try launching the image file from disk" log
   "g:\\8th\\rbh\\images\\image.png" null f:launch
   \ working 170317 - must use full path with \\
      
   "sleeping 5 seconds" log   
   5 sleep   
   
   \ try to change image of gui object
   G:reset  \ clear stack
   gui @ "myImage1" g:child  \ get gui object and child object
   myImage @ g:setimage  \ set child obj img to new image
   \ at this point it doesn't seem to display the new image straight away

   "try flipping the image" log
   myImage @ true img:flip myImage !
   \ img:flip returns a 'new' image

   "sleeping a second 5 seconds" log
   5 sleep   
   
   \ load flipped image into myImage1
   G:reset  \ clear stack
   gui @ "myImage1" g:child  \ get gui object and child object
   myImage @ g:setimage  \ set child obj img to new image   
        \ at this point the flipped image is displayed without the unflipped been shown   
   ;

*

ron

  • Administrator
  • Guru
  • *****
  • 3,238
Re: Referencing a child gui object
« Reply #4 on: March 17, 2017, 07:06:44 »
Yes, "g:invalidate" is what you're looking for.

*

RobertMeI

  • Novice
  • *
  • 17
Re: Referencing a child gui object
« Reply #5 on: March 17, 2017, 07:11:53 »
Thanks Ron, starting to understand the 'thinking' behind gui objects and how to manipulate them better.
regards Robert