-
-
Notifications
You must be signed in to change notification settings - Fork 163
fix(ui): let buttonSetImage size SF Symbols #10974
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| ### Fixed | ||
|
|
||
| - `buttonSetImage` accepts an optional point size for SF Symbol buttons on Apple platforms, so compact icons fit small controls without changing the size of existing two-argument calls. The JavaScript web backend also applies the requested icon size. (#10951) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| // AppKit must run on the process main thread, so this uses a harness-free binary. | ||
| #[cfg(target_os = "macos")] | ||
| fn main() { | ||
| use objc2::rc::Retained; | ||
| use objc2_app_kit::{NSApplication, NSButton}; | ||
| use objc2_core_foundation::CGSize; | ||
| use objc2_foundation::MainThreadMarker; | ||
| use perry_ui_macos::{perry_ui_button_set_image, widgets}; | ||
|
|
||
| if std::env::args().any(|arg| arg == "--list") { | ||
| println!("native_button_image_size: test"); | ||
| return; | ||
| } | ||
|
|
||
| let mtm = MainThreadMarker::new().expect("native button test runs on the main thread"); | ||
| let _app = NSApplication::sharedApplication(mtm); | ||
| let label = b"Copy"; | ||
| let label = perry_runtime::string::js_string_from_bytes(label.as_ptr(), label.len() as u32); | ||
| let button = widgets::button::create(label.cast(), 0.0); | ||
| widgets::button::set_bordered(button, false); | ||
| let symbol = b"doc.on.doc"; | ||
| let symbol = perry_runtime::string::js_string_from_bytes(symbol.as_ptr(), symbol.len() as u32); | ||
| let view = widgets::get_widget(button).expect("button is registered"); | ||
| let native_button = unsafe { &*(Retained::as_ptr(&view) as *const NSButton) }; | ||
|
|
||
| perry_ui_button_set_image(button, symbol as i64, 0.0); | ||
| let large: CGSize = unsafe { objc2::msg_send![native_button, fittingSize] }; | ||
| perry_ui_button_set_image(button, symbol as i64, 14.0); | ||
| let compact: CGSize = unsafe { objc2::msg_send![native_button, fittingSize] }; | ||
|
|
||
| assert!( | ||
| compact.height < large.height && compact.height <= 32.0, | ||
| "14pt image must fit a 32pt control: large={large:?}, compact={compact:?}" | ||
| ); | ||
| println!("PASS native button image size: {large:?} -> {compact:?}"); | ||
| } | ||
|
|
||
| #[cfg(not(target_os = "macos"))] | ||
| fn main() {} | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -39,9 +39,12 @@ A clickable button. | |
| ``` | ||
|
|
||
| **Helpers:** `buttonSetTitle`, `buttonSetBordered`, `buttonSetImage` | ||
| (SF Symbol name on macOS/iOS), `buttonSetImagePosition`, | ||
| (SF Symbol name and optional point size on Apple platforms), `buttonSetImagePosition`, | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win Document web point-size support. The optional point size also controls SVG icon dimensions in the JavaScript web backend. Do not describe the third argument as Apple-only. Separate the Apple SF Symbol behavior from the cross-platform point-size argument. 🤖 Prompt for AI Agents |
||
| `buttonSetContentTintColor`, `buttonSetTextColor`, `widgetSetEnabled`. | ||
|
|
||
| Pass a point size for compact icon buttons, for example | ||
| `buttonSetImage(copyButton, "doc.on.doc", 14)` inside a 32pt control. | ||
|
|
||
| ## TextField | ||
|
|
||
| An editable single-line text input. | ||
|
|
||
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
Assert the required symbol sizes.
This predicate does not verify the required 24pt default size or 20pt size for a 14pt image. A regression that produces 31pt and 30pt would pass. Assert the expected
large.heightandcompact.heightvalues in addition to the 32pt control bound.🤖 Prompt for AI Agents