wxScrolledWindow(3)

πŸ“¦
version 29.0.6 Β· 3 versions
, in ubuntu stonking

πŸ’– wxScrolledWindow(3) β€” Erlang Module Definition πŸ’–

okay bestie, buckle up, because this is the wxScrolledWindow page from the Erlang side of wxWidgets, and it's a chunky one. πŸ‘‘


✨ NAME ✨

wxScrolledWindow β€” the class that runs the scroll show for its client area: it takes your coordinates and reworks them based on where the scrollbars are sitting, and it sets the scroll positions, thumb sizes and ranges so everything matches what's actually in view. It's giving stage manager energy, fr fr. πŸŽ€


🌸 DESCRIPTION 🌸

There are two specializations of this class that people actually use all the time (they're not the only possible ones, but like, they're the main characters πŸ‘‘):

  • ?wxScrolledWindow, aka wxScrolled<wxPanel>, which is the same thing as ?wxScrolledWindow from the older versions. It descends from wxPanel, so it inherits all of wxPanel's behaviour around TAB traversal and focus handling. Pick this one if your scrolled window is gonna have child controls inside it. 🫢
  • ?wxScrolledCanvas, aka wxScrolled<wxWindow>, which descends from wxWindow and therefore does not do anything special for children. This is the vibe when you're implementing scrollable controls like tree controls or list controls. 🌈
Note: peek at wxScrolled::Create() (not implemented in wx) if you wanna use wxScrolled (not implemented in wx) with a custom class. iykyk.

Starting from version 2.4 of wxWidgets, there are several ways to use a ?wxScrolledWindow (and now wxScrolled (not implemented in wx) too). Specifically, there are three ways to set the size of the scrolling area:

One way is to set the scrollbars directly by calling setScrollbars/6. This is how it was done in every previous version of wxWidgets and it's being kept around for backwards compatibility. legacy queen behavior, honestly πŸ’…

Another method of manual control, which needs a little less math from you, is to set the total size of the scrolling area by calling either wxWindow:setVirtualSize/3 or wxWindow:fitInside/1, and then setting the scrolling increments for it by calling setScrollRate/3. Scrolling in a given orientation gets enabled by setting a non-zero increment for that orientation. no increment, no scroll, periodt. ✨

The most automatic and newest way is to just let sizers figure out the scrolling area for you. This is now the default when you set an interior sizer into a wxScrolled (not implemented in wx) with wxWindow:setSizer/3. The scrolling area gets set to the size the sizer asks for, and the scrollbars get assigned for each orientation based on whether they're needed plus the scrolling increment set by setScrollRate/3. Same as above: scrolling is only enabled in orientations with a non-zero increment. You can influence the minimum size of the scrolled area controlled by a sizer by calling wxWindow::SetVirtualSizeHints(). (Calling setScrollbars/6 has analogous effects in wxWidgets 2.4 β€” in later versions it may not keep on overriding the sizer.) 😭

Heads up: if maximum size hints are still supported by wxWindow::SetVirtualSizeHints(), use them at your own dire risk. They may or may not have been removed for 2.4, but honestly it only makes sense to set minimum size hints here anyway. We should probably replace wxWindow::SetVirtualSizeHints() with wxWindow::SetMinVirtualSize() or something like that and remove it entirely in the future. πŸ’€

Like with all windows, an app can draw onto a wxScrolled (not implemented in wx) using a device context.

You've got options, bestie: you can handle the OnPaint handler yourself, or you can override the wxScrolled::OnDraw() (not implemented in wx) function β€” which gets handed a pre-scrolled device context (prepared by doPrepareDC/2). obsessed. πŸŽ€

If you don't feel like calculating your own scrolling, you must call doPrepareDC/2 whenever you're not drawing from inside OnDraw() (not implemented in wx), so the device origin for the device context gets set according to the current scroll position. do not skip this one πŸ™ˆ

A wxScrolled (not implemented in wx) will normally scroll itself, and therefore its child windows along with it. But sometimes you want to scroll a different window than itself: for example, when you're designing a spreadsheet, you'll normally only need to scroll the (usually white) cell area, whereas the (usually grey) label area scrolls very differently. For that special purpose you can call setTargetWindow/2, which means pressing the scrollbars scrolls a different window instead. πŸ’…

Note: the underlying system knows nothing about scrolling coordinates, so all system functions (mouse events, expose events, refresh calls, etc.) as well as the position of subwindows are relative to the "physical" origin of the scrolled window. If the user inserts a child window at position (10,10) and scrolls the window down 100 pixels (moving the child window out of the visible area), the child window will report a position of (10,-90). math is math 😭

πŸ¦‹ Styles πŸ¦‹

This class supports the following styles:

  • wxHSCROLL β€” if this style is specified and ?wxVSCROLL isn't, the window will be scrollable only in the horizontal direction. (By default, i.e. if neither this style nor ?wxVSCROLL is specified, it scrolls in both directions.)
  • wxVSCROLL β€” if this style is specified and ?wxHSCROLL isn't, the window will be scrollable only in the vertical direction. (By default, i.e. if neither this style nor ?wxHSCROLL is specified, it scrolls in both directions.)
  • wxALWAYS_SHOW_SB β€” since wxWidgets 2.9.5, specifying this style makes the window always show its scrollbars, even if they're not being used. See ShowScrollbars() (not implemented in wx).
  • wxRETAINED β€” uses a backing pixmap to speed refreshes. Motif only. vintage ✨

See also:

  • wxScrollBar
  • wxClientDC
  • wxPaintDC

This class is derived from, and can use functions from:

  • wxPanel
  • wxWindow
  • wxEvtHandler

wxWidgets docs: wxScrolledWindow

πŸ’œ Events πŸ’œ

Event types emitted from this class:

  • scrollwin_top
  • scrollwin_bottom
  • scrollwin_lineup
  • scrollwin_linedown
  • scrollwin_pageup
  • scrollwin_pagedown
  • scrollwin_thumbtrack
  • scrollwin_thumbrelease

⭐ DATA TYPES ⭐

wxScrolledWindow() :: wx:wx_object().

okay that's the lore so far β€” part 2 is up next, keep scrolling bestie 🧚

✨ FUNCTIONS ✨

Okay bestie, here's the function menu. Every single one, no skips. πŸ’…


πŸ’– calcScrolledPosition πŸ’–

calcScrolledPosition(This, Pt) -> {X :: integer(), Y :: integer()}
                              when
                                  This :: wxScrolledWindow(),
                                  Pt :: {X :: integer(), Y :: integer()}.

calcScrolledPosition(This, X, Y) ->
                              {Xx :: integer(), Yy :: integer()}
                              when
                                  This :: wxScrolledWindow(),
                                  X :: integer(),
                                  Y :: integer().

Translates the logical coordinates to the device ones. πŸ’…

Example: if a window is scrolled 10 pixels to the bottom, the device coordinates of the origin are (0, 0) (as always), but the logical coordinates are (0, 10) and so the call to CalcScrolledPosition(0, 10, xx, yy) will return 0 in yy.

See: calcUnscrolledPosition/3


πŸ’– calcUnscrolledPosition πŸ’–

calcUnscrolledPosition(This, Pt) ->
                                {X :: integer(), Y :: integer()}
                                when
                                    This :: wxScrolledWindow(),
                                    Pt :: {X :: integer(), Y :: integer()}.

calcUnscrolledPosition(This, X, Y) ->
                                {Xx :: integer(), Yy :: integer()}
                                when
                                    This :: wxScrolledWindow(),
                                    X :: integer(),
                                    Y :: integer().

Translates the device coordinates to the logical ones. πŸ’–

Example: if a window is scrolled 10 pixels to the bottom, the device coordinates of the origin are (0, 0) (as always), but the logical coordinates are (0, 10) and so the call to CalcUnscrolledPosition(0, 0, xx, yy) will return 10 in yy.

See: calcScrolledPosition/3


πŸ’€ destroy πŸ’€

destroy(This :: wxScrolledWindow()) -> ok.

Destroys the object. πŸ’€ (cute destruction, periodt)


🎨 doPrepareDC 🎨

doPrepareDC(This, Dc) -> ok
                     when This :: wxScrolledWindow(), Dc :: wxDC:wxDC().

Call this function to prepare the device context for drawing a scrolled image.

It sets the device origin according to the current scroll position. doPrepareDC/2 is called automatically within the default wxEVT_PAINT event handler, so your OnDraw() (not implemented in wx) override will be passed an already 'pre-scrolled' device context. However, if you wish to draw from outside of OnDraw() (not implemented in wx) (e.g. from your own wxEVT_PAINT handler), you must call this function yourself.

For example:

Notice that the function sets the origin by moving it relatively to the current origin position, so you shouldn't change the origin before calling doPrepareDC/2 or, if you do, reset it to (0, 0) later. If you call doPrepareDC/2 immediately after device context creation, as in the example above, this problem doesn't arise, of course, so it is customary to do it like this.


πŸ”„ enableScrolling πŸ”„

enableScrolling(This, XScrolling, YScrolling) -> ok
                            when
                                This :: wxScrolledWindow(),
                                XScrolling :: boolean(),
                                YScrolling :: boolean().

Enable or disable use of wxWindow:scrollWindow/4 for scrolling.

By default, when a scrolled window is logically scrolled, wxWindow:scrollWindow/4 is called on the underlying window which scrolls the window contents and only invalidates the part of the window newly brought into view. If false is passed as an argument, then this "physical scrolling" is disabled and the window is entirely invalidated whenever it is scrolled by calling wxWindow:refresh/2.

It should be rarely necessary to disable physical scrolling, so this method shouldn't be called in normal circumstances.


πŸ“ getScrollPixelsPerUnit πŸ“

