Skip to content

Commit

Permalink
Merge pull request #863 from maharshi-gor/bugfix/ui-issues
Browse files Browse the repository at this point in the history
UI Bug fixes for Horizon
  • Loading branch information
Garyfallidis committed Feb 26, 2024
2 parents a6e6fe7 + 1357fc8 commit 6f7f3b0
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 17 deletions.
2 changes: 1 addition & 1 deletion fury/data/files/test_ui_combobox_2d.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"CharEvent": 0, "MouseMoveEvent": 695, "KeyPressEvent": 0, "KeyReleaseEvent": 0, "LeftButtonPressEvent": 13, "LeftButtonReleaseEvent": 13, "RightButtonPressEvent": 0, "RightButtonReleaseEvent": 0, "MiddleButtonPressEvent": 0, "MiddleButtonReleaseEvent": 0}
{"CharEvent": 0, "MouseMoveEvent": 296, "KeyPressEvent": 0, "KeyReleaseEvent": 0, "LeftButtonPressEvent": 16, "LeftButtonReleaseEvent": 16, "RightButtonPressEvent": 0, "RightButtonReleaseEvent": 0, "MiddleButtonPressEvent": 0, "MiddleButtonReleaseEvent": 0}
Binary file modified fury/data/files/test_ui_combobox_2d.log.gz
Binary file not shown.
25 changes: 14 additions & 11 deletions fury/ui/elements.py
Original file line number Diff line number Diff line change
Expand Up @@ -948,11 +948,11 @@ def _get_size(self):
width = None
height = None
if self.orientation == 'horizontal':
width = self.track.width + 2 * self.handles[0].size[0]
width = self.track.width + self.handles[0].size[0]
height = max(self.track.height, self.handles[0].size[1])
else:
width = max(self.track.width, self.handles[0].size[0])
height = self.track.height + 2 * self.handles[0].size[1]
height = self.track.height + self.handles[0].size[1]

return np.array([width, height])

Expand All @@ -966,13 +966,14 @@ def _set_position(self, coords):
"""
# Offset the slider line by the handle's radius.
track_position = coords + self.handles[0].size / 2.0
track_position = coords
if self.orientation == 'horizontal':
# Offset the slider line height by half the slider line width.
track_position[1] -= self.track.size[1] / 2.0
else:
# Offset the slider line width by half the slider line height.
track_position[0] -= self.track.size[0] / 2.0

self.track.position = track_position

self.handles[0].position = self.handles[0].position.astype(float)
Expand All @@ -985,11 +986,11 @@ def _set_position(self, coords):
# Position the text below the handles.
self.text[0].position = (
self.handles[0].center[0],
self.handles[0].position[1] - 20,
self.handles[0].position[1] - 10,
)
self.text[1].position = (
self.handles[1].center[0],
self.handles[1].position[1] - 20,
self.handles[1].position[1] - 10,
)
else:
# Position the text to the left of the handles.
Expand Down Expand Up @@ -2205,9 +2206,9 @@ def __init__(
self.menu_opacity = menu_opacity

# Define subcomponent sizes.
self.text_block_size = (int(0.8 * size[0]), int(0.3 * size[1]))
self.drop_menu_size = (size[0], int(0.7 * size[1]))
self.drop_button_size = (int(0.2 * size[0]), int(0.3 * size[1]))
self.text_block_size = (int(0.9 * size[0]), int(0.1 * size[1]))
self.drop_menu_size = (int(0.9 * size[0]), int(0.7 * size[1]))
self.drop_button_size = (int(0.1 * size[0]), int(0.1 * size[1]))

self._icon_files = [
('left', read_viz_icons(fname='circle-left.png')),
Expand Down Expand Up @@ -2322,9 +2323,9 @@ def resize(self, size):
"""
self.panel.resize(size)

self.text_block_size = (int(0.8 * size[0]), int(0.3 * size[1]))
self.drop_menu_size = (size[0], int(0.7 * size[1]))
self.drop_button_size = (int(0.2 * size[0]), int(0.3 * size[1]))
self.text_block_size = (int(0.9 * size[0]), int(0.1 * size[1]))
self.drop_menu_size = (int(0.9 * size[0]), int(0.7 * size[1]))
self.drop_button_size = (int(0.1 * size[0]), int(0.1 * size[1]))

self.panel.update_element(self.selection_box, (0.001, 0.7))
self.panel.update_element(self.drop_down_button, (0.8, 0.7))
Expand All @@ -2344,6 +2345,8 @@ def _set_position(self, coords):
"""
self.panel.position = coords
self.panel.position = (self.panel.position[0],
self.panel.position[1] - self.drop_menu_size[1])

def _add_to_scene(self, scene):
"""Add all subcomponents or VTK props that compose this UI component.
Expand Down
10 changes: 5 additions & 5 deletions fury/ui/tests/test_elements.py
Original file line number Diff line number Diff line change
Expand Up @@ -1074,8 +1074,8 @@ def test_ui_combobox_2d(interactive=False):
npt.assert_raises(TypeError, combobox.append_item, invalid_item)

npt.assert_equal(values, combobox.items)
npt.assert_equal((60, 60), combobox.drop_button_size)
npt.assert_equal([300, 140], combobox.drop_menu_size)
npt.assert_equal((30, 20), combobox.drop_button_size)
npt.assert_equal([270, 140], combobox.drop_menu_size)
npt.assert_equal([300, 200], combobox.size)

ui.ComboBox2D(items=values, draggable=False)
Expand All @@ -1094,9 +1094,9 @@ def test_ui_combobox_2d(interactive=False):
npt.assert_equal(1, combobox.selected_text_index)

combobox.resize((450, 300))
npt.assert_equal((360, 90), combobox.text_block_size)
npt.assert_equal((90, 90), combobox.drop_button_size)
npt.assert_equal((450, 210), combobox.drop_menu_size)
npt.assert_equal((405, 30), combobox.text_block_size)
npt.assert_equal((45, 30), combobox.drop_button_size)
npt.assert_equal((405, 210), combobox.drop_menu_size)


def test_ui_combobox_2d_dropdown_visibility(interactive=False):
Expand Down

0 comments on commit 6f7f3b0

Please sign in to comment.