Page 1 of 1

[Solved] OptionGadgets and ampersand

Posted: Mon Sep 02, 2019 2:00 pm
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

Re: OptionGadgets and ampersand

Posted: Mon Sep 02, 2019 2:18 pm
by Saboteur
I am testing PB 5.71 on MAC OS and do it well.
What is your version?

Re: OptionGadgets and ampersand

Posted: Mon Sep 02, 2019 2:31 pm
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

Re: OptionGadgets and ampersand

Posted: Mon Sep 02, 2019 3:29 pm
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?

Re: OptionGadgets and ampersand

Posted: Mon Sep 02, 2019 3:39 pm
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.

Re: OptionGadgets and ampersand

Posted: Tue Sep 03, 2019 12:56 am
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

Re: OptionGadgets and ampersand

Posted: Tue Sep 03, 2019 2:27 am
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

Re: OptionGadgets and ampersand

Posted: Tue Sep 03, 2019 4:51 am
by BarryG
kenmo wrote:you figured it out
Sorry, yes. Post title changed to solved.