Anonymous View

ui#

Fury UI module.

Anchor(*values)

Enum for Position Anchor Points.

Card2D(image_path, *[, body_text, ...])

A 2D card UI component that displays an image with title and body text.

Disk2D(outer_radius, *[, inner_radius, ...])

A 2D disk UI component.

ImageContainer2D(img_path, *[, position, size])

A 2D container to hold an image.

LineDoubleSlider2D(*[, position, ...])

A 2D Line Slider with two sliding handles.

LineSlider2D(*[, position, initial_value, ...])

A 2D Line Slider component.

ListBox2D(values, *[, position, size, ...])

UI component that allows the user to select items from a list.

ListBoxItem2D(on_select, size, *[, ...])

The text displayed in a listbox.

Panel2D(size, *[, position, color, opacity, ...])

A 2D UI Panel.

PlaybackPanel(*[, loop, position, width, ...])

A playback controller designed for FURY v2.

RangeSlider(*[, line_width, inner_radius, ...])

A compound UI element containing a LineSlider2D and a LineDoubleSlider2D.

Rectangle2D(*[, size, position, color, opacity])

A 2D rectangle sub-classed from UI.

RingSlider2D(*[, center, initial_value, ...])

A disk slider.

TabPanel2D(*[, position, size, title, ...])

A 2D tab header with an associated content panel.

TabUI(*[, position, size, tab_titles, ...])

A 2D container that switches between multiple content panels.

TextBlock2D(*[, text, font_size, ...])

A 2D text component with optional background.

TextBox2D(width, height, *[, text, ...])

An editable 2D text box that behaves as a UI component.

TextButton2D(label[, states, position, ...])

A button component that updates text and color based on state.

TexturedButton2D(states[, position, size, ...])

A button component that swaps textures based on interaction state.

UI(*[, position, x_anchor, y_anchor, z_order])

An umbrella class for all UI elements.

Anchor#

class fury.ui.Anchor(*values)[source]#

Bases: str, Enum

Enum for Position Anchor Points.

__init__(*args, **kwds)#
BOTTOM = 'BOTTOM'#
CENTER = 'CENTER'#
LEFT = 'LEFT'#
RIGHT = 'RIGHT'#
TOP = 'TOP'#

Card2D#

class fury.ui.Card2D(image_path, *, body_text='', draggable=True, title_text='', padding=10, position=(0, 0), size=(400, 400), image_scale=0.5, bg_color=(0.5, 0.5, 0.5), bg_opacity=1, title_color=(0.0, 0.0, 0.0), body_color=(0.0, 0.0, 0.0), border_color=(1.0, 1.0, 1.0), border_width=0, maintain_aspect=False, z_order=0)[source]#

Bases: UI

A 2D card UI component that displays an image with title and body text.

The card layout places the image at the top, followed by the title and body text below. It can optionally be dragged around the scene.

Parameters:
  • image_path (str) – Path to the image file. Supports png and jpg/jpeg images.

  • body_text (str, optional) – Card body text.

  • draggable (bool, optional) – If True, the card can be dragged with the mouse.

  • title_text (str, optional) – Card title text.

  • padding (int, optional) – Padding between image, title, and body in pixels.

  • position ((float, float), optional) – Absolute coordinates (x, y) for placement.

  • size ((int, int), optional) – Width and height in pixels of the card.

  • image_scale (float, optional) – Fraction of the card height taken by the image (between 0 and 1).

  • bg_color ((float, float, float) or str, optional) – Background color of the card. Can be RGB/RGBA array, or hex string.

  • bg_opacity (float, optional) – Background opacity. Must be in [0, 1].

  • title_color ((float, float, float) or str, optional) – Title text color. Can be RGB/RGBA array, or hex string.

  • body_color ((float, float, float) or str, optional) – Body text color. Can be RGB/RGBA array, or hex string.

  • border_color ((float, float, float) or str, optional) – Border color. Can be RGB/RGBA array, or hex string.

  • border_width (int, optional) – Width of the border in pixels.

  • maintain_aspect (bool, optional) – If True, the image is scaled to maintain its aspect ratio.

  • z_order (int, optional) – The stacking priority of the card.

image#

Renders the image on the card.

Type:

ImageContainer2D

title_box#

Displays the title on the card.

Type:

TextBlock2D

body_box#

Displays the body text on the card.

Type:

TextBlock2D

panel#

The background panel that holds all card elements.

Type:

Panel2D

__init__(image_path, *, body_text='', draggable=True, title_text='', padding=10, position=(0, 0), size=(400, 400), image_scale=0.5, bg_color=(0.5, 0.5, 0.5), bg_opacity=1, title_color=(0.0, 0.0, 0.0), body_color=(0.0, 0.0, 0.0), border_color=(1.0, 1.0, 1.0), border_width=0, maintain_aspect=False, z_order=0)[source]#

Initialize the Card2D instance.

property body#

Get the body text of the card.

Returns:

The body text.

Return type:

str

property color#

Get the background color of the card.

Returns:

RGB color of the card background.

Return type:

(float, float, float)

left_button_dragged(event)[source]#

Handle left mouse button drag event for card movement.

Parameters:

event (PointerEvent) – The PyGfx pointer event object.

left_button_pressed(event)[source]#

Handle left mouse button press event for card dragging.

Parameters:

event (PointerEvent) – The PyGfx pointer event object.

property opacity#

Get the opacity of the card.

Returns:

The opacity of the card.

Return type:

float

resize(size)[source]#

Resize the Card2D and reposition internal elements.

Parameters:

size ((int, int)) – Card size (width, height) in pixels.

property title#

Get the title text of the card.

Returns:

The title text.

Return type:

str

update_layout()[source]#

Propagate layout updates to child text elements.

The render loop calls this method on top-level UI elements so that TextBlock2D children can re-align their text actors once the actual bounding box is known after the first render pass.

Disk2D#

class fury.ui.Disk2D(outer_radius, *, inner_radius=0, center=(0, 0), color=(1, 1, 1), opacity=1.0)[source]#

Bases: UI

A 2D disk UI component.

Parameters:
  • outer_radius (int) – Outer radius of the disk.

  • inner_radius (int, optional) – Inner radius of the disk.

  • center ((float, float), optional) – Coordinates (x, y) of the center of the disk.

  • color ((float, float, float), optional) – Must take values in [0, 1].

  • opacity (float, optional) – Must take values in [0, 1].

__init__(outer_radius, *, inner_radius=0, center=(0, 0), color=(1, 1, 1), opacity=1.0)[source]#

Initialize a 2D Disk.

property color#

Get the color of this UI component.

Returns:

RGB color.

Return type:

(float, float, float)

property inner_radius#

Get the inner radius of the disk.

Returns:

Inner radius in pixels.

Return type:

int

property opacity#

Get the opacity of this UI component.

Returns:

Opacity value.

Return type:

float

property outer_radius#

Get the outer radius of the disk.

Returns:

Outer radius in pixels.

Return type:

int

ImageContainer2D#

class fury.ui.ImageContainer2D(img_path, *, position=(0, 0), size=(100, 100))[source]#

Bases: Rectangle2D

