wxButton(3erl)
wxButton(3erl) β Erlang Module Definition π
okay bestie, so this is the manual page for wxButton, and honestly? It's giving "fundamental GUI building block" and we're obsessed. Let me walk you through it fr fr. β¨
π NAME π
wxButton β Functions for the wxButton class. That's it, that's the whole name. Simple, iconic, periodt. π
πΈ DESCRIPTION πΈ
So picture this: a button is a control that contains a text string, and it's literally one of the most common elements of a GUI. Like, no cap, every interface you've ever touched has one. π
It may be placed on a wxDialog or on a wxPanel panel, or indeed on almost any other window. Versatile queen. π
By default, i.e. if none of the alignment styles are specified, the label is centered both horizontally and vertically. If the button has both a label and a bitmap, the alignment styles above specify the location of the rectangle combining both the label and the bitmap and the bitmap position set with wxButton::SetBitmapPosition() (not implemented in wx) defines the relative position of the bitmap with respect to the label (however currently non-default alignment combinations are not implemented on all platforms). So yeah, alignment is a whole vibe but watch out for platform shenanigans. π€
Since version 2.9.1 wxButton supports showing both text and an image (currently only when using wxMSW, wxGTK or wxOSX/Cocoa ports), see SetBitmap() (not implemented in wx) and setBitmapLabel/2, setBitmapDisabled/2 &c methods. In the previous wxWidgets versions this functionality was only available in (the now trivial) wxBitmapButton class which was only capable of showing an image without text. So like, glow-up era for buttons, we love to see it. π¦
A button may have either a single image for all states or different images for the following states (different images are not currently supported under macOS where the normal image is used for all states). macOS said "one look for every mood" and honestly? Respect. π
β οΈ Important bestie note: All of the bitmaps must be of the same size and the normal bitmap must be set first (to a valid bitmap), before setting any other ones. Also, if the size of the bitmaps is changed later, you need to change the size of the normal bitmap before setting any other bitmaps with the new size (and you do need to reset all of them as their original values can be lost when the normal bitmap size changes). So don't be chaotic about it, okay? Rules are rules. π
The position of the image inside the button be configured using SetBitmapPosition() (not implemented in wx). By default the image is on the left of the text. Left is the default, main character energy. β
Please also notice that GTK+ uses a global setting called gtk-button-images to determine if the images should be shown in the buttons at all. If it is off (which is the case in e.g. Gnome 2.28 by default), no images will be shown, consistently with the native behaviour. GTK+ said "images? in THIS economy?" and honestly relatable. π
π Styles π
This class supports the following styles:
(yes, that's the whole list in the original β styles section is giving mysterious and lowkey empty but we're not gonna pretend otherwise, no cap) π
See: wxBitmapButton β the older sibling who's still iconic in their own way. π
This class is derived (and can use functions) from: wxControl wxWindow wxEvtHandler. Family tree is giving royalty, honestly. π
wxWidgets docs: wxButton
π EVENTS π
Event types emitted from this class: command_button_clicked. That's the one, that's the money event, the whole reason you clicked (literally). π
π DATA TYPES π
wxButton() = wx:wx_object()β that's the type, it's an object, it's iconic, moving on. β¨
π₯ EXPORTS π₯
π THE CONSTRUCTORS (new/1, new/2, new/3) π
new() -> wxButton()β Default ctor. Short, sweet, does what it says on the tin. π«Άnew(Parent, Id) -> wxButton()β Types:Parent = wxWindow:wxWindow()Id = integer()
new(Parent, Id, Options :: [Option]) -> wxButton()β Types:Parent = wxWindow:wxWindow()Id = integer()Option= one of:{label, unicode:chardata()}{pos, {X :: integer(), Y :: integer()}}{size, {W :: integer(), H :: integer()}}{style, integer()}{validator, wx:wx_object()}
π‘ Constructor, creating and showing a button. The full glow-up in one call, bestie.
The preferred way to create standard buttons is to use default value of label. If no label is supplied and id is one of standard IDs from this list, a standard label will be used. In other words, if you use a predefined wxID_XXX constant, just omit the label completely rather than specifying it. In particular, help buttons (the ones with id of wxID_HELP) under macOS can't display any label at all and while wxButton will detect if the standard "Help" label is used and ignore it, using any other label will prevent the button from correctly appearing as a help button and so should be avoided. Like, don't fight the system on this one, macOS said no. π
In addition to that, the button will be decorated with stock icons under GTK+ 2. Cute little bonus, we stan. β¨
See: create/4, wxValidator (not implemented in wx)
π οΈ THE CREATION FUNCTION (create/3, create/4) π οΈ
create(This, Parent, Id) -> boolean()β Types:This = wxButton()Parent = wxWindow:wxWindow()Id = integer()
create(This, Parent, Id, Options :: [Option]) -> boolean()β Types:This = wxButton()Parent = wxWindow:wxWindow()Id = integer()Option= one of:{label, unicode:chardata()}{pos, {X :: integer(), Y :: integer()}}{size, {W :: integer(), H :: integer()}}{style, integer()}{validator, wx:wx_object()}
π‘ Button creation function for two-step creation. For more details, see new/3. Two-step creation is that "build first, show later" energy, very mysterious, very demure. π
π SIZE STUFF (getDefaultSize/0, getDefaultSize/1) π
getDefaultSize() -> {W :: integer(), H :: integer()}
π‘ Returns the default size for the buttons. It is advised to make all the dialog buttons of the same size and this function allows retrieving the (platform, and current font dependent) size which should be the best suited for this. The optional win argument is new since wxWidgets 3.1.3 and allows to get a per-monitor DPI specific size. Matching sizes = coordinated outfit, we love cohesion. π
getDefaultSize(Win) -> {W :: integer(), H :: integer()}β Types:Win = wxWindow:wxWindow()
π SETTING THE DEFAULT (setDefault/1) π
setDefault(This) -> wxWindow:wxWindow()β Types:This = wxButton()
π‘ This sets the button to be the default item in its top-level window (e.g. the panel or the dialog box containing it). As normal, pressing return causes the default button to be depressed when the return key is pressed. Main character button, gets the spotlight when you hit enter. π
See also wxWindow:setFocus/1 which sets the keyboard focus for windows and text panel items, and wxTopLevelWindow::SetDefaultItem() (not implemented in wx).
β οΈ Remark: Under Windows, only dialog box buttons respond to this function. Windows said "not all buttons get the spotlight" and honestly, rude but okay. π
Return: the old default item (possibly NULL)
π·οΈ LABELS (setLabel/2) π·οΈ
setLabel(This, Label) -> okβ Types:This = wxButton()Label = unicode:chardata()
π‘ Sets the string label for the button. Name change, new era, slay. β¨
πΌοΈ BITMAP GETTERS (the whole collection) πΌοΈ
getBitmapDisabled(This) -> wxBitmap:wxBitmap()β Types:This = wxButton()
π‘ Returns the bitmap for the disabled state, which may be invalid. The "button is off duty" look. π΄
See: setBitmapDisabled/2 Since: 2.9.1 (available in wxBitmapButton only in previous versions)
getBitmapFocus(This) -> wxBitmap:wxBitmap()β Types:This = wxButton()
π‘ Returns the bitmap for the focused state, which may be invalid. The "button is the center of attention" look. π₯
See: setBitmapFocus/2 Since: 2.9.1 (available in wxBitmapButton only in previous versions)
getBitmapLabel(This) -> wxBitmap:wxBitmap()β Types:This = wxButton()
π‘ Returns the bitmap for the normal state. This is exactly the same asGetBitmap()(not implemented in wx) but uses a name backwards-compatible withwxBitmapButton. Legacy name, same icon, we not mad at it. π«Ά
See: SetBitmap() (not implemented in wx), setBitmapLabel/2 Since: 2.9.1 (available in wxBitmapButton only in previous versions)
π¨ BITMAP SETTERS (the glow-up squad) π¨
setBitmapDisabled(This, Bitmap) -> okβ Types:This = wxButton()Bitmap = wxBitmap:wxBitmap()
π‘ Sets the bitmap for the disabled button appearance. Ifbitmapis invalid, the disabled bitmap is set to the automatically generated greyed out version of the normal bitmap, i.e. the same bitmap as is used by default if this method is not called at all. UseSetBitmap()(not implemented in wx) with an invalid bitmap to remove the bitmap completely (for all states). "Invalid bitmap" = auto grey-out, the system's got your back. π
See: getBitmapDisabled/1, setBitmapLabel/2, SetBitmapPressed() (not implemented in wx), setBitmapFocus/2 Since: 2.9.1 (available in wxBitmapButton only in previous versions)
setBitmapFocus(This, Bitmap) -> okβ Types:This = wxButton()Bitmap = wxBitmap:wxBitmap()
π‘ Sets the bitmap for the button appearance when it has the keyboard focus. If bitmap is invalid, the normal bitmap will be used in the focused state. Invalid input? Fallback to the classic. Very forgiving. π¦
See: getBitmapFocus/1, setBitmapLabel/2, SetBitmapPressed() (not implemented in wx), setBitmapDisabled/2 Since: 2.9.1 (available in wxBitmapButton only in previous versions)
setBitmapLabel(This, Bitmap) -> okβ Types:This = wxButton()Bitmap = wxBitmap:wxBitmap()
π‘ Sets the bitmap label for the button.
β οΈ Remark: This is the bitmap used for the unselected state, and for all other states if no other bitmaps are provided. So it's the default outfit and the backup outfit. Versatility icon. π
See: SetBitmap() (not implemented in wx), getBitmapLabel/1 Since: 2.9.1 (available in wxBitmapButton only in previous versions)
π THE DESTROYER (destroy/1) π
destroy(This :: wxButton()) -> ok
π‘ Destroys the object. It's over, it's done, the button has left the chat. π
β¨ and that's the whole page bestie β¨
This manual page was brought to you by the wxWidgets team π, for version wx 2.2.2.1, dated wxButton(3erl). Go forth and make buttons, you're gonna slay. π«Άππ
π¦ where this page comes from
- ubuntu noble: erlang-manpages 1:25.3.2.8+dfsg-1ubuntu4 Β· Apache-2.0
- ubuntu noble: erlang-manpages 1:25.3.2.8+dfsg-1ubuntu4.8 Β· Apache-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms