How to resize a gadget when font size can change ?

Just starting out? Need help? Post your questions and find answers here.
Phlos
User
User
Posts: 85
Joined: Fri May 16, 2003 7:17 pm

How to resize a gadget when font size can change ?

Post by Phlos »

Hello,

I want to know how to resize a gadget to fit it to any Windows font size configuration ?! :?
I tried this kind of code :

Code: Select all

If OpenWindow(0, 0, 0, 200, 200, "", #PB_Window_ScreenCentered | #PB_Window_MinimizeGadget)
  ComboBoxGadget(1, 0, 0, 100, 100)
  AddGadgetItem(1, -1, "String #1")
  AddGadgetItem(1, -1, "String #2")
  SetGadgetState(1, 1)
  
  ResizeGadget(1, #PB_Ignore, #PB_Ignore, GadgetWidth(1, #PB_Gadget_RequiredSize), GadgetHeight(1, #PB_Gadget_RequiredSize))
  
  Repeat
    If WaitWindowEvent() = #PB_Event_CloseWindow
      Break
    EndIf
  ForEver
EndIf
But the gadget is now even worst, we can't even see text. Is it a bug in PB or am I missing something ? :?:

Thank you !
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: How to resize a gadget when font size can change ?

Post by netmaestro »

Code: Select all

If OpenWindow(0, 0, 0, 200, 200, "", #PB_Window_ScreenCentered | #PB_Window_MinimizeGadget)
  ComboBoxGadget(1, 0, 0, 100, 25)
  AddGadgetItem(1, -1, "String #1")
  AddGadgetItem(1, -1, "String #2")
  SetGadgetState(1, 1)
  LoadFont(0, "arial", 24)
  SetGadgetFont(1, FontID(0))
  
  ButtonGadget(2, 50, 170, 100, 20, "Fix Combo Size")
  
  Repeat
    event=WaitWindowEvent()
    If event = #PB_Event_CloseWindow
      Break
    EndIf
    If event = #PB_Event_Gadget And EventGadget()=2
      font = GetGadgetFont(1)
      CreateImage(0, 100, 100)
      StartDrawing(ImageOutput(0))
        DrawingFont(font)
        h = TextHeight(GetGadgetText(1))+8
        w = TextWidth(GetGadgetText(1))+GadgetWidth(1, #PB_Gadget_RequiredSize)
      StopDrawing()
      FreeImage(0)
      ResizeGadget(1, #PB_Ignore, #PB_Ignore, w, h)
  
    EndIf
  ForEver
EndIf
BERESHEIT
Post Reply