ui#

Fury UI module.

Module: ui.containers#

UI container module.

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

A 2D UI Panel.

Module: ui.context#

UI context module.

UIContextClass()

Manage global UI context.

UIContext

Manage global UI context.

Module: ui.core#

UI core module that describe UI abstract class.

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

An umbrella class for all UI elements.

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

A 2D rectangle sub-classed from UI.

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

A 2D disk UI component.

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

A 2D text component with optional background.

Button2D([position, size, is_toggle])

Base class for interactive 2D Buttons.

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

Base class for interactive 2D Sliders.

Module: ui.elements#

UI components module.

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

A button component that swaps textures based on interaction state.

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

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

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

A 2D Line Slider component.

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

A playback controller designed for FURY v2.

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

A disk slider.

Module: ui.helpers#

Helper variable or function for UI Elements.

Anchor(*values)

Enum for Position Anchor Points.

UI_Z_RANGE

ndarray(shape, dtype=None, buffer=None, offset=0, strides=None, order=None)

clip_overflow(textblock, width, *[, side])

Clip overflowing text of TextBlock2D with respect to width.

wrap_overflow(textblock, wrap_width, *[, side])

Wrap overflowing text of TextBlock2D with respect to width.

check_overflow(textblock, width, *[, ...])

Check if the text is overflowing.

cal_bounding_box_2d(vertices)

Calculate the min, max position and the size of the bounding box.

rotate_2d(vertices, angle)

Rotate the given vertices by an angle.

get_anchor_to_multiplier()

Return a dictionary of anchor multipliers for the UI.

Panel2D#

class fury.ui.containers.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.

alignment#

Alignment of the panel with respect to the overall screen.

Type:

[left, right]

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.

__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.

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

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

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

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

  • align ([left, right], optional) – 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.

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.

UIContextClass#

class fury.ui.context.UIContextClass[source]#

Bases: object

Manage global UI context.

__init__()[source]#

Initialize the UIContext singleton.

property active_ui#

Get the currently active UI element.

Returns:

UI element that is currently active, or None if no element is active.

Return type:

UI or None

property canvas_size#

Get the current size of the rendering canvas in pixels.

Returns:

Canvas (width, height) dimensions.

Return type:

numpy.ndarray

property hot_ui#

Get the currently hot UI element.

Returns:

UI element that is currently hot, or None if no element is hot.

Return type:

UI or None

property z_order_bounds#

Get the minimum and maximum Z-order values in the UI.

Returns:

Z-order bounds [z_min, z_max].

Return type:

numpy.ndarray

UIContext#

fury.ui.context.UIContext()#

Manage global UI context.

UI#

class fury.ui.core.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.

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)

size#

Width and height in pixels of this UI component.

Type:

(int, int)

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

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.

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

Init scene.

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.

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.

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)

property z_order#

Get the Z-order of this UI element.

Returns:

Z-order of the UI.

Return type:

int

Rectangle2D#

class fury.ui.core.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), optional) – Initial (width, height) of the rectangle in pixels.

  • position ((float, float), optional) – Coordinates (x, y) of the rectangle. The interpretation of (x,y) (e.g., top-left, bottom-left) depends on the current UI version.

  • color ((float, float, float), optional) – RGB color tuple, with values in the range [0, 1].

  • opacity (float, optional) – Degree of transparency, with values in the range [0, 1]. 0 is fully transparent, 1 is fully opaque.

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

Initialize a rectangle.

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].

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

Disk2D#

class fury.ui.core.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) – 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.

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].

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

TextBlock2D#

class fury.ui.core.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.

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.

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.

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

Button2D#

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

Bases: UI

Base class for interactive 2D Buttons.

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

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

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

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

Initialize the button instance.

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

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

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

do_click()[source]#

Trigger the assigned click callback and handle toggle state.

property enabled#

Check if the button is enabled.

Returns:

True if interactive, False otherwise.

Return type:

bool

resize(size)[source]#

Resize the button and its child components.

Parameters:

size ((float, float)) – New width and height in pixels.

resolve_state_key(available_keys)[source]#

Determine the current visual state key based on priority.

The priority order is: 1. ‘disabled’ (if not enabled) 2. ‘pressed’ (if is_pressed or toggled is True) 3. ‘hover’ (if is_hovered) 4. ‘default’

Parameters:

available_keys (list or set) – The keys available in the subclass (e.g., in a color map).

Returns:

The key representing the highest priority active state.

Return type:

str

property toggled#

Check if the button is toggled.

Returns:

True if toggled, False otherwise.

Return type:

bool

update_visual_state()[source]#

Update the visual appearance of the button.

Slider2D#

class fury.ui.core.Slider2D(*, position=(0, 0), initial_value=50, min_value=0, max_value=100, handle_inner_radius=0, handle_outer_radius=10, handle_side=20, font_size=16, text_template='{value:.1f} ({ratio:.0%})', shape='disk', z_order=0)[source]#

Bases: UI

Base class for interactive 2D Sliders.

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.

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

  • handle_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.

  • text_template (str or callable, optional) – A formatting string or callable for the label.

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

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

__init__(*, position=(0, 0), initial_value=50, min_value=0, max_value=100, handle_inner_radius=0, handle_outer_radius=10, handle_side=20, font_size=16, text_template='{value:.1f} ({ratio:.0%})', shape='disk', z_order=0)[source]#

Initialize the 2D slider.

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.

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

  • handle_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.

  • text_template (str or callable, optional) – A formatting string or callable for the label.

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

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

format_text()[source]#

Return formatted text to display along the slider.

Returns:

The formatted text.

Return type:

str

abstractmethod handle_move_callback(event)[source]#

Handle mouse drag events to update the slider state.

Parameters:

event (PointerEvent) – The PyGfx pointer event.

handle_release_callback(event)[source]#

Handle the release of the mouse button.

Parameters:

event (PointerEvent) – The PyGfx pointer event.

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 ratio#

Get the current normalized ratio (0 to 1).

Returns:

The slider ratio.

Return type:

float

track_click_callback(event)[source]#

Handle mouse click events on the slider track.

Parameters:

event (PointerEvent) – The PyGfx pointer event.

property value#

Get the current numeric value of the slider.

Returns:

The slider value.

Return type:

float

TexturedButton2D#

class fury.ui.elements.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.

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.

update_visual_state()[source]#

Update the mesh texture based on the current button state.

TextButton2D#

class fury.ui.elements.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.

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.

update_visual_state()[source]#

Update the text message and background color based on state.

LineSlider2D#

class fury.ui.elements.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.

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.

handle_move_callback(event)[source]#

Handle mouse drag events to update the slider state.

Parameters:

event (PointerEvent) – The PyGfx pointer event.

PlaybackPanel#

class fury.ui.elements.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

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.

RingSlider2D#

class fury.ui.elements.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

Anchor#

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

Bases: str, Enum

Enum for Position Anchor Points.

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

UI_Z_RANGE#

fury.ui.helpers.UI_Z_RANGE()#

ndarray(shape, dtype=None, buffer=None, offset=0, strides=None, order=None) –

ndarray(shape, dtype=float, buffer=None, offset=0, strides=None, order=None)

An array object represents a multidimensional, homogeneous array of fixed-size items. An associated data-type object describes the format of each element in the array (its byte-order, how many bytes it occupies in memory, whether it is an integer, a floating point number, or something else, etc.)

Arrays should be constructed using array, zeros or empty (refer to the See Also section below). The parameters given here refer to a low-level method (ndarray(…)) for instantiating an array.

For more information, refer to the numpy module and examine the methods and attributes of an array.

Parameters:
  • below) ((for the __new__ method; see Notes)

  • shape (tuple of ints) – Shape of created array.

  • dtype (data-type, optional) – Any object that can be interpreted as a numpy data type. Default is numpy.float64.

  • buffer (object exposing buffer interface, optional) – Used to fill the array with data.

  • offset (int, optional) – Offset of array data in buffer.

  • strides (tuple of ints, optional) – Strides of data in memory.

  • order ({'C', 'F'}, optional) – Row-major (C-style) or column-major (Fortran-style) order.

fury.ui.helpers.T#

Transpose of the array.

Type:

ndarray

fury.ui.helpers.data#

The array’s elements, in memory.

Type:

buffer

fury.ui.helpers.dtype#

Describes the format of the elements in the array.

Type:

dtype object

fury.ui.helpers.flags#

Dictionary containing information related to memory use, e.g., ‘C_CONTIGUOUS’, ‘OWNDATA’, ‘WRITEABLE’, etc.

Type:

dict

fury.ui.helpers.flat#

Flattened version of the array as an iterator. The iterator allows assignments, e.g., x.flat = 3 (See ndarray.flat for assignment examples; TODO).

Type:

numpy.flatiter object

fury.ui.helpers.imag#

Imaginary part of the array.

Type:

ndarray

fury.ui.helpers.real#

Real part of the array.

Type:

ndarray

fury.ui.helpers.size#

Number of elements in the array.

Type:

int

fury.ui.helpers.itemsize#

The memory use of each array element in bytes.

Type:

int

fury.ui.helpers.nbytes#

The total number of bytes required to store the array data, i.e., itemsize * size.

Type:

int

fury.ui.helpers.ndim#

The array’s number of dimensions.

Type:

int

fury.ui.helpers.shape#

Shape of the array.

Type:

tuple of ints

fury.ui.helpers.strides#

The step-size required to move from one element to the next in memory. For example, a contiguous (3, 4) array of type int16 in C-order has strides (8, 2). This implies that to move from element to element in memory requires jumps of 2 bytes. To move from row-to-row, one needs to jump 8 bytes at a time (2 * 4).

Type:

tuple of ints

fury.ui.helpers.ctypes#

Class containing properties of the array needed for interaction with ctypes.

Type:

ctypes object

fury.ui.helpers.base#

If the array is a view into another array, that array is its base (unless that array is also a view). The base array is where the array data is actually stored.

Type:

ndarray

See also

array

Construct an array.

zeros

Create an array, each element of which is zero.

empty

Create an array, but leave its allocated memory unchanged (i.e., it contains “garbage”).

dtype

Create a data-type.

numpy.typing.NDArray

An ndarray alias generic w.r.t. its dtype.type <numpy.dtype.type>.

Notes

There are two modes of creating an array using __new__:

  1. If buffer is None, then only shape, dtype, and order are used.

  2. If buffer is an object exposing the buffer interface, then all keywords are interpreted.

No __init__ method is needed because the array is fully initialized after the __new__ method.

Examples

These examples illustrate the low-level ndarray constructor. Refer to the See Also section above for easier ways of constructing an ndarray.

First mode, buffer is None:

>>> import numpy as np
>>> np.ndarray(shape=(2,2), dtype=float, order='F')
array([[0.0e+000, 0.0e+000], # random
       [     nan, 2.5e-323]])

Second mode:

>>> np.ndarray((2,), buffer=np.array([1,2,3]),
...            offset=np.int_().itemsize,
...            dtype=int) # offset = 1*itemsize, i.e. skip first element
array([2, 3])

clip_overflow#

fury.ui.helpers.clip_overflow(textblock, width, *, side='right')[source]#

Clip overflowing text of TextBlock2D with respect to width.

Parameters:
  • textblock (TextBlock2D) – The textblock object whose text needs to be clipped.

  • width (int) – Required width of the clipped text.

  • side (str, optional) – Clips the overflowing text according to side. It takes values “left” or “right”. Default is “right”.

Returns:

Clipped version of the text.

Return type:

str

wrap_overflow#

fury.ui.helpers.wrap_overflow(textblock, wrap_width, *, side='right')[source]#

Wrap overflowing text of TextBlock2D with respect to width.

Parameters:
  • textblock (TextBlock2D) – The textblock object whose text needs to be wrapped.

  • wrap_width (int) – Required width of the wrapped text.

  • side (str, optional) – Clips the overflowing text according to side. It takes values “left” or “right”. Default is “right”.

Returns:

Wrapped version of the text.

Return type:

str

check_overflow#

fury.ui.helpers.check_overflow(textblock, width, *, overflow_postfix='', side='right')[source]#

Check if the text is overflowing.

Parameters:
  • textblock (TextBlock2D) – The textblock object whose text is to be checked.

  • width (int) – Required width of the text.

  • overflow_postfix (str, optional) – Postfix to be added to the text if it is overflowing. Default is “”.

  • side (str, optional) – Side from which to check overflow. It takes values “left” or “right”. Default is “right”.

Returns:

Overflow index of the text. Returns 0 if text is not overflowing.

Return type:

int

cal_bounding_box_2d#

fury.ui.helpers.cal_bounding_box_2d(vertices)[source]#

Calculate the min, max position and the size of the bounding box.

Parameters:

vertices (ndarray) – Vertices of the actors with shape (n,2) or (n,3).

Returns:

A tuple containing three arrays: - bounding_box_min : ndarray

Minimum coordinates of the bounding box [min_x, min_y].

  • bounding_box_maxndarray

    Maximum coordinates of the bounding box [max_x, max_y].

  • bounding_box_sizendarray

    Size of the bounding box [width, height].

Return type:

tuple

Raises:

OSError – If vertices is not a 2D array with shape (n,2) or (n,3).

rotate_2d#

fury.ui.helpers.rotate_2d(vertices, angle)[source]#

Rotate the given vertices by an angle.

Parameters:
  • vertices (ndarray) – Vertices of the actors with shape (n,3).

  • angle (float) – Value by which the vertices are rotated in radians.

Returns:

Rotated vertices.

Return type:

ndarray

Raises:

OSError – If vertices is not a 2D array with shape (n,3).

get_anchor_to_multiplier#

fury.ui.helpers.get_anchor_to_multiplier()[source]#

Return a dictionary of anchor multipliers for the UI.

Returns:

A dictionary mapping Anchor string values to float multipliers.

Return type:

dict