peng3d.gui.button
- Button Widgets¶
Button Widget allowing the user to trigger specific actions.
By default, this Widget uses
ButtonBackground
as its Background class.The border given is in pixels from the left/right and top/bottom, respectively.
The borderstyle may be either
flat
, which has no border at all,gradient
, which fades from the inner color to the background color,oldshadow
, which uses a simple fake shadow with the light from the top-left corner andmaterial
, which imitates Google Material Design shadows.Also, the label of the button may only be a single line of text, anything else may produce undocumented behavior.
If necessary, the font size of the Label may be changed via the global Constant
LABEL_FONT_SIZE
, changes will only apply to Buttons created after change. The text color used is[62,67,73,255]
in RGBA and the font used is Arial, which should be available on most systems.Deletes resources of this widget that require manual cleanup.
Currently removes all actions, event handlers and the background.
The background itself should automatically remove all vertex lists to avoid visual artifacts.
Note that this method is currently experimental, as it seems to have a memory leak.
Property for accessing the label of this Button.
Draws the background and the widget itself.
Subclasses should use
super()
to call this method, or rendering may glitch out.
Re-draws the label by calculating its position.
Currently, the label will always be centered on the Button.
Background for the
Button
Widget.This background renders the button and its border, but not the label.
Overrideable function that generates the colors to be used by various borderstyles.
Should return a 5-tuple of
(bg,o,i,s,h)
.bg
is the base color of the background.o
is the outer color, it is usually the same as the background color.i
is the inner color, it is usually lighter than the background color.s
is the shadow color, it is usually quite a bit darker than the background.h
is the highlight color, it is usually quite a bit lighter than the background.
Helper function converting the actual widget position and size into a usable and offsetted form.
This function should return a 6-tuple of
(sx,sy,x,y,bx,by)
where sx and sy are the size, x and y the position and bx and by are the border size.All values should be in pixels and already include all offsets, as they are used directly for generation of vertex data.
This method can also be overridden to limit the background to a specific part of its widget.
Called just before the background will be drawn the first time.
Commonly used to initialize vertex lists.
It is recommended to add all vertex lists to the
submenu.batch2d
Batch to speed up rendering and preventing glitches with grouping.
Read-only helper property to be used by borderstyles for determining if the widget should be rendered as hovered or not.
Note that this property may not represent the actual hovering state, it will always be False if
change_on_press
is disabled.
Read-only helper property to be used by borderstyles for determining if the widget should be rendered as pressed or not.
Note that this property may not represent the actual pressed state, it will always be False if
change_on_press
is disabled.
Method called by the parent widget every time its
Widget.redraw()
method is called.
Subclass of
Button
using an image as a background instead.By default, this Widget uses
ImageBackground
as its Background class.There are no changes to any other mechanics of the Button, only visually.
Background for the
ImageButton
Widget.This background renders a image given based on whether the widget is pressed, hovered over or disabled.
It should also be possible to use this class as a background for most other Widgets.
Called just before the background will be drawn the first time.
Commonly used to initialize vertex lists.
It is recommended to add all vertex lists to the
submenu.batch2d
Batch to speed up rendering and preventing glitches with grouping.
Read-only helper property to be used by borderstyles for determining if the widget should be rendered as pressed or not.
Note that this property may not represent the actual pressed state, it will always be False if
change_on_press
is disabled.
Method called by the parent widget every time its
Widget.redraw()
method is called.
Subclass of
ImageButton
adding smart scaling to the background.By default, this Widget uses
FramedImageBackground
as its Background class.frame
defines the ratio between the borders and the center. The sum of each item must be greater than zero, else a ZeroDivisionError may be thrown. Note that up to two items of each frame may be left as0
. This will cause the appropriate border or center to not be rendered at all.tex_size
may be left empty if a resource name is passed. It will then be automatically determined.Todo
Document
scale
Background for the
FramedImageButton
Widget.This background is similar to
ImageBackground
, but it attempts to scale smarter with less artifacts.Called just before the background will be drawn the first time.
Commonly used to initialize vertex lists.
It is recommended to add all vertex lists to the
submenu.batch2d
Batch to speed up rendering and preventing glitches with grouping.
Method called by the parent widget every time its
Widget.redraw()
method is called.
Variant of
Button
that stays pressed until clicked again.This widgets adds the following actions:
press_down
is called upon depressing the buttonpress_up
is called upon releasing the buttonclick
is changed to be called on every click on the button, e.g. likepress_down
andpress_up
combined
Variant of
ToggleButton
using a different visual indicator.By default, this Widget uses
CheckboxBackground
as its Background class.Note that the position and size given are for the indicator, the label will be bigger than the given size.
The label given will be displayed to the right of the Checkbox.
Re-calculates the position of the Label.
Background for the
Checkbox
Widget.This background looks like a button, but adds a square in the middle if it is pressed.
The color of the square defaults to a tone of orange commonly found in GTK GUIs on Ubuntu.
Called just before the background will be drawn the first time.
Commonly used to initialize vertex lists.
It is recommended to add all vertex lists to the
submenu.batch2d
Batch to speed up rendering and preventing glitches with grouping.
Method called by the parent widget every time its
Widget.redraw()
method is called.