pub struct Batch { /* private fields */ }Expand description
One batch, written by the runtime and by the Host into the same arena.
The Host opens it with Batch::begin, writes the records that are its own (the theme,
the window, assets, messages, notifications, streamed tails) and has the runtime write
the tree’s records between them, then closes it with Batch::finish. The bytes that
come back are what the boundary hands the Renderer.
A runtime has no fallible way to report a bad record from the middle of a diff, so
Batch::fail keeps the error and finish returns it in place of the batch.
Implementations§
Source§impl Batch
impl Batch
Sourcepub fn new() -> Self
pub fn new() -> Self
Sized so that an ordinary screen’s batches never grow it: once warm, writing a frame allocates nothing.
Sourcepub fn arena(&self) -> (*const u8, usize)
pub fn arena(&self) -> (*const u8, usize)
The batch arena, so a Renderer that reads Host memory through a mapped view can be handed one.
Sourcepub fn begin(&mut self)
pub fn begin(&mut self)
Starts a new batch, discarding the previous one and any error it carried.
Sourcepub fn finish(&mut self) -> Result<&[u8], ProtocolError>
pub fn finish(&mut self) -> Result<&[u8], ProtocolError>
Closes the batch and returns its bytes, or the first error written into it.
Sourcepub fn write(&mut self, mutation: Mutation<'_>)
pub fn write(&mut self, mutation: Mutation<'_>)
Writes one record. After an error nothing more is written: the batch is already going to be refused.
Sourcepub fn fail(&mut self, error: ProtocolError)
pub fn fail(&mut self, error: ProtocolError)
Records an error found while building the batch. finish returns it.
Sourcepub fn set_theme(&mut self, theme: Theme)
pub fn set_theme(&mut self, theme: Theme)
The root theme record. Written once per rebuild, never per frame.
Sourcepub fn set_overlay_tokens(&mut self, tokens: OverlayTokens)
pub fn set_overlay_tokens(&mut self, tokens: OverlayTokens)
Sets application-level overlay theme tokens for Dialog, Menu, Dropdown and Sheet.
Sourcepub fn set_window(&mut self, window: Window)
pub fn set_window(&mut self, window: Window)
The root window record. Written once per rebuild, never per frame.
pub fn set_text_node( &mut self, node_id: u32, text: &str, selection: Option<Selection>, )
Sourcepub fn register_asset(&mut self, asset_id: u32, kind: AssetKind, bytes: &[u8])
pub fn register_asset(&mut self, asset_id: u32, kind: AssetKind, bytes: &[u8])
Copies one asset into the batch. The bytes ride behind the records, and the Renderer takes its own copy inside the call that carries them.
pub fn release_asset(&mut self, asset_id: u32)
Sourcepub fn show_message(
&mut self,
handler_id: u64,
text: &str,
action: &str,
duration: MessageDuration,
)
pub fn show_message( &mut self, handler_id: u64, text: &str, action: &str, duration: MessageDuration, )
Writes one transient message into the batch.
It names no node, because a message is not in the tree: it is a sentence with a lifetime, and that lifetime belongs to the Renderer.
Sourcepub fn set_clipboard_text(&mut self, text: &str)
pub fn set_clipboard_text(&mut self, text: &str)
Writes one clipboard write. It names no node: the clipboard is the platform’s.
Sourcepub fn read_clipboard(&mut self, request: u32)
pub fn read_clipboard(&mut self, request: u32)
Writes one clipboard read request. It names no node either.
Sourcepub fn scroll_to(&mut self, node_id: u32, request: ScrollTo)
pub fn scroll_to(&mut self, node_id: u32, request: ScrollTo)
Writes one request to scroll the container node_id to an offset in physical
pixels. An axis left None is not touched; a request that names neither axis is
refused when the batch is finished.
A request, not a command: the Renderer owns the position. It keeps the offset
inside what the content allows, ignores the request while the user is dragging or
flinging, and says where the container ended up in ScrollChanged.
Sourcepub fn scroll_into_view(&mut self, node_id: u32, request: ScrollIntoView)
pub fn scroll_into_view(&mut self, node_id: u32, request: ScrollIntoView)
Writes one request to bring a rectangle into view in the container node_id. One
request moves one container: to show something inside nested containers, write one
for each of them, innermost first.
Sourcepub fn edit_code(
&mut self,
node_id: u32,
request_id: u32,
base_version: u32,
range: CodeRange,
text: &str,
)
pub fn edit_code( &mut self, node_id: u32, request_id: u32, base_version: u32, range: CodeRange, text: &str, )
Writes one edit the application asked of a code editor: replace range of the
document as it stood at base_version with text. The Renderer moves it past what
the reader typed since, or refuses it and reports request_id back.
Sourcepub fn set_selection(
&mut self,
node_id: u32,
base_version: u32,
anchor: Position,
active: Position,
)
pub fn set_selection( &mut self, node_id: u32, base_version: u32, anchor: Position, active: Position, )
Writes one request to put a code editor’s selection between two places in the
document as it stood at base_version. The Renderer moves both ends past what the
reader typed since and drops the request, with a protocol error, where an end is not
a place in the document.
Sourcepub fn reveal_range(
&mut self,
node_id: u32,
base_version: u32,
range: CodeRange,
align: RevealAlign,
)
pub fn reveal_range( &mut self, node_id: u32, base_version: u32, range: CodeRange, align: RevealAlign, )
Writes one request to scroll a code editor until range, as the document stood at
base_version, is on screen. A range inside a folded stretch unfolds it.
Sourcepub fn set_folded(&mut self, node_id: u32, start_line: u32, collapsed: bool)
pub fn set_folded(&mut self, node_id: u32, start_line: u32, collapsed: bool)
Writes one request to fold or unfold the stretch of a code editor that starts on
start_line.
Sourcepub fn set_scroll_offset(&mut self, node_id: u32, offset_px: f64)
pub fn set_scroll_offset(&mut self, node_id: u32, offset_px: f64)
Writes one request to scroll a code editor so that offset_px physical pixels of its
document are above the top of its view. The offset is the unit CodeScrolled
reports, so what one editor reported can be given to another to keep the two level.
The Renderer keeps it inside what the document allows.
Sourcepub fn append_text_node(&mut self, node_id: u32, text: &str)
pub fn append_text_node(&mut self, node_id: u32, text: &str)
Appends the streamed tail to a Text node without resending its whole value.
Sourcepub fn request_focus(&mut self, node_id: u32)
pub fn request_focus(&mut self, node_id: u32)
Requests input focus for node_id, or clears focus when node_id is 0.