Page 1 of 1

StringGadget() change font

Posted: Fri Feb 02, 2024 3:09 pm
by Alessandro777
Hello,

it seems there is no way to change the font of a StringGadget. I use this code but has no effect (only font size changes):

Code: Select all

Global FONT_MONOSPACE_16 = LoadFont(#PB_Any, "Courier", 16)

fldEmail = StringGadget(#PB_Any, 110, 10, 200, 25, "")
SetGadgetFont(fldEmail , FontID(FONT_MONOSPACE_16))
Please can you help me?

Thank you!

Re: StringGadget() change font

Posted: Fri Feb 02, 2024 3:29 pm
by Peter
Works as expected:

Image

Code: Select all

Global FONT_MONOSPACE_16 = LoadFont(#PB_Any, "Courier", 16)

If OpenWindow(0, 0, 0, 322, 80, "StringGadgets", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  NomalGadget = StringGadget(#PB_Any, 8,  10, 306, 20, "Normal StringGadget...")
  MonospaceGadget = StringGadget(#PB_Any, 8,  35, 306, 20, "Monospace StringGadget...")
  SetGadgetFont(MonospaceGadget, FontID(FONT_MONOSPACE_16))
EndIf
// Addendum: I have just seen that this only works with flat.css. With claro.css the font does not change. Looks like a bug.

Image

Re: StringGadget() change font

Posted: Fri Feb 02, 2024 3:52 pm
by Alessandro777
Hello,

I tried your code but does NOT work for me. I tried in Opera Browser and Ms Edge but I get the same result:
Image

Just to show you the issue, I also added a TextGadget (and it works...).

Code:

Code: Select all

If OpenWindow(0, 0, 0, 322, 80, "StringGadgets", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
    NomalGadget = StringGadget(#PB_Any, 8,  10, 306, 20, "Normal StringGadget...")
    MonospaceGadget = StringGadget(#PB_Any, 8,  35, 306, 20, "Monospace StringGadget...")
    
    labelGadget = TextGadget(#PB_Any, 8,  60, 306, 20, "Monospace TextGadget...")
    
    f = LoadFont(#PB_Any, "Courier", 16)
    SetGadgetFont(MonospaceGadget, FontID(f))
    SetGadgetFont(labelGadget, FontID(f))
  EndIf
I'm using SpiderBasic 2.51 (x86).

//// EDIT: CONFIRMED, it works in FLAT theme. Yes, maybe is a bug. Thank you (I work in flat mode for now).