wxScrollBar(3)
๐ wxScrollBar
okay bestie, so this is the wxScrollBar manual page โ it's an Erlang module definition from the wx 2.6 docs, and yes I'm about to make a scrollbar sound like the most interesting thing you've read all week (because it kind of is??). ๐
โจ NAME โจ
wxScrollBar โ bestie, it's a control that represents a horizontal or vertical scrollbar. that's it. that's the vibe. ๐
๐ธ DESCRIPTION ๐ธ
So, real talk: this one is distinct from the two scrollbars that some windows just... hand you automatically, unprompted, like a situationship. BUT ๐ซถ the two types of scrollbar share the way events are received, so you're not learning a whole new language, iykyk.
Remark: A scrollbar has the following main attributes: range, thumb size, page size, and position.
let's break that down because it's lowkey the whole personality of this class:
- range โ the total number of units associated with the view the scrollbar represents. a table with 15 columns? range is
15. periodt. - thumb size โ the number of units that are currently visible. for that same table, maybe the window is sized so you can only see 5 columns, in which case the app would set the thumb size to
5. - page size โ the number of units the scrollbar should scroll by when you're 'paging' through the data. normally this is the same as the thumb size length, because it's natural to assume that the visible window size defines a page. makes sense, slay.
- position โ the current thumb position.
โ ๏ธ important: when the thumb size becomes the same as or greater than the range, the scrollbar will be automatically hidden on most platforms. it's not broken, it's just not needed anymore, okay?? ๐ญ
Most applications will find it convenient to provide a function called AdjustScrollbars() which can be called initially, from an OnSize event handler, and whenever the application data changes in size. It will adjust the view, object and page size according to the size of the window and the size of the data. obsessed with a well-named helper function honestly ๐
๐ Styles
This class supports the following styles:
wxSB_HORIZONTALโ Specifies a horizontal scrollbar. โก๏ธwxSB_VERTICALโ Specifies a vertical scrollbar. โฌ๏ธ
๐ฆ The difference between EVT_SCROLL_THUMBRELEASE and EVT_SCROLL_CHANGED
okay this is the part where everybody gets confused so let's go sloooow ๐ง
The EVT_SCROLL_THUMBRELEASE event is only emitted when you're actually dragging the thumb using the mouse and releasing it. (And heads up bestie, this EVT_SCROLL_THUMBRELEASE event is also followed by an EVT_SCROLL_CHANGED event. two for one ๐
)
The EVT_SCROLL_CHANGED event also occurs when you use the keyboard to change the thumb position, and when clicking next to the thumb. (In all these cases the EVT_SCROLL_THUMBRELEASE event does not happen. nope. not invited. ๐)
In short, the EVT_SCROLL_CHANGED event is triggered when scrolling/moving has finished, independently of the way it had started. it doesn't care how you got there, it just cares that you arrived. main character energy fr fr โจ
Please see the page samples_widgets ("Slider" page) to see the difference between EVT_SCROLL_THUMBRELEASE and EVT_SCROLL_CHANGED in action. ๐
See:
- Overview scrolling
- Overview events
This class is derived, and can use functions, from:
wxControlwxWindowwxEvtHandler
wxWidgets docs: wxScrollBar
๐ Events
Event types emitted from this class:
scroll_topscroll_bottomscroll_lineupscroll_linedownscroll_pageupscroll_pagedownscroll_thumbtrackscroll_thumbreleasescroll_changedscroll_topscroll_bottomscroll_lineupscroll_linedownscroll_pageupscroll_pagedownscroll_thumbtrackscroll_thumbreleasescroll_changed
(yes bestie, the list really does appear twice. that's the original, I'm not touching it, and honestly? it's giving double the slay. ๐)
๐ DATA TYPES ๐
wxScrollBar() :: wx:wx_object().
that's the whole data type section. short. sweet. iconic. โญ
๐ฅ FUNCTIONS ๐ฅ
create(This, Parent, Id, [Option]) -> boolean()
when
This :: wxScrollBar(),
Parent :: wxWindow:wxWindow(),
Id :: integer(),
Option ::
{pos, {X :: integer(), Y :: integer()}} |
{size, {W :: integer(), H :: integer()}} |
{style, integer()} |
{validator, wx:wx_object()}.
Scrollbar creation function called by the scrollbar constructor. ๐ ๏ธ
See new/3 for details.
destroy(This :: wxScrollBar()) -> ok.
Destroys the object. ๐ bye bestie, you were real.
getPageSize(This) -> integer() when This :: wxScrollBar().
Returns the page size of the scrollbar.
This is the number of scroll units that will be scrolled when the user pages up or down. Often it is the same as the thumb size.
See: setScrollbar/6
getRange(This) -> integer() when This :: wxScrollBar().
Returns the length of the scrollbar. ๐
See: setScrollbar/6
getThumbPosition(This) -> integer() when This :: wxScrollBar().
Returns the current position of the scrollbar thumb. ๐
See: setThumbPosition/2
getThumbSize(This) -> integer() when This :: wxScrollBar().
Returns the thumb or 'view' size. ๐
See: setScrollbar/6
new() -> wxScrollBar().
Default constructor. no args, no problems, just vibes. โจ
new(Parent, Id, [Option]) -> wxScrollBar()
when
Parent :: wxWindow:wxWindow(),
Id :: integer(),
Option ::
{pos, {X :: integer(), Y :: integer()}} |
{size, {W :: integer(), H :: integer()}} |
{style, integer()} |
{validator, wx:wx_object()}.
Constructor, creating and showing a scrollbar. ๐
See: create/4
setScrollbar(This, Position, ThumbSize, Range, PageSize, [Option]) -> ok
when
This :: wxScrollBar(),
Position :: integer(),
ThumbSize :: integer(),
Range :: integer(),
PageSize :: integer(),
Option :: {refresh, boolean()}.
Sets the scrollbar properties. ๐ง
Remark: Let's say you wish to display 50 lines of text, using the same font. The window is sized so that you can only see 16 lines at a time. You would use: The page size is 1 less than the thumb size so that the last line of the previous page will be visible on the next page, to help orient the user. Note that with the window at this size, the thumb position can never go above 50 minus 16, or 34.
ngl, that little 50 - 16 = 34 moment? math but make it scrollable. ๐งฎโจ
You can determine how many lines are currently visible by dividing the current view size by the character height in pixels. When defining your own scrollbar behaviour, you will always need to recalculate the scrollbar settings when the window size changes. You could therefore put your scrollbar calculations and setScrollbar/6 call into a function named AdjustScrollbars, which can be called initially and also from a wxSizeEvent event handler function. ๐ซถ
setThumbPosition(This, ViewStart) -> ok
when
This :: wxScrollBar(),
ViewStart :: integer().
Sets the position of the scrollbar. ๐
See: getThumbPosition/1
and that's the whole page bestie, no cap, every option and every event present and accounted for ๐
this excellence was brought to you by Ericsson AB, from the wx 2.6 era โ so if you're out here scrolling in 2024, just know the ancestors did it first. mwah ๐ ๐ธ๐ ๐ฆ
๐ฆ where this page comes from
- ubuntu stonking: erlang-doc 1:29.0.6+dfsg-1 ยท Apache-2.0
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms