Memento JavaScript UI: Difference between revisions

From Memento Database Wiki
Jump to navigation Jump to search
No edit summary
Line 11: Line 11:
=== Notes ===
=== Notes ===


A script must return one UI object.
* A script must return one UI object.
If you want to display multiple UI objects, you can use a layout object, which can hold multiple objects.
* If you want to display multiple UI objects, you can use a layout object, which can hold multiple objects.
 
Example usage of a layout object:
Example usage of a layout object:
<source lang="javascript">
<source lang="javascript">

Revision as of 23:22, 3 April 2023

Overview

The ui() method is a JavaScript API provided by Memento Database that grants access to a framework of methods and objects for creating user interfaces (UIs) within Memento widgets. With this method, developers can create various UI elements such as text labels, buttons, images, layers, and checkboxes.

Example Usage

ui().text('Hello, world!');

In this example, the ui() method is called to create a new UI object, which is then used to create a text label with the text "Hello, world!".

Notes

  • A script must return one UI object.
  • If you want to display multiple UI objects, you can use a layout object, which can hold multiple objects.

Example usage of a layout object:

ui().layout([
ui().text('This is a text label'),
ui().button('Click me!'),
ui().image('https://example.com/myimage.png')
]);

In this example, the layout object is created by calling the layout() method on a UI object and passing in multiple UI objects as arguments. The layout object contains a text label, a button, and an image, which are grouped together within a single view.

Base Methods

Define size of an element: width(width: int): Sets the width of the UI element in pixels. height(height: int): Sets the height of the UI element in pixels. width_match_parent(): Sets the width of the UI element to match the parent container's width. height_match_parent(): Sets the height of the UI element to match the parent container's height. width_wrap_content(): Sets the width of the UI element to wrap the content. height_wrap_content(): Sets the height of the UI element to wrap the content. Weight and Margin: weight(weight: int): Sets the weight of the UI element in a layout. margin(left: int, top: int, right: int, bottom: int): Sets the margins of the UI element in pixels. Tag: tag(text: string): Sets the tag for the UI element. This tag can be used to find and manipulate the element later during events such as button clicks. Example Usage:

ui().button('Button').width(100).height(50).tag('button1');

In this example, a button UI element is created with a width of 100 pixels, a height of 50 pixels, and the tag "button1" is set for later reference during events such as button clicks.