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

Rework AdaptiveLayoutView #148

Merged
merged 18 commits into from
Sep 21, 2024
Merged

Conversation

joulei
Copy link
Contributor

@joulei joulei commented Sep 16, 2024

This PR introduces significant changes to our adaptive layout system, moving away from the previous DSL-heavy approach to a more flexible solution. It also introduces a new CachedWidget to optimize widget reuse across UI updates.

Key Changes

  1. Reworked AdaptiveViewLayout into AdaptiveView:

    • Simplified DSL usage
    • Introduced a variant selector mechanism for dynamic layout selection
    • Instead of having a single widget instance (of the widget to be adapted), we use separate DSL groups for each variant. This allows for a lot more flexibility when it comes to UI tree manipulation. However this implies having different widget instances by default for the different variants. This is important when considering live-resizing the application, where widgets will be reinitialized and their state management must be prepared for it. We plan on supporting state serialization which will take care of porting state between the widget instances without much manual intervention. For now, we're using CachedWidget to avoid re-initializing and porting state between instances.
    • Updated all existing usages of AdaptiveViewLayout to use the new AdaptiveView
  2. Introduced CachedWidget:

    • Allows reuse of complex widget instances across UI updates (wraps a widget in a singleton)
    • Particularly useful for maintaining state during live resizing
    • Implemented for RoomScreen and RoomsList to preserve their state
  3. Improved flexibility

    • AdaptiveView now uses a closure-based selector for determining layouts. This allows to define AdaptiveViews that for example adapt to their parent size instead of just the screen size.
    • Direct access to Cx provided in variant selectors for more control

Limitations and Future Work

  • Some limitations exist in the current implementation, particularly around widget finding and caching
  • Both AdaptiveView and CachedWidget will be ported to Makepad core soon, addressing current limitations
  • Detailed documentation and known limitations are provided in the code comments

Please refer to the inline documentation in adaptive_view.rs and cached_widget.rs for usage instructions and current limitations.

@joulei joulei marked this pull request as ready for review September 20, 2024 13:07
kevinaboos
kevinaboos previously approved these changes Sep 20, 2024
Copy link
Member

@kevinaboos kevinaboos left a comment

Choose a reason for hiding this comment

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

Phenomenal work, thanks! All looks good.

@kevinaboos kevinaboos self-requested a review September 21, 2024 20:15
@kevinaboos kevinaboos merged commit cd2f707 into project-robius:main Sep 21, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants