Page 1 of 1

Ampersand doesn't appear in option gadget text

Posted: Mon Dec 19, 2016 10:10 am
by Axeman
The problem that I'm having is that ampersands don't appear in option gadget text.

Example Code

Code: Select all

If OpenWindow(0, 0, 0, 140, 80, "OptionGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
	OptionGadget(0, 10, 10, 120, 20, "Option 1 - &Test")
	OptionGadget(1, 10, 30, 120, 20, "Option 2 - &Test")
	OptionGadget(2, 10, 50, 120, 20, "Option 3 - &Test")
	SetGadgetState(1, 1)   ; set second option as active one
	Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf

This issue appears to be something to do with a Windows #SS_NOPREFIX flag near as i can tell from the forum posts below. This seems to be a behavior that was changed for some gadgets (TextGadgets) a few years ago, but doesn't seem to have been changed for OptionGadgets. I can't see the point of having this behavior for OptionGadgets as it doesn't achieve anything useful, so I assume this is some kind of bug or oversight.

A couple of threads that seem to be related.
http://www.purebasic.fr/english/viewtop ... 13&t=61540
http://www.purebasic.fr/english/viewtop ... 13&t=58677

I can't seem to disable this nonsense either. Surely there's some way of including an ampersand in OptionGadget text?

Code: Select all

If OpenWindow(0, 0, 0, 140, 80, "OptionGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
	OptionGadget(0, 10, 10, 120, 20, "Option 1 - &Test")
	OptionGadget(1, 10, 30, 120, 20, "Option 2 - &Test")
	OptionGadget(2, 10, 50, 120, 20, "Option 3 - &Test")
	SetGadgetState(1, 1)   ; set second option as active one
	SetWindowLongPtr_( GadgetID( 0 ), #GWL_STYLE, GetWindowLongPtr_( GadgetID( 0 ), #GWL_STYLE ) | #SS_NOPREFIX )
	SetGadgetText( 0, "Option X - &Test" )
	Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf

Re: Ampersand doesn't appear in option gadget text

Posted: Mon Dec 19, 2016 10:16 am
by TI-994A
Axeman wrote:...Surely there's some way of including an ampersand in OptionGadget text?
Just prefix another ampersand:

Code: Select all

If OpenWindow(0, 0, 0, 140, 80, "OptionGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
   OptionGadget(0, 10, 10, 120, 20, "Option 1 - &&Test")
   OptionGadget(1, 10, 30, 120, 20, "Option 2 - &&Test")
   OptionGadget(2, 10, 50, 120, 20, "Option 3 - &&Test")
   SetGadgetState(1, 1)   ; set second option as active one
   Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf

Re: Ampersand doesn't appear in option gadget text

Posted: Mon Dec 19, 2016 10:19 am
by Mistrel
The ampersand will underline up to a single following letter in the denoted string and is meant to provide a hint for accelerators such as alt-key shortcuts. You have to escape it with "&&".

I only know that this is the functionality by-design for Win32. It might behave differently on other platforms.

Re: Ampersand doesn't appear in option gadget text

Posted: Mon Dec 19, 2016 10:55 am
by Axeman
Ok, thanks for the info. The double ampersand fix worked for me.

I think this really needs to be added somewhere in the Purebasic docs, though. Possibly in the main 'Gadgets' documentation page.

Re: Ampersand doesn't appear in option gadget text

Posted: Sat Apr 21, 2018 9:30 pm
by Andre
I leave to this for Fred/freak to check + comment, especially to be aware of probably different behaviour on the different supported OS.
(furthermore I wouldn't be sure, where the best place is to add a note in the docs...)