Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UI: Adding TreeUI #821

Open
wants to merge 51 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
bb45d1c
feat: added TreeNode2D to UI
antrikshmisri Jun 28, 2021
070b3b1
feat: added TreeNode2D, Tree2D to UI
antrikshmisri Jun 30, 2021
71528fc
feat: example for Tree2D
antrikshmisri Jun 30, 2021
533b0b3
fix: code cleanup
antrikshmisri Jun 30, 2021
76ad554
removed redundant files
antrikshmisri Jun 30, 2021
abc0afa
fix: code cleanup, reduced duplication, methods
antrikshmisri Jul 5, 2021
86b16ba
fix: rebased w.r.t UI restructuring
antrikshmisri Jul 5, 2021
62fbc47
fix: code clean-up
antrikshmisri Jul 7, 2021
4984f99
test files
antrikshmisri Jul 7, 2021
5e7fdac
feat: icon for TreeNode2D
antrikshmisri Jul 8, 2021
ec1844b
test files
antrikshmisri Jul 8, 2021
35ad93b
minor fixes
antrikshmisri Jul 8, 2021
0578e3a
feat: TreeNode2D parent auto resizing
antrikshmisri Jul 13, 2021
69b5c56
fix: fixed logic for auto resizing
antrikshmisri Jul 14, 2021
1492254
fix: increased indentation for better visuals
antrikshmisri Jul 14, 2021
07cdf1c
feat: tutorial for Tree2D
antrikshmisri Jul 14, 2021
b6dcf60
removed redundant files
antrikshmisri Jul 14, 2021
ad21080
fix: pep8 issues
antrikshmisri Jul 15, 2021
4340135
feat: selected nodes attribute
antrikshmisri Jul 19, 2021
86654eb
tests: added tests for Tree2D UI
antrikshmisri Jul 19, 2021
84ca86a
events recording
antrikshmisri Jul 19, 2021
101d04c
fix: pep8 issues
antrikshmisri Jul 19, 2021
e3d445a
feat: added a select child method
antrikshmisri Jul 20, 2021
82d4703
tests: added tests for TreeNode2D
antrikshmisri Jul 20, 2021
69f1bd2
fix: pep8 issues
antrikshmisri Jul 20, 2021
4a2eccb
fix: removed unused imports
antrikshmisri Jul 20, 2021
c12a96a
test example
antrikshmisri Jul 21, 2021
dcd2ed9
UI fixes, addressed reviews
antrikshmisri Jul 21, 2021
6f32fea
fix: updated the Tree2D Ui widgety
antrikshmisri Jul 21, 2021
6cc23c1
feat: resize w.r.t largest child
antrikshmisri Jul 25, 2021
60aa08e
fix: fixed title panel resizing
antrikshmisri Jul 26, 2021
d6f9b0a
docs: added actor modifier using tree in tutorials
antrikshmisri Jul 26, 2021
ce4d8f9
fix: addressed comments
antrikshmisri Jul 26, 2021
ef7bab6
fix: fixed the tree2d tutorial
antrikshmisri Jul 27, 2021
e1ce8a5
feat: added multiselct feature
antrikshmisri Jul 27, 2021
5e6c66c
test: updated tests for TreeNode2D
antrikshmisri Jul 27, 2021
3a2d8a0
Merge branch 'master' into tree-ui
antrikshmisri Jul 28, 2021
f83e1c4
Merge branch 'master' into tree-ui
antrikshmisri Aug 1, 2021
ee49b34
feat: allow UI to be dragged by text/icon
antrikshmisri Aug 2, 2021
8f9fd88
feat: icon setter/getter, click callback on text
antrikshmisri Aug 7, 2021
201d774
fix: pep8
antrikshmisri Aug 7, 2021
62e47fa
fix: pep8 fixes in example
antrikshmisri Aug 7, 2021
aa316e8
fix: auto-resizing, label_text coords
antrikshmisri Aug 24, 2021
d568836
fix: removed redundant files
antrikshmisri Aug 24, 2021
a1b0e95
Merge branch 'master' into pr/antrikshmisri/460
ganimtron-10 Jul 14, 2023
5832963
Merge branch 'master' into treeui
ganimtron-10 Aug 16, 2023
b96a4b2
updating the return actors from the TextBlock2D
ganimtron-10 Sep 14, 2023
a1895a2
updating set_visibility to set_content_visibility
ganimtron-10 Sep 14, 2023
fc44468
updating title label text position
ganimtron-10 Sep 14, 2023
07a3f5c
Merge branch 'master' into treeui
ganimtron-10 Sep 14, 2023
0e2bd11
updating tests
ganimtron-10 Sep 14, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
172 changes: 172 additions & 0 deletions docs/examples/viz_tree_actor_modifier.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
# -*- coding: utf-8 -*-
"""
==============================
Actor Modifier using a Tree UI
==============================

This example shows how to create an actor moidifier using a Tree UI.
The parameters that will be modified are the colors, position,
rotation of the cube.

First, some imports.
"""
import numpy as np
from fury import ui, window, actor, utils

