peng3d.gui.widgets
- 2D GUI Widget Base classes¶
-
peng3d.gui.widgets.
mouse_aabb
(mpos, size, pos)[source]¶ Simple AABB collision algorithm used for checking if a mouse click hit a widget.
-
class
peng3d.gui.widgets.
BasicWidget
(name, submenu, window, peng, pos=None, size=None)[source]¶ Basic Widget class.
Every widget must be registered with their appropriate sub-menus to work properly.
pos
may be either a list or 2-tuple of(x,y)
for static positions or a function with the signaturewindow_width,window_height,widget_width,widget_height
returning a tuple.size
is similar topos
but will only getwindow_width,window_height
as its arguments.Commonly, the lambda
lambda sw,sh,bw,bh: (sw/2.-bw/2.,sh/2.-bh/2.)
is used to center the widget.-
addAction
(action, func, *args, **kwargs)[source]¶ Adds the a callback to the specified action.
All other positional and keyword arguments will be stored and passed to the function upon activation.
The actions available may differ from widget to widget, by default these are used:
press
is called upon starting to click on the widgetclick
is called if the mouse is released on the widget while also having been pressed on it before, recommended for typical button callbackscontext
is called upon right-clicking on the widget and may be used to display a context menuhover_start
signals that the cursor is now hovering over the widgethover
is called every time the cursor moves while still being over the widgethover_end
is called after the cursor leaves the widget
-
clickable
¶ Property used for determining if the widget should be clickable by the user.
This is only true if the submenu of this widget is active and this widget is enabled.
The widget may be either disabled by setting this property or the
enabled
attribute.
-
draw
()[source]¶ Draws all vertex lists associated with this widget.
Deprecated: Add vertex lists to the submenu instead
-
enabled
¶ Property used for storing whether or not this widget is enabled.
May influence rendering and behavior.
Note that the widget will be immediately redrawn if this property is changed.
-
pos
¶ Property that will always be a 2-tuple representing the position of the widget.
Note that this method may call the method given as
pos
in the initializer.The returned object will actually be an instance of a helper class to allow for setting only the x/y coordinate.
This property also respects any
Container
set as its parent, any offset will be added automatically.Note that setting this property will override any callable set permanently.
-
redraw
()[source]¶ Callback to be overridden by subclasses called if redrawing the widget seems necessary.
-
-
class
peng3d.gui.widgets.
Background
(widget)[source]¶ Class representing the background of a widget.
This base class does not do anything.
-
init_bg
()[source]¶ 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.
-
peng
¶ Property for accessing the parent widget’s instance of
peng3d.peng.Peng
.
-
redraw_bg
()[source]¶ Method called by the parent widget every time its
Widget.redraw()
method is called.
Property for accessing the parent widget’s submenu.
-
window
¶ Property for accessing the parent widget’s window.
-
-
class
peng3d.gui.widgets.
Widget
(name, submenu, window, peng, pos=None, size=None, bg=None)[source]¶ Subclass of
BasicWidget
adding support for changing theBackground
.If no background is given, an
EmptyBackground
will be used instead.