Scrollbar width?
Posted: Sat Jan 04, 2014 2:23 am
I'm looking for a way to get the width of a vertical scrollbar in a scrollarea (pretty much like a getsystemmetrics(#SM_CXVSCROLL) for windows). Does anyone know how to do that?
http://www.purebasic.com
https://www.purebasic.fr/english/
Code: Select all
If OpenWindow(0, 0, 0, 200, 200, "Test", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
ScrollBarGadget(0, 10, 10, 0, 100, 0, 100, 10, #PB_ScrollBar_Vertical)
w = GadgetWidth(0, #PB_Gadget_RequiredSize)
ResizeGadget(0, #PB_Ignore, #PB_Ignore, w, #PB_Ignore)
Repeat
Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf
Code: Select all
EnableExplicit
#NSScrollerKnobSlot = 6
#NSScrollerStyleOverlay = 1
#NSSmallControlSize = 1
Procedure GetVerticalScrollBarWidth(ScrollAreaGadgetID.I)
Protected Rect.NSRect
Protected VerticalScrollBar.I
Protected VerticalScrollBarWidth.I
VerticalScrollBar = CocoaMessage(0, GadgetID(ScrollAreaGadgetID), "verticalScroller")
CocoaMessage(@Rect, VerticalScrollBar, "rectForPart:", #NSScrollerKnobSlot)
VerticalScrollBarWidth = Int(Rect\size\width)
If OSVersion() > #PB_OS_MacOSX_10_6
If CocoaMessage(0, VerticalScrollBar, "scrollerStyle") = #NSScrollerStyleOverlay
VerticalScrollBarWidth = 0
Else
VerticalScrollBarWidth + 1
EndIf
EndIf
ProcedureReturn VerticalScrollBarWidth
EndProcedure
Define ContentWidth.I
Define VerticalScrollBarWidth.I
OpenWindow(0, 270, 100, 240, 210, "ScrollAreaGadget")
ScrollAreaGadget(0, 10, 10, WindowWidth(0) - 20, 70, WindowWidth(0) - 37, 200)
SetGadgetColor(0, #PB_Gadget_BackColor, $6BB7BD)
VerticalScrollBarWidth = GetVerticalScrollBarWidth(0)
ContentWidth = GadgetWidth(0) - VerticalScrollBarWidth
TextGadget(1, 10, 10, GadgetWidth(0), 25, "Width of vertical scroll bar: " +
Str(VerticalScrollBarWidth))
CloseGadgetList()
TextGadget(2, 10, 81, ContentWidth, 18, "Usable content width: " + Str(ContentWidth), #PB_Text_Center)
SetGadgetColor(2, #PB_Gadget_BackColor, $6BB7BD)
ScrollAreaGadget(3, 10, 110, WindowWidth(0) - 20, 70, WindowWidth(0) - 33, 200)
SetGadgetColor(3, #PB_Gadget_BackColor, $6BB7BD)
CocoaMessage(0, CocoaMessage(0, GadgetID(3), "verticalScroller"),
"setControlSize:", #NSSmallControlSize)
VerticalScrollBarWidth = GetVerticalScrollBarWidth(3)
ContentWidth = GadgetWidth(3) - VerticalScrollBarWidth
TextGadget(4, 10, 10, GadgetWidth(3), 25, "Width of vertical scroll bar: " +
Str(VerticalScrollBarWidth))
CloseGadgetList()
TextGadget(5, 10, 181, ContentWidth, 18, "Usable content width: " + Str(ContentWidth), #PB_Text_Center)
SetGadgetColor(5, #PB_Gadget_BackColor, $6BB7BD)
Repeat
Until WaitWindowEvent() = #PB_Event_CloseWindowNot here on maverick, the scrollbar is always displayed (and I'd rather have it hide itself T_T)with Lion the scrollbar default display changed to an overlay with the scrollbar being only visible during the scrolling process.
What are your settings in System Preferences / General / Show scroll bar ?Poshu wrote:Not here on maverick, the scrollbar is always displayed (and I'd rather have it hide itself T_T)
Chris Mason wrote:Apple has apparently changed NSScrollView in 10.9 so it draws in layers -- for special scrolling effects, or speed, or maybe just to give us something to do, because we're all so under-worked.
Yup, default setting is now always shown (too bad).Shardik wrote: What are your settings in System Preferences / General / Show scroll bar ?