Skip to main content

Command

Enum Command 

Source
pub enum Command {
Show 66 variants Focus, Blur, ClearSelection, SelectAll, ScrollTo { x: Points, y: Points, animated: bool, }, LayoutAnimation(LayoutAnimation), ExitApp, SetAppUrl(String), PushAppUrl(String), Back, Reload, GoBack, GoForward, StopLoading, InjectJavaScript(String), Evaluate { request: u32, script: String, }, CancelEvaluate { request: u32, }, PostMessage(String), SendInput(WebInput), Load(WebLoad), Seek(f64), ScrollToIndex { index: u32, animated: bool, view_position: Percentage, view_offset: Points, }, ZoomTo { scale: f32, center: Option<Point<Points>>, animated: bool, }, Reveal(RevealOptions), ScrollToEnd { animated: bool, }, StatusBar(StatusBarConfig), Tokens(Arc<Tokens>), TextLocale(Locale), SetStatusBar(StatusBarSetting), Dialog(Box<AlertDialogRequest>), CloseDialog(u32), SetJsResponder { block: bool, }, ClearJsResponder, SetSelection { start: u32, end: u32, }, InsertText(String), Announce(String), PerfMonitor(bool), PerfMonitorMode(FpsMode), ImageInfo { id: u32, uri: String, }, AccessibilityFocus, Measure { call: u32, }, MeasureScrollPosition { call: u32, }, SetClipboard(String), SetClipboardItem(ClipboardItem), ReadClipboard { id: u32, has_only: bool, }, SetClipboardImage(String), ReadClipboardImage { id: u32, has_only: bool, }, ReadClipboardFiles { id: u32, }, PickImages { id: u32, request: PickRequest, }, PickFiles { id: u32, request: FilePickRequest, }, OpenUrl { id: u32, url: String, }, OpenAppSettings { id: u32, }, PickScreenColor { id: u32, }, RenderCanvas { id: u32, drawing: Arc<Drawing>, width: u32, height: u32, scale: f32, format: ImageFormat, }, FileRequest { id: u32, request: Box<FileRequest>, }, Audio(AudioCommand), Notification(NotificationCommand), Haptic(Haptic), Orientations(u8), Desktop(Box<DesktopCommand>), HostCall { id: u64, name: String, args: JsonValue, }, HostPost { name: String, args: JsonValue, }, Native { name: Arc<str>, args: JsonValue, }, OpenEditMenu { bounds: Bounds<Points>, actions: Vec<EditAction>, }, CloseEditMenu, WebViewRequest(WebViewRequest), // some variants omitted
}
Expand description

An imperative call on a native view (ref.focus() and the like).

Variants§

§

Focus

Focus an input (show the keyboard).

§

Blur

Unfocus an input; on the root view, unfocus whatever is focused.

§

ClearSelection

Clear the selection of a selectable view (ViewProps::selectable_view) the view is, is inside or holds.

§

SelectAll

Select all the text of the selectable view (ViewProps::selectable_view) the view is or is inside, as the selection menu’s Select All does.

§

ScrollTo

Scroll a scroll view to an offset.

Fields

§x: Points

Horizontal offset.

§y: Points

Vertical offset.

§animated: bool

Animate the change.

§

LayoutAnimation(LayoutAnimation)

Animate the layout changes of the next commit. On the root, all of them; on a node, with its update, only the frames that node’s change moves (ElementRef::animate_layout, core/layout_scope.rs).

§

ExitApp

Leave the app (Android back handling; on the root).

§

SetAppUrl(String)

The app’s address (UrlScheme.setUrl, set_app_url; on the root): the web replaces the current history entry’s; iOS and macOS give it to the system when the app opts in (Handoff); the other platforms keep none (crate::url_scheme).

§

PushAppUrl(String)

The app’s address as an entry of its own after the current one (UrlScheme.setUrl(url, { history: "push" }), set_app_url_with; on the root): the web pushes one unless the same turn pushed a page’s or it is the address shown; iOS and macOS take it as Command::SetAppUrl; the other platforms keep none.

§

Back

What the back button does when none of the app’s listeners took it: the innermost stack pops (or asks, with popOnBack false); with none, the app leaves on Android (on the root).

§

Reload

Reload a web view.

§

GoBack

Go back in a web view’s history.

§

GoForward

Go forward in a web view’s history.

§

StopLoading

Stop loading a web view.

§

InjectJavaScript(String)

Run JavaScript in a web view’s page.

§

Evaluate

Run a script in a web view’s page for its result (crate::platform::web_evaluation); the platform answers on this node with EventKind::WebEvaluation (id: the request, data: the JSON envelope), once.

Fields

§request: u32

The engine’s request, echoed in the reply.

§script: String

The app’s script.

§

CancelEvaluate

Give up request request of Command::Evaluate: release what the platform keeps for it, answering nothing.

Fields

§request: u32

The request.

§

PostMessage(String)

Send a message to a web view’s page (window.onmessage data).

§

SendInput(WebInput)

Give a web view’s page input as the user’s own (trusted events).

§

Load(WebLoad)

Load a page in a web view with headers on its request.

§

Seek(f64)

Seek a video to a time in seconds.

§

ScrollToIndex

Scroll a list to an item (resolved by the core into ScrollTo).

Fields

§index: u32

The item.

§animated: bool

Animate the change.

§view_position: Percentage

Where the item ends up: 0 at the start of the viewport, 1 at the end, 0.5 in the middle.

§view_offset: Points

Extra distance from that position.

§

ZoomTo

Zoom a zoomable scroll view to scale, with the content point (x, y) (points, unzoomed) in the middle of the viewport, or around the viewport’s middle.

Fields

§scale: f32

The zoom scale (clamped to the view’s limits).

§center: Option<Point<Points>>

The content point to center.

§animated: bool

Animate the change.

§

Reveal(RevealOptions)

Scroll the scroll views around the view so it shows (resolved by the core into their ScrollTo; never mounted).

§

ScrollToEnd

Scroll a list to the end of its content.

Fields

§animated: bool

Animate the change.

§

StatusBar(StatusBarConfig)

Set the status bar (on the root): what the platform shows.

§

Tokens(Arc<Tokens>)

The design tokens the app is drawn with (on the root), sent when they change (crate::Core::tokens): what the platform’s own controls (Linux’s menus, Android’s and iOS’s alerts and action sheets) take their colors from, by the tokens’ names (popover, accent, border, …).

§

TextLocale(Locale)

The language the app’s text shows in (crate::i18n: its selected language, setLocale’s or the embedding app’s included), on the root of an iOS or Android surface, sent when it changes: the words the platform speaks for states it has no system words for (checked, expanded, invalid…) follow it.

§

SetStatusBar(StatusBarSetting)

Change what functions set for the status bar (on the root): the core merges it under the settings components render and sends Command::StatusBar when the result changes.

§

Dialog(Box<AlertDialogRequest>)

Show an alert or action sheet (on the root); the answer comes back as EventKind::Dialog.

§

CloseDialog(u32)

Close the dialog Command::Dialog showed with this id (on the root), as if dismissed, without reporting an answer: the app no longer wants one, and the core has already answered it.

§

SetJsResponder

A JS responder took the touches on this view: block keeps native scroll views around it from taking them over.

Fields

§block: bool

Block native scrolling.

§

ClearJsResponder

The JS responder let go (on the root).

§

SetSelection

Select a range of an input (UTF-16 units; equal for a caret). Platforms drop it when the same batch brought the input a value they dropped as stale (MountItem::InputValue’s count): its offsets are for the text JS had, not for what the user typed since.

Fields

§start: u32

Start.

§end: u32

End.

§

InsertText(String)

Insert text into an input in place of its selection, as the user’s edit: the input’s maxLength and line rules apply, onChangeText reports it, no key is reported, and where the platform keeps an undo history it is a step of it (unlike a new value). With pasteBehavior "report", the app inserts a paste it allowed or rewrote this way.

§

Announce(String)

Have the screen reader read a message (on the root).

§

PerfMonitor(bool)

Turn the performance monitor on or off (on the root; setFpsEnabled): what the platform has of one, the macOS panel or the other platforms’ nsh::fps lines. Platforms without a monitor ignore it.

§

PerfMonitorMode(FpsMode)

How the performance monitor shows (on the root; setFpsMode): its whole panel, collapsed to its frame rate, or nothing while it still measures. Platforms without a panel ignore it.

§

ImageInfo

Load the image at uri (keeping its bytes for views that show it next) and report its pixel size as EventKind::ImageInfo id (on the root).

Fields

§id: u32

The request.

§uri: String

URL or asset:/ URI.

§

AccessibilityFocus

Move the screen reader’s focus to this view.

§

Measure

Measure the view with this commit’s layout (ref.measure()): answered by the core in its events for promise call (crate::element::JsEvent::Reply: a crate::Measurement, or null when the view is not laid out); never mounted.

Fields

§call: u32

The call to answer.

§

MeasureScrollPosition

Where a list’s viewport starts among its rows, with this commit’s layout (ref.measureScrollPosition()): answered by the core in its events for promise call (a crate::ListScrollPosition, or null for a view that is no list or a list without items); never mounted.

Fields

§call: u32

The call to answer.

§

SetClipboard(String)

Put text on the system clipboard (on the root; Clipboard.writeText).

§

SetClipboardItem(ClipboardItem)

Put one item on the system clipboard, each of its formats in one write: the text as plain text, the HTML (when it has some) as the platform’s HTML type, which apps that read formatting paste (on the root; Clipboard.write). A platform without an HTML type puts the text only. New formats of crate::element::ClipboardItem come in the same command.