A 2D container to hold an image.

Currently Supports: - png and jpg/jpeg images

Parameters:
  • img_path (str) – URL or local path of the image.

  • position ((float, float), optional) – Absolute coordinates (x, y) of the lower-left corner of the image.

  • size ((int, int), optional) – Width and height in pixels of the image.

size#

Image size (width, height) in pixels.

Type:

(float, float)

img#

The image loaded from the specified path as a NumPy array.

Type:

ndarray

__init__(img_path, *, position=(0, 0), size=(100, 100))[source]#

Init class instance.

Parameters:
  • img_path (str or ndarray) – URL, local path of the image, or a NumPy array containing image data.

  • position ((float, float), optional) – Absolute coordinates (x, y) of the lower-left corner of the image.

  • size ((int, int), optional) – Width and height in pixels of the image.

scale(factor)[source]#

Scale the image.

Parameters:

factor ((float, float)) – Scaling factor (width, height) in pixels.

set_img(img)[source]#

Modify the image displayed by this container.

Parameters:

img (ndarray) – Image data as a NumPy array. Supports grayscale (H, W), RGB (H, W, 3), and RGBA (H, W, 4) formats.

LineDoubleSlider2D#

class fury.ui.LineDoubleSlider2D(*, position=(0, 0), initial_values=(0, 100), min_value=0, max_value=100, length=200, line_width=5, inner_radius=0, outer_radius=10, handle_side=20, font_size=16, text_template='{value:.1f}', orientation='horizontal', shape='disk', z_order=0)[source]#

Bases: UI

A 2D Line Slider with two sliding handles.

Useful for setting min and max values for something.

Parameters:
  • position ((float, float), optional) – Absolute coordinates (x, y) of the lower-left corner of the slider.

  • initial_values ((float, float), optional) – Initial values for the left and right handles respectively.

  • min_value (float, optional) – Minimum value for the slider.

  • max_value (float, optional) – Maximum value for the slider.

  • length (int, optional) – Length of the slider track in pixels.

  • line_width (int, optional) – Width of the line on which the handles will slide.

  • inner_radius (int, optional) – Inner radius of the handles (when shape is ‘disk’).

  • outer_radius (int, optional) – Outer radius of the handles (when shape is ‘disk’).

  • handle_side (int, optional) – Length of the square handles (when shape is ‘square’).

  • font_size (int, optional) – Size of the text font displaying the values.

  • text_template (str or callable, optional) – Template for the text displaying the values. Can use {value} and {ratio}.

  • orientation (str, optional) – Orientation of the slider (‘horizontal’ or ‘vertical’).

  • shape (str, optional) – Shape of the handles (‘disk’ or ‘square’).

  • z_order (int, optional) – Stacking order of the slider.

__init__(*, position=(0, 0), initial_values=(0, 100), min_value=0, max_value=100, length=200, line_width=5, inner_radius=0, outer_radius=10, handle_side=20, font_size=16, text_template='{value:.1f}', orientation='horizontal', shape='disk', z_order=0)[source]#

Init scene.

format_text(idx)[source]#

Format the text for a specific handle.

Parameters:

idx (int) – Index of the handle (0 for left/bottom, 1 for right/top).

Returns:

The formatted text.

Return type:

str

handle_down(idx)[source]#

Mark the specific handle as active.

Parameters:

idx (int) – Index of the handle (0 for left/bottom, 1 for right/top).

handle_move_callback(event, idx=None)[source]#

Handle mouse drag events to update the slider state.

Parameters:
  • event (PointerEvent) – The PyGfx pointer event.

  • idx (int, optional) – Index of the handle being moved. If None, uses the active handle.

handle_release_callback(event, idx=None)[source]#

Handle the release of the mouse button.

Parameters:
  • event (PointerEvent) – The PyGfx pointer event.

  • idx (int, optional) – Index of the handle being released.

property left_disk_value#

Get the value of the left/bottom handle.

Returns:

The current value.

Return type:

float

property max_value#

Get the maximum value of the slider.

Returns:

The maximum value.

Return type:

float

property min_value#

Get the minimum value of the slider.

Returns:

The minimum value.

Return type:

float

property right_disk_value#

Get the value of the right/top handle.

Returns:

The current value.

Return type:

float

track_click_callback(event)[source]#

Handle mouse click events on the slider track.

Parameters:

event (PointerEvent) – The PyGfx pointer event.

LineSlider2D#

class fury.ui.LineSlider2D(*, position=(0, 0), initial_value=50, min_value=0, max_value=100, length=200, line_width=5, inner_radius=0, outer_radius=10, handle_side=20, font_size=16, orientation='horizontal', text_template='{value:.1f} ({ratio:.0%})', shape='disk', z_order=0)[source]#

Bases: Slider2D

A 2D Line Slider component.

Parameters:
  • position ((float, float), optional) – Absolute coordinates (x, y) for placement.

  • initial_value (float, optional) – The starting value of the slider.

  • min_value (float, optional) – The minimum value of the slider range.

  • max_value (float, optional) – The maximum value of the slider range.

  • length (int, optional) – The length of the slider track in pixels.

  • line_width (int, optional) – The thickness of the slider track.

  • inner_radius (int, optional) – The inner radius for disk-shaped handles (for rings).

  • outer_radius (int, optional) – The outer radius for disk-shaped handles.

  • handle_side (int, optional) – The side length for square-shaped handles.

  • font_size (int, optional) – The font size for the value label.

  • orientation (str, optional) – The slider orientation: “horizontal” or “vertical”.

  • text_template (str, optional) – A formatting string for the label. Supports {value} and {ratio}.

  • shape (str, optional) – The handle shape: “disk” or “square”.

  • z_order (int, optional) – The stacking priority. The handle is assigned z_order + 1.

__init__(*, position=(0, 0), initial_value=50, min_value=0, max_value=100, length=200, line_width=5, inner_radius=0, outer_radius=10, handle_side=20, font_size=16, orientation='horizontal', text_template='{value:.1f} ({ratio:.0%})', shape='disk', z_order=0)[source]#

Initialize the slider instance.

handle_move_callback(event)[source]#

Handle mouse drag events to update the slider state.

Parameters:

event (PointerEvent) – The PyGfx pointer event.

ListBox2D#

class fury.ui.ListBox2D(values, *, position=(0, 0), size=(100, 300), multiselection=True, reverse_scrolling=False, font_size=20, line_spacing=1.4, text_color=(0.2, 0.2, 0.2), selected_color=(0.9, 0.6, 0.6), unselected_color=(0.6, 0.6, 0.6), scroll_bar_active_color=(0.6, 0.2, 0.2), scroll_bar_inactive_color=(0.9, 0.0, 0.0), background_opacity=1.0)[source]#

Bases: UI

UI component that allows the user to select items from a list.

Parameters:
  • values (list of objects) – Values used to populate this listbox. Objects must be castable to string.

  • position ((float, float), optional) – Absolute coordinates (x, y) of the lower-left corner of this UI component.

  • size ((int, int), optional) – Width and height in pixels of this UI component.

  • multiselection (bool, optional) – Whether multiple values can be selected at once.

  • reverse_scrolling (bool, optional) – If True, scrolling up will move the list of files down.

  • font_size (int, optional) – The font size in pixels.

  • line_spacing (float, optional) – Distance between listbox’s items in pixels.

  • text_color (tuple of 3 floats, optional) – Color of the text.

  • selected_color (tuple of 3 floats, optional) – Background color of selected item.

  • unselected_color (tuple of 3 floats, optional) – Background color of unselected item.

  • scroll_bar_active_color (tuple of 3 floats, optional) – Color of active scroll bar.

  • scroll_bar_inactive_color (tuple of 3 floats, optional) – Color of inactive scroll bar.

  • background_opacity (float, optional) – Opacity of the background.

on_change#

Callback function for when the selected items have changed.

Type:

function

__init__(values, *, position=(0, 0), size=(100, 300), multiselection=True, reverse_scrolling=False, font_size=20, line_spacing=1.4, text_color=(0.2, 0.2, 0.2), selected_color=(0.9, 0.6, 0.6), unselected_color=(0.6, 0.6, 0.6), scroll_bar_active_color=(0.6, 0.2, 0.2), scroll_bar_inactive_color=(0.9, 0.0, 0.0), background_opacity=1.0)[source]#

Init class instance.

clear_selection()[source]#

Clear all items from the current selection.

resize(size)[source]#

Resize the component.

Parameters:

size ((int, int)) – Size to resize to.

scroll_click_callback(event)[source]#

Callback to change the color of the bar when it is clicked.

Parameters:

event (object) – The pygfx event.

scroll_down()[source]#

Scroll down by one item.

scroll_drag_callback(event)[source]#

Drag scroll bar in the combo box.

Parameters:

event (object) – The pygfx event.

scroll_release_callback(event)[source]#

Callback to change the color of the bar when it is released.

Parameters:

event (object) – The pygfx event.

scroll_up()[source]#

Scroll up by one item.

select(item, *, multiselect=False, range_select=False)[source]#

Select the item.

Parameters:
  • item (object) – Item to select.

  • multiselect (bool, optional) – If True and multiselection is allowed, the item is added to the selection.

  • range_select (bool, optional) – If True and multiselection is allowed, all items between the last selected item and the current one will be added.

update()[source]#

Refresh listbox content.

update_scrollbar()[source]#

Change the scroll-bar height when the values change.

wheel_callback(event)[source]#

Handle mouse wheel scroll events.

Parameters:

event (object) – The pygfx event.

ListBoxItem2D#

class fury.ui.ListBoxItem2D(on_select, size, *, text_color=(1.0, 0.0, 0.0), selected_color=(0.4, 0.4, 0.4), unselected_color=(0.9, 0.9, 0.9), background_opacity=1.0)[source]#

Bases: UI

The text displayed in a listbox.

Parameters:
  • on_select (callable) – Callback invoked when the item is clicked.

  • size ((int, int)) – Size of the item.

  • text_color (tuple of 3 floats, optional) – Text color.

  • selected_color (tuple of 3 floats, optional) – Selected background color.

  • unselected_color (tuple of 3 floats, optional) – Unselected background color.

  • background_opacity (float, optional) – Opacity.

__init__(on_select, size, *, text_color=(1.0, 0.0, 0.0), selected_color=(0.4, 0.4, 0.4), unselected_color=(0.9, 0.9, 0.9), background_opacity=1.0)[source]#

Init ListBox Item instance.

Parameters:
  • on_select (callable) – Callback invoked when the item is clicked.

  • size (tuple of 2 ints) – The size of the listbox item.

  • text_color (tuple of 3 floats)

  • unselected_color (tuple of 3 floats)

  • selected_color (tuple of 3 floats)

  • background_opacity (float)

deselect()[source]#

Deselect the item and remove highlight.

property element#

Get the stored element.

Returns:

Element.

Return type:

object

left_button_clicked(event)[source]#

Handle left click for this UI element.

Parameters:

event (object) – The pygfx event.

resize(size)[source]#

Resize the component.

Parameters:

size ((int, int)) – Size to resize to.

select()[source]#

Select the item and highlight its background.

Panel2D#

class fury.ui.Panel2D(size, *, position=(0, 0), color=(0.1, 0.1, 0.1), opacity=0.7, align='left', border_color=(1, 1, 1), border_width=0, has_border=False)[source]#

Bases: UI

A 2D UI Panel.

Can contain one or more UI elements.

Parameters:
  • size ((int, int)) – Size (width, height) in pixels of the panel.

  • position ((float, float)) – Absolute coordinates (x, y) of the lower-left corner of the panel.

  • color ((float, float, float)) – Must take values in [0, 1].

  • opacity (float) – Must take values in [0, 1].

  • align ([left, right]) – Alignment of the panel with respect to the overall screen.

  • border_color ((float, float, float), optional) – RGB color of the border. Must take values in [0, 1].

  • border_width (float, optional) – Width of the border.

  • has_border (bool, optional) – If the panel should have borders.

alignment#

Alignment of the panel with respect to the overall screen.

Type:

[left, right]

__init__(size, *, position=(0, 0), color=(0.1, 0.1, 0.1), opacity=0.7, align='left', border_color=(1, 1, 1), border_width=0, has_border=False)[source]#

Initialize class instance.

add_element(element, coords, *, anchor='position', _is_internal=False)[source]#

Add a UI component to the panel.

The coordinates represent an offset from the lower left corner of the panel.

Parameters:
  • element (UI) – The UI item to be added.

  • coords ((float, float) or (int, int)) – If float, normalized coordinates are assumed and they must be between [0,1]. If int, pixels coordinates are assumed and it must fit within the panel’s size.

  • anchor (str, optional) – Supported anchors are ‘position’ (top-left) and ‘center’.

  • _is_internal (bool, optional) – Flag used to distinguish between user-added elements and internal elements added by the Panel itself.

Raises:

ValueError – If coordinates are normalized but outside the [0,1] range, or if an unknown anchor is provided.

property border_color#

Get the current color of all four borders.

Returns:

A list containing the color (RGB tuple) of the left, right, top, and bottom borders, respectively.

Return type:

list

property border_width#

Get the current width/height of the borders.

Returns:

A list containing the width (for left/right) and height (for top/bottom) of the borders.

Return type:

list

property color#

Get the background color of the panel.

Returns:

RGB color of the panel background.

Return type:

(float, float, float)

left_button_dragged(event)[source]#

Handle left mouse button drag event for panel movement.

Parameters:

event (PointerEvent) – The PyGfx pointer event object.

left_button_pressed(event)[source]#

Handle left mouse button press event for panel.

Parameters:

event (PointerEvent) – The PyGfx pointer event object.

property opacity#

Get the opacity of the panel.

Returns:

Opacity value.

Return type:

float

re_align(window_size_change)[source]#

Re-organise the elements in case the window size is changed.

Parameters:

window_size_change ((int, int)) – New window size (width, height) in pixels.

Raises:

ValueError – If alignment is not ‘left’ or ‘right’.

remove_element(element)[source]#

Remove a UI component from the panel.

Parameters:

element (UI) – The UI item to be removed.

Raises:

ValueError – If the element is not found in the panel’s elements list.

resize(size)[source]#

Set the panel size.

Parameters:

size ((float, float)) – Panel size (width, height) in pixels.

set_visibility(visibility)[source]#

Set visibility of this UI component.

Parameters:

visibility (bool) – If True, the panel and its elements will be visible. If False, it will be hidden.

update_border_coords()[source]#

Update the coordinates of the borders.

update_element(element, coords, *, anchor='position')[source]#

Update the position of a UI component in the panel.

Parameters:
  • element (UI) – The UI item to be updated.

  • coords ((float, float) or (int, int)) – New coordinates. If float, normalized coordinates are assumed and they must be between [0,1]. If int, pixel coordinates are assumed and it must fit within the panel’s size.

  • anchor (str, optional) – Supported anchors are ‘position’ (top-left) and ‘center’.

Raises:

ValueError – If coordinates are normalized but outside the [0,1] range, or if an unknown anchor is provided.

PlaybackPanel#

class fury.ui.PlaybackPanel(*, loop=False, position=(0, 0), width=900, z_order=0)[source]#

Bases: UI

A playback controller designed for FURY v2.

Parameters:
  • loop (bool, optional) – If True, the playback starts in looping mode.

  • position ((float, float), optional) – Absolute coordinates (x, y) for placement.

  • width (int, optional) – The total width of the playback panel in pixels.

  • z_order (int, optional) – The stacking priority of the panel.

__init__(*, loop=False, position=(0, 0), width=900, z_order=0)[source]#

Initialize the playback panel instance.

Parameters:
  • loop (bool, optional) – If True, the playback starts in looping mode.

  • position ((float, float), optional) – Absolute coordinates (x, y) for placement.

  • width (int, optional) – The total width of the playback panel in pixels.

  • z_order (int, optional) – The stacking priority of the panel.

property current_time#

Get the current playback time.

Returns:

Current time in seconds.

Return type:

float

property current_time_str#

Get the formatted string representation of current time.

Returns:

Formatted time string.

Return type:

str

property final_time#

Get the total duration of the playback.

Returns:

Total duration in seconds.

Return type:

float

left_button_dragged(event)[source]#

Handle left mouse button drag event for PlaybackPanel.

Parameters:

event (PointerEvent) – The PyGfx pointer event object.

left_button_pressed(event)[source]#

Handle left mouse button press event for PlaybackPanel.

Parameters:

event (PointerEvent) – The PyGfx pointer event object.

loop()[source]#

Enable looping mode.

pause()[source]#

Set the controller to paused state.

play()[source]#

Set the controller to playing state.

play_once()[source]#

Disable looping mode.

property speed#

Get the current playback speed.

Returns:

Playback speed multiplier.

Return type:

float

stop()[source]#

Stop the playback and reset the timer.

RangeSlider#

class fury.ui.RangeSlider(*, line_width=5, inner_radius=0, outer_radius=10, handle_side=20, range_slider_center=(450, 400), value_slider_center=(450, 300), length=200, min_value=0, max_value=100, font_size=16, range_precision=1, orientation='horizontal', value_precision=2, shape='disk')[source]#

Bases: UI

A compound UI element containing a LineSlider2D and a LineDoubleSlider2D.

The double slider is used to set the minimum and maximum value bounds for the single value slider.

Parameters:
  • line_width (int, optional) – Width of the line on which the handles will slide.

  • inner_radius (int, optional) – Inner radius of the handles (when shape is ‘disk’).

  • outer_radius (int, optional) – Outer radius of the handles (when shape is ‘disk’).

  • handle_side (int, optional) – Length of the square handles (when shape is ‘square’).

  • range_slider_center ((float, float), optional) – Position of the LineDoubleSlider2D object.

  • value_slider_center ((float, float), optional) – Position of the LineSlider2D object.

  • length (int, optional) – Length of both sliders in pixels.

  • min_value (float, optional) – Minimum value for the range slider.

  • max_value (float, optional) – Maximum value for the range slider.

  • font_size (int, optional) – Size of the text font displaying the values.

  • range_precision (int, optional) – Number of decimal places to show on the range slider text.

  • orientation (str, optional) – Orientation of the sliders (‘horizontal’ or ‘vertical’).

  • value_precision (int, optional) – Number of decimal places to show on the value slider text.

  • shape (str, optional) – Shape of the handles (‘disk’ or ‘square’).

__init__(*, line_width=5, inner_radius=0, outer_radius=10, handle_side=20, range_slider_center=(450, 400), value_slider_center=(450, 300), length=200, min_value=0, max_value=100, font_size=16, range_precision=1, orientation='horizontal', value_precision=2, shape='disk')[source]#

Init scene.

range_slider_handle_move_callback(ui)[source]#

Handle updates to the range bounds.

Parameters:

ui (UI) – The UI component triggering the callback.

Rectangle2D#

class fury.ui.Rectangle2D(*, size=(100, 100), position=(0, 0), color=(1, 1, 1), opacity=1.0)[source]#

Bases: UI

A 2D rectangle sub-classed from UI.

Parameters:
  • size ((int, int)) – The size of the rectangle (width, height) in pixels.

  • position ((float, float)) – Coordinates (x, y) of the lower-left corner of the rectangle.

  • color ((float, float, float)) – Must take values in [0, 1].

  • opacity (float) – Must take values in [0, 1].

__init__(*, size=(100, 100), position=(0, 0), color=(1, 1, 1), opacity=1.0)[source]#

Initialize a rectangle.

property color#

Get the rectangle color.

Returns:

RGB color.

Return type:

(float, float, float)

property height#

Get the current height of the rectangle.

Returns:

The height of the rectangle in pixels.

Return type:

float

property opacity#

Get the rectangle opacity.

Returns:

Opacity value.

Return type:

float

resize(size)[source]#

Set the rectangle size.

Parameters:

size ((float, float)) – Rectangle size (width, height) in pixels.

property width#

Get the current width of the rectangle.

Returns:

The width of the rectangle in pixels.

Return type:

float

RingSlider2D#

class fury.ui.RingSlider2D(*, center=(0, 0), initial_value=0, min_value=0, max_value=360, slider_inner_radius=40, slider_outer_radius=44, handle_inner_radius=0, handle_outer_radius=10, handle_side=20, font_size=16, text_template='{ratio:.0%}', shape='disk', z_order=0)[source]#

Bases: Slider2D

A disk slider.

A disk moves along the boundary of a ring. Goes from 0-360 degrees.

Parameters:
  • center ((float, float), optional) – Position (x, y) of the slider’s center.

  • initial_value (float, optional) – Initial value of the slider.

  • min_value (float, optional) – Minimum value of the slider.

  • max_value (float, optional) – Maximum value of the slider.

  • slider_inner_radius (int, optional) – Inner radius of the base disk.

  • slider_outer_radius (int, optional) – Outer radius of the base disk.

  • handle_inner_radius (int, optional) – Inner radius of the slider’s handle.

  • handle_outer_radius (int, optional) – Outer radius of the slider’s handle.

  • handle_side (int, optional) – The side length of the square handle when shape=”square”.

  • font_size (int, optional) – Size of the text to display alongside the slider (pt).

  • text_template (str or callable, optional) – If str, text template can contain one or multiple of the replacement fields: {value:}, {ratio:}, {angle:}. If callable, this instance of :class:RingSlider2D will be passed as argument to the text template function.

  • shape (str, optional) – The handle shape. Supported values are “disk” and “square”.

  • z_order (int, optional) – Stacking priority of the slider. The handle and text are placed above the track.

