Skip to content

Improve hover color behavior for selectors #799

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

Merged
merged 2 commits into from
Apr 15, 2025
Merged
Changes from all commits
Commits
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
27 changes: 22 additions & 5 deletions fastplotlib/graphics/selectors/_base_selector.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,13 @@ def __init__(

self._hover_responsive: Tuple[WorldObject, ...] = hover_responsive

# Original color of object that we change the colors of
self._original_colors = {}

# Colors as they are changed by the hover events, so they can be restored after a move action
self._hover_colors = {}

if hover_responsive is not None:
self._original_colors = dict()
for wo in self._hover_responsive:
self._original_colors[wo] = wo.material.color

Expand Down Expand Up @@ -325,6 +330,11 @@ def _move_end(self, ev):
self._move_info = None
self._moving = False

# Reset hover state
for wo, color in self._hover_colors.items():
wo.material.color = color
self._hover_colors.clear()

# restore the initial controller state
# if it was disabled, keep it disabled
if self._initial_controller_state is not None:
Expand Down Expand Up @@ -378,6 +388,7 @@ def _move_to_pointer(self, ev):
self._move_info = None

def _pointer_enter(self, ev):

if self._hover_responsive is None:
return

Expand All @@ -388,17 +399,23 @@ def _pointer_enter(self, ev):
if wo in self._edges:
self._edge_hovered = True

wo.material.color = "magenta"
if self._moving:
self._hover_colors[wo] = "magenta"
else:
wo.material.color = "magenta"

def _pointer_leave(self, ev):
if self._hover_responsive is None:
return

self._edge_hovered = False

# reset colors
for wo in self._hover_responsive:
wo.material.color = self._original_colors[wo]

self._edge_hovered = False
if self._moving:
self._hover_colors[wo] = self._original_colors[wo]
else:
wo.material.color = self._original_colors[wo]

def _toggle_arrow_key_moveable(self, ev):
self.arrow_key_events_enabled = not self.arrow_key_events_enabled
Expand Down