§

ReadClipboard

Read the system clipboard and report it as EventKind::Clipboard id (on the root): has and, unless has_only, text. Asking only whether it holds text does not read it (no iOS paste notice).

Fields

§id: u32

The request.

§has_only: bool

Only whether it holds text (Clipboard.hasText).

§

SetClipboardImage(String)

Put the image of a data: URI on the system clipboard, replacing what it holds (on the root; Clipboard.writeImage).

§

ReadClipboardImage

Read the image on the system clipboard and report it as EventKind::Clipboard id (on the root): has and, unless has_only, the image as a data: URI (uri) and its size in pixels (width, height), or for an image over crate::platform::clipboard::MAX_IMAGE_BYTES its size in bytes (tooLarge; crate::platform::clipboard::image_answer).

Fields

§id: u32

The request.

§has_only: bool

Only whether it holds an image (Clipboard.hasImage).

§

ReadClipboardFiles

Read the local files on the system clipboard (files copied in a file manager) and report them as EventKind::Clipboard id (on the root): has and files, their file: URLs one per line.

Fields

§id: u32

The request.

§

PickImages

Show the system’s picker for images (on the root; Picker.pickImages), prepare the picked ones as request says (crate::picker) and report them as EventKind::Pick (EventPayload::Picked id; no files when cancelled).

Fields

§id: u32

The request.

§request: PickRequest

What to show and how to prepare the images.

§

PickFiles

Show the system’s picker for files of any type (on the root; Picker.pickFiles) and report the picked ones, their bytes as they are, as EventKind::Pick (EventPayload::Picked id; no files when cancelled; crate::picker).

Fields

§id: u32

The request.

§request: FilePickRequest

What to show.

§

OpenUrl

Open url outside the app (on the root; openUrl of nsh/device, crate::open_url): the browser, the mail or phone app, the app that registered its scheme. Report whether it opened as EventKind::OpenUrl id. The core sends it once the URL was checked and the embedding app did not take it.

Fields

§id: u32

The request.

§url: String

The URL (crate::open_url::check_url passed it).

§

OpenAppSettings

Open the app’s own page in the system’s settings (on the root; nsh/mobile’s AppSettings.open, crate::mobile::open_app_settings): iOS’s UIApplication.openSettingsURLString, Android’s application details. Report whether the system opened it as EventKind::OpenAppSettings id. Sent only on platforms whose crate::platform::Environment::app_settings is set.

Fields

§id: u32

The request.

§

PickScreenColor

Let the user pick a color anywhere on the screen (on the root; a color picker’s eyedropper, [crate::element::ambient::pick_screen_color]): the system’s color sampler or the browser’s EyeDropper. Report it as EventKind::ScreenColor id, with no color when the user cancelled. Sent only on platforms whose crate::platform::Environment::screen_color is set.

Fields

§id: u32

The request.

§

RenderCanvas

Render drawing offscreen into a width × height pixel image (on the root; OffscreenCanvas’s convertToBlob, crate::canvas::render): replay it as a canvas of scale pixels per point draws it on screen, into a bitmap of its own that starts transparent, its animated values at 0, and report the encoded image as EventKind::CanvasImage id (EventPayload::CanvasImage). Sent only on platforms whose crate::platform::Environment::canvas_render is set, with a size [crate::canvas::render::pixel_size] passed.

Fields

§id: u32

The request.

§drawing: Arc<Drawing>

What to draw, in points.

§width: u32

The image’s width in pixels.

§height: u32

The image’s height in pixels.

§scale: f32

Pixels per point.

§format: ImageFormat

The encoding.

§

FileRequest

Carry out request on local paths (on the root; crate::file_dialog): show the open or save dialog, open a file in its app, show it in the file manager or move it to the trash. Report it as EventKind::FileRequest id (EventPayload::FileRequest). Sent only on platforms whose crate::platform::Environment::file_requests is set.

Fields

§id: u32

The request.

§request: Box<FileRequest>

What to do.

§

Audio(AudioCommand)

Load, play and free sounds, open and drive players (on the root; Sound and AudioPlayer of nsh, crate::audio) and report what happens as EventKind::Audio (EventPayload::Audio). Sent only on platforms whose crate::platform::Environment::audio is set.

§

Notification(NotificationCommand)

Show a notification, ask for the permission, set the app’s badge (on the root; Notifications of nsh, crate::notifications).

§

Haptic(Haptic)

Play a haptic (on the root; Haptics of nsh/mobile, crate::element::haptic). Platforms without haptics ignore it.

§

Orientations(u8)

The orientations the screen may take (on the root; the supportedOrientations of the page shown, ScreenProp::Orientations): crate::ModalConfig::PORTRAIT bits, 0 for the app’s own. iOS and Android; the other platforms ignore it.

