Required StringGadget Height

Mac OSX specific forum
User avatar
mk-soft
Always Here
Always Here
Posts: 5406
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Required StringGadget Height

Post by mk-soft »

Update v1.04

Code: Select all

;-TOP by mk-soft, v1.04, 15.03.2020

CompilerIf #PB_Compiler_OS = #PB_OS_MacOS
  
  Procedure OSX_GadgetHeight(Gadget, Mode = #PB_Gadget_ActualSize)
    Protected top.d, bottom.d, height
    
    If Mode = #PB_Gadget_RequiredSize
      If GadgetType(Gadget) = #PB_GadgetType_String Or GadgetType(Gadget) = #PB_GadgetType_Text
        CocoaMessage(@top, GadgetID(Gadget), "firstBaselineOffsetFromTop")
        CocoaMessage(@bottom, GadgetID(Gadget), "lastBaselineOffsetFromBottom")
        height = top + bottom + 2.0
        ProcedureReturn height
      EndIf
    EndIf
    ProcedureReturn GadgetHeight(Gadget, Mode)
  EndProcedure
  
  Macro GadgetHeight(Gadget, Mode = #PB_Gadget_ActualSize)
    OSX_GadgetHeight(Gadget, Mode)
  EndMacro
  
CompilerEndIf

; ****

CompilerIf #PB_Compiler_IsMainFile
  
  LoadFont(0, "Arial", 13)
  LoadFont(1, "Arial", 28)
  LoadFont(2, "Arial", 36)
  
  If OpenWindow(0, 0, 0, 400, 200, "StringGadget Flags", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
    StringGadget(0, 10,  10, 380, 23, "Normal StringGadget...")
    SetGadgetFont(0, FontID(0))
    ResizeGadget(0, #PB_Ignore, #PB_Ignore, #PB_Ignore, GadgetHeight(0, #PB_Gadget_RequiredSize))
    
    StringGadget(1, 10,  60, 380, 23, "Big StringGadget...")
    SetGadgetFont(1, FontID(1))
    ResizeGadget(1, #PB_Ignore, #PB_Ignore, #PB_Ignore, GadgetHeight(1, #PB_Gadget_RequiredSize))
    
    TextGadget(2, 10,  120, 380, 23, "Big TextGadget...")
    SetGadgetFont(2, FontID(2))
    ResizeGadget(2, #PB_Ignore, #PB_Ignore, #PB_Ignore, GadgetHeight(2, #PB_Gadget_RequiredSize))
    
    Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
  EndIf
  
CompilerEndIf
Last edited by mk-soft on Sun Mar 15, 2020 12:46 pm, edited 1 time in total.
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
User avatar
mk-soft
Always Here
Always Here
Posts: 5406
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: Set Required StringGadget Height

Post by mk-soft »

Update...

Replace PB Function GadgetHeight :wink:
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
Post Reply