track#

The circle on which the slider’s handle moves.

Type:

Disk2D

handle#

The moving part of the slider.

Type:

Disk2D

text#

The text that shows percentage.

Type:

TextBlock2D

default_color#

Color of the handle when in unpressed state.

Type:

(float, float, float)

active_color#

Color of the handle when it is pressed.

Type:

(float, float, float)

__init__(*, center=(0, 0), initial_value=0, min_value=0, max_value=360, slider_inner_radius=40, slider_outer_radius=44, handle_inner_radius=0, handle_outer_radius=10, handle_side=20, font_size=16, text_template='{ratio:.0%}', shape='disk', z_order=0)[source]#

Init this UI element.

Parameters:
  • center ((float, float), optional) – Position (x, y) of the slider’s center.

  • initial_value (float, optional) – Initial value of the slider.

  • min_value (float, optional) – Minimum value of the slider.

  • max_value (float, optional) – Maximum value of the slider.

  • slider_inner_radius (int, optional) – Inner radius of the base disk.

  • slider_outer_radius (int, optional) – Outer radius of the base disk.

  • handle_inner_radius (int, optional) – Inner radius of the slider’s handle.

  • handle_outer_radius (int, optional) – Outer radius of the slider’s handle.

  • handle_side (int, optional) – The side length of the square handle when shape=”square”.

  • font_size (int, optional) – Size of the text to display alongside the slider (pt).

  • text_template (str or callable, optional) – If str, text template can contain one or multiple of the replacement fields: {value:}, {ratio:}, {angle:}. If callable, this instance of :class:RingSlider2D will be passed as argument to the text template function.

  • shape (str, optional) – The handle shape. Supported values are “disk” and “square”.

  • z_order (int, optional) – Stacking priority of the slider. The handle and text are placed above the track.

property angle#

Return Angle (in rad) the handle makes with the y-axis.

Returns:

The angle.

Return type:

float

handle_move_callback(event)[source]#

Handle mouse drag events to update the slider state.

Parameters:

event (PointerEvent) – The PyGfx pointer event.

property mid_track_radius#

Return the distance from the center of the slider to the track middle.

Returns:

The mid track radius.

Return type:

float

TabPanel2D#

class fury.ui.TabPanel2D(*, position=(0, 0), size=(100, 100), title='New Tab', color=(0.5, 0.5, 0.5), content_size=None, content_visible=False, content_panel=None)[source]#

Bases: UI

A 2D tab header with an associated content panel.

This component represents a single tab inside TabUI. It owns the clickable tab header and delegates user-added UI elements to its content_panel. The content panel visibility is controlled by TabUI.

Parameters:
  • position ((float, float), optional) – Absolute coordinates (x, y) of the upper-left corner of the tab header.

  • size ((int, int), optional) – Width and height in pixels of the tab header.

  • title (str, optional) – Initial text displayed in the tab header.

  • color ((float, float, float), optional) – RGB color of the tab header background. Values must be in [0, 1].

  • content_size ((int, int), optional) – Width and height in pixels of the content panel. If None, size is used.

  • content_visible (bool, optional) – Initial visibility of the content panel.

  • content_panel (Panel2D, optional) – Panel used to store content for this tab. If None, a new panel with content_size is created.

panel#

Header panel used as the clickable tab background.

Type:

Panel2D

content_panel#

Panel that stores the UI elements displayed when this tab is active.

Type:

Panel2D

text_block#

Text component used to render the tab title.

Type:

TextBlock2D

__init__(*, position=(0, 0), size=(100, 100), title='New Tab', color=(0.5, 0.5, 0.5), content_size=None, content_visible=False, content_panel=None)[source]#

Initialize the tab panel.

add_element(element, coords, *, anchor='position')[source]#

Add an element to this tab’s content panel.

Parameters:
  • element (UI) – UI component to add to the tab content area.

  • coords ((float, float) or (int, int)) – Coordinates relative to the content panel. If floats are supplied, normalized coordinates in [0, 1] are assumed. If integers are supplied, pixel coordinates are assumed.

  • anchor (str, optional) – Anchor used to position element. Supported values are the same as Panel2D.add_element().

property color#

Get the tab header background color.

Returns:

RGB color of the tab header background.

Return type:

(float, float, float)

remove_element(element)[source]#

Remove an element from this tab’s content panel.

Parameters:

element (UI) – UI component to remove from the tab content area.

resize(size)[source]#

Resize the tab header.

Parameters:

size ((int, int)) – New width and height in pixels of the tab header.

property title#

Get the tab title.

Returns:

Text displayed in the tab header.

Return type:

str

property title_bold#

Get whether the tab title is bold.

Returns:

True when the tab title is rendered in bold.

Return type:

bool

property title_color#

Get the tab title color.

Returns:

RGB color of the tab title.

Return type:

(float, float, float)

property title_font_size#

Get the tab title font size.

Returns:

Font size of the tab title.

Return type:

int

property title_italic#

Get whether the tab title is italic.

Returns:

True when the tab title is rendered in italic.

Return type:

bool

update_element(element, coords, *, anchor='position')[source]#

Update an element in this tab’s content panel.

Parameters:
  • element (UI) – UI component already present in the tab content area.

  • coords ((float, float) or (int, int)) – New coordinates relative to the content panel.

  • anchor (str, optional) – Anchor used to position element. Supported values are the same as Panel2D.add_element().

TabUI#

class fury.ui.TabUI(*, position=(0, 0), size=(100, 100), tab_titles=None, active_color=(1, 1, 1), inactive_color=(0.5, 0.5, 0.5), font_size=18, draggable=False, startup_tab_id=None, tab_bar_pos='top')[source]#

Bases: UI

A 2D container that switches between multiple content panels.

TabUI creates tab headers and one content panel per tab. The tab bar can be placed horizontally at the top or bottom, or vertically on the left or right. It can also use an accordion layout where each tab title spans the width of the widget and the selected tab expands below its title. A left click on a tab header selects that tab and hides the other tab content panels. A second left click on the active tab hides its content while keeping the tab selected. A right click collapses the tab UI and clears the active tab.

Parameters:
  • position ((float, float), optional) – Absolute coordinates (x, y) of the upper-left corner of the tab UI.

  • size ((int, int), optional) – Width and height in pixels of the full tab UI.

  • tab_titles (list of str, optional) – Titles used to create tabs during initialization. If None, one tab with the default title is created.

  • active_color ((float, float, float), optional) – RGB color of the active tab header. Values must be in [0, 1].

  • inactive_color ((float, float, float), optional) – RGB color of inactive tab headers. Values must be in [0, 1].

  • font_size (int, optional) – Font size used by tab titles.

  • draggable (bool, optional) – If True, the tab UI can be dragged from tab headers or content panel backgrounds.

  • startup_tab_id (int, optional) – Index of the tab to show initially. If None, all content panels are hidden on startup.

  • tab_bar_pos ({'top', 'bottom', 'left', 'right', 'accordion'}, optional) – Position of the tab bar relative to the content panel. "accordion" creates an accordion-style layout.

