-
-
Notifications
You must be signed in to change notification settings - Fork 161
feat(ui): add a Solid universal renderer for native widgets #9825
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
Closed
proggeramlug
wants to merge
2
commits into
PerryTS:main
from
proggeramlug:feat/4644-solid-native-renderer
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| - Add `perry-solid`, a Solid universal-renderer bridge for native stacks, text, buttons, spacers, and dividers, with hyperscript authoring, reactive properties, keyed widget moves, and owner disposal. Add a counter/list example, a Node/native release fixture, and a macOS Geisterhand smoke test. Correct macOS indexed stack insertion and retained layout metadata, match the compiler's reorder arguments to the native floating-point ABI, and implement Windows child reordering. Solid JSX compilation remains a separate stage of #4644. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,89 @@ | ||
| #[cfg(target_os = "macos")] | ||
| fn main() { | ||
| use objc2::rc::Retained; | ||
| use objc2_app_kit::{NSApplication, NSStackView, NSView}; | ||
| use objc2_foundation::MainThreadMarker; | ||
| use perry_runtime as _; | ||
| use perry_ui_macos::widgets; | ||
|
|
||
| fn children(handle: i64) -> Vec<usize> { | ||
| let view = widgets::get_widget(handle).unwrap(); | ||
| let stack = unsafe { &*(Retained::as_ptr(&view) as *const NSStackView) }; | ||
| stack | ||
| .arrangedSubviews() | ||
| .iter() | ||
| .map(|v| Retained::as_ptr(&v) as usize) | ||
| .collect() | ||
| } | ||
| fn ptr(handle: i64) -> usize { | ||
| Retained::as_ptr(&widgets::get_widget(handle).unwrap()) as usize | ||
| } | ||
|
|
||
| if std::env::args().any(|arg| arg == "--list") { | ||
| println!("native_widget_order: test"); | ||
| return; | ||
| } | ||
| let mtm = MainThreadMarker::new().expect("native widget test runs on the main thread"); | ||
| let _app = NSApplication::sharedApplication(mtm); | ||
| let parent = widgets::vstack::create(0.0); | ||
| let other = widgets::hstack::create(0.0); | ||
| let a = widgets::spacer::create(); | ||
| let b = widgets::spacer::create(); | ||
| let c = widgets::spacer::create(); | ||
| widgets::add_child(parent, a); | ||
| widgets::add_child(parent, b); | ||
| widgets::add_child_at(parent, c, 1); | ||
| assert_eq!( | ||
| children(parent), | ||
| vec![ptr(a), ptr(c), ptr(b)], | ||
| "indexed insertion must affect native order" | ||
| ); | ||
|
|
||
| widgets::add_child_at(parent, a, 2); | ||
| assert_eq!(children(parent), vec![ptr(c), ptr(b), ptr(a)]); | ||
| widgets::set_width(b, 80.0); | ||
| widgets::add_child_at(other, b, 0); | ||
| assert_eq!(children(parent), vec![ptr(c), ptr(a)]); | ||
| assert_eq!(children(other), vec![ptr(b)]); | ||
| let b_view = widgets::get_widget(b).unwrap(); | ||
| assert!( | ||
| b_view | ||
| .constraints() | ||
| .iter() | ||
| .any(|constraint| constraint.constant() == 80.0 && constraint.isActive()), | ||
| "moving a widget preserves its width constraint" | ||
| ); | ||
|
|
||
| widgets::add_child_at(parent, b, -1); | ||
| assert_eq!(children(parent), vec![ptr(b), ptr(c), ptr(a)]); | ||
| assert!(children(other).is_empty()); | ||
| widgets::reorder_child(parent, 0, 2); | ||
| assert_eq!(children(parent), vec![ptr(c), ptr(a), ptr(b)]); | ||
|
|
||
| // Simulate a stack-detached hidden child, then exercise the cached position | ||
| // used by set_hidden. Reordering must update that position for every child. | ||
| let parent_view = widgets::get_widget(parent).unwrap(); | ||
| let stack = unsafe { &*(Retained::as_ptr(&parent_view) as *const NSStackView) }; | ||
| let a_view: Retained<NSView> = widgets::get_widget(a).unwrap(); | ||
| stack.removeArrangedSubview(&a_view); | ||
| a_view.removeFromSuperview(); | ||
| widgets::set_hidden(a, false); | ||
| assert_eq!(children(parent), vec![ptr(c), ptr(a), ptr(b)]); | ||
| widgets::remove_child(parent, c); | ||
| stack.removeArrangedSubview(&a_view); | ||
| a_view.removeFromSuperview(); | ||
| widgets::set_hidden(a, false); | ||
| assert_eq!( | ||
| children(parent), | ||
| vec![ptr(a), ptr(b)], | ||
| "removal refreshes surviving cached positions" | ||
| ); | ||
| widgets::add_child_at(parent, c, i64::MAX); | ||
| assert_eq!(children(parent), vec![ptr(a), ptr(b), ptr(c)]); | ||
| println!( | ||
| "PASS native widget ordering, reparenting, retained constraints, and hidden reattachment" | ||
| ); | ||
| } | ||
|
|
||
| #[cfg(not(target_os = "macos"))] | ||
| fn main() {} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| node_modules/ | ||
| *.log | ||
| out |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Keep negative indexed insertion consistent on Windows.
Line 530 clamps a negative index to zero. The macOS native test expects
add_child_at(parent, b, -1)to insertbfirst. Windows converts the same value tousizebefore clamping, so it appends the child instead. Updatecrates/perry-ui-windows/src/widgets/mod.rsto clamp before conversion.Proposed fix
🤖 Prompt for AI Agents