-
Notifications
You must be signed in to change notification settings - Fork 26
Widget
Alessandro Febretti edited this page Jun 5, 2014
·
29 revisions
Last revision: ver. 6.0 - 28 May 2014
Base class for GUI elements
Method(s) | Description |
---|---|
setVisible(bool visible) , bool isVisible()
|
Gets or sets the visibility for the widget |
setPosition(Vector2 position) , Vector2 getPosition()
|
Gets or sets the widget position in pixels (see Vector2). |
Vector2 getSize() , 'setSize(Vector2 size)
|
Gets or sets the size of the widget in pixels (see Vector2). |
float getScale() , setScale(float scale)
|
Sets the widget scale. Scale controls the visual appearance of a widget without changing its actual size or forcing a layout refresh of the widget container. Scale is indicated as a proportion of the current widget size. |
float getRotation() , setRotation(float degrees)
|
Gets or sets a widget rotation in degrees |
int getWidth() , 'setWidth(int value)
|
Gets or sets the widget width |
int getHeight() , 'setHeight(int value)
|
Gets or sets the widget height |
setAutosize(bool value) , bool getAutosize()
|
Enables / disables autosize mode. |
setName(stirng name) , string getName()
|
Gets or sets the widget name |
setStyle(string style) |
Sets one or more widget styles as key: value pairs |
(v6.0) setActiveStyle(string style) string getActiveStyle()
|
Gets or sets the style used when the widget is active. |
(v6.0) setInactiveStyle(string style) string getInactiveStyle()
|
Gets or sets the style used when the widget is inactive. |
setStyleValue(style, value) |
Sets the value for a single style key |
setFillEnabled(bool value) |
|
setFillColor(Color color) |
Sets the foll Color for the widget area. |
refresh() |
Forces a widget refresh |
hitTest(Vector2 position) |
Checks if the specified pixel position lies within the widget area. (see Vector2). |
setUIEventCommand(string command) |
Sets the command to be invoked when events happen in the widget area (like clicks or value changes) |
WidgetLayer getLayer() , setLayer(WidgetLayer value)
|
Gets or sets the WidgetLayer for the widget. Layers influence the drawing order of widgets within the same container |
Vector2 transformPoint(Vector2 point) |
Transforms a point from global pixel coordinates to local pixel coordinates in the widget space. (see Vector2). |
setCenter(Vector2 point) , Vector2 getCenter()
|
Gets or Sets the widget position by it center. (see Vector2). |
setAlpha(float value) float getAlpha()
|
Gets or sets the transparency of the widget. Blendng must be enabled through setBlendMode
|
setBlendMode(WidgetBlendMode value) WidgetBlendMode setBlendMode()
|
Gets or sets the blend mode for the widget |
setUpdateCommand(string cmdstring) string getUpdateCommand()
|
Gets or specified an update command to be executed for each update cycle on the widget. Example: widget.setUpdateCommand("print('widget updated')")
|
bool isStereo() setStereo(bool value)
|
Gets or sets stereo mode for the Widget. Some widgets (like Image ) perform rendering differently when stereo mode is enabled. For instance, Image supports rendering of side-by-side stereo images. |
Layout | |
requestLayoutRefresh() |
Forces a layout recalculation for this widget and parent containers |
setDraggable(bool value) , bool isDraggable()
|
|
setPinned(bool value) , bool isPinned()
|
When a widget is pinned, its position will remain fixed with respect to its container. Pinning widgets is useful to make container draggable only on a sub-section represented by the pinned widget. |
setSizeAnchorEnabled(bool) , bool isSizeAnchorEnabled()
|
Gets or sets size anchor mode. When size anchor is enabled, this widget size will follow its container size plus an offset specified by the setSizeAnchor method. |
setSizeAnchor(Vector2 size) , Vector2 getSizeAnchor()
|
gets or sets the widget size anchor. |
Navigation | |
Widget getHorizontalNextWidget() , setHorizontalNextWidget(Widget w)
|
Gets or sets the widget that will be selected when the user presses the right arrow on this widget. |
Widget getHorizontalPrevWidget() , setHorizontalPrevWidget(Widget w)
|
Gets or sets the widget that will be selected when the user presses the left arrow on this widget. |
Widget getVerticalNextWidget() , setVerticalNextWidget(Widget w)
|
Gets or sets the widget that will be selected when the user presses the down arrow on this widget. |
Widget getVerticalPrevWidget() , setVerticalPrevWidget(Widget w)
|
Gets or sets the widget that will be selected when the user presses the up arrow on this widget. |
bool isNavigationEnabled() , setNavigationEnabled(bool enabled)
|
Enables key-based widget navigation on this widget, or checks its state. |
The method getLayer()
returns a value from the WidgetLayer
enumeration. The WidgetLayer
enumeration contains the following values: Front
, Middle
, Back
The method getLayer()
returns a value from the WidgetBlendMode
enumeration. The WidgetLayer
enumeration:
-
BlendInherit
sets the blend mode to inherited from parent -
BlendNormal
sets the blend mode to standard blending -
BlendAdditive
sets the blend mode to additive blending
The methods setStyle
and setStyleValue
accept the following style keys:
-
fill
: sets the widget fill color. Example:widget.setStyleValue('fill', '#ff0000')
-
border
: sets the border style for all borders. widget fill color. Border style is a border width followed by a borer color. Example:widget.setStyleValue('border', '2 #ffff00')
-
border-top
,border-bottom
,border-left
,border-right
: sets each border side style separately
# Create a sub-menu that will contain the multiple columns
mm = MenuManager.createAndInitialize()
menu2 = mm.getMainMenu().addSubMenu("TestMenu")
# Get the menu container, set its layout to horizontal
mc = menu2.getContainer()
mc.setLayout(ContainerLayout.LayoutHorizontal)
# Create 3 vertical columns, add them to the menu
c1 = Container.create(ContainerLayout.LayoutVertical, mc)
c2 = Container.create(ContainerLayout.LayoutVertical, mc)
c3 = Container.create(ContainerLayout.LayoutVertical, mc)
# Add a bunch of buttons to the columns
# Column 1
b1c1 = Button.create(c1)
b2c1 = Button.create(c1)
# Column 2
b1c2 = Button.create(c2)
b2c2 = Button.create(c2)
b3c2 = Button.create(c2)
# Column 3
b1c3 = Button.create(c3)
b2c3 = Button.create(c3)
b3c3 = Button.create(c3)
# setup navigation
# vertical navigation for buttons will be set up automatically by the container.
# we set horizontal navigation manually
# Buttons on the first row
b1c1.setHorizontalNextWidget(b1c2)
b1c2.setHorizontalPrevWidget(b1c1)
b1c2.setHorizontalNextWidget(b1c3)
b1c3.setHorizontalPrevWidget(b1c2)
# Buttons on the second row
b2c1.setHorizontalNextWidget(b2c2)
b2c2.setHorizontalPrevWidget(b2c1)
b2c2.setHorizontalNextWidget(b2c3)
b2c3.setHorizontalPrevWidget(b2c2)
# Buttons on the third row
# since the first column does not have a third row, prev navigation
# from column 2 goes to the last button of column 1
b3c2.setHorizontalPrevWidget(b2c1)
b3c2.setHorizontalNextWidget(b3c3)
b3c3.setHorizontalPrevWidget(b3c2)