Retrieve text from StringGadget that is inside ContainerGadget

Just starting out? Need help? Post your questions and find answers here.
User avatar
Distorted Pixel
Enthusiast
Enthusiast
Posts: 303
Joined: Sun Aug 29, 2021 4:34 am

Retrieve text from StringGadget that is inside ContainerGadget

Post by Distorted Pixel »

Hi,

If I run the code of the one window that has the StringGadget inside the ContainerGadget it debugs the user typed text fine, but if I run the same window with the rest of my program it will not debug at all. Why would this happen?
To be popular is way to much work. I just want to be me, myself and I. Oh no, does that mean I'm bipolar? :shock:

No one cares how much you know until they know how much you care
boddhi
Enthusiast
Enthusiast
Posts: 524
Joined: Mon Nov 15, 2010 9:53 pm

Re: Retrieve text from StringGadget that is inside ContainerGadget

Post by boddhi »

Distorted Pixel wrote: Why would this happen?
An example code that would generate this "anomaly" would be helpful...
Distorted Pixel wrote: To be popular is way to much work. I just want to be me, myself and I. Oh no, does that mean I'm bipolar? :shock:
Tripolar, no? :mrgreen:
If my English syntax and lexicon are incorrect, please bear with Google translate and DeepL. They rarely agree with each other!
Except on this sentence...
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: Retrieve text from StringGadget that is inside ContainerGadget

Post by netmaestro »

The problem as stated cannot be solved. There are just too many reasons this would happen. Try to put together a snippet where it's happening and post that.
BERESHEIT
User avatar
Distorted Pixel
Enthusiast
Enthusiast
Posts: 303
Joined: Sun Aug 29, 2021 4:34 am

Re: Retrieve text from StringGadget that is inside ContainerGadget

Post by Distorted Pixel »

:
boddhi Said:
Tripolar no?
I can't say I have heard of that :D

I have been using IceDesigner for my interface creating. As I said in my first post, If I run just the one window code it works, but running it in the whole program it will not debug the user typed string.

Below isn't the code including the IceDesigner code, but it is doing the same thing even though it is running by itself with no other previous windows as in my program.
[Edit] I just rearranged the drawing code to be more like original code when it comes to the images. (In the original code I actually load an image into an ImageGadget and disable the gadget. It is as big as the main window and redrawn to the ScreenOuput for the WindowedScreen.)

Example code:

Code: Select all

; window 1
EnableExplicit

Global PlayerName.s, return_key_down, String_1
Global Cont_1 = 0

If OpenWindow(0, 0, 0, 600, 250,"ContainerGadget with StringGadget",#PB_Window_SystemMenu|#PB_Window_SizeGadget|#PB_Window_ScreenCentered)
  
  CreateImage(0, 600, 250, 32)
  
  StartDrawing(ImageOutput(0))
  DrawingMode(#PB_2DDrawing_Default)
  Box(0, 0, 600, 250, RGB(0, 0, 110))
  StopDrawing()

  ImageGadget(0, 0, 0, 600, 250, ImageID(0))
  DisableGadget(0, #True)
  
  InitSprite() : InitKeyboard()
  OpenWindowedScreen(WindowID(0), 0, 0, 600, 250, #True, #False, #False)
  
  StartDrawing(ScreenOutput())
  DrawingMode(#PB_2DDrawing_Default)
  Box(0, 0, 600, 250, RGB(0, 0, 110))
  StopDrawing()
  
ContainerGadget(Cont_1, 115, 70, 350, 150, #PB_Container_Raised)
SetGadgetColor(Cont_1,#PB_Gadget_BackColor, RGB(0, 0, 150))
StringGadget(1, 45, 70, 250, 25, "")
SetActiveGadget(1)
CloseGadgetList()

  Repeat
    ExamineKeyboard()
    PlayerName = GetGadgetText(String_1)
    
    If KeyboardPushed(#PB_Key_Return) And return_key_down = #False
      Debug PlayerName
      return_key_down = #True
    ElseIf KeyboardReleased(#PB_Key_Return) And return_key_down = #True
      return_key_down = #False
      SetGadgetText(String_1, "")
      Break
    EndIf
    
  Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf

Last edited by Distorted Pixel on Wed Jul 03, 2024 1:02 am, edited 2 times in total.
To be popular is way to much work. I just want to be me, myself and I. Oh no, does that mean I'm bipolar? :shock:

No one cares how much you know until they know how much you care
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4955
Joined: Sun Apr 12, 2009 6:27 am

Re: Retrieve text from StringGadget that is inside ContainerGadget

Post by RASHAD »

What is your problem?

Code: Select all

EnableExplicit

Global PlayerName.s, return_key_down, String_1
Global Cont_1 = 0

If OpenWindow(0, 0, 0, 600, 250,"ContainerGadget with StringGadget",#PB_Window_SystemMenu|#PB_Window_SizeGadget|#PB_Window_ScreenCentered)
  SetWindowColor(0, RGB(0, 0, 190))
  
  InitSprite() : InitKeyboard()
  OpenWindowedScreen(WindowID(0), 0, 0, 600, 250, #True, #False, #False)
  
 CreateImage(0, 600, 250, 32)
 
 StartDrawing(ImageOutput(0))
 DrawingMode(#PB_2DDrawing_Default)
 Box(0, 0, 600, 250, RGB(10, 10, 110))
 StopDrawing()

ImageGadget(0, 0, 0, 600, 250, ImageID(0))
DisableGadget(0, #True)

ContainerGadget(Cont_1, 115, 70, 350, 150, #PB_Container_Raised)
SetGadgetColor(Cont_1,#PB_Gadget_BackColor, RGB(0, 0, 150))
StringGadget(1, 45, 70, 250, 25, "")
SetActiveGadget(1)
CloseGadgetList()

  Repeat
    ExamineKeyboard()
    If KeyboardPushed(#PB_Key_Return) ;And return_key_down = #False
      return_key_down = #True
    ElseIf KeyboardReleased(#PB_Key_Return) ;And return_key_down = #True
      return_key_down = #False
      Debug GetGadgetText(1)
      ;Break
    EndIf
    
  Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf
Egypt my love
User avatar
Distorted Pixel
Enthusiast
Enthusiast
Posts: 303
Joined: Sun Aug 29, 2021 4:34 am

Re: Retrieve text from StringGadget that is inside ContainerGadget

Post by Distorted Pixel »

RASHAD wrote: Wed Jul 03, 2024 12:57 am What is your problem?
The above code in my first post is just a quick example code that does the same thing as my original code. It won't debug the user typed string to the debug window. The debug opens, but is blank
To be popular is way to much work. I just want to be me, myself and I. Oh no, does that mean I'm bipolar? :shock:

No one cares how much you know until they know how much you care
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4955
Joined: Sun Apr 12, 2009 6:27 am

Re: Retrieve text from StringGadget that is inside ContainerGadget

Post by RASHAD »

It seems that Your IF conditions are wrong
No problem getting the text from the string gadget inside a container or no container at all
Egypt my love
User avatar
Distorted Pixel
Enthusiast
Enthusiast
Posts: 303
Joined: Sun Aug 29, 2021 4:34 am

Re: Retrieve text from StringGadget that is inside ContainerGadget

Post by Distorted Pixel »

I have fixed my example code in the first post. I found that I had a "1" in places that should have been String_1.

Unfortunately, it didn't help with figuring out why my original code is not working with the rest of the program. When I run the whole program, I get to the screen that the user can type in their name and press return key and I type a name and press return key and nothing happens. It doesn't clear what I type or close the window.

IceDesigner uses a fair amount of CompilerIf/EndCompilerIf statements and for me that is more complicated to some degree. I am also trying to use only one main game loop. So far up to this enter player name screen I have succeeded, but this screen is haunting me lol.

Code: Select all

EnableExplicit

Global PlayerName.s, return_key_down
Global Cont_1 = 0
Global String_1 = 1

If OpenWindow(0, 0, 0, 600, 250,"ContainerGadget with StringGadget",#PB_Window_SystemMenu|#PB_Window_SizeGadget|#PB_Window_ScreenCentered)
  
  CreateImage(0, 600, 250, 32)
  
  StartDrawing(ImageOutput(0))
  DrawingMode(#PB_2DDrawing_Default)
  Box(0, 0, 600, 250, RGB(0, 0, 110))
  StopDrawing()

  ImageGadget(0, 0, 0, 600, 250, ImageID(0))
  DisableGadget(0, #True)
  
  InitSprite() : InitKeyboard()
  OpenWindowedScreen(WindowID(0), 0, 0, 600, 250, #True, #False, #False)
  
  StartDrawing(ScreenOutput())
  DrawingMode(#PB_2DDrawing_Default)
  Box(0, 0, 600, 250, RGB(0, 0, 110))
  StopDrawing()
  
ContainerGadget(Cont_1, 115, 70, 350, 150, #PB_Container_Raised)
SetGadgetColor(Cont_1,#PB_Gadget_BackColor, RGB(0, 0, 150))
StringGadget(String_1, 45, 70, 250, 25, "")
SetActiveGadget(String_1)
CloseGadgetList()

  Repeat
    ExamineKeyboard()
    PlayerName = GetGadgetText(String_1)
    
    If KeyboardPushed(#PB_Key_Return) And return_key_down = #False
      Debug PlayerName
      return_key_down = #True
    ElseIf KeyboardReleased(#PB_Key_Return) And return_key_down = #True
      return_key_down = #False
      SetGadgetText(String_1, "")
      Break
    EndIf
    
  Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf

To be popular is way to much work. I just want to be me, myself and I. Oh no, does that mean I'm bipolar? :shock:

No one cares how much you know until they know how much you care
#NULL
Addict
Addict
Posts: 1499
Joined: Thu Aug 30, 2007 11:54 pm
Location: right here

Re: Retrieve text from StringGadget that is inside ContainerGadget

Post by #NULL »

You have an ImageGadget 0 and a ContainerGadget Cont_1 which is also 0, so that's a conflict right there. Your StringGadget problem might have a similar reason.
infratec
Always Here
Always Here
Posts: 7627
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: Retrieve text from StringGadget that is inside ContainerGadget

Post by infratec »

Works:

Code: Select all

EnableExplicit

Enumeration Gadget
  #Img_1
  #Cont_1
  #String_1
EndEnumeration


Global PlayerName.s, return_key_down


If OpenWindow(0, 0, 0, 600, 250,"ContainerGadget with StringGadget",#PB_Window_SystemMenu|#PB_Window_SizeGadget|#PB_Window_ScreenCentered)
  
  CreateImage(0, 600, 250, 32)
  
  StartDrawing(ImageOutput(0))
  DrawingMode(#PB_2DDrawing_Default)
  Box(0, 0, 600, 250, RGB(0, 0, 110))
  StopDrawing()

  ImageGadget(#Img_1, 0, 0, 600, 250, ImageID(0))
  DisableGadget(#Img_1, #True)
  
  InitSprite() : InitKeyboard()
  OpenWindowedScreen(WindowID(0), 0, 0, 600, 250, #True, #False, #False)
  
  StartDrawing(ScreenOutput())
  DrawingMode(#PB_2DDrawing_Default)
  Box(0, 0, 600, 250, RGB(0, 0, 110))
  StopDrawing()
  
  ContainerGadget(#Cont_1, 115, 70, 350, 150, #PB_Container_Raised)
  SetGadgetColor(#Cont_1,#PB_Gadget_BackColor, RGB(0, 0, 150))
  StringGadget(#String_1, 45, 70, 250, 25, "")
  SetActiveGadget(#String_1)
  CloseGadgetList()

  Repeat
    ExamineKeyboard()
    PlayerName = GetGadgetText(#String_1)
    
    If KeyboardPushed(#PB_Key_Return) And return_key_down = #False
      Debug PlayerName
      return_key_down = #True
    ElseIf KeyboardReleased(#PB_Key_Return) And return_key_down = #True
      return_key_down = #False
      SetGadgetText(#String_1, "")
      Break
    EndIf
    
  Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf
User avatar
Distorted Pixel
Enthusiast
Enthusiast
Posts: 303
Joined: Sun Aug 29, 2021 4:34 am

Re: Retrieve text from StringGadget that is inside ContainerGadget

Post by Distorted Pixel »

#NULL wrote: Wed Jul 03, 2024 5:41 am You have an ImageGadget 0 and a ContainerGadget Cont_1 which is also 0, so that's a conflict right there. Your StringGadget problem might have a similar reason.
In my last post with code, I changed certain variable numbers so they would be different and it works.

@infratec
Yes, that code works, and so does the code in my last post with code.

I did forget to mention that in the original code, all gadgets are set with #PB_Any so they are all different

I will try to put together a new example created with IceDesigner. I will post it when I get it finished.
To be popular is way to much work. I just want to be me, myself and I. Oh no, does that mean I'm bipolar? :shock:

No one cares how much you know until they know how much you care
User avatar
blueb
Addict
Addict
Posts: 1116
Joined: Sat Apr 26, 2003 2:15 pm
Location: Cuernavaca, Mexico

Re: Retrieve text from StringGadget that is inside ContainerGadget

Post by blueb »

IceDesign offers many ways to do things. Personally I don't like to use '#PB_Any'.
I find it adds a lot of 'fluff', although I have used it in some instances.

I prefer to use the '#Constants' option along with the 'Bind All Gadgets Events' flag, so that my events are isolated to my liking.

Just say'in :D
- It was too lonely at the top.

System : PB 6.21(x64) and Win 11 Pro (x64)
Hardware: AMD Ryzen 9 5900X w/64 gigs Ram, AMD RX 6950 XT Graphics w/16gigs Mem
User avatar
mk-soft
Always Here
Always Here
Posts: 6263
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: Retrieve text from StringGadget that is inside ContainerGadget

Post by mk-soft »

That's how I see it too.

I also always use constants with named enumeration.
No unnecessary variables, clear assignment.
With my EventDesigner, I can then also call the function for events with a virtual table.
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
User avatar
Distorted Pixel
Enthusiast
Enthusiast
Posts: 303
Joined: Sun Aug 29, 2021 4:34 am

Re: Retrieve text from StringGadget that is inside ContainerGadget

Post by Distorted Pixel »

[/quote]
blueb wrote: Wed Jul 03, 2024 1:44 pm IceDesign offers many ways to do things. Personally I don't like to use '#PB_Any'.
I find it adds a lot of 'fluff', although I have used it in some instances.

I prefer to use the '#Constants' option along with the 'Bind All Gadgets Events' flag, so that my events are isolated to my liking.

Just say'in :D
I have to say I agree now, I like the #Constants because if you use Enumeration/EndEnumeration it numbers them for you.
I can't say I like using #PB_Any myself either now unless needed for specific situations(what ever they may be lol)
mk-soft wrote: Wed Jul 03, 2024 4:26 pm That's how I see it too.

I also always use constants with named enumeration.
No unnecessary variables, clear assignment.
With my EventDesigner, I can then also call the function for events with a virtual table.
I have tested your EventDesigner and I like the idea, but it was kind of confusing to me. I don't know if you have updated it since I have tested it so I'd have to take a look at it again.

Below is a example project only to download. I set it up just like the original project I'm working on, but I used cheesy quick images I created in Gimp for this example. I created it with IceDesigner using #Constants
I will be removing the link at some point soon. THE DOWNLOAD DOES NOT INCLUDE ICEDESIGNER SOFTWARE just the test project folder

Run the program and click the Splash Screen image to continue to the next screen

https://mega.nz/file/E9sXyJKJ#_ZdCjTRIY ... NYiEPzqdIA
Last edited by Distorted Pixel on Fri Jul 05, 2024 9:09 pm, edited 3 times in total.
To be popular is way to much work. I just want to be me, myself and I. Oh no, does that mean I'm bipolar? :shock:

No one cares how much you know until they know how much you care
#NULL
Addict
Addict
Posts: 1499
Joined: Thu Aug 30, 2007 11:54 pm
Location: right here

Re: Retrieve text from StringGadget that is inside ContainerGadget

Post by #NULL »

Here on linux, normal gadgets mixed with a screen don't work (especially not overlapping). I think the screen continuously steals the focus from the StringGadget.
You also need a Flipbuffers() once per frame I think if you use a screen.
And you need a proper event handling, processing all events once per frame, not just one event per frame.
If all that doesn't apply to Windows (I don't know really) then forget about my post :)
Post Reply