[Solved] OptionGadgets and ampersand

Windows specific forum
BarryG
Addict
Addict
Posts: 3318
Joined: Thu Apr 18, 2019 8:17 am

[Solved] OptionGadgets and ampersand

Post by BarryG »

How can I make all three OptionGadgets below show their respective number of ampersands? That is, I specifically want to see "1&" for the first one, "2&&" for the second, and "3&&&" for the third. Reason is that the OptionGadget text has to match exactly what is in the clipboard, and sometimes the clipboard has "&&" or "&&&" in it.

Code: Select all

If OpenWindow(0, 300, 200, 140, 110, "OptionGadgets", #PB_Window_SystemMenu)
  OptionGadget(0, 30, 20, 100, 20, "Option 1&")
  OptionGadget(1, 30, 45, 100, 20, "Option 2&&")
  OptionGadget(2, 30, 70, 100, 20, "Option 3&&&")
  Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf
Image
Last edited by BarryG on Tue Sep 03, 2019 4:50 am, edited 1 time in total.
Saboteur
Enthusiast
Enthusiast
Posts: 272
Joined: Fri Apr 25, 2003 7:09 pm
Location: (Madrid) Spain
Contact:

Re: OptionGadgets and ampersand

Post by Saboteur »

I am testing PB 5.71 on MAC OS and do it well.
What is your version?
[:: PB Registered ::]

Win10 Intel core i5-3330 8GB RAM Nvidia GTX 1050Ti
Sirius-2337
User
User
Posts: 53
Joined: Sat May 14, 2011 10:39 am

Re: OptionGadgets and ampersand

Post by Sirius-2337 »

Code: Select all

If OpenWindow(0, 300, 200, 140, 110, "OptionGadgets", #PB_Window_SystemMenu)
  OptionGadget(0, 30, 20, 100, 20, "Option 1&&")
  OptionGadget(1, 30, 45, 100, 20, "Option 2&&&&")
  OptionGadget(2, 30, 70, 100, 20, "Option 3&&&&&&")
  Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf
Saboteur
Enthusiast
Enthusiast
Posts: 272
Joined: Fri Apr 25, 2003 7:09 pm
Location: (Madrid) Spain
Contact:

Re: OptionGadgets and ampersand

Post by Saboteur »

Sirius-2337 wrote:

Code: Select all

If OpenWindow(0, 300, 200, 140, 110, "OptionGadgets", #PB_Window_SystemMenu)
  OptionGadget(0, 30, 20, 100, 20, "Option 1&&")
  OptionGadget(1, 30, 45, 100, 20, "Option 2&&&&")
  OptionGadget(2, 30, 70, 100, 20, "Option 3&&&&&&")
  Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf
In MAC this not fix the problem.
Works this in a different way in Mac and Windows?
[:: PB Registered ::]

Win10 Intel core i5-3330 8GB RAM Nvidia GTX 1050Ti
User avatar
Derren
Enthusiast
Enthusiast
Posts: 313
Joined: Sat Jul 23, 2011 1:13 am
Location: Germany

Re: OptionGadgets and ampersand

Post by Derren »

Yes, it's a windows issue.

I could have sworn "&" was used in Menus to underscore a character to show the key associated with a command. Apparently that's not the case anymore in windows 10.
The function is still there, though.

Open the Menu in this code and hit the keys N, O or X.

Code: Select all

If OpenWindow(0, 300, 200, 140, 150, "OptionGadgets", #PB_Window_SystemMenu)
	CreateMenu(0, WindowID(0))
	MenuTitle("Menu")
	MenuItem(1, "Option 1 Press &N")
	MenuItem(2, "Option 2 Press &O")
	MenuItem(3, "Option 3 Press &X")
	
	OptionGadget(0, 30, 20, 100, 25, "Option 1 Press &A")
	OptionGadget(1, 30, 45, 100, 25, "Option 2 Press &B")
	OptionGadget(2, 30, 70, 100, 25, "Option 3 Press &C")
	Repeat
		e=WaitWindowEvent()	
		If e=#PB_Event_Menu
			Select EventMenu()
				Case 1: MessageRequester("Menu", "Option 1 / N")
				Case 2: MessageRequester("Menu", "Option 2 / O")
				Case 3: MessageRequester("Menu", "Option 3 / X")
			EndSelect 
		EndIf 
	Until e= #PB_Event_CloseWindow
EndIf
I thought maybe it's a relict of that time.
The way it is now, is useless, though (still works with menus but no visual cue, and doesn't do anything for the Option Gadget)

I'm just not sure if PB can do anything about it.
BarryG
Addict
Addict
Posts: 3318
Joined: Thu Apr 18, 2019 8:17 am

Re: OptionGadgets and ampersand

Post by BarryG »

Sirius-2337, so I just have to double the count when using them with OptionGadgets? That works, but it's a shame there's no simple flag or something for the OptionGadget to avoid having to do a string operation each time.

Code: Select all

Procedure.s KeepAmpersands(text$)
  ProcedureReturn ReplaceString(text$,"&","&&")
EndProcedure

If OpenWindow(0, 300, 200, 140, 110, "OptionGadgets", #PB_Window_SystemMenu)
  OptionGadget(0, 30, 20, 100, 20, KeepAmpersands("Option 1&"))
  OptionGadget(1, 30, 45, 100, 20, KeepAmpersands("Option 2&&"))
  OptionGadget(2, 30, 70, 100, 20, KeepAmpersands("Option 3&&&"))
  Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf
Image
User avatar
kenmo
Addict
Addict
Posts: 1967
Joined: Tue Dec 23, 2003 3:54 am

Re: OptionGadgets and ampersand

Post by kenmo »

Yes, it's different on Windows and Mac. That's something to be aware of for cross-platform GUIs.

No, it's not useless!

On Windows you use "&" to underline the next character. As Derren said, in a menu, it also sets what key will trigger that item.

To display an ampersand character, you double it to "&&".

The underline used to always be visible (a long time ago). Since Windows 7 (or maybe earlier) it's hidden by default, you can show the underlined letters by activating the menu by keyboard (press Alt).
(You can also enable the underlines all the time: https://www.groovypost.com/howto/make-w ... tcut-keys/ )

In an OptionGadget, it doesn't automatically add a hotkey. But it's still useful to indicate keyboard shortcuts (which you add manually). Microsoft Excel uses this.

If you don't want to underline anything, you can easily write a function that turns "&" to "&&" on Windows:

Code: Select all

Procedure.s GUIEscape(Text.s)
  CompilerIf (#PB_Compiler_OS = #PB_OS_Windows)
    ProcedureReturn (ReplaceString(Text, "&", "&&"))
  CompilerElse
    ProcedureReturn (Text)
  CompilerEndIf
EndProcedure


If OpenWindow(0, 300, 200, 140, 110, "OptionGadgets", #PB_Window_SystemMenu)
  OptionGadget(0, 30, 20, 100, 20, GUIEscape("Option 1&"))
  OptionGadget(1, 30, 45, 100, 20, GUIEscape("Option 2&&"))
  OptionGadget(2, 30, 70, 100, 20, GUIEscape("Option 3&&&"))
  Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf

EDIT: Yeah, you figured it out
BarryG
Addict
Addict
Posts: 3318
Joined: Thu Apr 18, 2019 8:17 am

Re: OptionGadgets and ampersand

Post by BarryG »

kenmo wrote:you figured it out
Sorry, yes. Post title changed to solved.
Post Reply