§

Desktop(Box<DesktopCommand>)

A desktop command (on the root; nsh/desktop): the window, its title bar, menus. Mobile platforms ignore it.

§

HostCall

Call function name of the app embedding NSH (on the root; nsh/host’s host.call): the platform answers with EventKind::Host { type: "reply", id, .. }. Sent only on platforms whose crate::platform::Environment::host is set, for functions the app’s capabilities.host grants.

Fields

§id: u64

The call, echoed by the reply.

§name: String

The host’s function.

§args: JsonValue

Its argument (any JSON value; null without one).

§

HostPost

Hand args to function name of the app embedding NSH, with no answer (on the root; nsh/host’s host.post without a native SDK channel). Sent only on platforms whose crate::platform::Environment::host is set, for functions the app’s capabilities.host grants.

Fields

§name: String

The host’s function.

§args: JsonValue

Its argument (any JSON value; null without one).

§

Native

A call on a registered native component (ref.command(name, args)).

Fields

§name: Arc<str>

The command.

§args: JsonValue

Its arguments (any JSON value).

§

OpenEditMenu

Open the system’s edit menu over bounds (in the root view) on an input that has the focus: the menu of a component that draws its own text selection (RichEditor’s on touch screens). UIKit’s UIEditMenuInteraction on iOS, a floating ActionMode on Android; platforms without such a menu ignore it. It offers actions, in the platform’s order: Paste pastes into the input as the user’s paste does (onPaste), the others are reported as EventKind::EditAction. The menu closes when an action is chosen.

Fields

§bounds: Bounds<Points>

What the menu points at, in the root view.

§actions: Vec<EditAction>

The actions it offers; those that cannot apply are left out, not disabled.

§

CloseEditMenu

Close the edit menu Command::OpenEditMenu opened on an input.

§

WebViewRequest(WebViewRequest)

A request on a web view (crate::webview) sent once the target is known to be a mounted, granted web view; the platform answers on this node with EventKind::WebViewReply (id: the request).

Trait Implementations§

Source§

impl Clone for Command

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Command

Source§

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

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

impl PartialEq for Command

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Command

Auto Trait Implementations§

§

impl !RefUnwindSafe for Command

§

impl !UnwindSafe for Command

§

impl Forget for Command

§

impl Freeze for Command
where *const u8 is !null: Freeze, PhantomData<u8>: Freeze, PhantomData<(String, String)>: Freeze, *const ArcInner<Tokens> is !null: Freeze, PhantomData<ArcInner<Tokens>>: Freeze, *const AlertDialogRequest is !null: Freeze, PhantomData<AlertDialogRequest>: Freeze, PhantomData<FileFilter>: Freeze, *const ArcInner<Drawing> is !null: Freeze, PhantomData<ArcInner<Drawing>>: Freeze, *const FileRequest is !null: Freeze, PhantomData<FileRequest>: Freeze, *const ArcInner<dyn AsRef<[u8]> + Sync + Send> is !null: Freeze, PhantomData<ArcInner<dyn AsRef<[u8]> + Sync + Send>>: Freeze, *const ArcInner<Rgba> is !null: Freeze, PhantomData<ArcInner<Rgba>>: Freeze, *const DesktopCommand is !null: Freeze, PhantomData<DesktopCommand>: Freeze, PhantomData<Value>: Freeze, *const LeafNode<String, Value> is !null: Freeze, PhantomData<(Owned, LeafOrInternal)>: Freeze, PhantomData<Box<(String, Value)>>: Freeze, *const ArcInner<str> is !null: Freeze, PhantomData<ArcInner<str>>: Freeze, PhantomData<EditAction>: Freeze,

§

impl Move for Command

§

impl Send for Command
where RawVecInner: Send, Arc<Tokens>: Send, BoxRaw<AlertDialogRequest>: Send, Arc<Drawing>: Send, BoxRaw<FileRequest>: Send, Arc<dyn AsRef<[u8]> + Sync + Send>: Send, Arc<Rgba>: Send, BoxRaw<DesktopCommand>: Send, NodeRef<Owned, String, Value, LeafOrInternal>: Send, BoxRaw<(String, Value)>: Send, Arc<str>: Send,

§

impl Sync for Command
where RawVecInner: Sync, Arc<Tokens>: Sync, BoxRaw<AlertDialogRequest>: Sync, Arc<Drawing>: Sync, BoxRaw<FileRequest>: Sync, Arc<dyn AsRef<[u8]> + Sync + Send>: Sync, Arc<Rgba>: Sync, BoxRaw<DesktopCommand>: Sync, NodeRef<Owned, String, Value, LeafOrInternal>: Sync, BoxRaw<(String, Value)>: Sync, Arc<str>: Sync,

§

impl Unpin for Command

§

impl UnsafeUnpin for Command

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> 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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.