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

Resolving icon flaw in comboBox2D #576

Closed
wants to merge 4 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
70 changes: 41 additions & 29 deletions fury/ui/elements.py
Expand Up @@ -2068,6 +2068,7 @@ def __init__(self, items=[], position=(0, 0), size=(300, 200),
self.scroll_active_color = scroll_bar_active_color
self.scroll_inactive_color = scroll_bar_inactive_color
self.menu_opacity = menu_opacity
self.callback_flag = False

# Define subcomponent sizes.
self.text_block_size = (int(0.8*size[0]), int(0.3*size[1]))
Expand Down Expand Up @@ -2246,20 +2247,26 @@ def select_option_callback(self, i_ren, _obj, listboxitem):
"""

# Set the Text of TextBlock2D to the text of listboxitem
self._selection = listboxitem.element
self._selection_ID = self.items.index(self._selection)
# The callback_flag prevents unnecessary loops
if not self.callback_flag:
self._selection = listboxitem.element
self._selection_ID = self.items.index(self._selection)

self.selection_box.message = self._selection
clip_overflow(self.selection_box,
self.selection_box.background.size[0])
self.drop_down_menu.set_visibility(False)
self._menu_visibility = False
self.selection_box.message = self._selection
clip_overflow(self.selection_box,
self.selection_box.background.size[0])

self.drop_down_button.next_icon()
self.drop_down_menu.set_visibility(False)
self._menu_visibility = False

self.on_change(self)
self.drop_down_button.next_icon()

self.on_change(self)

i_ren.force_render()
self.callback_flag = True
self.drop_down_menu.callback_flag = True

i_ren.force_render()
i_ren.event.abort()

def menu_toggle_callback(self, i_ren, _vtkactor, _combobox):
Expand All @@ -2273,6 +2280,9 @@ def menu_toggle_callback(self, i_ren, _vtkactor, _combobox):
combobox : :class:`ComboBox2D`

"""
self.callback_flag = False
self.drop_down_menu.callback_flag = False

self._menu_visibility = not self._menu_visibility
self.drop_down_menu.set_visibility(self._menu_visibility)

Expand Down Expand Up @@ -2373,6 +2383,7 @@ def __init__(self, values, position=(0, 0), size=(100, 300),

self.position = position
self.scroll_init_position = 0
self.callback_flag = False
self.update()

# Offer some standard hooks to the user.
Expand Down Expand Up @@ -2668,29 +2679,30 @@ def select(self, item, multiselect=False, range_select=False):
multi_select is True.

"""
selection_idx = self.values.index(item.element)
if self.multiselection and range_select:
self.clear_selection()
step = 1 if selection_idx >= self.last_selection_idx else -1
for i in range(self.last_selection_idx,
selection_idx + step,
step):
self.selected.append(self.values[i])
if not self.callback_flag:
selection_idx = self.values.index(item.element)
if self.multiselection and range_select:
self.clear_selection()
step = 1 if selection_idx >= self.last_selection_idx else -1
for i in range(self.last_selection_idx,
selection_idx + step,
step):
self.selected.append(self.values[i])

elif self.multiselection and multiselect:
if item.element in self.selected:
self.selected.remove(item.element)
else:
self.selected.append(item.element)
self.last_selection_idx = selection_idx

elif self.multiselection and multiselect:
if item.element in self.selected:
self.selected.remove(item.element)
else:
self.clear_selection()
self.selected.append(item.element)
self.last_selection_idx = selection_idx

else:
self.clear_selection()
self.selected.append(item.element)
self.last_selection_idx = selection_idx
self.last_selection_idx = selection_idx

self.on_change() # Call hook.
self.update()
self.on_change() # Call hook.
self.update()


class ListBoxItem2D(UI):
Expand Down