Skip to main content

MacBackend

Struct MacBackend 

Source
pub struct MacBackend {
    pub(crate) mtm: MainThreadMarker,
    pub(crate) app: Retained<NSApplication>,
    pub(crate) _delegate: Retained<AppDelegate>,
    pub(crate) menu_target: RefCell<Option<Retained<MenuTarget>>>,
}

Fields§

§mtm: MainThreadMarker§app: Retained<NSApplication>§_delegate: Retained<AppDelegate>§menu_target: RefCell<Option<Retained<MenuTarget>>>

What the app’s own menu items tell when chosen; menu items hold it weakly.

Implementations§

Source§

impl MacBackend

Source

pub fn new() -> Self

§Panics

When called off the main thread, which AppKit forbids.

Trait Implementations§

Source§

impl Backend for MacBackend

Source§

fn set_backdrop(&self, window: &MacWindow, backdrop: Backdrop)

A Mica-like material doesn’t exist on macOS, where a standard window is already the platform’s own look, so only Translucent changes anything.

Source§

type Window = MacWindow

Source§

type Widget = MacWidget

Source§

type Waker = MacWaker

Source§

fn open_window( &self, title: &str, size: Size, on_resize: ResizeHandler, on_close: CloseHandler, ) -> MacWindow

The window starts hidden; on_resize receives the new content size after every resize, and whenever something else changes how the content must be laid out, such as the width of scroll bars. on_close runs when the user asks to close the window, such as with its close button, in place of closing it: the app closes it with Backend::close_window. The app quits once its last window closes.
Source§

fn content_size(&self, window: &MacWindow) -> Size

Source§

fn show_window(&self, window: &MacWindow)

Shows the window in front of the others, with the keyboard.
Source§

fn focus_window(&self, window: &MacWindow)

Brings a window already shown to the front, with the keyboard.
Source§

fn set_title(&self, window: &MacWindow, title: &str)

Source§

fn set_content_size(&self, window: &MacWindow, size: Size)

Resizes the window’s content area; its on_resize handler then reports the new size.
Source§

fn close_window(&self, window: MacWindow)

Closes the window, whose widgets have all been removed already.
Source§

fn title_bar_inset(&self, window: &MacWindow) -> f32

How far the title bar reaches down over the content area, which is 0 where the title bar sits outside it.
Source§

fn set_min_content_width(&self, window: &MacWindow, width: f32)

Stops the user from making the content area narrower than width.
Source§