tabs#

Tab panels managed by this widget.

Type:

list of TabPanel2D

parent_panel#

Transparent panel that anchors tab headers and content panels.

Type:

Panel2D

active_tab_idx#

Index of the currently selected tab. None when the tab UI is collapsed.

Type:

int or None

collapsed#

True when no tab content panel is visible due to right-click collapse.

Type:

bool

on_change#

Callback invoked after a tab is selected. The callback receives this TabUI instance.

Type:

callable

on_collapse#

Callback invoked after the tab UI is collapsed. The callback receives this TabUI instance.

Type:

callable

Raises:

ValueError – If tab_titles is empty or is not a list of strings.

__init__(*, position=(0, 0), size=(100, 100), tab_titles=None, active_color=(1, 1, 1), inactive_color=(0.5, 0.5, 0.5), font_size=18, draggable=False, startup_tab_id=None, tab_bar_pos='top')[source]#

Initialize the tab UI.

add_element(tab_idx, element, coords, *, anchor='position')[source]#

Add an element to a tab content panel.

Parameters:
  • tab_idx (int) – Index of the tab receiving the element.

  • element (UI) – UI component to add to the tab content panel.

  • coords ((float, float) or (int, int)) – Coordinates relative to the tab content panel. If floats are supplied, normalized coordinates in [0, 1] are assumed. If integers are supplied, pixel coordinates are assumed.

  • anchor (str, optional) – Anchor used to position element. Supported values are the same as Panel2D.add_element().

Raises:

IndexError – If tab_idx is outside the range of available tabs.

collapse_tab_ui()[source]#

Collapse the active tab content.

Hides the active tab content panel, resets active_tab_idx to None, marks the tab UI as collapsed, and invokes on_collapse.

left_button_dragged(event)[source]#

Drag the tab UI.

Parameters:

event (PointerEvent) – PyGfx pointer event containing the current pointer coordinates.

left_button_pressed(event, tab_idx=None)[source]#

Start dragging the tab UI.

Parameters:
  • event (PointerEvent) – PyGfx pointer event containing the current pointer coordinates.

  • tab_idx (int, optional) – Index of the tab to select before starting the drag operation. If None, only dragging is initialized.

property nb_tabs#

Get the number of tabs in this tab UI.

Returns:

Number of tabs in this tab UI.

Return type:

int

remove_element(tab_idx, element)[source]#

Remove an element from a tab content panel.

Parameters:
  • tab_idx (int) – Index of the tab containing the element.

  • element (UI) – UI component to remove from the tab content panel.

Raises:

IndexError – If tab_idx is outside the range of available tabs.

resize(size)[source]#

Resize the full tab UI.

Parameters:

size ((int, int)) – New width and height in pixels of the full tab UI.

select_tab(tab_idx)[source]#

Select a tab.

Selecting a tab hides all other content panels. If the selected tab is already visible, its content panel is hidden and the tab remains the active tab. The on_change callback is invoked after selection.

Parameters:

tab_idx (int) – Index of the tab to select.

Raises:

IndexError – If tab_idx is outside the range of available tabs.

update_element(tab_idx, element, coords, *, anchor='position')[source]#

Update an element in a tab content panel.

Parameters:
  • tab_idx (int) – Index of the tab containing the element.

  • element (UI) – UI component already present in the tab content panel.

  • coords ((float, float) or (int, int)) – New coordinates relative to the tab content panel.

  • anchor (str, optional) – Anchor used to position element. Supported values are the same as Panel2D.add_element().

Raises:

IndexError – If tab_idx is outside the range of available tabs.

update_tabs()[source]#

Update tab layout and callbacks.

This recomputes each tab header position, content panel position, tab size, and event callbacks. If tab_bar_pos is invalid, it falls back to "top" and emits a warning.

TextBlock2D#

class fury.ui.TextBlock2D(*, text='Text Block', font_size=18, font_family='Arial', justification='left', vertical_justification='top', bold=False, italic=False, size=None, color=(1, 1, 1), bg_color=None, position=(0, 0), dynamic_bbox=False)[source]#

Bases: UI

A 2D text component with optional background.

Parameters:
  • text (str, optional) – The initial text message.

  • font_size (int, optional) – Size of the text font.

  • font_family (str, optional) – The font family name.

  • justification (str, optional) – Horizontal alignment (“left”, “center”, “right”).

  • vertical_justification (str, optional) – Vertical alignment (“top”, “middle”, “bottom”).

  • bold (bool, optional) – If True, makes text bold.

  • italic (bool, optional) – If True, makes text italicized.

  • size ((int, int), optional) – The (width, height) in pixels for the text bounding box.

  • color ((float, float, float), optional) – RGB color for the text (0-1).

  • bg_color ((float, float, float), optional) – RGB color for the background (0-1). If None, no background is drawn.

  • position ((float, float), optional) – Absolute coordinates (x, y) for placement.

  • dynamic_bbox (bool, optional) – If True, resizes the bounding box to fit the content.

__init__(*, text='Text Block', font_size=18, font_family='Arial', justification='left', vertical_justification='top', bold=False, italic=False, size=None, color=(1, 1, 1), bg_color=None, position=(0, 0), dynamic_bbox=False)[source]#

Initialize the text block instance.

property background_color#

Get the background color.

Returns:

The RGB color of the background, or None if no background exists.

Return type:

(float, float, float) or None

property bold#

Return whether the text is bold.

Returns:

Text is bold if True.

Return type:

bool

property color#

Get text color.

Returns:

Returns text color in RGB.

Return type:

(float, float, float)

property dynamic_bbox#

Check if the bounding box is dynamic.

Returns:

True if dynamic, False otherwise.

Return type:

bool

property font_family#

Get font family.

Returns:

Text font family.

Return type:

str

property font_size#

Get text font size.

Returns:

Text font size.

Return type:

int

get_formatted_text(text)[source]#

Format the given text with markdown syntax for bold/italic styles.

Parameters:

text (str) – The raw text to format.

Returns:

The formatted markdown string.

Return type:

str

get_text_actor_size()[source]#

Get the rendered size of the text actor.

Returns:

The (width, height) of the rendered text.

Return type:

(float, float)

property italic#

Return whether the text is italicised.

Returns:

Text is italicised if True.

Return type:

bool

property justification#

Get text justification.

Returns:

Text justification.

Return type:

str

property message#

Get the current text message.

Returns:

The text message.

Return type:

str

resize(size)[source]#

Resize the TextBlock2D bounding box.

Parameters:

size ((int, int)) – The new (width, height) in pixels.

set_visibility(visibility)[source]#

Set visibility of this text block.

Parameters:

visibility (bool) – If True, the text will be visible. The background is shown only when this text block was created with a background color. If False, both text and background are hidden.

property shadow#

Return whether the text has a shadow.

Returns:

True if text has a shadow.

Return type:

bool

update_alignment()[source]#

Update the text actor alignment within the bounding box.

update_bounding_box(*, size=None)[source]#

Update the text bounding box and background.

Parameters:

size ((int, int), optional) – If provided, uses this size. Otherwise, uses the current size.

update_layout()[source]#

Update the component layout based on current text dimensions.

property vertical_justification#

Get text vertical justification.

Returns:

Text vertical justification.

Return type:

str

TextBox2D#

class fury.ui.TextBox2D(width, height, *, text='Enter Text', position=(100, 10), color=(0, 0, 0), font_size=18, font_family='Arial', justification='left', bold=False, italic=False, shadow=False, z_order=0)[source]#

Bases: UI

An editable 2D text box that behaves as a UI component.

Currently supports: - Basic text editing. - Cursor movements. - Single and multi-line text boxes. - Pre text formatting (text needs to be formatted beforehand).

Parameters:
  • width (int) – The number of characters in a single line of text.

  • height (int) – The number of lines in the textbox.

  • text (str, optional) – The initial text while building the actor.

  • position ((float, float), optional) – (x, y) in pixels.

  • color ((float, float, float), optional) – RGB values between 0 and 1.

  • font_size (int, optional) – Size of the text font.

  • font_family (str, optional) – Currently only supports Arial.

  • justification (str, optional) – Left, right, or center.

  • bold (bool, optional) – Makes text bold.

  • italic (bool, optional) – Makes text italic.

  • shadow (bool, optional) – Adds text shadow.

  • z_order (int, optional) – Rendering order of the widget.

text#

The internal text UI component.

Type:

TextBlock2D

width#

The number of characters in a single line of text.

Type:

int

height#

The number of lines in the textbox.

Type:

int

window_left#

Left limit of visible text in the textbox.

Type:

int

window_right#

Right limit of visible text in the textbox.

Type:

int

caret_pos#

Position of the caret in the text.

Type:

int

init#

Flag which says whether the textbox has just been initialized.

Type:

bool

__init__(width, height, *, text='Enter Text', position=(100, 10), color=(0, 0, 0), font_size=18, font_family='Arial', justification='left', bold=False, italic=False, shadow=False, z_order=0)[source]#

Init this UI element.

Parameters:
  • width (int) – The number of characters in a single line of text.

  • height (int) – The number of lines in the textbox.

  • text (str, optional) – The initial text while building the actor.

  • position ((float, float), optional) – (x, y) in pixels.

  • color ((float, float, float), optional) – RGB values between 0 and 1.

  • font_size (int, optional) – Size of the text font.

  • font_family (str, optional) – Currently only supports Arial.

  • justification (str, optional) – Left, right, or center.

  • bold (bool, optional) – Makes text bold.

  • italic (bool, optional) – Makes text italic.

  • shadow (bool, optional) – Adds text shadow.

  • z_order (int, optional) – Rendering order of the widget.

add_character(character)[source]#

Insert a character into the text and moves window and caret.

Parameters:

character (str) – The character to be inserted.

blur_textbox(event=None)[source]#

Handle blur event for textbox.

Parameters:

event (PointerEvent) – The pointer event.

edit_mode()[source]#

Turn on edit mode.

handle_character(key, key_char, modifiers=None)[source]#

Handle button events.

# TODO: Need to handle all kinds of characters like !, +, etc.

Parameters:
  • key (str) – The key identifier.

  • key_char (str) – The character representation of the key.

  • modifiers (tuple, optional) – The active keyboard modifiers.

Returns:

True if editing is finished, otherwise False.

Return type:

bool

key_press(event)[source]#

Handle Key press for textbox.

Parameters:

event (KeyboardEvent) – The keyboard event.

key_release(event)[source]#

Handle Key release for textbox.

Parameters:

event (KeyboardEvent) – The keyboard event.

left_button_press(event)[source]#

Handle left button press for textbox.

Parameters:

event (PointerEvent) – The pointer event.

left_move_left()[source]#

Move left boundary of the text window left-wards.

left_move_right()[source]#

Move left boundary of the text window right-wards.

move_caret_left()[source]#

Move the caret towards left.

move_caret_right()[source]#

Move the caret towards right.

move_down()[source]#

Handle down button press.

move_left()[source]#

Handle left button press.

move_right()[source]#

Handle right button press.

move_up()[source]#

Handle up button press.

remove_character()[source]#

Remove a character and moves window and caret accordingly.

render_text(*, show_caret=True)[source]#

Render text after processing.

Parameters:

show_caret (bool) – Whether or not to show the caret.

right_move_left()[source]#

Move right boundary of the text window left-wards.

right_move_right()[source]#

Move right boundary of the text window right-wards.

set_message(message)[source]#

Set custom text to textbox.

Parameters:

message (str) – The custom message to be set.

showable_text(show_caret)[source]#

Chop out text to be shown on the screen.

Parameters:

show_caret (bool) – Whether or not to show the caret.

Returns:

The visible portion of the text.

Return type:

str

wheel_scroll(event)[source]#

Handle mouse wheel event for textbox.

Parameters:

event (WheelEvent) – The wheel event.

width_set_text(text)[source]#

Add newlines to text where necessary, needed for multi-line text boxes.

Parameters:

text (str) – The final text to be formatted.

Returns:

A multi-line formatted text.

Return type:

str

TextButton2D#

class fury.ui.TextButton2D(label, states=None, position=(0, 0), size=(100, 40), font_size=25, is_toggle=False)[source]#

Bases: Button2D

A button component that updates text and color based on state.

Parameters:
  • label (str) – The default text to display on the button.

  • states (dict) – Configuration for visual states. Supports mapping keys to RGB tuples or dictionaries containing ‘text’ and ‘color’ keys.

  • position ((float, float)) – Absolute coordinates (x, y) for placement.

  • size ((int, int)) – Width and height in pixels for the button background.

  • font_size (int) – Size of the text font.

  • is_toggle (bool, optional) – If True, the button behaves as a toggle switch.

__init__(label, states=None, position=(0, 0), size=(100, 40), font_size=25, is_toggle=False)[source]#

Initialize the text button instance.

update_visual_state()[source]#

Update the text message and background color based on state.

TexturedButton2D#

class fury.ui.TexturedButton2D(states, position=(0, 0), size=(30, 30), is_toggle=False)[source]#

Bases: Button2D

A button component that swaps textures based on interaction state.

Parameters:
  • states (dict) – A mapping of state names to image file paths.

  • position ((float, float)) – Absolute coordinates (x, y) for placement.

  • size ((int, int)) – Width and height in pixels.

  • is_toggle (bool, optional) – If True, the button behaves as a toggle switch.

__init__(states, position=(0, 0), size=(30, 30), is_toggle=False)[source]#

Initialize the textured button instance.

update_visual_state()[source]#

Update the mesh texture based on the current button state.

UI#

class fury.ui.UI(*, position=(0, 0), x_anchor=Anchor.LEFT, y_anchor=Anchor.TOP, z_order=0)[source]#

Bases: object

An umbrella class for all UI elements.

While adding UI elements to the scene, we go over all the sub-elements that come with it and add those to the scene automatically.

Parameters:
  • position ((float, float)) – Absolute pixel coordinates (x, y) which, in combination with x_anchor and y_anchor, define the initial placement of this UI component.

  • x_anchor (str, optional) – Define the horizontal anchor point for position. Can be “LEFT”, “CENTER”, or “RIGHT”.

  • y_anchor (str, optional) – Define the vertical anchor point for position. Can be “BOTTOM”, “CENTER”, or “TOP”.

  • z_order (int, optional) – The initial Z-order of the UI component.

position#

Absolute coordinates (x, y) of the lower-left corner of this UI component.

Type:

(float, float)

center#

Absolute coordinates (x, y) of the center of this UI component.

Type:

(float, float)

on_left_mouse_button_pressed#

Callback function for when the left mouse button is pressed.

Type:

function

on_left_mouse_button_released#

Callback function for when the left mouse button is released.

Type:

function

on_left_mouse_button_clicked#

Callback function for when clicked using the left mouse button (i.e. pressed -> released).

Type:

function

on_left_mouse_double_clicked#

Callback function for when left mouse button is double clicked (i.e pressed -> released -> pressed -> released).

Type:

function

on_left_mouse_button_dragged#

Callback function for when dragging using the left mouse button.

Type:

function

on_right_mouse_button_pressed#

Callback function for when the right mouse button is pressed.

Type:

function

on_right_mouse_button_released#

Callback function for when the right mouse button is released.

Type:

function

on_right_mouse_button_clicked#

Callback function for when clicking using the right mouse button (i.e. pressed -> released).

Type:

function

on_right_mouse_double_clicked#

Callback function for when right mouse button is double clicked (i.e pressed -> released -> pressed -> released).

Type:

function

on_right_mouse_button_dragged#

Callback function for when dragging using the right mouse button.

Type:

function

on_middle_mouse_button_pressed#

Callback function for when the middle mouse button is pressed.

Type:

function

on_middle_mouse_button_released#

Callback function for when the middle mouse button is released.

Type:

function

on_middle_mouse_button_clicked#

Callback function for when clicking using the middle mouse button (i.e. pressed -> released).

Type:

function

on_middle_mouse_double_clicked#

Callback function for when middle mouse button is double clicked (i.e pressed -> released -> pressed -> released).

Type:

function

on_middle_mouse_button_dragged#

Callback function for when dragging using the middle mouse button.

Type:

function

on_key_press#

Callback function for when a keyboard key is pressed.

Type:

function

__init__(*, position=(0, 0), x_anchor=Anchor.LEFT, y_anchor=Anchor.TOP, z_order=0)[source]#

Init scene.

property actors#

Get actors composing this UI component.

Returns:

List of actors composing this UI component.

Return type:

list

get_position(x_anchor=Anchor.LEFT, y_anchor=Anchor.TOP)[source]#

Get the position of this UI component according to the specified anchor.

Parameters:
  • x_anchor (str, optional) – Define the horizontal anchor point for the returned coordinates. Can be “LEFT”, “CENTER”, or “RIGHT”.

  • y_anchor (str, optional) – Define the vertical anchor point for the returned coordinates. Can be “BOTTOM”, “CENTER”, or “TOP”.

Returns:

The (x, y) pixel coordinates of the specified anchor point.

Return type:

(float, float)

handle_events(actor)[source]#

Attach event handlers to the UI object.

Parameters:

actor (Mesh) – The PyGfx mesh to which event handlers should be attached.

key_press_callback(event)[source]#

Handle key press event.

Parameters:

event (KeyboardEvent) – The PyGfx keyboard event object.

key_release_callback(event)[source]#

Handle key release event.

Parameters:

event (KeyboardEvent) – The PyGfx keyboard event object.

left_button_click_callback(event)[source]#

Handle left mouse button press event.

Parameters:

event (PointerEvent) – The PyGfx pointer event object.

left_button_release_callback(event)[source]#

Handle left mouse button release event.

Parameters:

event (PointerEvent) – The PyGfx pointer event object.

middle_button_click_callback(event)[source]#

Handle middle mouse button press event.

Parameters:

event (PointerEvent) – The PyGfx pointer event object.

middle_button_release_callback(event)[source]#

Handle middle mouse button release event.

Parameters:

event (PointerEvent) – The PyGfx pointer event object.

mouse_button_down_callback(event)[source]#

Handle mouse button press event.

Parameters:

event (PointerEvent) – The PyGfx pointer event object.

mouse_button_up_callback(event)[source]#

Handle mouse button release event.

Parameters:

event (PointerEvent) – The PyGfx pointer event object.

mouse_move_callback(event)[source]#

Handle mouse move event.

Parameters:

event (PointerEvent) – The PyGfx pointer event object.

perform_position_validation(x_anchor, y_anchor)[source]#

Perform validation checks for anchor string and the ‘size’ property.

Parameters:
  • x_anchor (str) – Horizontal anchor string to validate (e.g., “LEFT”, “CENTER”, “RIGHT”).

  • y_anchor (str) – Vertical anchor string to validate (e.g., “TOP”, “CENTER”, “BOTTOM”).

pointer_enter_callback(event)[source]#

Handle pointer enter event.

Parameters:

event (PointerEvent) – The PyGfx pointer event object.

pointer_leave_callback(event)[source]#

Handle pointer leave event.

Parameters:

event (PointerEvent) – The PyGfx pointer event object.

right_button_click_callback(event)[source]#

Handle right mouse button press event.

Parameters:

event (PointerEvent) – The PyGfx pointer event object.

right_button_release_callback(event)[source]#

Handle right mouse button release event.

Parameters:

event (PointerEvent) – The PyGfx pointer event object.

set_actor_position(actor, center_position, z_order)[source]#

Set the position of the PyGfx actor.

Parameters:
  • actor (Mesh) – The PyGfx mesh actor whose position needs to be set.

  • center_position (tuple or ndarray) – A 2-element array (x, y) representing the desired center position of the actor.

  • z_order (int) – The Z-order of the UI component.

set_position(coords, x_anchor=Anchor.LEFT, y_anchor=Anchor.TOP)[source]#

Position this UI component according to the specified anchor.

Parameters:
  • coords ((float, float)) – Absolute pixel coordinates (x, y). These coordinates are interpreted based on x_anchor and y_anchor.

  • x_anchor (str, optional) – Define the horizontal anchor point for coords. Can be “LEFT”, “CENTER”, or “RIGHT”.

  • y_anchor (str, optional) – Define the vertical anchor point for coords. Can be “TOP”, “CENTER”, or “BOTTOM”.

set_visibility(visibility)[source]#

Set visibility of this UI component.

Parameters:

visibility (bool) – If True, the UI component will be visible. If False, it will be hidden.

property size#

Get width and height of this UI component.

Returns:

Width and Height of UI component in pixels.

Return type:

(int, int)

wheel_callback(event)[source]#

Handle wheel event.

Parameters:

event (WheelEvent) – The PyGfx wheel event object.

property z_order#

Get the Z-order of this UI element.

Returns:

Z-order of the UI.

Return type:

int