Skip to content

EmuCore

Michael edited this page Jun 13, 2020 · 13 revisions

Emu uses a "container" system, which lets you add elements to a container and recursively update and draw all of its contents. EmuCore is the main container object which you will want to add contents to.

Note that all container contents will be drawn relative to their containers.

Constructor

EmuCore(x, y, width, height)

Parameter Type Description
x real The x coordinate where the container will be created
y real The y coordinate where the container will be created
w real The width of the container
h real The height of the container

Relevant Methods

EmuCore::AddContent(elements)

Returns: N/A

Parameter Type Description
elements EmuCore The element(s) you wish to add to the container

Use this to add sub-elements to the container. This may be a single element, or an array of elements. If you give it an array, all of the elements will be added.

You would normally position elements manually, but if you would like elements to automatically be placed below the previous element you may specify EMU_AUTO as the y coordinate in an element's constructor. The spacing between elements is determined by the EmuCore variable element_spacing_y.

EmuCore::RemoveContent(elements)

Returns: N/A

Parameter Type Description
elements EmuCore The element(s) you wish to remove from the container

Use this to remove sub-elements from the container. This may be a single element, or an array of elements. If you give it an array, all of the elements will be removed.

EmuCore::SetNext(element)

Returns: N/A

Parameter Type Description
element EmuCore The element that you would like to link as the "next" element

If a "next" element is defined, pressing the Tab key with the current element active will activate it. Passing a non-null value to this method will also set the next element's "previous" value.

EmuCore::SetPrevious(element)

Returns: N/A

Parameter Type Description
element EmuCore The element that you would like to link as the "previous" element

If a "next" element is defined, pressing the Shift and Tab keys with the current element active will activate it. Passing a non-null value to this method will also set the next element's "next" value.

EmuCore::GetHeight()

Returns: real

Use this to retrieve the height of the container.

EmuCore::Render([base_x], [base_y])

Parameter Type Description
base_x real (optional) The position on the x axis that the container and its contents will be drawn
base_y real (optional) The position on the y axis that the container and its contents will be drawn

Returns: N/A

Use this to draw the container and all of its contents. All contents will be drawn relative to their container. If no coordinates are specified, they will default to 0.

EmuCore::Destroy()

Returns: N/A

The garbage collector will automatically remove some types of data, but not others. Use this to explicitly destroy the container and its contents. The struct will continue to exist until all references to it are lost and it is removed by the garbage collector; only call this method when you know you are finished with it.

EmuCore::SetInteractive(interactive)

Returns: N/A

Parameter Type Description
interactive boolean Whether or not the element is interactive

Setting an element's interactivity to false will prevent it from responding to input, but will allow it to remain visible. The element will be grayed out to indicate its deactivated state. This is will not affect a container's contents, and is only useful for element types which respond to input.

If you wish to deactivate an element and also prevent it from being rendered (effectively deactivating all of its child elements, as well) use the element's enabled variable.

EmuCore::Activate()

Returns: N/A

Use this to activate the UI element (e.g. enable typing in a text input field).

EmuCore::GetInteractive()

Returns: boolean

Use this to check if the element is currently interactive. Elements will not be interactive if they have been explicitly disabled, or if there is another element (e.g. a dialog window) blocking them.

Example

container = new EmuCore(32, 32, 640, 640);
container.AddContent(new EmuText(32, 32, 256, 32, "Text label"));
container.AddContent(new EmuButton(32, 64, 256, 32, "Top Button", emu_null));
container.AddContent(new EmuButton(32, 96, 256, 32, "Bottom Button", emu_null));

This will create an EmuCore container and populate it with a text label and two buttons.

container.Render(0, 0);

If you really like JavaScript, you may add elements to the container like this instead:

container.AddContent([
    new EmuText(32, 32, 256, 32, "Text label"),
    new EmuButton(32, 64, 256, 32, "Top Button", emu_null),
    new EmuButton(32, 96, 256, 32, "Bottom Button", emu_null)
]);

This will draw the previously created container and all of its elements.

Derived classes

EmuCore is also the base class that all other Emu elements derive from.

Helpful Functions

emu_null()

A placeholder function which does not perform any action and does not return a value. This is useful for callbacks which you do not actually need to do anything. You are also free to use it as a placeholder function elsewhere in your code.