Page 1 of 1

Required StringGadget Height

Posted: Sat Mar 14, 2020 12:11 pm
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

Re: Set Required StringGadget Height

Posted: Sat Mar 14, 2020 4:17 pm
by mk-soft
Update...

Replace PB Function GadgetHeight :wink: