The Widget class allows you to create components for a graphical user interface. More...
The D3PLOT JavaScript API provides many class constants, properties and methods. For Arup to
be able to extend and enhance the API in the future any constant, property or method names beginning with a lowercase
or uppercase letter are reserved.
If you need to add your own properties or methods to one of the existing classes then to avoid any potential future conflict you
should ensure that the name begins with either an underscore (_) or a dollar sign ($) or the name is prefixed with your
own unique identifier.
For example if company 'ABC' need to add a property called 'example' then to avoid any potential future conflict use one of:
| Name | Description |
| Widget.RGB24 | 24 bits for RGB data in widget images |
| Widget.RGB8 | 8 bits for RGB data in widget images |
| Name | Description |
| Widget.HORIZONTAL | Horizontal orientation (for sliders) |
| Widget.VERTICAL | Vertical orientation (for sliders) |
| Name | Description |
| Widget.SELECT_ENHANCED | Multiple WidgetItems in a ListBox or tree Widget can be selected. When the user selects a WidgetItem the selection is cleared and the new WidgetItem selected. However, if the user presses the Ctrl key when clicking on a WidgetItem, the clicked WidgetItem gets toggled and all other WidgetItems are left untouched. If the user presses the Shift key while clicking on a WidgetItem, all WidgetItems between the last selected WidgetItem and the clicked WidgetItem are selected or unselected, depending on the state of the clicked WidgetItem. |
| Widget.SELECT_MULTIPLE | Multiple WidgetItems in a ListBox Widget can be selected.
When the user selects a WidgetItem, the selection status of that WidgetItem is toggled
and the other WidgetItems are left alone. Not valid for tree widgets. Widget.SELECT_ENHANCED will be used. |
| Widget.SELECT_NONE | No WidgetItem in a ListBox or tree Widget can be selected |
| Widget.SELECT_SINGLE | A single WidgetItem in a ListBox or tree Widget can be selected. When the user selects a WidgetItem, any already-selected WidgetItem becomes unselected, and the user cannot unselect the selected WidgetItem by clicking on it. |
| Name | Description |
| Widget.AFTER | Add a WidgetItem after the existing WidgetItem for a tree widget. |
| Widget.BEFORE | Add a WidgetItem before the existing WidgetItem for a tree widget. |
| Widget.CHILD | Add a WidgetItem as a child of the existing WidgetItem for a tree widget. |
| Name | Description |
| Widget.SCROLL_BOTTOM | Scroll tree or listbox widget to bottom. |
| Widget.SCROLL_DOWN | Scroll tree or listbox widget down one. |
| Widget.SCROLL_PAGE_DOWN | Scroll tree or listbox widget down one page. |
| Widget.SCROLL_PAGE_UP | Scroll tree or listbox widget up one page. |
| Widget.SCROLL_TOP | Scroll tree or listbox widget to top. |
| Widget.SCROLL_UP | Scroll tree or listbox widget up one. |
| Name | Type | Description |
| active | logical | If widget is active (true) or disabled (false) |
| arrows | boolean | Whether arrows will be shown for a slider (default is true). Slider Widgets only. |
| background | constant | Widget background colour. Can be: Widget.BLACK, Widget.WHITE, Widget.RED, Widget.GREEN, Widget.BLUE, Widget.CYAN, Widget.MAGENTA, Widget.YELLOW, Widget.DARKRED, Widget.DARKGREEN, Widget.DARKBLUE, Widget.GREY, Widget.DARKGREY, Widget.LIGHTGREY, Widget.ORANGE, Widget.DEFAULT, Widget.COLOUR_NEUTRAL, Widget.COLOUR_CONTRAST, Widget.COLOUR_CONTRAST_2, Widget.COLOUR_WARNING, Widget.COLOUR_SAFE, Widget.COLOUR_TITLE, Widget.COLOUR_INVERSE, Widget.DARKGREY_NEUTRAL, Widget.LIGHTGREY_NEUTRAL Widget.COLOUR_LATENT, Note, background colours in the Window.THEME_DARK, Window.THEME_LIGHT, and Window.THEME_CLASSIC themes will be determined by the category of the widget not the background colour. To override this behaviour and use this background colour first set the widget category to Widget.NO_CATEGORY. |
| bottom | integer | Widget bottom coordinate |
| category | constant | The button category which determines the button's appearance when using the new user interface, see Window.Theme() |
| currentItem | WidgetItem object | The current WidgetItem for a tree Widget. The current WidgetItem in a tree is shown with a dashed border. |
| fontSize | integer | Widget font size in points. Currently only supports the following sizes: 6, 7, 8, 10, 12, 14, 18, 24. Can be used only with Widget.LABEL and Widget.BUTTON. Both LATIN1 and UTF-8 encoding is supported on Windows but Linux only supports LATIN1 encoding at the moment. |
| foreground | constant | Widget foreground colour. Can be: Widget.BLACK, Widget.WHITE, Widget.RED, Widget.GREEN, Widget.BLUE, Widget.CYAN, Widget.MAGENTA, Widget.YELLOW, Widget.DARKRED, Widget.DARKGREEN, Widget.DARKBLUE, Widget.GREY, Widget.DARKGREY, Widget.LIGHTGREY, Widget.ORANGE, Widget.DEFAULT, Widget.COLOUR_NEUTRAL, Widget.COLOUR_CONTRAST, Widget.COLOUR_CONTRAST_2, Widget.COLOUR_WARNING, Widget.COLOUR_SAFE, Widget.COLOUR_TITLE, Widget.COLOUR_LABEL, Widget.COLOUR_INVERSE, Widget.DARKGREY_NEUTRAL, Widget.LIGHTGREY_NEUTRAL Widget.COLOUR_LATENT, Note, foreground colours in the Window.THEME_DARK, Window.THEME_LIGHT, and Window.THEME_CLASSIC themes will be determined by the category of the widget not the foreground colour. To override this behaviour and use this foreground colour first set the widget category to Widget.NO_CATEGORY. |
| hover | string | Widget hover text |
| imageHeight (read only) | integer | Height of widget image (pixels) |
| imageWidth (read only) | integer | Width of widget image (pixels) |
| justify | constant | Widget justification. Can be: Widget.LEFT, Widget.RIGHT or Widget.CENTRE (default). |
| left | integer | Widget left coordinate |
| lineWidth | integer | Width of lines when drawing graphics (initially 1; values 1-100 allowed). |
| macroTag | string | Tag to use for this widget when recording a macro. If empty then the text property value will be used. |
| maximum | integer | The maximum value allowed for a slider (default is 100). Slider Widgets only. |
| minimum | integer | The minimum value allowed for a slider (default is 0). Slider Widgets only. |
| monospace | boolean | true if the widget uses a monospace font instead of a proportional width font (default). Label and button Widgets only. |
| onChange | function | Function to call when the text in a
TEXTBOX widget, the selection
in a COMBOBOX widget or the value of
a SLIDER is changed.
The Widget object is accessible in the function using the 'this' keyword
(see the example below for more details of how to define the function and how to use the 'this' keyword).
To unset the function set the property to null. Note that this function is called when the user actually types something into the textbox, selects an item in the combobox or moves the slider, NOT when the Widget.text or Widget.value property changes. |
| onClick | function | Function to call when a
BUTTON,
CHECKBOX,
COMBOBOX,
LABEL,
RADIOBUTTON or
TREE widget is clicked.
The Widget object is accessible in the function using the 'this' keyword
(see the example below for more details of how to define the function and how to use the 'this' keyword).
To unset the function set the property to null. Note that this function is called when the user actually clicks on the button, NOT when the Widget.pushed property changes. For the COMBOBOX widget the function is called before the list of items is mapped. |
| onPopup | function | Function to call when a
BUTTON,
LABEL,
TEXTBOX or TREE
widget is right clicked to map a popup.
The Widget object is accessible in the function using the 'this' keyword. The
PopupWindow can then be found by using the popupWindow
property of the Widget.
The function is called before the popup is mapped so you can change the widgets in the popup as required. |
| onTimer | function | Function to call for a widget when timerDelay ms
have elapsed after setting this. Additionally if timerRepeat
is set this function will be called repetitively, every timerDelay ms.
The Widget object is accessible in the function using the 'this' keyword.
To unset the function set the property to null. Note that as soon as this property is set the timer starts! |
| orientation | constant | The orientation of a slider. Can be: Widget.VERTICAL or Widget.HORIZONTAL (default). Slider Widgets only. |
| popupDirection | constant | How PopupWindow will be mapped relative to this widget. Can be Widget.LEFT, Widget.RIGHT, Widget.TOP or Widget.BOTTOM (default). For tree widgets this will be ignored as the popup is always shown on the WidgetItem that is right clicked. |
| popupSymbol | logical | TRUE (default) if a symbol will be shown for a PopupWindow. |
| popupWindow | PopupWindow object | PopupWindow for this Widget. Only available for Button, Label and Textbox Widgets. To remove a PopupWindow from a Widget set to null. |
| pushed | logical | If widget is pushed (true) or not (false). This only affects Widget.BUTTON with the Widget.toggle property set, and Widget.CHECKBOX widgets. |
| right | integer | Widget right coordinate |
| select | constant | Selection method for ListBox and tree Widgets. Can be: Widget.SELECT_NONE, Widget.SELECT_SINGLE or Widget.SELECT_MULTIPLE or Widget.SELECT_ENHANCED (default). |
| selectedItem | WidgetItem object | WidgetItem that is currently selected
for a ComboBox or Radiobutton, Widget. If null no
WidgetItem is selected. For a ListBox Widget this property contains the last WidgetItem that was (de)selected. To get a list of all of the selected WidgetItems use WidgetItems() to return all of the WidgetItems and inspect the WidgetItem selected property. |
| shown (read only) | boolean | true if the widget is visible. To alter the visibility of a widget use the Show() and Hide() methods. |
| step | integer | The step value of a slider (default is 1). Slider Widgets only. |
| text | string | Widget text. For a ComboBox Widget this will be the text for the currently selected WidgetItem |
| textHidden | boolean | true if the widget text is hidden and replaced by asterisks. This may be used to create textboxes to type passwords in. TextBox Widgets only. |
| timerDelay | integer | Delay in ms before the function set for onTimer will be called. The initial value is 1000 (ms). Also see timerRepeat. |
| timerRepeat | logical | If the function set for onTimer will be called once (false) or repeatedly (true). The initial value is false. Also see timerDelay. |
| toggle | logical | If widget can be toggled (true) or not (false). This only affects Widget.BUTTON widgets. |
| top | integer | Widget top coordinate |
| type (read only) | integer | Type of the widget. The widget type could be Widget.BUTTON, Widget.CHECKBOX, Widget.COMBOBOX, Widget.LABEL, Widget.LISTBOX, Widget.RADIOBUTTON, Widget.SLIDER, Widget.TEXTBOX or Widget.TREE |
| value | integer | The current value of a slider (initially will be the minimum value). Slider Widgets only. |
| window (read only) | Window object | The Window that this widget is defined in |
| xResolution | integer | X resolution of button when drawing lines, circles, polygons and rectangles (initially 100). X coordinates on the Widget can be from 0 (on the left of the widget) to xResolution (on the right of the widget). Available for Widget.LABEL and Widget.BUTTON Widgets. |
| yResolution | integer | Y resolution of button when drawing lines, circles, polygons and rectangles (initially 100). Y coordinates on the Widget can be from 0 (on the top of the widget) to yResolution (on the bottom of the widget). Available for Widget.LABEL and Widget.BUTTON Widgets. |
Detailed DescriptionThe Widget class allows you to create Widgets (buttons, textboxes etc) in a Window for a graphical user interface. Callback functions can be declared for widgets to give actions when a button is pressed or the text in a textbox is selected etc. The following example displays various widgets in a window. Several callback methods are used. The exit button allows the user to exit the script but the button is only made active if the checkbox widget is ticked. If the button widgets are pressed feedback is given to the user |
var count = 0;
// Create window
var w = new Window("Test", 0.8, 1.0, 0.5, 0.6);
// Create all of the widgets
var l = new Widget(w, Widget.LABEL, 1, 30, 1, 7, "Text:");
var t = new Widget(w, Widget.TEXTBOX, 31, 80, 1, 7, "Enter text");
var b = new Widget(w, Widget.BUTTON, 1, 30, 8, 14, "Press me");
var b2= new Widget(w, Widget.BUTTON, 31, 61, 8, 14, "Don't press me");
var c = new Widget(w, Widget.CHECKBOX,62, 68, 8, 14);
var l2= new Widget(w, Widget.LABEL, 1, 80, 15, 21, "You haven't pressed the button yet...");
var e = new Widget(w, Widget.BUTTON, 1, 21, 22, 28, "Exit");
// Allow button widget b2 to toggle
b2.toggle = true;
// The exit button is initially inactive
e.active = false;
// Assign the callback functions
b.onClick = clicked;
b2.onClick = clicked;
c.onClick = clicked;
t.onChange = changed;
e.onClick = confirm_exit;
// Show the window and start event loop
w.Show();
////////////////////////////////////////////////////////////////////////////////
function clicked()
{
// If checkbox is clicked then set the state of the exit button
if (this === c)
{
Message("Checkbox clicked");
e.active = c.pushed;
}
// If the "Don't press me' button is pressed then change the colour if the button is pressed in.
else if (this === b2)
{
Message("I said don't press!!!");
if (b2.pushed) b2.background = Widget.WHITE;
else b2.background = Widget.DEFAULT;
}
// If the "Press me" button is pressed then update the text in the label widget
// with how many times the button has been pressed.
else
{
Message("You pressed...");
count++;
l2.text = "Button pressed " + count + " times";
}
}
////////////////////////////////////////////////////////////////////////////////
function changed()
{
// If the user has changed the text in the textbox then give a message in
// the dialogue box
Message("Text has changed to " + this.text);
}
////////////////////////////////////////////////////////////////////////////////
function confirm_exit()
{
// Map confirm box
var ret = Window.Question("Confirm exit", "Are you sure you want to quit?");
// If the user has answered yes then exit from the script.
if (ret == Window.YES) Exit();
}
In version 20 a tree widget was added. A simple tree widget example is shown below.
Window.Theme(Window.THEME_CURRENT);
let wi, cwi;
// Create a popup window and some widgets
let pw = new PopupWindow();
let pw_l1 = new Widget(pw, Widget.LABEL, 1, 61, 1, 7, "");
let pw_l2 = new Widget(pw, Widget.LABEL, 1, 61, 7, 13, "");
let pw_l3 = new Widget(pw, Widget.LABEL, 1, 61, 13, 19, "");
let pw_l4 = new Widget(pw, Widget.LABEL, 1, 61, 19, 25, "");
let pw_l5 = new Widget(pw, Widget.LABEL, 1, 61, 25, 31, "");
let pw_l6 = new Widget(pw, Widget.LABEL, 1, 61, 31, 37, "");
// Create window
let w = new Window("JavaScript Tree widget test", 0.85, 1.0, 0.75, 1.0);
// Create tree widget
let t = new Widget(w, Widget.TREE, 1, 61, 1, 51, "Suite");
// Add a root node to tree
let env_wi = new WidgetItem(t, "MyItem");
// Add a child to the root node
wi = new WidgetItem(t, "PRIMER", Widget.CHILD, env_wi);
cwi = new WidgetItem(t, "Prepare", Widget.CHILD, wi);
wi.onMouseOver = wi_onmouseover;
cwi.hover = "Efficient, reliable model setup with support for all of the latest Ansys LS-DYNA features";
wi = new WidgetItem(t, "Ansys LS-DYNA", Widget.CHILD, env_wi);
cwi = new WidgetItem(t, "Analyse", Widget.CHILD, wi);
wi.onMouseOver = wi_onmouseover;
// Add a sibling node after Ansys LS-DYNA
wi = new WidgetItem(t, "REPORTER", Widget.AFTER, wi);
cwi = new WidgetItem(t, "Report", Widget.CHILD, wi);
wi.onMouseOver = wi_onmouseover;
cwi.hover = "Automatic report generation for Ansys LS-DYNA simulations";
// Add a sibling node before REPORTER
wi = new WidgetItem(t, "T/HIS", Widget.BEFORE, wi);
cwi = new WidgetItem(t, "Process", Widget.CHILD, wi);
wi.onMouseOver = wi_onmouseover;
cwi.hover = "Plot, manipulate and process XY data from Ansys LS-DYNA";
// Alternatively, create WidgetItem without parent and add
let d3plot_wi = new WidgetItem(null, "D3PLOT");
t.AddWidgetItem(d3plot_wi, Widget.BEFORE, wi);
cwi = new WidgetItem(null, "Visualise");
t.AddWidgetItem(cwi, Widget.CHILD, d3plot_wi);
d3plot_wi.onMouseOver = wi_onmouseover;
cwi.hover = " In-depth 3D visualisation of Ansys LS-DYNA results";
// Expand root node
env_wi.expanded = true;
// Link popup to tree widget
t.popupWindow = pw;
// Assign callbacks
t.onClick = click_tree;
t.onPopup = do_popup;
// Show the widget and start event loop
w.Show();
////////////////////////////////////////////////////////////////////////////////
function do_popup()
{
pw_l1.text = this.currentItem.text;
if (this.currentItem.selected) pw_l2.text = "Selected";
else pw_l2.text = "Not selected";
if (this.currentItem.Parent())
pw_l3.text = "Parent: " + this.currentItem.Parent().text;
else
pw_l3.text = "No parent";
if (this.currentItem.FirstChild())
pw_l4.text = "First child: " + this.currentItem.FirstChild().text;
else
pw_l4.text = "No children";
if (this.currentItem.PreviousSibling())
pw_l5.text = "Previous: " + this.currentItem.PreviousSibling().text;
else
pw_l5.text = "No previous";
if (this.currentItem.NextSibling())
pw_l6.text = "Next: " + this.currentItem.NextSibling().text;
else
pw_l6.text = "No next";
}
////////////////////////////////////////////////////////////////////////////////
function click_tree()
{
Message("Clicked on "+this.currentItem.text+" in tree");
}
////////////////////////////////////////////////////////////////////////////////
function wi_onmouseover()
{
Message("Called onMouseOver for WidgetItem "+this.text+" in tree");
}Graphics (lines, circles, rectangles etc) can be drawn on Widget.LABEL and Widget.BUTTON widgets. If these methods are used the resolution of the widget is 100 units in x and y and the origin is at the top left of the widget. See the documentation below and the WidgetItem and Window classes for more details.
Constructornew Widget(window[Window or PopupWindow], type[constant], left[integer], right[integer], top[integer], bottom[integer], text (optional)[string])DescriptionCreate a new Widget object. |
Window or PopupWindow that widget will be created in
Widget type. Can be Widget.BUTTON, Widget.CHECKBOX, Widget.COMBOBOX, Widget.LABEL, Widget.LISTBOX, Widget.RADIOBUTTON, Widget.SLIDER, Widget.TEXTBOX or Widget.TREE
left coordinate of widget
right coordinate of widget
top coordinate of widget
bottom coordinate of widget
Text to show on widget (optional for LABEL, BUTTON, TEXTBOX and TREE, not required for CHECKBOX, COMBOBOX, LISTBOX, RADIOBUTTON and SLIDER). For a TREE widget the text will be used as a macroTag.
ReturnsWidget object Return typeWidget |
Details of functionsAddWidgetItem(item[WidgetItem], position (optional)[integer])DescriptionAdds a WidgetItem to a ComboBox ListBox or Radiobutton Widget. Also see Widget.RemoveAllWidgetItems and Widget.RemoveWidgetItem. |
WidgetItem to add
Position on Widget to add the WidgetItem. Any existing WidgetItems will be shifted down as required. If omitted the WidgetItem will be added to the end of the existing ones. Note that positions start at 0.
ReturnsNo return value |
ExampleTo add WidgetItem wi to widget w: w.AddWidgetItem(wi);
|
AddWidgetItem(item[WidgetItem], relationship[constant], relitem[WidgetItem])DescriptionAdds a WidgetItem to a Tree Widget. Also see Widget.RemoveAllWidgetItems and Widget.RemoveWidgetItem. |
WidgetItem to add
What relationship (relative to relitem) to use when adding item to the Widget.
Can be:
Widget.BEFORE,
Widget.AFTER or
Widget.CHILD.
Existing WidgetItem to add item relative to. If relationship is Widget.CHILD then relitem can be null and then the WidgetItem will be added to the root node of the tree.
ReturnsNo return value |
Circle(colour[constant], fill[boolean], xc[integer], yc[integer], radius[integer])DescriptionDraws a circle on the widget. Only possible for Widget.LABEL and Widget.BUTTON widgets. The coordinates are local to the Widget, not the Window. See properties xResolution and yResolution for more details. Note that the widget graphics will only be updated when the widget is redrawn. This is to allow the user to do multiple drawing commands on a widget. To force the widget to be redrawn call Show(). |
Colour of circle. See foreground for colours.
If circle should be filled or not.
x coordinate of centre of circle.
y coordinate of centre of circle.
radius of circle.
Returnsno return value |
ExampleTo draw a red filled circle, radius 25, at (50, 50) on widget w: w.Circle(Widget.RED, true, 50, 50, 25);
|
Clear()DescriptionClears any graphics on the widget. Only possible for Widget.LABEL and Widget.BUTTON widgets. Note that the widget graphics will only be updated when the widget is redrawn. This is to allow the user to do multiple drawing commands on a widget. To force the widget to be redrawn call Show(). |
No arguments
Returnsno return value |
ExampleTo clear any graphics for widget w: w.Clear();
|
ClearSelection()DescriptionClears selection of any WidgetItems on the widget. Only possible for Widget.COMBOBOX, Widget.LISTBOX, Widget.RADIOBUTTON and Widget.TREE widgets. |
No arguments
Returnsno return value |
ExampleTo clear selection of any WidgetItems for widget w: w.ClearSelection();
|
Cross(colour (optional)[constant])DescriptionDraws a cross symbol on the widget. Only possible for Widget.LABEL and Widget.BUTTON widgets. |
Colour of cross symbol. See foreground for colours. If omitted, current foreground colour is used.
Returnsno return value |
ExampleTo draw a red cross symbol on widget w: w.Cross(Widget.RED);
|
CtrlPressed() [static]DescriptionCheck to see if the Ctrl key is pressed |
No arguments
Returnstrue/false Return typeBoolean |
ExampleTo test if someone has the Ctrl key pressed: if (Widget.CtrlPressed()) { ... }
|
Delete()DescriptionDeletes the widget from D3PLOT (removing it from the window it is defined in) and returns any memory/resources used for the widget. This function should not normally need to be called. However, sometimes a script may want to recreate widgets in a window many times and unless the old widgets are deleted D3PLOT will reach the maximum number of widgets for a window (Options.max_widgets). To avoid this problem this method can be used to force D3PLOT to delete and return the resources for a widget. Do not use the Widget object after calling this method. |
No arguments
Returnsno return value |
ExampleTo delete widget w: w.Delete();
|
DirectoryIcon(line_colour[constant], fill_colour[constant])DescriptionDraws a directory icon on the widget. Only possible for Widget.BUTTON widgets. |
Colour of lines of folder (only used in the old UI - in the new UI it will be ignored, a standard icon is always used). See foreground for colours.
Colour of fill of folder (only used in the old UI - in the new UI it will be ignored, a standard icon is always used). See foreground for colours.
Returnsno return value |
ExampleTo draw a directory icon on widget btn: btn.DirectoryIcon(Widget.BLACK, Widget.YELLOW);
|
DumpImageString(filename[string], format (optional)[constant])DescriptionDumps a string representation of an image for a widget to a file in a form that can be used by Widget.ReadImageString(). Only possible for Widget.LABEL and Widget.BUTTON widgets. |
Filename to dump string representation to
Can be Widget.RGB8 or Widget.RGB24. Before version 15 D3PLOT only used 8 bits to store RGB (red, green and blue) colour information for widget images. In version 15 widget images have been changed to use 24 bits to store RGB information (8 bits for red, 8 bits for green and 8 bits for blue). Both formats are supported. If omitted the new Widget.RGB24 format will be used. See Widget.ReadImageString() for more details.
Returnsno return value |
Hide()DescriptionHides the widget on the screen |
No arguments
ReturnsNo return value |
ExampleTo hide widget w w.Hide();
|
ItemAt(index[integer])DescriptionReturns the WidgetItem object used at index in this Widget. See also Widget.TotalItems() and Widget.WidgetItems(). Note that for tree Widgets the items will not be returned in the order that they are displayed in, they will be returned in the order they were added to the tree. |
index to return WidgetItem for. Note that indices start at 0.
ReturnsWidgetItem object. Return typeWidgetItem |
ExampleTo loop over the WidgetItems used in Widget w for (i=0; i<w.TotalItems(); i++)
{
wi = w.ItemAt(i);
}
|
Line(colour[constant], x1[integer], y1[integer], x2[integer], y2[integer])DescriptionDraws a line on the widget. Only possible for Widget.LABEL and Widget.BUTTON widgets. The coordinates are local to the Widget, not the Window. See properties xResolution and yResolution for more details. Note that the widget graphics will only be updated when the widget is redrawn. This is to allow the user to do multiple drawing commands on a widget. To force the widget to be redrawn call Show(). |
Colour of line. See foreground for colours.
x coordinate of start of line.
y coordinate of start of line.
x coordinate of end of line.
y coordinate of end of line.
Returnsno return value |
ExampleTo draw a red line from (10, 90) to (90, 10) on widget w: w.Line(Widget.RED, 10, 90, 90, 10);
|
MoveWidgetItem(item[WidgetItem], relationship[constant], relitem[WidgetItem or null])DescriptionMoves an existing WidgetItem in a tree Widget. Also see Widget.RemoveAllWidgetItems and Widget.RemoveWidgetItem. |
WidgetItem to move
What relationship (relative to relitem) to use when moving item to the Widget.
Can be:
Widget.BEFORE,
Widget.AFTER or
Widget.AFTER.
Existing WidgetItem to move item relative to. If relationship is Widget.CHILD then relitem can be null and then the WidgetItem will be moved to the root node of the tree.
ReturnsNo return value |
PixelsPerUnit() [static]DescriptionReturns the number of pixels per unit coordinate. This will vary depending on the monitor D3PLOT is running on. |
No arguments
Returnspixels/unit (real) Return typeNumber |
ExampleTo return how many pixels there are per unit coordinate: var ppu = Widget.PixelsPerUnit();
|
Polygon(colour[constant], fill[boolean], points[array])DescriptionDraws a polygon on the widget. Only possible for Widget.LABEL and Widget.BUTTON widgets. The coordinates are local to the Widget, not the Window. See properties xResolution and yResolution for more details. Note that the widget graphics will only be updated when the widget is redrawn. This is to allow the user to do multiple drawing commands on a widget. To force the widget to be redrawn call Show(). The number of points (x, y pairs) is limited to 500. Any extra points will be ignored. |
Colour of polygon. See foreground for colours.
If polygon should be filled or not.
Array of point coordinates
Returnsno return value |
ExampleTo draw a red filled triangle with corners (20, 20) and (50, 80) and (80, 20) on widget w: var a = new Array(20, 20, 50, 80, 80, 20); w.Polygon(Widget.RED, true, a);
|
Polygon(colour[constant], fill[boolean], x1[integer], y1[integer], x2[integer], y2[integer], ... xn[integer], ... yn[integer]) [deprecated]This function is deprecated in version 21.0. It is only provided to keep old scripts working. We strongly advise against using it in new scripts. Support may be removed in future versions. DescriptionDraws a polygon on the widget. Only possible for Widget.LABEL and Widget.BUTTON widgets. The coordinates are local to the Widget, not the Window. See properties xResolution and yResolution for more details. Note that the widget graphics will only be updated when the widget is redrawn. This is to allow the user to do multiple drawing commands on a widget. To force the widget to be redrawn call Show(). The number of points (x, y pairs) is limited to 500. Any extra points will be ignored. |
Colour of polygon. See foreground for colours.
If polygon should be filled or not.
x coordinate of point 1.
y coordinate of point 1.
x coordinate of point 2.
y coordinate of point 2.
x coordinate of point n.
y coordinate of point n.
Returnsno return value |
ExampleTo draw a red filled triangle with corners (20, 20) and (50, 80) and (80, 20) on widget w: w.Polygon(Widget.RED, true, 20, 20, 50, 80, 80, 20);
|
ReadImageFile(filename[string], justify (optional)[constant], transparent (optional)[colour value (integer)], tolerance (optional)[integer])DescriptionReads an image from a file to show on the widget. Only possible for Widget.LABEL and Widget.BUTTON widgets. The image will be shown on the widget underneath any text. Note that due to the way that colours are used for menus in D3PLOT only a small number of colours are available for Widget images. Black and white images will display without any issues but colour images will be displayed with a reduced set of colours. |
Image file (BMP, GIF, JPEG or PNG) to read. To remove an image use null.
Widget justification. Can be a bitwise or of Widget.LEFT, Widget.RIGHT or Widget.CENTRE and Widget.TOP, Widget.MIDDLE or Widget.BOTTOM. Additionally Widget.SCALE can be used to scale the image (either reducing or enlarging it) so that it fills the widget. If omitted the default is Widget.CENTRE|Widget.MIDDLE without scaling.
Transparent colour. Must be a colour returned by Colour.RGB() in D3PLOT. If given then this colour will be replaced by a transparent colour. i.e. the widget background colour will be shown. If omitted or null no transparency will be used.
Tolerance for transparent colour (0-255).
Any pixels in the image that have a red, green and blue colour value within tolerance of the transparent colour will be transparent.
For example if the transparent colour was given as Colour.RGB(255, 0, 0) and tolerance is 0 only pixels which have red value 255 and green value 0 and blue value 0 will be made transparent.
If tolerance is 4, pixels which have red values between 251 and 255 and green values between 0 and 4 and blue values between 0 and 4
will be made transparent.
If omitted a value of 8 will be used.
Returnsno return value |
ReadImageString(string[string], justify (optional)[constant], transparent (optional)[colour value (integer)], tolerance (optional)[integer])DescriptionReads an image from a JavaScript string previously created by
Widget.DumpImageString() to show on the widget. Only possible for
Widget.LABEL and
Widget.BUTTON widgets.
The image will be shown on the widget underneath any text. |
String containing the image data previously created by Widget.DumpImageString(). To remove an image use null.
Widget justification. Can be a bitwise or of Widget.LEFT, Widget.RIGHT or Widget.CENTRE and Widget.TOP, Widget.MIDDLE or Widget.BOTTOM. Additionally Widget.SCALE can be used to scale the image (either reducing or enlarging it) so that it fills the widget. If omitted the default is Widget.CENTRE|Widget.MIDDLE without scaling.
Transparent colour. Must be a colour returned by Colour.RGB() in D3PLOT. If given then this colour will be replaced by a transparent colour. i.e. the widget background colour will be shown. If omitted or null no transparency will be used.
Tolerance for transparent colour (0-255). Only used for the new 24bit format Widget.RGB24
(strings beginning with "RGB24_Z"). Ignored for the old 8 bit format Widget.RGB8
(strings beginning with "RRRGGGBB_RLE").
Any pixels in the image that have a red, green and blue colour value within tolerance of the transparent colour will be transparent.
For example if the transparent colour was given as Colour.RGB(255, 0, 0) and tolerance is 0 only pixels which have red value 255 and green value 0 and blue value 0 will be made transparent.
If tolerance is 4, pixels which have red values between 251 and 255 and green values between 0 and 4 and blue values between 0 and 4
will be made transparent.
If omitted a value of 8 will be used.
Returnsno return value |
Rectangle(colour[constant], fill[boolean], x1[integer], y1[integer], x2[integer], y2[integer])DescriptionDraws a rectangle on the widget. Only possible for Widget.LABEL and Widget.BUTTON widgets. The coordinates are local to the Widget, not the Window. See properties xResolution and yResolution for more details. Note that the widget graphics will only be updated when the widget is redrawn. This is to allow the user to do multiple drawing commands on a widget. To force the widget to be redrawn call Show(). |
Colour of rectangle. See foreground for colours.
If rectangle should be filled or not.
x coordinate of first corner of rectangle.
y coordinate of first corner of rectangle.
x coordinate of second (opposite) corner of rectangle.
y coordinate of second (opposite) corner of rectangle.
Returnsno return value |
ExampleTo draw a red filled rectangle with corners (20, 20) and (80, 80) on widget w: w.Rectangle(Widget.RED, true, 20, 20, 80, 80);
|
RemoveAllWidgetItems()DescriptionRemoves any WidgetItems from the Widget. Also see Widget.AddWidgetItem and Widget.RemoveWidgetItem. |
No arguments
ReturnsNo return value |
ExampleTo remove all WidgetItems from widget w: w.RemoveAllWidgetItems();
|
RemoveWidgetItem(item[WidgetItem])DescriptionRemoves a WidgetItem from the Widget. Also see Widget.AddWidgetItem and Widget.RemoveAllWidgetItems. |
WidgetItem to remove
ReturnsNo return value |
ExampleTo remove WidgetItem wi from widget w: w.RemoveWidgetItem(wi);
|
Scroll(scroll[constant or WidgetItem object])DescriptionScrolls a tree or listbox widget |
How to scroll the tree/listbox widget. Can be: Widget.SCROLL_TOP, Widget.SCROLL_BOTTOM, Widget.SCROLL_UP, Widget.SCROLL_DOWN, Widget.SCROLL_PAGE_UP or Widget.SCROLL_PAGE_DOWN in which case the tree/listbox widget will be scrolled by that value or a WidgetItem, in which case the tree/listbox will be scrolled to make the WidgetItem visible, (expanding any branches as necessary to do so for the tree widget).
ReturnsNo return value |
ExampleTo scroll tree widget w to the top: w.Scroll(Widget.SCROLL_TOP); To scroll listbox widget w so that WidgetItem wi is visible: w.Scroll(wi);
|
ShiftPressed() [static]DescriptionCheck to see if the Shift key is pressed |
No arguments
Returnstrue/false Return typeBoolean |
ExampleTo test if someone has the Shift key pressed: if (Widget.ShiftPressed()) { ... }
|
Show()DescriptionShows the widget on the screen |
No arguments
ReturnsNo return value |
ExampleTo show widget w: w.Show();
|
Static()DescriptionWindows have two different regions for Widgets. A 'normal' region which can be scrolled if required (if the window is made smaller scrollbars will be shown which can be used to scroll the contents) and a 'static' region at the top of the Window which is fixed and does not scroll. For an example of a static region in a Window see any of the keyword editing panels. The 'Dismiss', 'Create', 'Reset' etc buttons are in the static region. By default Widgets are put into the normal region of the Window. This method puts the Widget to the static region of the Window. |
No arguments
ReturnsNo return value |
ExampleTo put widget w in the static part of the window: w.Static();
|
Text to find the width of
If true then width will be calculated using a monospace font. If false (default) then the normal proportional width font will be used
Calculation can be based on a defined font size, at the moment support is added only for font sizes of 6, 7, 8, 10, 12, 14, 18 and 24.
Returnsinteger Return typeNumber |
ExampleTo get the width of string 'Example': var len = Widget.StringLength('Example');
|
Tick(colour (optional)[constant])DescriptionDraws a tick symbol on the widget. Only possible for Widget.LABEL and Widget.BUTTON widgets. |
Colour of tick symbol. See foreground for colours. If omitted, current foreground colour is used.
Returnsno return value |
ExampleTo draw a red tick symbol on widget w: w.Tick(Widget.RED);
|
TotalItems()DescriptionReturns the number of the WidgetItem objects used in this Widget (or 0 if none used). See also Widget.ItemAt() and Widget.WidgetItems(). |
No arguments
Returnsinteger Return typeNumber |
ExampleTo return the total number of WidgetItems used for Widget w var total = w.TotalItems();
|
WidgetItems()DescriptionReturns an array of the WidgetItem objects used in this Widget (or null if none used). See also Widget.ItemAt() and Widget.TotalItems(). |
No arguments
ReturnsArray of WidgetItem objects Return typeArray |
ExampleTo return WidgetItems used for Widget w var wi = w.WidgetItems();
|