StringGadget() change font

Just starting out? Need help? Post your questions and find answers here.
Alessandro777
Posts: 4
Joined: Fri Feb 02, 2024 3:06 pm

StringGadget() change font

Post 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!
User avatar
Peter
Posts: 1197
Joined: Mon Feb 24, 2014 10:17 pm
Location: 127.0.0.1:9080
Contact:

Re: StringGadget() change font

Post 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
Alessandro777
Posts: 4
Joined: Fri Feb 02, 2024 3:06 pm

Re: StringGadget() change font

Post 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).
Post Reply