Skip to content

raylib: simpler callbacks #35488

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 8 commits into from
Jun 7, 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
16 changes: 3 additions & 13 deletions selfdrive/ui/layouts/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ def __init__(self):
self._current_mode = MainState.HOME
self._prev_onroad = False
self._window_rect = None
self._current_callback: callable | None = None

# Initialize layouts
self._layouts = {MainState.HOME: HomeLayout(), MainState.SETTINGS: SettingsLayout(), MainState.ONROAD: AugmentedRoadView()}
Expand All @@ -34,23 +33,14 @@ def __init__(self):
self._setup_callbacks()

def _render(self, rect):
self._current_callback = None

self._update_layout_rects(rect)
self._handle_onroad_transition()
self._render_main_content()

if self._current_callback:
self._current_callback()

def _setup_callbacks(self):
self._sidebar.set_callbacks(
on_settings=lambda: setattr(self, '_current_callback', self._on_settings_clicked),
on_flag=lambda: setattr(self, '_current_callback', self._on_flag_clicked),
)
self._layouts[MainState.SETTINGS].set_callbacks(
on_close=lambda: setattr(self, '_current_callback', self._set_mode_for_state)
)
self._sidebar.set_callbacks(on_settings=self._on_settings_clicked,
on_flag=self._on_flag_clicked)
self._layouts[MainState.SETTINGS].set_callbacks(on_close=self._set_mode_for_state)
self._layouts[MainState.ONROAD].on_click = self._on_onrad_clicked
Comment on lines +41 to 44
Copy link
Contributor Author

@sshane sshane Jun 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@deanlee let's decide on if we should use set functions or not soon, this is two different patterns for no reason

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

think using a set method for is clearer than direct assignment

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some modules, like ui_state with offroad transition, may need multiple callbacks. Using a consistent set_ / add_ pattern makes it easier to manage them than assigning callbacks directly.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What are your thoughts?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


def _update_layout_rects(self, rect):
Expand Down
Loading