fn create_surface( &self, parent: Parent<'_, Self>, surface: Surface, ) -> MacWidget

Draws surface behind the widgets created after it. Widgets stack in the order they are created, and a stack’s surface is created before its children, so the surface is behind everything inside it. It is never Surface::None.
Source§

fn create_scroll(&self, parent: Parent<'_, Self>) -> MacWidget

An area whose content scrolls up and down when it is taller than the area. Widgets created with it as their Parent::Scroll are its content.
Source§

fn scroll_bar_width(&self, _window: &MacWindow) -> f32

How much of a scroll area’s width its vertical scroll bar takes from the content, in points; 0 where scroll bars float over the content. It is asked again at every layout, since the user can change it while the app runs.
Source§

fn set_scroll_content(&self, scroll: &MacWidget, size: Size)

Sets the size of a scroll area’s content, which is as wide as the area less its scroll bar, and may be taller than the area.
Source§

fn create_label( &self, parent: Parent<'_, Self>, text: &str, style: LabelStyle, ) -> MacWidget

Source§

fn create_button( &self, parent: Parent<'_, Self>, title: &str, style: ButtonStyle, icon: Icon, selected: Option<bool>, on_click: ClickHandler, ) -> MacWidget

A button that shows whether it is selected when selected is Some; clicking it leaves that to set_checked.
Source§

fn create_nav_item( &self, parent: Parent<'_, Self>, title: &str, icon: Icon, badge: &str, selected: bool, on_click: ClickHandler, ) -> MacWidget

A row of a sidebar list: an icon, a title and a badge such as a count, highlighted while selected. on_click runs when the user picks it; it stays as it is until set_checked changes it.
Source§

fn create_text_field( &self, parent: Parent<'_, Self>, text: &str, placeholder: &str, lines: u32, on_change: TextHandler, on_submit: Option<ClickHandler>, ) -> MacWidget

A text field lines lines tall: one line, or more that wrap the text, take Return as a new line, and scroll; only a one-line field shows its placeholder. on_change runs after each edit the user makes, not when set_text changes the value, with lines ending in \n. A one-line field with on_submit runs it when the user presses Return in it, instead of pressing the window’s primary button.
Source§

fn create_checkbox( &self, parent: Parent<'_, Self>, title: &str, checked: bool, style: ToggleStyle, on_toggle: ToggleHandler, ) -> MacWidget

A checkbox ticks a box before its title, and a switch sits at the end of its title. on_toggle runs when the user toggles it, not when set_checked changes it.
Source§

fn create_slider( &self, parent: Parent<'_, Self>, value: i64, min: i64, max: i64, on_change: NumberHandler, ) -> MacWidget

A slider for whole numbers from min to max, at value. on_change runs with each new value as the user drags it, not when set_value moves it.
Source§

fn create_picker( &self, parent: Parent<'_, Self>, options: &[String], selected: &str, on_pick: TextHandler, ) -> MacWidget

A pop-up menu of options, showing the one equal to selected, or none when no option is. on_pick runs with the option the user picks, not when set_text or set_options change what it shows.
Source§

fn create_divider(&self, parent: Parent<'_, Self>) -> MacWidget

A thin line separating content; it is drawn along its longer side.
Source§

fn create_drop_target( &self, parent: Parent<'_, Self>, on_drop: DropHandler, ) -> MacWidget

An area that takes files and links the user drags onto it from other apps, such as the Finder, File Explorer or a browser. It draws nothing, takes clicks from no control, and is placed like any widget; where areas overlap, the smallest one takes the drop. on_drop runs with a path for each file and an address for each link, in the order the system gives them.
Source§

fn create_context_menu( &self, parent: Parent<'_, Self>, entries: &[MenuEntry<usize>], on_select: MenuHandler, ) -> MacWidget

An area that shows a menu of entries when the user right-clicks in it, or opens the context menu from the keyboard there. It draws nothing, takes clicks from no control, and is placed like any widget; where areas overlap, the smallest one’s menu shows. Controls that have a menu of their own, such as text fields, keep it. on_select runs with the number of the item the user chooses.
Source§

fn create_image( &self, parent: Parent<'_, Self>, path: Option<&Path>, size: ImageSize, ) -> MacWidget

The image in the file at path, as large as fits its frame, keeping its shape, and centred; it measures as size.frame of the image’s own size, in points. With no path, or a file that can’t be read as an image, it shows nothing.
Source§

fn set_image(&self, widget: &MacWidget, path: Option<&Path>)

Shows the image at path instead, as create_image does.
Source§

fn create_progress( &self, parent: Parent<'_, Self>, percent: Option<i64>, ) -> MacWidget

A progress bar filled to percent, from 0 to 100, or one showing that work is under way, animated, when there is no percentage.
Source§

fn set_text(&self, widget: &MacWidget, text: &str)

Sets a label’s text, a button’s or nav item’s title, a text field’s value, or the option a picker shows.
Source§

fn set_checked(&self, widget: &MacWidget, checked: bool)

Ticks a checkbox or switch, highlights a nav item as selected, or shows a button made with a selection as selected.
Source§

fn set_badge(&self, widget: &MacWidget, badge: &str)

Sets a nav item’s badge; empty hides it.
Source§

fn set_value(&self, widget: &MacWidget, value: i64)

Fills a progress bar to value percent, from 0 to 100, or moves a slider to value.
Source§

fn set_options(&self, widget: &MacWidget, options: &[String])

Replaces a picker’s options, keeping the one it shows if it is still there.
Source§

fn measure(&self, widget: &MacWidget) -> Size

The widget’s natural size for its current content.
Source§

fn set_frame(&self, widget: &MacWidget, frame: Frame)

Positions the widget relative to its parent’s content.
Source§

fn remove_widget(&self, widget: MacWidget)

Takes the widget off screen. It may be the widget whose handler is running right now, so the backend must keep that handler alive until the handler returns.
Source§

fn set_menu_bar(&self, menus: &[Menu<usize>], on_select: MenuHandler)

Gives the app menus, in place of any it had, alongside the system’s own: in the menu bar on macOS, and in every window’s menu bar on Windows, with their items’ shortcuts working wherever the app has the keyboard. on_select runs with an item’s number when the user chooses it or presses its shortcut.
Source§

fn waker(&self, on_wake: WakeHandler) -> MacWaker

on_wake runs on the UI thread soon after each wake, which any thread may call.
Source§

fn show_file_dialog(&self, dialog: &FileDialog, on_close: DialogHandler)

Shows dialog over the app’s active window, or on its own when no window is active, and passes how it closed to on_close on the UI thread. It is only called between events, so it may run a modal loop and call on_close before returning.
Source§

fn run(&self)

Runs the platform event loop until the app quits.
Source§

impl Debug for MacBackend

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for MacBackend

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> AutoreleaseSafe for T
where T: ?Sized,

Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<B> ShowDialog for B
where B: Backend,

Source§

fn show_dialog(&self, dialog: &FileDialog, on_close: Box<dyn FnOnce(Picked)>)

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.