Focus of Cursor

Just starting out? Need help? Post your questions and find answers here.
matalog
Enthusiast
Enthusiast
Posts: 165
Joined: Tue Sep 05, 2017 10:07 am

Focus of Cursor

Post by matalog »

Is there something that will return a 1 if a StringGadget or ButtonGadget has the focus or cursor blinking in it and a 0 if it does not have the focus? What I mean by focus is: If I place the cursor in one StringGadget then press TAB the 'Focus' (In this case, the cursor) moves to the next StringGadget or Button Gadget (in the case of a ButtonGadget there is a dotted rectangle around the button text) to the right, or next line down and left most, if right most gadget has been met.

I require this to work for StringGadgets and ButtonGadgets.

I will check to see which row of gadgets has the focus and that will determine which ButtonGadget is 'clicked' or activated when I press the Enter Key.
User avatar
Mijikai
Addict
Addict
Posts: 1360
Joined: Sun Sep 11, 2016 2:17 pm

Re: Focus of Cursor

Post by Mijikai »

Do you have code for the window and gadgets to experiment with?
Last edited by Mijikai on Sun Nov 29, 2020 6:56 pm, edited 3 times in total.
matalog
Enthusiast
Enthusiast
Posts: 165
Joined: Tue Sep 05, 2017 10:07 am

Re: Focus of Cursor

Post by matalog »

Yes, something like this:

Code: Select all

EnableExplicit


Enumeration
  #InputText
  #InputString
  #ResultText
  #ResultString
  #ConvertButton
EndEnumeration



Define Event.i, Exit.i, Input$

OpenWindow(0, 0, 0, 220, 100, "Inch To cm", #PB_Window_SystemMenu|#PB_Window_ScreenCentered)
TextGadget(#InputText, 10, 10, 60, 20, "Input")
TextGadget(#ResultText, 150, 10, 60, 20, "Result")
StringGadget(#InputString, 10, 40, 60, 20, "0")
ButtonGadget(#ConvertButton, 80, 40, 60, 20, "Convert")
StringGadget(#ResultString, 150, 40, 60, 20, "0")


Repeat
 
  Event = WaitWindowEvent()
 
  Select Event
    Case #PB_Event_Gadget
      Select EventGadget()
        Case #InputString
          Input$ = GetGadgetText(#InputString)
          If Input$ = ""
            DisableGadget(#ConvertButton, #True)
          Else
            DisableGadget(#ConvertButton, #False)
          EndIf
        Case #ConvertButton
          SetGadgetText(#ResultString, StrF(ValD(GetGadgetText(#InputString)) * 2.54, 3))
      EndSelect
     
    Case #PB_Event_CloseWindow
      Exit = #True
  EndSelect
 
Until Exit
I have extended that to 2 rows of StringGadgets and ButtonGadgets
User avatar
Mijikai
Addict
Addict
Posts: 1360
Joined: Sun Sep 11, 2016 2:17 pm

Re: Focus of Cursor

Post by Mijikai »

Mby this helps...

Code: Select all

Procedure.i GadgetActive(Gadget.i)
  ProcedureReturn Bool(Gadget = GetActiveGadget())
EndProcedure 
Or do you need a GadgetHover() function?
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4664
Joined: Sun Apr 12, 2009 6:27 am

Re: Focus of Cursor

Post by RASHAD »

Hi

Code: Select all

EnableExplicit

Enumeration
  #InputText
  #InputString
  #ResultText
  #ResultString
  #ConvertButton
  #TextGadget
EndEnumeration

Define Event.i, Exit.i, Input$

OpenWindow(0, 0, 0, 220, 100, "Inch To cm", #PB_Window_SystemMenu|#PB_Window_ScreenCentered)
TextGadget(#InputText, 10, 10, 60, 20, "Input")
TextGadget(#ResultText, 150, 10, 60, 20, "Result")
StringGadget(#InputString, 10, 40, 60, 20, "0")
ButtonGadget(#ConvertButton, 80, 40, 60, 20, "Convert")
StringGadget(#ResultString, 150, 40, 60, 20, "0")

TextGadget(#TextGadget,10,70,200,20,"Gadget : "+Str(GetActiveGadget())+" has the focus")
AddWindowTimer(0,10,100)
Repeat 
  Event = WaitWindowEvent()
 
  Select Event
    Case #PB_Event_Timer
      SetGadgetText(#TextGadget,"Gadget : "+Str(GetActiveGadget())+" has the focus")
        
    Case #PB_Event_Gadget
      Select EventGadget()
        Case #InputString
          Input$ = GetGadgetText(#InputString)
          If Input$ = ""
            DisableGadget(#ConvertButton, #True)
          Else
            DisableGadget(#ConvertButton, #False)
          EndIf
        Case #ConvertButton
          SetGadgetText(#ResultString, StrF(ValD(GetGadgetText(#InputString)) * 2.54, 3))
      EndSelect
     
    Case #PB_Event_CloseWindow
      Exit = #True
  EndSelect
 
Until Exit
Egypt my love
matalog
Enthusiast
Enthusiast
Posts: 165
Joined: Tue Sep 05, 2017 10:07 am

Re: Focus of Cursor

Post by matalog »

Brilliant Guys, thanks.
Post Reply