Unigine.Widget Class
This base class is used to create graphical user interface widgets of different types. The Widget class doesn't provide creating of a widget: you can create the required widget by using a constructor of the corresponding class inherited from the Widget class.
Widgets can be used separately or form a hierarchy.
Working with Widgets#
The example below demonstrates how to create a single widget, a hierarchy of widgets, and subscribe for a widget's event.
WidgetClass.cs
public void on_button_click()
{
Log.Message("world button click\n");
}
private void Init()
{
// create a single widget
WidgetButton button = new WidgetButton("WORLD_BUTTON");
// subscribing for the button Click event
button.EventClicked.Connect(on_button_click);
// add the button to WindowManager
WindowManager.MainWindow.AddChild(button);
// create a hierarchy of widgets
WidgetHBox hbox = new WidgetHBox();
hbox.Background = 1;
hbox.BackgroundColor = vec4.WHITE;
WindowManager.MainWindow.AddChild(hbox, Gui.ALIGN_EXPAND);
WidgetGroupBox group = new WidgetGroupBox();
group.Background = 1;
group.Text = "Widgets Hierarchy";
hbox.AddChild(group);
group.AddChild(new WidgetLabel("hierarchy_label_0"));
group.AddChild(new WidgetLabel("hierarchy_label_1"));
}
Lifetime of Widgets#
By default each new widget's lifetime matches the lifetime of the Engine (i.e. the widget shall be deleted on Engine shutdown). But you can choose widget's lifetime to be managed:
- By a separate window — in this case the widget is deleted automatically on deleting the window.
- By the world — in this case the widget is deleted when the world is closed.
- Manually — in this case the widget should be deleted manually.
The examples below show how the different lifetime management types work.
Managing Lifetime by the World#
In this example, the widgets appear on loading the world. When you reload or exit the world, or close the Engine window, the widgets are deleted as their lifetime is managed by the world. The corresponding messages will be shown in the console.
WidgetLifetimeWorld.cs
public void on_button_click()
{
Log.Message("world button click\n");
}
public void on_button_remove()
{
Log.Message("world button removed\n");
}
public void on_hbox_remove()
{
Log.Message("world hbox hierarchy removed\n");
}
private void Init()
{
// create a single widget
WidgetButton button = new WidgetButton("WORLD_BUTTON");
// set the world lifetime
button.Lifetime = Widget.LIFETIME.WORLD;
// subscribing for the button Click event
button.EventClicked.Connect(on_button_click);
// the "on_button_remove" handler will be executed on reloading or closing the world, or on Engine shutdown
button.EventRemove.Connect(on_button_remove);
// add the button to WindowManager
WindowManager.MainWindow.AddChild(button);
// create a hierarchy of widgets
WidgetHBox hbox = new WidgetHBox();
// set the world lifetime
hbox.Lifetime = Widget.LIFETIME.WORLD;
// the "on_hbox_remove" handler will be executed on reloading or closing the world, or on Engine shutdown
hbox.EventRemove.Connect(on_hbox_remove);
hbox.Background = 1;
hbox.BackgroundColor = vec4.WHITE;
WindowManager.MainWindow.AddChild(hbox, Gui.ALIGN_EXPAND);
WidgetGroupBox group = new WidgetGroupBox();
group.Background = 1;
group.Text = "Widgets Hierarchy";
hbox.AddChild(group);
group.AddChild(new WidgetLabel("hierarchy_label_0"));
group.AddChild(new WidgetLabel("hierarchy_label_1"));
}
Managing Lifetime by the Window#
In this example, widgets appear in a separate window. When you close the window, the widgets are deleted as their lifetime is managed by this window. The console shows the following information:
- Whether the window, button and hbox hierarchy are deleted or not.
- Whether the remove callbacks are fired or not.
- Messages from the remove callbacks.
After closing, the window can be re-created by pressing T.
WidgetLifetimeWindow.cs
public EngineWindowViewport window;
public WidgetButton button;
public WidgetHBox hbox;
bool button_remove_handler = false;
bool hbox_remove_handler = false;
public void on_window_button_click()
{
Log.Message("window button click\n");
}
public void on_window_button_remove()
{
Log.Message("window button removed\n");
button_remove_handler = true;
}
public void on_window_hbox_remove()
{
Log.Message("window hbox hierarchy removed\n");
hbox_remove_handler = true;
}
public void create_window()
{
button_remove_handler = false;
hbox_remove_handler = false;
window = new EngineWindowViewport("Test", 512, 256, (int)EngineWindow.FLAGS.SHOWN);
// single window widget
button = new WidgetButton("WINDOW_BUTTON");
button.Lifetime = Widget.LIFETIME.WINDOW;
button.EventClicked.Connect(on_window_button_click);
button.EventRemove.Connect(on_window_button_remove);
window.AddChild(button);
// window hierarchy
hbox = new WidgetHBox();
hbox.Lifetime = Widget.LIFETIME.WINDOW;
hbox.EventRemove.Connect(on_window_hbox_remove);
hbox.Background = 1;
hbox.BackgroundColor = vec4.WHITE;
window.AddChild(hbox, Gui.ALIGN_EXPAND);
WidgetGroupBox group = new WidgetGroupBox();
group.Background = 1;
group.Text = "Window Hierarchy";
hbox.AddChild(group);
group.AddChild(new WidgetLabel("hierarchy_window_label_0"));
group.AddChild(new WidgetLabel("hierarchy_window_label_1"));
}
private void Init()
{
create_window();
}
private void Update()
{
if (Input.IsKeyDown(Input.KEY.T) && window.IsDeleted)
create_window();
Log.Message("window deleted: {0}, button deleted: {1}, hbox deleted: {2}, button remove handler: {3}, hbox remove handler: {4}\n",
window.IsDeleted, button.IsDeleted, hbox.IsDeleted, button_remove_handler, hbox_remove_handler);
}
Managing Lifetime by the Engine#
Widgets are created on Engine initialization, and then added to a separate window. The console shows the following information:
- Whether the window, button and hbox hierarchy are deleted or not.
- Whether the remove callbacks are fired or not.
- Messages from the remove callbacks.
If you close the window, it will be deleted and the information in the console will change. All the other widgets are deleted only on Engine shutdown, as their lifetime is managed by the Engine.
If the separate window is closed, press T to re-create it.
WidgetLifetimeEngine.cs
EngineWindowViewport engine_window;
WidgetButton engine_button;
WidgetHBox engine_hbox;
bool engine_button_remove_handler = false;
bool engine_hbox_remove_handler = false;
void on_engine_button_click()
{
Log.Message("engine button click\n");
}
void on_engine_button_remove()
{
Log.Message("engine button removed\n");
engine_button_remove_handler = true;
}
void on_engine_hbox_remove()
{
Log.Message("engine hbox hierarchy removed\n");
engine_hbox_remove_handler = true;
}
void create_engine_window()
{
engine_window = new EngineWindowViewport("Test", 512, 256, (int)EngineWindow.FLAGS.SHOWN);
engine_window.AddChild(engine_button);
engine_window.AddChild(engine_hbox, Gui.ALIGN_EXPAND);
}
private void Init()
{
engine_button_remove_handler = false;
engine_hbox_remove_handler = false;
// single engine widget
engine_button = new WidgetButton("ENGINE_BUTTON");
engine_button.Lifetime = Widget.LIFETIME.ENGINE;
engine_button.EventClicked.Connect(on_engine_button_click);
engine_button.EventRemove.Connect(on_engine_button_remove);
// engine hierarchy
engine_hbox = new WidgetHBox();
engine_hbox.Lifetime = Widget.LIFETIME.ENGINE;
engine_hbox.EventRemove.Connect(on_engine_hbox_remove);
engine_hbox.Background = 1;
engine_hbox.BackgroundColor = vec4.WHITE;
WidgetGroupBox engine_group = new WidgetGroupBox();
engine_group.Background = 1;
engine_group.Text = "Engine Hierarchy";
engine_hbox.AddChild(engine_group);
engine_group.AddChild(new WidgetLabel("hierarchy_engine_label_0"));
engine_group.AddChild(new WidgetLabel("hierarchy_engine_label_1"));
create_engine_window();
}
private void Update()
{
if (Input.IsKeyDown(Input.KEY.T) && engine_window.IsDeleted)
create_engine_window();
Log.Message("engine window deleted: {0}, engine button deleted: {1}, engine hbox deleted: {2}, engine button remove handler: {3}, engine hbox remove handler: {4}\n",
engine_window.IsDeleted, engine_button.IsDeleted, engine_hbox.IsDeleted, engine_button_remove_handler, engine_hbox_remove_handler);
}
See Also#
- Widgets sample set in CPP Samples suite
- Widgets sample in C# Component Samples suite
- A set of UnigineScript API samples located in the <UnigineSDK>/data/samples/widgets/ folder
Widget Class
Enums
TYPE#
Name | Description |
---|---|
WIDGET_VBOX = 0 | Vertical box. See also: WidgetVBox. |
WIDGET_HBOX = 1 | Horizontal box. See also: WidgetHBox. |
WIDGET_GRID_BOX = 2 | Grid box. See also: WidgetGridBox. |
WIDGET_VPANED = 3 | Vertical box that allows resizing of its children. See also: WidgetVPaned. |
WIDGET_HPANED = 4 | Horizontal box that allows resizing of its children. See also: WidgetHPaned. |
WIDGET_LABEL = 5 | Text label. See also: WidgetLabel. |
WIDGET_BUTTON = 6 | Simple button. See also: WidgetButton. |
WIDGET_EDIT_LINE = 7 | Text field. See also: WidgetEditline. |
WIDGET_EDIT_TEXT = 8 | Multiline text field. See also: WidgetEdittext. |
WIDGET_CHECK_BOX = 9 | Checkbox. See also: WidgetCheckbox. |
WIDGET_COMBO_BOX = 10 | Combobox. See also: WidgetCombobox. |
WIDGET_CANVAS = 11 | Canvas widget for drawing text, lines and polygons. See also: WidgetCanvas. |
WIDGET_GROUP_BOX = 12 | Group box. See also: WidgetGroupBox. |
WIDGET_LIST_BOX = 13 | List box. See also: WidgetListBox. |
WIDGET_TREE_BOX = 14 | Tree box. See also: WidgetTreeBox. |
WIDGET_TAB_BOX = 15 | Tabbed box. See also: WidgetTabBox. |
WIDGET_SCROLL = 16 | A scrollbar: horizontal or vertical one. See also: WidgetScroll. |
WIDGET_SCROLL_BOX = 17 | Box with scrolling. See also: WidgetScrollBox. |
WIDGET_SPACER = 18 | Spacer: horizontal or vertical one. See also: WidgetSpacer. |
WIDGET_SLIDER = 19 | A slider: horizontal or vertical one. See also: WidgetSlider. |
WIDGET_SPIN_BOX = 20 | Spinbox. See also: WidgetSpinBox. |
WIDGET_SPIN_BOX_DOUBLE = 21 | Spinbox with double values. See also: WidgetSpinBoxDouble. |
WIDGET_ICON = 22 | Icon. See also: WidgetIcon. |
WIDGET_SPRITE = 23 | Sprite. See also: WidgetSprite. |
WIDGET_SPRITE_VIDEO = 24 | Video Sprite. See also: WidgetSpriteVideo. |
WIDGET_SPRITE_SHADER = 25 | Shader Sprite. See also: WidgetSpriteShader. |
WIDGET_SPRITE_VIEWPORT = 26 | Viewport Sprite. See also: WidgetSpriteViewport. |
WIDGET_SPRITE_NODE = 27 | Node Sprite. See also: WidgetSpriteNode. |
WIDGET_MENU_BAR = 28 | Menu bar. See also: WidgetMenuBar. |
WIDGET_MENU_BOX = 29 | Menu. See also: WidgetMenuBox. |
WIDGET_WINDOW = 30 | Window. See also: WidgetWindow. |
WIDGET_DIALOG = 31 | Dialog window. See also: WidgetDialog. |
WIDGET_DIALOG_MESSAGE = 32 | Message Dialog. See also: WidgetDialogMessage. |
WIDGET_DIALOG_FILE = 33 | File Dialog. See also: WidgetDialogFile. |
WIDGET_DIALOG_COLOR = 34 | Color Dialog. See also: WidgetDialogColor. |
WIDGET_DIALOG_IMAGE = 35 | Image Dialog. See also: WidgetDialogImage. |
WIDGET_MANIPULATOR = 36 | Manipulator widget. See also: WidgetManipulator. |
WIDGET_MANIPULATOR_TRANSLATOR = 37 | Translator Manipulator. See also: WidgetManipulatorTranslator. |
WIDGET_MANIPULATOR_ROTATOR = 38 | Rotator Manipulator. See also: WidgetManipulatorRotator. |
WIDGET_MANIPULATOR_SCALER = 39 | Scaler Manipulator. See also: WidgetManipulatorScaler. |
WIDGET_EXTERN = 40 | External widget. |
WIDGET_ENGINE = 41 | Engine-specific widget (manipulator). See also: WidgetManipulator. |
WIDGET_HIT_TEST_AREA = 42 | Hit-Test Area. See also: WidgetHitTestArea. |
NUM_WIDGETS = 43 | Total number of widget types. |
LIFETIME#
Name | Description |
---|---|
WORLD = 0 | Lifetime of the widget or user interface is managed by the world. The widget/user interface will be deleted automatically on closing the world. |
WINDOW = 1 | Lifetime of the widget or user interface is managed by the window. The widget/user interface will be deleted automatically on deleting the window. |
ENGINE = 2 | Lifetime of the widget or user interface is managed by the Engine. The widget/user interface will be deleted automatically on Engine shutdown.
When using this lifetime management type, the GUI instance can be empty for the widget: it will be assigned automatically when adding the widget to a window. For a user interface, the Gui instance must be set via the setGui() method. |
MANUAL = 3 | Lifetime of the widget or user interface is managed by the user. The widget/user interface should be deleted manually.
When using this lifetime management type, the GUI instance can be empty for the widget: it will be assigned automatically when adding the widget to a window. For a user interface, the Gui instance must be set via the setGui() method. |
Properties
int NumChildren#
int FontWrap#
int FontRich#
int FontOutline#
int FontVOffset#
int FontHOffset#
int FontVSpacing#
int FontHSpacing#
int FontPermanent#
vec4 FontColor#
int FontSize#
int MouseCursor#
int MouseY#
int MouseX#
int Height#
int Width#
int ScreenPositionY#
int ScreenPositionX#
int PositionY#
int PositionX#
Widget NextFocus#
string Data#
int Order#
bool Hidden#
bool Enabled#
bool IntersectionEnabled#
int Flags#
Widget Parent#
Gui ParentGui#
Gui Gui#
string TypeName#
Widget.TYPE Type#
bool IsLayout#
bool IsFixed#
bool IsBackground#
bool IsOverlapped#
bool IsExpanded#
Widget.LIFETIME Lifetime#
float DpiScale#
int RenderHeight#
int RenderWidth#
Event<Widget> EventRemove#
Usage Example
// implement the Remove event handler
void remove_event_handler(Widget widget)
{
Log.Message("\Handling Remove event\n");
}
//////////////////////////////////////////////////////////////////////////////
// 1. Multiple subscriptions can be linked to an EventConnections instance
// class that you can use later to remove all these subscriptions at once
//////////////////////////////////////////////////////////////////////////////
// create an instance of the EventConnections class
EventConnections remove_event_connections = new EventConnections();
// link to this instance when subscribing to an event (subscription to various events can be linked)
publisher.EventRemove.Connect(remove_event_connections, remove_event_handler);
// other subscriptions are also linked to this EventConnections instance
// (e.g. you can subscribe using lambdas)
publisher.EventRemove.Connect(remove_event_connections, (Widget widget) => {
Log.Message("Handling Remove event lambda\n");
}
);
// later all of these linked subscriptions can be removed with a single line
remove_event_connections.DisconnectAll();
//////////////////////////////////////////////////////////////////////////////
// 2. You can subscribe and unsubscribe via the handler function directly
//////////////////////////////////////////////////////////////////////////////
// subscribe to the Remove event with a handler function
publisher.EventRemove.Connect(remove_event_handler);
// remove subscription to the Remove event later by the handler function
publisher.EventRemove.Disconnect(remove_event_handler);
//////////////////////////////////////////////////////////////////////////////
// 3. Subscribe to an event and unsubscribe later via an EventConnection instance
//////////////////////////////////////////////////////////////////////////////
// define a connection to be used to unsubscribe later
EventConnection remove_event_connection;
// subscribe to the Remove event with a lambda handler function and keeping the connection
remove_event_connection = publisher.EventRemove.Connect((Widget widget) => {
Log.Message("Handling Remove event lambda\n");
}
);
// ...
// you can temporarily disable a particular event connection
remove_event_connection.Enabled = false;
// ... perform certain actions
// and enable it back when necessary
remove_event_connection.Enabled = true;
// ...
// remove the subscription later using the saved connection
remove_event_connection.Disconnect();
//////////////////////////////////////////////////////////////////////////////
// 4. Ignoring Remove events when necessary
//////////////////////////////////////////////////////////////////////////////
// you can temporarily disable the event to perform certain actions without triggering it
publisher.EventRemove.Enabled = false;
// ... actions to be performed
// and enable it back when necessary
publisher.EventRemove.Enabled = true;
Event<Widget, Widget> EventDragDrop#
Usage Example
// implement the DragDrop event handler
void dragdrop_event_handler(Widget widget, Widget target_widget)
{
Log.Message("\Handling DragDrop event\n");
}
//////////////////////////////////////////////////////////////////////////////
// 1. Multiple subscriptions can be linked to an EventConnections instance
// class that you can use later to remove all these subscriptions at once
//////////////////////////////////////////////////////////////////////////////
// create an instance of the EventConnections class
EventConnections dragdrop_event_connections = new EventConnections();
// link to this instance when subscribing to an event (subscription to various events can be linked)
publisher.EventDragDrop.Connect(dragdrop_event_connections, dragdrop_event_handler);
// other subscriptions are also linked to this EventConnections instance
// (e.g. you can subscribe using lambdas)
publisher.EventDragDrop.Connect(dragdrop_event_connections, (Widget widget, Widget target_widget) => {
Log.Message("Handling DragDrop event lambda\n");
}
);
// later all of these linked subscriptions can be removed with a single line
dragdrop_event_connections.DisconnectAll();
//////////////////////////////////////////////////////////////////////////////
// 2. You can subscribe and unsubscribe via the handler function directly
//////////////////////////////////////////////////////////////////////////////
// subscribe to the DragDrop event with a handler function
publisher.EventDragDrop.Connect(dragdrop_event_handler);
// remove subscription to the DragDrop event later by the handler function
publisher.EventDragDrop.Disconnect(dragdrop_event_handler);
//////////////////////////////////////////////////////////////////////////////
// 3. Subscribe to an event and unsubscribe later via an EventConnection instance
//////////////////////////////////////////////////////////////////////////////
// define a connection to be used to unsubscribe later
EventConnection dragdrop_event_connection;
// subscribe to the DragDrop event with a lambda handler function and keeping the connection
dragdrop_event_connection = publisher.EventDragDrop.Connect((Widget widget, Widget target_widget) => {
Log.Message("Handling DragDrop event lambda\n");
}
);
// ...
// you can temporarily disable a particular event connection
dragdrop_event_connection.Enabled = false;
// ... perform certain actions
// and enable it back when necessary
dragdrop_event_connection.Enabled = true;
// ...
// remove the subscription later using the saved connection
dragdrop_event_connection.Disconnect();
//////////////////////////////////////////////////////////////////////////////
// 4. Ignoring DragDrop events when necessary
//////////////////////////////////////////////////////////////////////////////
// you can temporarily disable the event to perform certain actions without triggering it
publisher.EventDragDrop.Enabled = false;
// ... actions to be performed
// and enable it back when necessary
publisher.EventDragDrop.Enabled = true;
Event<Widget, Widget> EventDragMove#
Usage Example
// implement the DragMove event handler
void dragmove_event_handler(Widget widget, Widget underlying_widget)
{
Log.Message("\Handling DragMove event\n");
}
//////////////////////////////////////////////////////////////////////////////
// 1. Multiple subscriptions can be linked to an EventConnections instance
// class that you can use later to remove all these subscriptions at once
//////////////////////////////////////////////////////////////////////////////
// create an instance of the EventConnections class
EventConnections dragmove_event_connections = new EventConnections();
// link to this instance when subscribing to an event (subscription to various events can be linked)
publisher.EventDragMove.Connect(dragmove_event_connections, dragmove_event_handler);
// other subscriptions are also linked to this EventConnections instance
// (e.g. you can subscribe using lambdas)
publisher.EventDragMove.Connect(dragmove_event_connections, (Widget widget, Widget underlying_widget) => {
Log.Message("Handling DragMove event lambda\n");
}
);
// later all of these linked subscriptions can be removed with a single line
dragmove_event_connections.DisconnectAll();
//////////////////////////////////////////////////////////////////////////////
// 2. You can subscribe and unsubscribe via the handler function directly
//////////////////////////////////////////////////////////////////////////////
// subscribe to the DragMove event with a handler function
publisher.EventDragMove.Connect(dragmove_event_handler);
// remove subscription to the DragMove event later by the handler function
publisher.EventDragMove.Disconnect(dragmove_event_handler);
//////////////////////////////////////////////////////////////////////////////
// 3. Subscribe to an event and unsubscribe later via an EventConnection instance
//////////////////////////////////////////////////////////////////////////////
// define a connection to be used to unsubscribe later
EventConnection dragmove_event_connection;
// subscribe to the DragMove event with a lambda handler function and keeping the connection
dragmove_event_connection = publisher.EventDragMove.Connect((Widget widget, Widget underlying_widget) => {
Log.Message("Handling DragMove event lambda\n");
}
);
// ...
// you can temporarily disable a particular event connection
dragmove_event_connection.Enabled = false;
// ... perform certain actions
// and enable it back when necessary
dragmove_event_connection.Enabled = true;
// ...
// remove the subscription later using the saved connection
dragmove_event_connection.Disconnect();
//////////////////////////////////////////////////////////////////////////////
// 4. Ignoring DragMove events when necessary
//////////////////////////////////////////////////////////////////////////////
// you can temporarily disable the event to perform certain actions without triggering it
publisher.EventDragMove.Enabled = false;
// ... actions to be performed
// and enable it back when necessary
publisher.EventDragMove.Enabled = true;
Event<Widget> EventLeave#
Usage Example
// implement the Leave event handler
void leave_event_handler(Widget widget)
{
Log.Message("\Handling Leave event\n");
}
//////////////////////////////////////////////////////////////////////////////
// 1. Multiple subscriptions can be linked to an EventConnections instance
// class that you can use later to remove all these subscriptions at once
//////////////////////////////////////////////////////////////////////////////
// create an instance of the EventConnections class
EventConnections leave_event_connections = new EventConnections();
// link to this instance when subscribing to an event (subscription to various events can be linked)
publisher.EventLeave.Connect(leave_event_connections, leave_event_handler);
// other subscriptions are also linked to this EventConnections instance
// (e.g. you can subscribe using lambdas)
publisher.EventLeave.Connect(leave_event_connections, (Widget widget) => {
Log.Message("Handling Leave event lambda\n");
}
);
// later all of these linked subscriptions can be removed with a single line
leave_event_connections.DisconnectAll();
//////////////////////////////////////////////////////////////////////////////
// 2. You can subscribe and unsubscribe via the handler function directly
//////////////////////////////////////////////////////////////////////////////
// subscribe to the Leave event with a handler function
publisher.EventLeave.Connect(leave_event_handler);
// remove subscription to the Leave event later by the handler function
publisher.EventLeave.Disconnect(leave_event_handler);
//////////////////////////////////////////////////////////////////////////////
// 3. Subscribe to an event and unsubscribe later via an EventConnection instance
//////////////////////////////////////////////////////////////////////////////
// define a connection to be used to unsubscribe later
EventConnection leave_event_connection;
// subscribe to the Leave event with a lambda handler function and keeping the connection
leave_event_connection = publisher.EventLeave.Connect((Widget widget) => {
Log.Message("Handling Leave event lambda\n");
}
);
// ...
// you can temporarily disable a particular event connection
leave_event_connection.Enabled = false;
// ... perform certain actions
// and enable it back when necessary
leave_event_connection.Enabled = true;
// ...
// remove the subscription later using the saved connection
leave_event_connection.Disconnect();
//////////////////////////////////////////////////////////////////////////////
// 4. Ignoring Leave events when necessary
//////////////////////////////////////////////////////////////////////////////
// you can temporarily disable the event to perform certain actions without triggering it
publisher.EventLeave.Enabled = false;
// ... actions to be performed
// and enable it back when necessary
publisher.EventLeave.Enabled = true;
Event<Widget> EventEnter#
Usage Example
// implement the Enter event handler
void enter_event_handler(Widget widget)
{
Log.Message("\Handling Enter event\n");
}
//////////////////////////////////////////////////////////////////////////////
// 1. Multiple subscriptions can be linked to an EventConnections instance
// class that you can use later to remove all these subscriptions at once
//////////////////////////////////////////////////////////////////////////////
// create an instance of the EventConnections class
EventConnections enter_event_connections = new EventConnections();
// link to this instance when subscribing to an event (subscription to various events can be linked)
publisher.EventEnter.Connect(enter_event_connections, enter_event_handler);
// other subscriptions are also linked to this EventConnections instance
// (e.g. you can subscribe using lambdas)
publisher.EventEnter.Connect(enter_event_connections, (Widget widget) => {
Log.Message("Handling Enter event lambda\n");
}
);
// later all of these linked subscriptions can be removed with a single line
enter_event_connections.DisconnectAll();
//////////////////////////////////////////////////////////////////////////////
// 2. You can subscribe and unsubscribe via the handler function directly
//////////////////////////////////////////////////////////////////////////////
// subscribe to the Enter event with a handler function
publisher.EventEnter.Connect(enter_event_handler);
// remove subscription to the Enter event later by the handler function
publisher.EventEnter.Disconnect(enter_event_handler);
//////////////////////////////////////////////////////////////////////////////
// 3. Subscribe to an event and unsubscribe later via an EventConnection instance
//////////////////////////////////////////////////////////////////////////////
// define a connection to be used to unsubscribe later
EventConnection enter_event_connection;
// subscribe to the Enter event with a lambda handler function and keeping the connection
enter_event_connection = publisher.EventEnter.Connect((Widget widget) => {
Log.Message("Handling Enter event lambda\n");
}
);
// ...
// you can temporarily disable a particular event connection
enter_event_connection.Enabled = false;
// ... perform certain actions
// and enable it back when necessary
enter_event_connection.Enabled = true;
// ...
// remove the subscription later using the saved connection
enter_event_connection.Disconnect();
//////////////////////////////////////////////////////////////////////////////
// 4. Ignoring Enter events when necessary
//////////////////////////////////////////////////////////////////////////////
// you can temporarily disable the event to perform certain actions without triggering it
publisher.EventEnter.Enabled = false;
// ... actions to be performed
// and enable it back when necessary
publisher.EventEnter.Enabled = true;
Event<Widget, uint> EventTextPressed#
You can subscribe to events via Connect() and unsubscribe via Disconnect(). You can also use EventConnection and EventConnections classes for convenience (see examples below).
Usage Example
// implement the TextPressed event handler
void textpressed_event_handler(Widget widget, uint unicode)
{
Log.Message("\Handling TextPressed event\n");
}
//////////////////////////////////////////////////////////////////////////////
// 1. Multiple subscriptions can be linked to an EventConnections instance
// class that you can use later to remove all these subscriptions at once
//////////////////////////////////////////////////////////////////////////////
// create an instance of the EventConnections class
EventConnections textpressed_event_connections = new EventConnections();
// link to this instance when subscribing to an event (subscription to various events can be linked)
publisher.EventTextPressed.Connect(textpressed_event_connections, textpressed_event_handler);
// other subscriptions are also linked to this EventConnections instance
// (e.g. you can subscribe using lambdas)
publisher.EventTextPressed.Connect(textpressed_event_connections, (Widget widget, uint unicode) => {
Log.Message("Handling TextPressed event lambda\n");
}
);
// later all of these linked subscriptions can be removed with a single line
textpressed_event_connections.DisconnectAll();
//////////////////////////////////////////////////////////////////////////////
// 2. You can subscribe and unsubscribe via the handler function directly
//////////////////////////////////////////////////////////////////////////////
// subscribe to the TextPressed event with a handler function
publisher.EventTextPressed.Connect(textpressed_event_handler);
// remove subscription to the TextPressed event later by the handler function
publisher.EventTextPressed.Disconnect(textpressed_event_handler);
//////////////////////////////////////////////////////////////////////////////
// 3. Subscribe to an event and unsubscribe later via an EventConnection instance
//////////////////////////////////////////////////////////////////////////////
// define a connection to be used to unsubscribe later
EventConnection textpressed_event_connection;
// subscribe to the TextPressed event with a lambda handler function and keeping the connection
textpressed_event_connection = publisher.EventTextPressed.Connect((Widget widget, uint unicode) => {
Log.Message("Handling TextPressed event lambda\n");
}
);
// ...
// you can temporarily disable a particular event connection
textpressed_event_connection.Enabled = false;
// ... perform certain actions
// and enable it back when necessary
textpressed_event_connection.Enabled = true;
// ...
// remove the subscription later using the saved connection
textpressed_event_connection.Disconnect();
//////////////////////////////////////////////////////////////////////////////
// 4. Ignoring TextPressed events when necessary
//////////////////////////////////////////////////////////////////////////////
// you can temporarily disable the event to perform certain actions without triggering it
publisher.EventTextPressed.Enabled = false;
// ... actions to be performed
// and enable it back when necessary
publisher.EventTextPressed.Enabled = true;
Event<Widget, int> EventKeyPressed#
You can subscribe to events via Connect() and unsubscribe via Disconnect(). You can also use EventConnection and EventConnections classes for convenience (see examples below).
Usage Example
// implement the KeyPressed event handler
void keypressed_event_handler(Widget widget, int key)
{
Log.Message("\Handling KeyPressed event\n");
}
//////////////////////////////////////////////////////////////////////////////
// 1. Multiple subscriptions can be linked to an EventConnections instance
// class that you can use later to remove all these subscriptions at once
//////////////////////////////////////////////////////////////////////////////
// create an instance of the EventConnections class
EventConnections keypressed_event_connections = new EventConnections();
// link to this instance when subscribing to an event (subscription to various events can be linked)
publisher.EventKeyPressed.Connect(keypressed_event_connections, keypressed_event_handler);
// other subscriptions are also linked to this EventConnections instance
// (e.g. you can subscribe using lambdas)
publisher.EventKeyPressed.Connect(keypressed_event_connections, (Widget widget, int key) => {
Log.Message("Handling KeyPressed event lambda\n");
}
);
// later all of these linked subscriptions can be removed with a single line
keypressed_event_connections.DisconnectAll();
//////////////////////////////////////////////////////////////////////////////
// 2. You can subscribe and unsubscribe via the handler function directly
//////////////////////////////////////////////////////////////////////////////
// subscribe to the KeyPressed event with a handler function
publisher.EventKeyPressed.Connect(keypressed_event_handler);
// remove subscription to the KeyPressed event later by the handler function
publisher.EventKeyPressed.Disconnect(keypressed_event_handler);
//////////////////////////////////////////////////////////////////////////////
// 3. Subscribe to an event and unsubscribe later via an EventConnection instance
//////////////////////////////////////////////////////////////////////////////
// define a connection to be used to unsubscribe later
EventConnection keypressed_event_connection;
// subscribe to the KeyPressed event with a lambda handler function and keeping the connection
keypressed_event_connection = publisher.EventKeyPressed.Connect((Widget widget, int key) => {
Log.Message("Handling KeyPressed event lambda\n");
}
);
// ...
// you can temporarily disable a particular event connection
keypressed_event_connection.Enabled = false;
// ... perform certain actions
// and enable it back when necessary
keypressed_event_connection.Enabled = true;
// ...
// remove the subscription later using the saved connection
keypressed_event_connection.Disconnect();
//////////////////////////////////////////////////////////////////////////////
// 4. Ignoring KeyPressed events when necessary
//////////////////////////////////////////////////////////////////////////////
// you can temporarily disable the event to perform certain actions without triggering it
publisher.EventKeyPressed.Enabled = false;
// ... actions to be performed
// and enable it back when necessary
publisher.EventKeyPressed.Enabled = true;
Event<Widget, int> EventReleased#
- WidgetButton
- WidgetGroupBox
- WidgetIcon
- WidgetManipulatorRotator (mouse_buttons is always 0)
- WidgetManipulatorScaler (mouse_buttons is always 0)
- WidgetManipulatorTranslator (mouse_buttons is always 0)
- WidgetSlider
- WidgetSpinBox
- WidgetSpinBoxDouble
- WidgetWindow
- EngineWindow (mouse_buttons is always 0)
- The mouse_buttons argument is a mask representing a combination of the following flags: Gui.MOUSE_MASK_LEFT | Gui.MOUSE_MASK_MIDDLE | Gui.MOUSE_MASK_RIGHT.
Usage Example:
// auxiliary variable simplifying subscriptions management
EventConnections econn = new EventConnections();
// ...
// creating a button widget and adding it to GUI
WidgetButton widget_button = new WidgetButton(WindowManager.MainWindow.Gui, "button");
WindowManager.MainWindow.Gui.AddChild(widget_button, Gui.ALIGN_OVERLAP | Gui.ALIGN_FIXED);
// enabling Console onscreen overlay
Console.Onscreen = true;
// subscribing to the Released event with a lambda-handler displaying the list of released mouse buttons
widget_button.EventReleased.Connect(econn, (Widget widget, int mouse_buttons) => {
bool left = (mouse_buttons & Gui.MOUSE_MASK_LEFT) == Gui.MOUSE_MASK_LEFT;
bool right = (mouse_buttons & Gui.MOUSE_MASK_RIGHT) == Gui.MOUSE_MASK_RIGHT;
bool middle = (mouse_buttons & Gui.MOUSE_MASK_MIDDLE) == Gui.MOUSE_MASK_MIDDLE;
// displaying information on the currently released mouse buttons
Console.OnscreenMessageLine(
"EventReleased(mouse_buttons: {0} {1} {2})",
left ? "left" : "",
right ? "right" : "",
middle ? "middle" : ""
);
});
Usage Example
// implement the Released event handler
void released_event_handler(Widget widget, int mouse_buttons)
{
Log.Message("\Handling Released event\n");
}
//////////////////////////////////////////////////////////////////////////////
// 1. Multiple subscriptions can be linked to an EventConnections instance
// class that you can use later to remove all these subscriptions at once
//////////////////////////////////////////////////////////////////////////////
// create an instance of the EventConnections class
EventConnections released_event_connections = new EventConnections();
// link to this instance when subscribing to an event (subscription to various events can be linked)
publisher.EventReleased.Connect(released_event_connections, released_event_handler);
// other subscriptions are also linked to this EventConnections instance
// (e.g. you can subscribe using lambdas)
publisher.EventReleased.Connect(released_event_connections, (Widget widget, int mouse_buttons) => {
Log.Message("Handling Released event lambda\n");
}
);
// later all of these linked subscriptions can be removed with a single line
released_event_connections.DisconnectAll();
//////////////////////////////////////////////////////////////////////////////
// 2. You can subscribe and unsubscribe via the handler function directly
//////////////////////////////////////////////////////////////////////////////
// subscribe to the Released event with a handler function
publisher.EventReleased.Connect(released_event_handler);
// remove subscription to the Released event later by the handler function
publisher.EventReleased.Disconnect(released_event_handler);
//////////////////////////////////////////////////////////////////////////////
// 3. Subscribe to an event and unsubscribe later via an EventConnection instance
//////////////////////////////////////////////////////////////////////////////
// define a connection to be used to unsubscribe later
EventConnection released_event_connection;
// subscribe to the Released event with a lambda handler function and keeping the connection
released_event_connection = publisher.EventReleased.Connect((Widget widget, int mouse_buttons) => {
Log.Message("Handling Released event lambda\n");
}
);
// ...
// you can temporarily disable a particular event connection
released_event_connection.Enabled = false;
// ... perform certain actions
// and enable it back when necessary
released_event_connection.Enabled = true;
// ...
// remove the subscription later using the saved connection
released_event_connection.Disconnect();
//////////////////////////////////////////////////////////////////////////////
// 4. Ignoring Released events when necessary
//////////////////////////////////////////////////////////////////////////////
// you can temporarily disable the event to perform certain actions without triggering it
publisher.EventReleased.Enabled = false;
// ... actions to be performed
// and enable it back when necessary
publisher.EventReleased.Enabled = true;
Event<Widget, int> EventPressed#
- WidgetButton
- WidgetCanvas
- WidgetEditLine
- WidgetSlider
- WidgetIcon
- WidgetLabel
- WidgetListBox
- WidgetSpinBox
- WidgetSprite
- WidgetWindow
- The mouse_buttons argument is a mask representing a combination of the following flags: Gui.MOUSE_MASK_LEFT | Gui.MOUSE_MASK_MIDDLE | Gui.MOUSE_MASK_RIGHT.
Usage Example:
// auxiliary variable simplifying subscriptions management
EventConnections econn = new EventConnections();
// ...
// creating a button widget and adding it to GUI
WidgetButton widget_button = new WidgetButton(WindowManager.MainWindow.Gui, "button");
WindowManager.MainWindow.Gui.AddChild(widget_button, Gui.ALIGN_OVERLAP | Gui.ALIGN_FIXED);
// enabling Console onscreen overlay
Console.Onscreen = true;
// subscribing to the Pressed event with a lambda-handler displaying the list of pressed mouse buttons
widget_button.EventPressed.Connect(econn, (Widget widget, int mouse_buttons) => {
bool left = (mouse_buttons & Gui.MOUSE_MASK_LEFT) == Gui.MOUSE_MASK_LEFT;
bool right = (mouse_buttons & Gui.MOUSE_MASK_RIGHT) == Gui.MOUSE_MASK_RIGHT;
bool middle = (mouse_buttons & Gui.MOUSE_MASK_MIDDLE) == Gui.MOUSE_MASK_MIDDLE;
// displaying information on the currently pressed mouse buttons
Console.OnscreenMessageLine(
"EventPressed(mouse_buttons: {0} {1} {2})",
left ? "left" : "",
right ? "right" : "",
middle ? "middle" : ""
);
});
Usage Example
// implement the Pressed event handler
void pressed_event_handler(Widget widget, int mouse_buttons)
{
Log.Message("\Handling Pressed event\n");
}
//////////////////////////////////////////////////////////////////////////////
// 1. Multiple subscriptions can be linked to an EventConnections instance
// class that you can use later to remove all these subscriptions at once
//////////////////////////////////////////////////////////////////////////////
// create an instance of the EventConnections class
EventConnections pressed_event_connections = new EventConnections();
// link to this instance when subscribing to an event (subscription to various events can be linked)
publisher.EventPressed.Connect(pressed_event_connections, pressed_event_handler);
// other subscriptions are also linked to this EventConnections instance
// (e.g. you can subscribe using lambdas)
publisher.EventPressed.Connect(pressed_event_connections, (Widget widget, int mouse_buttons) => {
Log.Message("Handling Pressed event lambda\n");
}
);
// later all of these linked subscriptions can be removed with a single line
pressed_event_connections.DisconnectAll();
//////////////////////////////////////////////////////////////////////////////
// 2. You can subscribe and unsubscribe via the handler function directly
//////////////////////////////////////////////////////////////////////////////
// subscribe to the Pressed event with a handler function
publisher.EventPressed.Connect(pressed_event_handler);
// remove subscription to the Pressed event later by the handler function
publisher.EventPressed.Disconnect(pressed_event_handler);
//////////////////////////////////////////////////////////////////////////////
// 3. Subscribe to an event and unsubscribe later via an EventConnection instance
//////////////////////////////////////////////////////////////////////////////
// define a connection to be used to unsubscribe later
EventConnection pressed_event_connection;
// subscribe to the Pressed event with a lambda handler function and keeping the connection
pressed_event_connection = publisher.EventPressed.Connect((Widget widget, int mouse_buttons) => {
Log.Message("Handling Pressed event lambda\n");
}
);
// ...
// you can temporarily disable a particular event connection
pressed_event_connection.Enabled = false;
// ... perform certain actions
// and enable it back when necessary
pressed_event_connection.Enabled = true;
// ...
// remove the subscription later using the saved connection
pressed_event_connection.Disconnect();
//////////////////////////////////////////////////////////////////////////////
// 4. Ignoring Pressed events when necessary
//////////////////////////////////////////////////////////////////////////////
// you can temporarily disable the event to perform certain actions without triggering it
publisher.EventPressed.Enabled = false;
// ... actions to be performed
// and enable it back when necessary
publisher.EventPressed.Enabled = true;
Event<Widget> EventDoubleClicked#
- WidgetButton
- WidgetCheckBox
- WidgetComboBox
- WidgetEditLine
- WidgetEditText
- WidgetHPaned
- WidgetIcon
- WidgetLabel
- WidgetListBox
- WidgetManipulatorRotator
- WidgetManipulatorScaler
- WidgetManipulatorTranslator
- WidgetScroll
- WidgetSpinBox
- WidgetTreeBox
- WidgetVPaned
- WidgetWindow
Usage Example
// implement the DoubleClicked event handler
void doubleclicked_event_handler(Widget widget)
{
Log.Message("\Handling DoubleClicked event\n");
}
//////////////////////////////////////////////////////////////////////////////
// 1. Multiple subscriptions can be linked to an EventConnections instance
// class that you can use later to remove all these subscriptions at once
//////////////////////////////////////////////////////////////////////////////
// create an instance of the EventConnections class
EventConnections doubleclicked_event_connections = new EventConnections();
// link to this instance when subscribing to an event (subscription to various events can be linked)
publisher.EventDoubleClicked.Connect(doubleclicked_event_connections, doubleclicked_event_handler);
// other subscriptions are also linked to this EventConnections instance
// (e.g. you can subscribe using lambdas)
publisher.EventDoubleClicked.Connect(doubleclicked_event_connections, (Widget widget) => {
Log.Message("Handling DoubleClicked event lambda\n");
}
);
// later all of these linked subscriptions can be removed with a single line
doubleclicked_event_connections.DisconnectAll();
//////////////////////////////////////////////////////////////////////////////
// 2. You can subscribe and unsubscribe via the handler function directly
//////////////////////////////////////////////////////////////////////////////
// subscribe to the DoubleClicked event with a handler function
publisher.EventDoubleClicked.Connect(doubleclicked_event_handler);
// remove subscription to the DoubleClicked event later by the handler function
publisher.EventDoubleClicked.Disconnect(doubleclicked_event_handler);
//////////////////////////////////////////////////////////////////////////////
// 3. Subscribe to an event and unsubscribe later via an EventConnection instance
//////////////////////////////////////////////////////////////////////////////
// define a connection to be used to unsubscribe later
EventConnection doubleclicked_event_connection;
// subscribe to the DoubleClicked event with a lambda handler function and keeping the connection
doubleclicked_event_connection = publisher.EventDoubleClicked.Connect((Widget widget) => {
Log.Message("Handling DoubleClicked event lambda\n");
}
);
// ...
// you can temporarily disable a particular event connection
doubleclicked_event_connection.Enabled = false;
// ... perform certain actions
// and enable it back when necessary
doubleclicked_event_connection.Enabled = true;
// ...
// remove the subscription later using the saved connection
doubleclicked_event_connection.Disconnect();
//////////////////////////////////////////////////////////////////////////////
// 4. Ignoring DoubleClicked events when necessary
//////////////////////////////////////////////////////////////////////////////
// you can temporarily disable the event to perform certain actions without triggering it
publisher.EventDoubleClicked.Enabled = false;
// ... actions to be performed
// and enable it back when necessary
publisher.EventDoubleClicked.Enabled = true;
Event<Widget, int> EventClicked#
- WidgetButton
- WidgetCheckBox
- WidgetComboBox
- WidgetDialog
- WidgetDialogFile
- WidgetEditLine
- WidgetEditText
- WidgetHPaned
- WidgetScroll
- WidgetSlider
- WidgetIcon
- WidgetLabel
- WidgetListBox
- WidgetManipulatorRotator
- WidgetManipulatorScaler
- WidgetManipulatorTranslator
- WidgetMenuBox
- WidgetSpinBox
- WidgetSprite
- WidgetTreeBox
- WidgetVPaned
- The mouse_buttons argument is a mask representing a combination of the following flags: Gui.MOUSE_MASK_LEFT | Gui.MOUSE_MASK_MIDDLE | Gui.MOUSE_MASK_RIGHT.
Usage Example:
// auxiliary variable simplifying subscriptions management
EventConnections econn = new EventConnections();
// ...
// creating a button widget and adding it to GUI
WidgetButton widget_button = new WidgetButton(WindowManager.MainWindow.Gui, "button");
WindowManager.MainWindow.Gui.AddChild(widget_button, Gui.ALIGN_OVERLAP | Gui.ALIGN_FIXED);
// enabling Console onscreen overlay
Console.Onscreen = true;
// subscribing to the Clicked event with a lambda-handler displaying the list of clicked mouse buttons
widget_button.EventClicked.Connect(econn, (Widget widget, int mouse_buttons) => {
bool left = (mouse_buttons & Gui.MOUSE_MASK_LEFT) == Gui.MOUSE_MASK_LEFT;
bool right = (mouse_buttons & Gui.MOUSE_MASK_RIGHT) == Gui.MOUSE_MASK_RIGHT;
bool middle = (mouse_buttons & Gui.MOUSE_MASK_MIDDLE) == Gui.MOUSE_MASK_MIDDLE;
// displaying information on the currently clicked mouse buttons
Console.OnscreenMessageLine(
"EventClicked(mouse_buttons: {0} {1} {2})",
left ? "left" : "",
right ? "right" : "",
middle ? "middle" : ""
);
});
Usage Example
// implement the Clicked event handler
void clicked_event_handler(Widget widget, int mouse_buttons)
{
Log.Message("\Handling Clicked event\n");
}
//////////////////////////////////////////////////////////////////////////////
// 1. Multiple subscriptions can be linked to an EventConnections instance
// class that you can use later to remove all these subscriptions at once
//////////////////////////////////////////////////////////////////////////////
// create an instance of the EventConnections class
EventConnections clicked_event_connections = new EventConnections();
// link to this instance when subscribing to an event (subscription to various events can be linked)
publisher.EventClicked.Connect(clicked_event_connections, clicked_event_handler);
// other subscriptions are also linked to this EventConnections instance
// (e.g. you can subscribe using lambdas)
publisher.EventClicked.Connect(clicked_event_connections, (Widget widget, int mouse_buttons) => {
Log.Message("Handling Clicked event lambda\n");
}
);
// later all of these linked subscriptions can be removed with a single line
clicked_event_connections.DisconnectAll();
//////////////////////////////////////////////////////////////////////////////
// 2. You can subscribe and unsubscribe via the handler function directly
//////////////////////////////////////////////////////////////////////////////
// subscribe to the Clicked event with a handler function
publisher.EventClicked.Connect(clicked_event_handler);
// remove subscription to the Clicked event later by the handler function
publisher.EventClicked.Disconnect(clicked_event_handler);
//////////////////////////////////////////////////////////////////////////////
// 3. Subscribe to an event and unsubscribe later via an EventConnection instance
//////////////////////////////////////////////////////////////////////////////
// define a connection to be used to unsubscribe later
EventConnection clicked_event_connection;
// subscribe to the Clicked event with a lambda handler function and keeping the connection
clicked_event_connection = publisher.EventClicked.Connect((Widget widget, int mouse_buttons) => {
Log.Message("Handling Clicked event lambda\n");
}
);
// ...
// you can temporarily disable a particular event connection
clicked_event_connection.Enabled = false;
// ... perform certain actions
// and enable it back when necessary
clicked_event_connection.Enabled = true;
// ...
// remove the subscription later using the saved connection
clicked_event_connection.Disconnect();
//////////////////////////////////////////////////////////////////////////////
// 4. Ignoring Clicked events when necessary
//////////////////////////////////////////////////////////////////////////////
// you can temporarily disable the event to perform certain actions without triggering it
publisher.EventClicked.Enabled = false;
// ... actions to be performed
// and enable it back when necessary
publisher.EventClicked.Enabled = true;
Event<Widget> EventChanged#
- WidgetButton
- WidgetCheckBox
- WidgetComboBox
- WidgetDialogColor
- WidgetEditLine
- WidgetEditText
- WidgetHPaned
- WidgetScroll
- WidgetScrollBox
- WidgetSlider
- WidgetIcon
- WidgetLabel
- WidgetListBox
- WidgetManipulator
- WidgetManipulatorRotator
- WidgetManipulatorScaler
- WidgetManipulatorTranslator
- WidgetSpinBox
- WidgetSpinBoxDouble
- WidgetTabBox
- WidgetTreeBox
- WidgetVPaned
Usage Example
// implement the Changed event handler
void changed_event_handler(Widget widget)
{
Log.Message("\Handling Changed event\n");
}
//////////////////////////////////////////////////////////////////////////////
// 1. Multiple subscriptions can be linked to an EventConnections instance
// class that you can use later to remove all these subscriptions at once
//////////////////////////////////////////////////////////////////////////////
// create an instance of the EventConnections class
EventConnections changed_event_connections = new EventConnections();
// link to this instance when subscribing to an event (subscription to various events can be linked)
publisher.EventChanged.Connect(changed_event_connections, changed_event_handler);
// other subscriptions are also linked to this EventConnections instance
// (e.g. you can subscribe using lambdas)
publisher.EventChanged.Connect(changed_event_connections, (Widget widget) => {
Log.Message("Handling Changed event lambda\n");
}
);
// later all of these linked subscriptions can be removed with a single line
changed_event_connections.DisconnectAll();
//////////////////////////////////////////////////////////////////////////////
// 2. You can subscribe and unsubscribe via the handler function directly
//////////////////////////////////////////////////////////////////////////////
// subscribe to the Changed event with a handler function
publisher.EventChanged.Connect(changed_event_handler);
// remove subscription to the Changed event later by the handler function
publisher.EventChanged.Disconnect(changed_event_handler);
//////////////////////////////////////////////////////////////////////////////
// 3. Subscribe to an event and unsubscribe later via an EventConnection instance
//////////////////////////////////////////////////////////////////////////////
// define a connection to be used to unsubscribe later
EventConnection changed_event_connection;
// subscribe to the Changed event with a lambda handler function and keeping the connection
changed_event_connection = publisher.EventChanged.Connect((Widget widget) => {
Log.Message("Handling Changed event lambda\n");
}
);
// ...
// you can temporarily disable a particular event connection
changed_event_connection.Enabled = false;
// ... perform certain actions
// and enable it back when necessary
changed_event_connection.Enabled = true;
// ...
// remove the subscription later using the saved connection
changed_event_connection.Disconnect();
//////////////////////////////////////////////////////////////////////////////
// 4. Ignoring Changed events when necessary
//////////////////////////////////////////////////////////////////////////////
// you can temporarily disable the event to perform certain actions without triggering it
publisher.EventChanged.Enabled = false;
// ... actions to be performed
// and enable it back when necessary
publisher.EventChanged.Enabled = true;
Event<Widget> EventFocusOut#
Usage Example
// implement the FocusOut event handler
void focusout_event_handler(Widget widget)
{
Log.Message("\Handling FocusOut event\n");
}
//////////////////////////////////////////////////////////////////////////////
// 1. Multiple subscriptions can be linked to an EventConnections instance
// class that you can use later to remove all these subscriptions at once
//////////////////////////////////////////////////////////////////////////////
// create an instance of the EventConnections class
EventConnections focusout_event_connections = new EventConnections();
// link to this instance when subscribing to an event (subscription to various events can be linked)
publisher.EventFocusOut.Connect(focusout_event_connections, focusout_event_handler);
// other subscriptions are also linked to this EventConnections instance
// (e.g. you can subscribe using lambdas)
publisher.EventFocusOut.Connect(focusout_event_connections, (Widget widget) => {
Log.Message("Handling FocusOut event lambda\n");
}
);
// later all of these linked subscriptions can be removed with a single line
focusout_event_connections.DisconnectAll();
//////////////////////////////////////////////////////////////////////////////
// 2. You can subscribe and unsubscribe via the handler function directly
//////////////////////////////////////////////////////////////////////////////
// subscribe to the FocusOut event with a handler function
publisher.EventFocusOut.Connect(focusout_event_handler);
// remove subscription to the FocusOut event later by the handler function
publisher.EventFocusOut.Disconnect(focusout_event_handler);
//////////////////////////////////////////////////////////////////////////////
// 3. Subscribe to an event and unsubscribe later via an EventConnection instance
//////////////////////////////////////////////////////////////////////////////
// define a connection to be used to unsubscribe later
EventConnection focusout_event_connection;
// subscribe to the FocusOut event with a lambda handler function and keeping the connection
focusout_event_connection = publisher.EventFocusOut.Connect((Widget widget) => {
Log.Message("Handling FocusOut event lambda\n");
}
);
// ...
// you can temporarily disable a particular event connection
focusout_event_connection.Enabled = false;
// ... perform certain actions
// and enable it back when necessary
focusout_event_connection.Enabled = true;
// ...
// remove the subscription later using the saved connection
focusout_event_connection.Disconnect();
//////////////////////////////////////////////////////////////////////////////
// 4. Ignoring FocusOut events when necessary
//////////////////////////////////////////////////////////////////////////////
// you can temporarily disable the event to perform certain actions without triggering it
publisher.EventFocusOut.Enabled = false;
// ... actions to be performed
// and enable it back when necessary
publisher.EventFocusOut.Enabled = true;
Event<Widget> EventFocusIn#
Usage Example
// implement the FocusIn event handler
void focusin_event_handler(Widget widget)
{
Log.Message("\Handling FocusIn event\n");
}
//////////////////////////////////////////////////////////////////////////////
// 1. Multiple subscriptions can be linked to an EventConnections instance
// class that you can use later to remove all these subscriptions at once
//////////////////////////////////////////////////////////////////////////////
// create an instance of the EventConnections class
EventConnections focusin_event_connections = new EventConnections();
// link to this instance when subscribing to an event (subscription to various events can be linked)
publisher.EventFocusIn.Connect(focusin_event_connections, focusin_event_handler);
// other subscriptions are also linked to this EventConnections instance
// (e.g. you can subscribe using lambdas)
publisher.EventFocusIn.Connect(focusin_event_connections, (Widget widget) => {
Log.Message("Handling FocusIn event lambda\n");
}
);
// later all of these linked subscriptions can be removed with a single line
focusin_event_connections.DisconnectAll();
//////////////////////////////////////////////////////////////////////////////
// 2. You can subscribe and unsubscribe via the handler function directly
//////////////////////////////////////////////////////////////////////////////
// subscribe to the FocusIn event with a handler function
publisher.EventFocusIn.Connect(focusin_event_handler);
// remove subscription to the FocusIn event later by the handler function
publisher.EventFocusIn.Disconnect(focusin_event_handler);
//////////////////////////////////////////////////////////////////////////////
// 3. Subscribe to an event and unsubscribe later via an EventConnection instance
//////////////////////////////////////////////////////////////////////////////
// define a connection to be used to unsubscribe later
EventConnection focusin_event_connection;
// subscribe to the FocusIn event with a lambda handler function and keeping the connection
focusin_event_connection = publisher.EventFocusIn.Connect((Widget widget) => {
Log.Message("Handling FocusIn event lambda\n");
}
);
// ...
// you can temporarily disable a particular event connection
focusin_event_connection.Enabled = false;
// ... perform certain actions
// and enable it back when necessary
focusin_event_connection.Enabled = true;
// ...
// remove the subscription later using the saved connection
focusin_event_connection.Disconnect();
//////////////////////////////////////////////////////////////////////////////
// 4. Ignoring FocusIn events when necessary
//////////////////////////////////////////////////////////////////////////////
// you can temporarily disable the event to perform certain actions without triggering it
publisher.EventFocusIn.Enabled = false;
// ... actions to be performed
// and enable it back when necessary
publisher.EventFocusIn.Enabled = true;
Event<Widget> EventHide#
Usage Example
// implement the Hide event handler
void hide_event_handler(Widget widget)
{
Log.Message("\Handling Hide event\n");
}
//////////////////////////////////////////////////////////////////////////////
// 1. Multiple subscriptions can be linked to an EventConnections instance
// class that you can use later to remove all these subscriptions at once
//////////////////////////////////////////////////////////////////////////////
// create an instance of the EventConnections class
EventConnections hide_event_connections = new EventConnections();
// link to this instance when subscribing to an event (subscription to various events can be linked)
publisher.EventHide.Connect(hide_event_connections, hide_event_handler);
// other subscriptions are also linked to this EventConnections instance
// (e.g. you can subscribe using lambdas)
publisher.EventHide.Connect(hide_event_connections, (Widget widget) => {
Log.Message("Handling Hide event lambda\n");
}
);
// later all of these linked subscriptions can be removed with a single line
hide_event_connections.DisconnectAll();
//////////////////////////////////////////////////////////////////////////////
// 2. You can subscribe and unsubscribe via the handler function directly
//////////////////////////////////////////////////////////////////////////////
// subscribe to the Hide event with a handler function
publisher.EventHide.Connect(hide_event_handler);
// remove subscription to the Hide event later by the handler function
publisher.EventHide.Disconnect(hide_event_handler);
//////////////////////////////////////////////////////////////////////////////
// 3. Subscribe to an event and unsubscribe later via an EventConnection instance
//////////////////////////////////////////////////////////////////////////////
// define a connection to be used to unsubscribe later
EventConnection hide_event_connection;
// subscribe to the Hide event with a lambda handler function and keeping the connection
hide_event_connection = publisher.EventHide.Connect((Widget widget) => {
Log.Message("Handling Hide event lambda\n");
}
);
// ...
// you can temporarily disable a particular event connection
hide_event_connection.Enabled = false;
// ... perform certain actions
// and enable it back when necessary
hide_event_connection.Enabled = true;
// ...
// remove the subscription later using the saved connection
hide_event_connection.Disconnect();
//////////////////////////////////////////////////////////////////////////////
// 4. Ignoring Hide events when necessary
//////////////////////////////////////////////////////////////////////////////
// you can temporarily disable the event to perform certain actions without triggering it
publisher.EventHide.Enabled = false;
// ... actions to be performed
// and enable it back when necessary
publisher.EventHide.Enabled = true;
Event<Widget> EventShow#
Usage Example
// implement the Show event handler
void show_event_handler(Widget widget)
{
Log.Message("\Handling Show event\n");
}
//////////////////////////////////////////////////////////////////////////////
// 1. Multiple subscriptions can be linked to an EventConnections instance
// class that you can use later to remove all these subscriptions at once
//////////////////////////////////////////////////////////////////////////////
// create an instance of the EventConnections class
EventConnections show_event_connections = new EventConnections();
// link to this instance when subscribing to an event (subscription to various events can be linked)
publisher.EventShow.Connect(show_event_connections, show_event_handler);
// other subscriptions are also linked to this EventConnections instance
// (e.g. you can subscribe using lambdas)
publisher.EventShow.Connect(show_event_connections, (Widget widget) => {
Log.Message("Handling Show event lambda\n");
}
);
// later all of these linked subscriptions can be removed with a single line
show_event_connections.DisconnectAll();
//////////////////////////////////////////////////////////////////////////////
// 2. You can subscribe and unsubscribe via the handler function directly
//////////////////////////////////////////////////////////////////////////////
// subscribe to the Show event with a handler function
publisher.EventShow.Connect(show_event_handler);
// remove subscription to the Show event later by the handler function
publisher.EventShow.Disconnect(show_event_handler);
//////////////////////////////////////////////////////////////////////////////
// 3. Subscribe to an event and unsubscribe later via an EventConnection instance
//////////////////////////////////////////////////////////////////////////////
// define a connection to be used to unsubscribe later
EventConnection show_event_connection;
// subscribe to the Show event with a lambda handler function and keeping the connection
show_event_connection = publisher.EventShow.Connect((Widget widget) => {
Log.Message("Handling Show event lambda\n");
}
);
// ...
// you can temporarily disable a particular event connection
show_event_connection.Enabled = false;
// ... perform certain actions
// and enable it back when necessary
show_event_connection.Enabled = true;
// ...
// remove the subscription later using the saved connection
show_event_connection.Disconnect();
//////////////////////////////////////////////////////////////////////////////
// 4. Ignoring Show events when necessary
//////////////////////////////////////////////////////////////////////////////
// you can temporarily disable the event to perform certain actions without triggering it
publisher.EventShow.Enabled = false;
// ... actions to be performed
// and enable it back when necessary
publisher.EventShow.Enabled = true;
Members
Widget GetChild ( int num ) #
Returns a child widget with a given number.Arguments
- int num - Widget number.
Return value
Required widget.int IsChild ( Widget w ) #
Checks if a given widget is a child of the current one.Arguments
- Widget w - Widget to check.
Return value
1 if the widget in question is a child; otherwise, 0.void SetFocus ( ) #
Sets focus on the widget.int IsFocused ( ) #
Returns a value indicating if the widget is currently in focus.Return value
1 if the widget is in focus; otherwise, 0.void SetFont ( string name ) #
Sets a true-type font (*.ttf) that will be used to render text on the widget by file path.Arguments
- string name - Path to the font file (*.ttf) stored in your project's data folder.
bool GetIntersection ( int local_pos_x, int local_pos_y ) #
Checks for an intersection with the widget's bounds for the given point.Arguments
- int local_pos_x - Local X coordinate.
- int local_pos_y - Local Y coordinate.
Return value
true if the input coordinate is inside the widget; otherwise, false.Widget GetHierarchyIntersection ( int screen_pos_x, int screen_pos_y ) #
Checks for an intersection with a widget that belongs to the hierarchy of the current widget.Arguments
- int screen_pos_x - The X coordinate of the screen position.
- int screen_pos_y - The Y coordinate of the screen position.
Return value
Widget the intersection with which is found.int GetKeyActivity ( uint key ) #
Checks if a given key already has a special purpose for the widget.Arguments
- uint key - ASCII key code: one of the Input.KEY.*values.
Return value
1 if the key cannot be used; otherwise, 0.void SetPermanentFocus ( ) #
Sets permanent focus on the widget (it means that the widget is always in focus).void SetPosition ( int x, int y ) #
Sets a position of the widget relative to its parent.Arguments
- int x - X coordinate of the upper left corner of the widget.
- int y - Y coordinate of the upper left corner of the widget.
void SetToolTip ( string str, int reset = 0 ) #
Sets a tooltip for the widget.Arguments
- string str - Tooltip text.
- int reset - 1 to recalculate a tooltip location if the mouse cursor was relocated; otherwise — 0(by default).
string GetToolTip ( ) #
Returns the widget's tooltip text.Return value
Tooltip text.void AddAttach ( Widget w, string format = 0, int multiplier = 1, int flags = 0 ) #
Attaches a given widget to the current one. When applied to checkboxes, converts them into a group of radio buttons. A horizontal/vertical slider can be attached to a label or a text field. The text field can be attached to any of the sliders.Arguments
- Widget w - Widget to attach.
- string format - Format string for values entered into the attached widget. If none specified, "%d" is implied. This is an optional parameter.
- int multiplier - Multiplier value, which is used to scale values provided by the attached widget. This is an optional parameter.
- int flags - One of the ATTACH_* pre-defined variables. This is an optional parameter.
void AddChild ( Widget w, int flags = 0 ) #
Adds a child to the widget.Arguments
- Widget w - Child widget.
- int flags - One of the ALIGN_* pre-defined variables. This is an optional parameter.
void Arrange ( ) #
Rearranges the widget and its children to lay them out neatly. This function forces to recalculate widget size and allows to get updated GUI layout data in the current frame. If this function is not called, widget modifications made in the current update() will be available only in the next frame (i.e. with one-frame lag), as GUI is calculated and rendered after the script update() function has been executed.void Raise ( Widget w ) #
Brings a given widget to the top.Arguments
- Widget w - Widget to be brought up.
void RemoveAttach ( Widget w ) #
Detaches a given widget from the current one.Arguments
- Widget w - Widget to detach.
void RemoveChild ( Widget w ) #
Removes a child widget from the list of the widget's children.Arguments
- Widget w - Child widget.
void RemoveFocus ( ) #
Removes focus from the widget.void ReplaceChild ( Widget w, Widget old_w, int flags = 0 ) #
Replaces one child widget with another.Arguments
- Widget w - Replacement widget.
- Widget old_w - Widget to be replaced.
- int flags - One of the ALIGN_* pre-defined variables. This is an optional parameter.
Widget.LIFETIME GetLifetimeSelf ( ) #
Returns the lifetime management type set for the widget.int ToRenderSize ( int unit_size ) #
Transforms the unit value to the pixel value.Arguments
- int unit_size - Size in units.
Return value
Size in pixels.int ToUnitSize ( int render_size ) #
Transforms the pixel value to the unit value.Arguments
- int render_size - Size in pixels.
Return value
Size in units.ivec2 ToRenderSize ( ivec2 unit_size ) #
Transforms the unit value to the pixel value.Arguments
- ivec2 unit_size - Size in units.
Return value
Size in pixels.ivec2 ToUnitSize ( ivec2 render_size ) #
Transforms the pixel value to the unit value.Arguments
- ivec2 render_size - Size in pixels.
Return value
Size in units.ivec2 GetTextRenderSize ( char[] OUT_text ) #
Returns the size (in pixels) of the specified text string rendered on the screen with taking into account all text output settings such as dpi, font size and style.Arguments
- char[]
OUT_text - Text string.This output buffer is to be filled by the Engine as a result of executing the method.
Return value
Text size in pixels.void RunEventShow ( ) #
Emulates the Show event.void RunEventHide ( ) #
Emulates the Hide event.void RunEventFocusIn ( ) #
Emulates the FocusIn event.void RunEventFocusOut ( ) #
Emulates the FocusOut event.void RunEventChanged ( ) #
Emulates the Changed event.void RunEventClicked ( int mouse_buttons ) #
Emulates the Clicked event.Arguments
- int mouse_buttons - Mouse button - a mask representing a combination of the following flags: Gui.MOUSE_MASK_LEFT | Gui.MOUSE_MASK_MIDDLE | Gui.MOUSE_MASK_RIGHT.
void RunEventDoubleClicked ( ) #
Emulates the DoubleClicked event.void RunEventPressed ( int mouse_buttons ) #
Emulates the Pressed event.Arguments
- int mouse_buttons - Mouse button - a mask representing a combination of the following flags: Gui.MOUSE_MASK_LEFT | Gui.MOUSE_MASK_MIDDLE | Gui.MOUSE_MASK_RIGHT.
void RunEventReleased ( int mouse_buttons ) #
Emulates the Released event.Arguments
- int mouse_buttons - Mouse button - a mask representing a combination of the following flags: Gui.MOUSE_MASK_LEFT | Gui.MOUSE_MASK_MIDDLE | Gui.MOUSE_MASK_RIGHT.
void RunEventKeyPressed ( int key ) #
Emulates the KeyPressed event.Arguments
- int key - Key scan code.
void RunEventTextPressed ( uint code ) #
Emulates the TextPressed event.Arguments
- uint code - Vistual key.
void RunEventEnter ( ) #
Emulates the Enter event.void RunEventLeave ( ) #
Emulates the Leave event.void RunEventDragMove ( Widget pointer ) #
Emulates the DragMove event.Arguments
- Widget pointer - Underlying widget.
void RunEventDragDrop ( Widget pointer ) #
Emulates the DragDrop event.Arguments
- Widget pointer - Target widget.