跳到正文

Host

基于 NSHostingView 的叶节点,用于在 QuickGUI 中挂载一棵 SwiftUI 组件树。

#导入

从 quickgui 导入 MacSwiftUiHost。

use quickgui::*;

#用法

let mut host = MacSwiftUiHost::new(|_id| {})?;
host.sync(&[SwiftUiButton::new(1).label("Continue").into()])?;
native_view(host.view())

#API 参考

展开条目查看说明和完整签名。短横线表示声明中未记录默认值。

MacSwiftUiHost

查看源码
pub fn new(action: impl Fn(u64) + 'static) -> Result<Self, String>
new_with_eventspub fn new_with_events( action: impl Fn(u64) + 'static, presentation: impl Fn(u64, bool) + 'static, ) -> Result<Self, String>—

Configures new with events for this part.

pub fn new_with_events( action: impl Fn(u64) + 'static, presentation: impl Fn(u64, bool) + 'static, ) -> Result<Self, String>
查看源码
new_with_control_eventspub fn new_with_control_events( action: impl Fn(u64) + 'static, presentation: impl Fn(u64, bool) + 'static, value: impl Fn(u64, &str) + 'static, submit: impl Fn(u64) + 'static, ) -> Result<Self, String>—

Construct a host that also reports controlled value changes and text-field submissions.

pub fn new_with_control_events( action: impl Fn(u64) + 'static, presentation: impl Fn(u64, bool) + 'static, value: impl Fn(u64, &str) + 'static, submit: impl Fn(u64) + 'static, ) -> Result<Self, String>
查看源码
viewpub fn view(&self) -> &objc2_app_kit::NSView—

Configures view for this part.

pub fn view(&self) -> &objc2_app_kit::NSView
查看源码
syncpub fn sync(&mut self, elements: &[SwiftUiElement]) -> Result<bool, String>—

Synchronize the complete ordered SwiftUI descriptor tree. Returns whether the native root view or one of its embedded QuickGUI surfaces changed.

pub fn sync(&mut self, elements: &[SwiftUiElement]) -> Result<bool, String>
查看源码
sync_buttonspub fn sync_buttons(&mut self, buttons: &[SwiftUiButton]) -> Result<bool, String>—

Compatibility convenience for the original button-only bridge.

pub fn sync_buttons(&mut self, buttons: &[SwiftUiButton]) -> Result<bool, String>
查看源码
fitting_sizepub fn fitting_size(&self) -> Result<Size, String>—

Current fitting size of the hosted SwiftUI controls at their native size. The headroom the host keeps around content whose effects draw past its bounds, such as Liquid Glass, is excluded; [`Self::effect_inset`] reports it, and placing the view with [`crate::native_view_with_outset`] keeps it outside layout.

pub fn fitting_size(&self) -> Result<Size, String>
查看源码
effect_insetpub fn effect_inset(&self) -> Result<f32, String>—

Padding the host keeps on each side of its content for effects that draw past a control's bounds; zero unless the content contains such a control.

pub fn effect_inset(&self) -> Result<f32, String>
查看源码

native_view

查看源码
pub fn native_view(view: &NSView) -> Element

Embed an AppKit view as a declarative leaf on macOS. QuickGUI synchronizes layout, clipping, visibility, and sibling order while AppKit keeps ownership of the view's rendering and input behavior.