[solution provided by mk-soft] gadget hidden or not?

Just starting out? Need help? Post your questions and find answers here.
eck49
Enthusiast
Enthusiast
Posts: 153
Joined: Sat Nov 14, 2020 10:08 pm
Location: England

[solution provided by mk-soft] gadget hidden or not?

Post by eck49 »

Is there a way of knowing whether a gadget is hidden or not?

There may be many paths to a particular point in the code, some of which will leave the gadget hidden and some showing.

At this point, I want to fill the gadget (in this case a textgadget), show it and after a while restore its previous content and maybe hide it again. But hide it only if it was previously hidden. All very simple, except for the lack of a function to tell me whether a gadget is currently hidden.

Code: Select all

Protected.i hh
Protected.s st
st = GetGadgetText(#txtgad)
hh = IsVisible(#txtgad)     <<<< or something functionally equivalent
SetGadgetText(#txtgad, "Here is the latest news")
HideGadget(#txtgad, 0)
--do some other stuff--
HideGadget(#txtgad, hh)
SetGadgetText(#txtgad, st)
Last edited by eck49 on Sat Jun 05, 2021 7:16 pm, edited 1 time in total.
Ubuntu 22.04 64-bit
Purebasic 6.00 (as of 5 Sep 2022)
(native tongue: English)
User avatar
Saki
Addict
Addict
Posts: 830
Joined: Sun Apr 05, 2020 11:28 am
Location: Pandora

Re: gadget hidden or not?

Post by Saki »

You can set a flag with SetGadgetData()
地球上の平和
eck49
Enthusiast
Enthusiast
Posts: 153
Joined: Sat Nov 14, 2020 10:08 pm
Location: England

Re: gadget hidden or not?

Post by eck49 »

@Saki

Wouldn't the flag need to be set every time the gadget was Hidden/Shown? Could be a lot of work! Like having a dedicated variable for the task.
Ubuntu 22.04 64-bit
Purebasic 6.00 (as of 5 Sep 2022)
(native tongue: English)
User avatar
Keya
Addict
Addict
Posts: 1891
Joined: Thu Jun 04, 2015 7:10 am

Re: gadget hidden or not?

Post by Keya »

in Windows there is the IsWindowVisible(hWnd) API function, I'm not sure if it works with controls though
eck49
Enthusiast
Enthusiast
Posts: 153
Joined: Sat Nov 14, 2020 10:08 pm
Location: England

Re: gadget hidden or not?

Post by eck49 »

@Keya

Nice thought, but I'm on Linux.
Ubuntu 22.04 64-bit
Purebasic 6.00 (as of 5 Sep 2022)
(native tongue: English)
User avatar
mk-soft
Always Here
Always Here
Posts: 5409
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: gadget hidden or not?

Post by mk-soft »

Code: Select all

;-TOP

; IsGadgetVisible by mk-soft, v1.01.1, 05.06.2021, All OS

CompilerIf #PB_Compiler_OS = #PB_OS_Linux
  ImportC ""
    gtk_widget_is_visible(widget)
  EndImport
CompilerEndIf

Procedure IsGadgetVisible(Gadget)
  
  CompilerSelect #PB_Compiler_OS
    CompilerCase #PB_OS_Windows
      ProcedureReturn IsWindowVisible_(GadgetID(Gadget))
      
    CompilerCase #PB_OS_MacOS
      ProcedureReturn Bool(Not CocoaMessage(0, GadgetID(Gadget), "isHidden"))
      
    CompilerCase #PB_OS_Linux
      ProcedureReturn gtk_widget_is_visible(GadgetID(Gadget))
      
  CompilerEndSelect
  
EndProcedure

; ****

Enumeration Windows
  #Main
EndEnumeration

Enumeration Gadgets
  #Text
EndEnumeration

Enumeration Status
  #MainStatusBar
EndEnumeration

Procedure Main()
  
  #MainStyle = #PB_Window_SystemMenu | #PB_Window_MaximizeGadget | #PB_Window_MinimizeGadget
  
  If OpenWindow(#Main, #PB_Ignore, #PB_Ignore, 800, 600, "Window" , #MainStyle)
    
    TextGadget(#Text, 10, 10, 790, 25, "Hello World!")
    
    HideGadget(#Text, #True)
    r1 = IsGadgetVisible(#Text)
    Debug r1
    
    HideGadget(#Text, #False)
    r1 = IsGadgetVisible(#Text)
    Debug r1
     
    Repeat
      Select WaitWindowEvent()
        Case #PB_Event_CloseWindow
          Break
      EndSelect
    ForEver
    
  EndIf
  
EndProcedure : Main()
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
eck49
Enthusiast
Enthusiast
Posts: 153
Joined: Sat Nov 14, 2020 10:08 pm
Location: England

Re: [solution provided by mk-soft] gadget hidden or not?

Post by eck49 »

@mk-soft

Thanks - great to have your expertise & knowledge on side.
I'll mark as solved although I can't personally vouch for Windows & Mac.
Ubuntu 22.04 64-bit
Purebasic 6.00 (as of 5 Sep 2022)
(native tongue: English)
BarryG
Addict
Addict
Posts: 3330
Joined: Thu Apr 18, 2019 8:17 am

Re: [solution provided by mk-soft] gadget hidden or not?

Post by BarryG »

eck49 wrote: Sat Jun 05, 2021 7:18 pmI can't personally vouch for Windows
This is for Windows:

Code: Select all

Debug IsWindowVisible_(GadgetID(gad))
Post Reply