Skip to content

Commit

Permalink
Better example of how to create UIKit and AppKit handles
Browse files Browse the repository at this point in the history
  • Loading branch information
madsmtm committed Jan 26, 2025
1 parent 95b6d88 commit d4f6bbe
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 17 deletions.
20 changes: 12 additions & 8 deletions src/appkit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,18 @@ impl AppKitWindowHandle {
///
/// # Example
///
/// ```
/// # use core::ptr::NonNull;
/// # use raw_window_handle::AppKitWindowHandle;
/// # type NSView = ();
/// #
/// let view: &NSView;
/// # view = &();
/// let handle = AppKitWindowHandle::new(NonNull::from(view).cast());
/// Create a handle from the content view of a `NSWindow`.
///
/// ```ignore
/// use std::ptr::NonNull;
/// use objc2::rc::Retained;
/// use objc2_app_kit::{NSWindow, NSView};
/// use raw_window_handle::AppKitWindowHandle;
///
/// let ns_window: Retained<NSWindow> = ...;
/// let ns_view: Retained<NSView> = window.contentView();
/// let ns_view: NonNull<NSView> = NonNull::from(&*ns_view);
/// let handle = AppKitWindowHandle::new(ns_view.cast());
/// ```
pub fn new(ns_view: NonNull<c_void>) -> Self {
Self { ns_view }
Expand Down
21 changes: 12 additions & 9 deletions src/uikit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,15 +97,18 @@ impl UiKitWindowHandle {
///
/// # Example
///
/// ```
/// # use core::ptr::NonNull;
/// # use raw_window_handle::UiKitWindowHandle;
/// # type UIView = ();
/// #
/// let view: &UIView;
/// # view = &();
/// let mut handle = UiKitWindowHandle::new(NonNull::from(view).cast());
/// // Optionally set the view controller.
/// Create a handle from a `UIView`.
///
/// ```ignore
/// use std::ptr::NonNull;
/// use objc2::rc::Retained;
/// use objc2_ui_kit::UIView;
/// use raw_window_handle::UiKitWindowHandle;
///
/// let ui_view: Retained<UIView> = ...;
/// let ui_view: NonNull<UIView> = NonNull::from(&*ui_view);
/// let mut handle = UiKitWindowHandle::new(ui_view.cast());
/// // Optionally, set the view controller too.
/// handle.ui_view_controller = None;
/// ```
pub fn new(ui_view: NonNull<c_void>) -> Self {
Expand Down

0 comments on commit d4f6bbe

Please sign in to comment.