structure = [{'Cube': ['Translate', 'Color']},
{'Cylinder': []},
{'Cone': []}]

tree = ui.elements.Tree2D(structure=structure, tree_name="Actor Modifier",
size=(400, 400), position=(0, 400),
color=(0.8, 0.4, 0.2), opacity=1)

###############################################################################
# Slider Controls for the node Cube
# ==========================================
#
# Now we prepare content for the Cube node.

ring_slider = ui.RingSlider2D(initial_value=0,
text_template="{angle:5.1f}°")

line_slider_x = ui.LineSlider2D(initial_value=0,
min_value=-10, max_value=10,
orientation="horizontal",
text_alignment="Top")

line_slider_y = ui.LineSlider2D(initial_value=0,
min_value=-10, max_value=10,
orientation="vertical",
text_alignment="Right")

line_slider_r = ui.LineSlider2D(initial_value=0,
min_value=0, max_value=1,
orientation="vertical",
text_alignment="Left")

line_slider_g = ui.LineSlider2D(initial_value=0,
min_value=0, max_value=1,
orientation="vertical",
text_alignment="Left")

line_slider_b = ui.LineSlider2D(initial_value=0,
min_value=0, max_value=1,
orientation="vertical",
text_alignment="Left")

cube = actor.box(centers=np.array([[10, 0, 0]]),
directions=np.array([[0, 1, 0]]),
colors=np.array([[0, 0, 1]]),
scales=np.array([[0.3, 0.3, 0.3]]))

cube_x = 0
cube_y = 0
cube_r = 0
cube_g = 0
cube_b = 0


def rotate_cube(slider):
angle = slider.value
previous_angle = slider.previous_value
rotation_angle = angle - previous_angle
cube.RotateX(rotation_angle)


def translate_cube_x(slider):
global cube_x, cube_y
cube_x = slider.value
cube.SetPosition(cube_x, cube_y, 0)


def translate_cube_y(slider):
global cube_x, cube_y
cube_y = slider.value
cube.SetPosition(cube_x, cube_y, 0)


def update_colors():
global cube
vcolors = utils.colors_from_actor(cube)
colarr = np.array([cube_r, cube_g, cube_b])*255
vcolors[:] = colarr
utils.update_actor(cube)


def change_r(slider):
global cube_r, cube_g, cube_b
cube_r = slider.value
update_colors()


def change_g(slider):
global cube_r, cube_g, cube_b
cube_g = slider.value
update_colors()


def change_b(slider):
global cube_r, cube_g, cube_b
cube_b = slider.value
update_colors()


ring_slider.on_change = rotate_cube
line_slider_x.on_change = translate_cube_x
line_slider_y.on_change = translate_cube_y


# Callbacks for color sliders
line_slider_r.on_change = change_r
line_slider_g.on_change = change_g
line_slider_b.on_change = change_b

###############################################################################
# Adding sliders to their respective nodes

tree.add_content('Translate', ring_slider, (0.5, 0.5))
tree.add_content('Translate', line_slider_x, (0, 0.))
tree.add_content('Translate', line_slider_y, (0., 0.))

tree.add_content('Color', line_slider_r, (0., 0.))
tree.add_content('Color', line_slider_g, (0.25, 0.))
tree.add_content('Color', line_slider_b, (0.5, 0.))

###############################################################################
# Defining hook to toggle the visibility of the cube


def visibility_on(tree_ui):
global cube
cube.SetVisibility(1)


def visibility_off(tree_ui):
global cube
cube.SetVisibility(0)

###############################################################################
# Adding hooks to relevant nodes


cube_node = tree.select_node('Cube')
color_node = tree.select_node('Color')

cube_node.on_node_select = visibility_on
cube_node.on_node_deselect = visibility_off

current_size = (1000, 1000)
show_manager = window.ShowManager(size=current_size,
title="FURY Tree2D Example")

show_manager.scene.add(tree, cube)

# To interact with the UI, set interactive = True
interactive = False

if interactive:
show_manager.start()