getScrollPixelsPerUnit(This) ->
                                {XUnit :: integer(), YUnit :: integer()}
                                when This :: wxScrolledWindow().

Get the number of pixels per scroll unit (line), in each direction, as set by setScrollbars/6.

A value of zero indicates no scrolling in that direction.

See:

  • setScrollbars/6
  • wxWindow:getVirtualSize/1

πŸ‘€ getViewStart πŸ‘€

getViewStart(This) -> {X :: integer(), Y :: integer()}
                      when This :: wxScrolledWindow().

This is a simple overload of GetViewStart(int,int); see that function for more info.


✨ new/0 ✨

new() -> wxScrolledWindow().

Default constructor. ✨


🧸 new/2 🧸

new(Parent, [Option]) -> wxScrolledWindow()
             when
                 Parent :: wxWindow:wxWindow(),
                 Option ::
                     {winid, integer()} |
                     {pos, {X :: integer(), Y :: integer()}} |
                     {size, {W :: integer(), H :: integer()}} |
                     {style, integer()}.

Constructor. πŸ’…

Remark: The window is initially created without visible scrollbars. Call setScrollbars/6 to specify how big the virtual window size should be.


πŸ•°οΈ prepareDC πŸ•°οΈ

prepareDC(This, Dc) -> ok
                   when This :: wxScrolledWindow(), Dc :: wxDC:wxDC().

This function is for backwards compatibility only and simply calls doPrepareDC/2 now.

Notice that it is not called by the default paint event handle (doPrepareDC/2 is), so overriding this method in your derived class is useless.


πŸŒ€ scroll/2 πŸŒ€

scroll(This, Pt) -> ok
                when
                    This :: wxScrolledWindow(),
                    Pt :: {X :: integer(), Y :: integer()}.

This is an overload of scroll/3; see that function for more info.


πŸŒ€ scroll/3 πŸŒ€

scroll(This, X, Y) -> ok
                when
                    This :: wxScrolledWindow(),
                    X :: integer(),
                    Y :: integer().

Scrolls a window so the view start is at the given point.

Remark: The positions are in scroll units, not pixels, so to convert to pixels you will have to multiply by the number of pixels per scroll increment. If either parameter is ?wxDefaultCoord (-1), that position will be ignored (no change in that direction).

See:

  • setScrollbars/6
  • getScrollPixelsPerUnit/1

⚑ setScrollRate ⚑

setScrollRate(This, Xstep, Ystep) -> ok
                       when
                           This :: wxScrolledWindow(),
                           Xstep :: integer(),
                           Ystep :: integer().

Set the horizontal and vertical scrolling increment only.

See the pixelsPerUnit parameter in setScrollbars/6.


🎚️ setScrollbars 🎚️

setScrollbars(This, PixelsPerUnitX, PixelsPerUnitY, NoUnitsX,
                    NoUnitsY,
                    [Option]) ->
                       ok
                       when
                           This :: wxScrolledWindow(),
                           PixelsPerUnitX :: integer(),
                           PixelsPerUnitY :: integer(),
                           NoUnitsX :: integer(),
                           NoUnitsY :: integer(),
                           Option ::
                               {xPos, integer()} |
                               {yPos, integer()} |
                               {noRefresh, boolean()}.

Sets up vertical and/or horizontal scrollbars.

The first pair of parameters give the number of pixels per 'scroll step', i.e. amount moved when the up or down scroll arrows are pressed. The second pair gives the length of scrollbar in scroll steps, which sets the size of the virtual window.

xPos and yPos optionally specify a position to scroll to immediately.

For example, the following gives a window horizontal and vertical scrollbars with 20 pixels per scroll step, and a size of 50 steps (1000 pixels) in each direction:

wxScrolled (not implemented in wx) manages the page size itself, using the current client window size as the page size.

Note that for more sophisticated scrolling applications, for example where scroll steps may be variable according to the position in the document, it will be necessary to derive a new class from wxWindow, overriding OnSize() and adjusting the scrollbars appropriately.

See: wxWindow:setVirtualSize/3


🎯 setTargetWindow 🎯

setTargetWindow(This, Window) -> ok
                         when
                             This :: wxScrolledWindow(),
                             Window :: wxWindow:wxWindow().

Call this function to tell wxScrolled (not implemented in wx) to perform the actual scrolling on a different window (and not on itself).

This method is useful when only a part of the window should be scrolled. A typical example is a control consisting of a fixed header and the scrollable contents window: the scrollbars are attached to the main window itself, hence it, and not the contents window must be derived from wxScrolled (not implemented in wx), but only the contents window scrolls when the scrollbars are used. To implement such setup, you need to call this method with the contents window as argument.

Notice that if this method is used, GetSizeAvailableForScrollTarget() (not implemented in wx) method must be overridden.


Big love from Ericsson AB β€” this is wx 2.6 energy, and the page is wxScrolledWindow(3). Stay scrolly, bestie πŸ’…πŸ’–

πŸ“¦ where this page comes from