window.record(show_manager.scene, size=current_size,
out_path="viz_tree_actor_modifier.png")
88 changes: 88 additions & 0 deletions docs/examples/viz_tree_ui.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
# -*- coding: utf-8 -*-
"""
=============================
FURY UI Breakdown with Tree2D
=============================

This example vizualizes different types of UI elements that are available,
in FURY's UI sub-module with the help of a Tree2D UI element.

First, some imports.
"""
from fury import ui, window
from fury.ui.core import Disk2D, Rectangle2D
from fury.ui.elements import LineSlider2D, ListBox2D
from fury.ui.containers import ImageContainer2D

structure = [{'Containers': ['Panels', 'ImageContainers']},
{'Elements': ['ListBox', 'LineSlider']},
{'Core': ['Rectangle', 'Disk']}]

tree = ui.elements.Tree2D(structure=structure, tree_name="FURY UI Breakdown",
size=(500, 500), position=(0, 500),
color=(0.8, 0.4, 0.2))

###############################################################################
# Now, we create UI elements for the Containers node
# First, we create panles for the Panels node
panel_first = ui.Panel2D(size=(100, 100), color=(0.5, 0.7, 0.3))
panel_second = ui.Panel2D(size=(100, 100), color=(0.3, 0.8, 0.5))

###############################################################################
# Now, we create an ImageContainer2D for the ImageContainers node
path = "https://raw.githubusercontent.com/fury-gl/"\
"fury-communication-assets/main/fury-logo.png"

img = ImageContainer2D(img_path=path, size=(100, 100))

###############################################################################
# Now, we add the UI elements to their respective nodes.

tree.add_content('Panels', panel_first)
tree.add_content('Panels', panel_second, (0.5, 0.5))
tree.add_content('ImageContainers', img, (0.5, 0.5))

###############################################################################
# Now, lets create UI elements for the Elements node
# First we create Listbox for the ListBox node
listbox = ListBox2D(values=['First', 'Second', 'Third', 'Fourth'])

###############################################################################
# Now, lets create a LineSlider for the LineSlider node
lineslider = LineSlider2D(length=200, orientation="vertical")

###############################################################################
# Now, we add the UI elements to their respective nodes.

tree.add_content('ListBox', listbox)
tree.add_content('LineSlider', lineslider, (0.5, 0.5))

###############################################################################
# Now, lets create UI elements for the Core node
# First we create Rectangle2D for teh Rectangle node

Check failure on line 62 in docs/examples/viz_tree_ui.py

View workflow job for this annotation

GitHub Actions / Check for spelling errors

teh ==> the
rect = Rectangle2D(size=(100, 100), color=(0.8, 0.4, 0.7))

###############################################################################
# Now, let's create Disk2D for the Disk node
disk = Disk2D(outer_radius=50, color=(0.6, 0.2, 0.8))

###############################################################################
# Now, we add the UI elements to their respective nodes.

tree.add_content('Rectangle', rect)
tree.add_content('Disk', disk, (0.5, 0.5))

current_size = (1000, 1000)
show_manager = window.ShowManager(size=current_size,
title="FURY Tree2D Example")

show_manager.scene.add(tree)

# To interact with the UI, set interactive = True
interactive = False

if interactive:
show_manager.start()

window.record(show_manager.scene, size=current_size,
out_path="viz_tree2d.png")
1 change: 1 addition & 0 deletions fury/data/files/test_ui_tree_ed.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"CharEvent": 0, "MouseMoveEvent": 843, "KeyPressEvent": 0, "KeyReleaseEvent": 0, "LeftButtonPressEvent": 18, "LeftButtonReleaseEvent": 18, "RightButtonPressEvent": 0, "RightButtonReleaseEvent": 0, "MiddleButtonPressEvent": 0, "MiddleButtonReleaseEvent": 0}
Binary file added fury/data/files/test_ui_tree_ed.log.gz
Binary file not shown.
1 change: 1 addition & 0 deletions fury/data/files/test_ui_treenode_2d.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"CharEvent": 0, "MouseMoveEvent": 478, "KeyPressEvent": 0, "KeyReleaseEvent": 0, "LeftButtonPressEvent": 26, "LeftButtonReleaseEvent": 26, "RightButtonPressEvent": 0, "RightButtonReleaseEvent": 0, "MiddleButtonPressEvent": 0, "MiddleButtonReleaseEvent": 0}
Binary file added fury/data/files/test_ui_treenode_2d.log.gz
Binary file not shown.
4 changes: 3 additions & 1 deletion fury/ui/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -781,7 +781,9 @@ def resize(self, size):

def _get_actors(self):
"""Get the actors composing this UI component."""
return [self.actor] + self.background.actors
if self.have_bg:
return [self.actor] + self.background.actors
return [self.actor]

def _add_to_scene(self, scene):
"""Add all subcomponents or VTK props that compose this UI component.
Expand Down
Loading
Loading