pub trait ResourceSurface<R: Resource, E: Effect = NoEffect>: Widget {
Show 13 methods
// Required method
fn present(&mut self, state: &Rc<R::State>);
// Provided methods
fn supports_device_shell(&self) -> bool { ... }
fn device_shell_operation(
&mut self,
_operation: &DeviceShellOperation,
) -> Result<Value, String> { ... }
fn request_device_shell(&mut self) -> bool { ... }
fn take_host_intent(&mut self) -> Option<AppHostIntent> { ... }
fn attach(&mut self, cx: SurfaceCx<R>) { ... }
fn landed(&mut self, participant: &ParticipantId, place: &Place) { ... }
fn read_only_changed(&mut self, read_only: bool) { ... }
fn stage(&mut self, scenario: Option<&str>) { ... }
fn effect(&mut self, effect: E, cx: &mut EffectCx<R, Self>) -> EffectAnswer
where Self: Sized { ... }
fn effects(&self) -> Vec<EffectStatus> { ... }
fn live_rows(&self) -> Vec<LiveRow> { ... }
fn live_row(&self, id: &str) -> Option<LiveRow> { ... }
}Expand description
A custom widget or renderer — a timeline, a canvas, a GPU viewport, a page layout engine — taking part in a resource.
Pixels, layout and input stay the toolkit’s Widget contract, unchanged.
This trait adds only what the framework cannot infer:
- Read —
presentreceives the resource state whenever it changes: a local edit, a collaborator’s, an undo. In History mode the framework builds the surface again from a read-onlyViewCxand presents a past version, so time travel needs no extra code as long as the surface draws from what it was presented. A surface over a large resource reads throughSurfaceCx::liveinstead of copying, and demands the parts it shows (Live::demand) from the document itssyncreceives — the live one, or the past version in History mode. - Write — edits go through the
Dispatcherhanded toattach: a named action, or any typed action value viaDispatcher::apply. The host checks permissions, applies, records one undo step per action, attributes it in history and replicates it. A surface never writes the document. - Undo granularity — one action is one undo step. Preview a gesture
locally (a drag, a scrub) and dispatch one action when it ends; a
gesture that is several edits goes in one
Dispatcher::group(or holds aDispatcher::begin_groupguard for the input event), so one Ctrl+Z takes all of it back. - Permissions —
RecordEnv::read_onlysays the participant may only view; present accordingly. It follows role changes while the app runs, andread_only_changedannounces each one. Refused actions change nothing. - Confirmation — a typed value whose
riskis destructive (deleting a clip) waits for the user’s confirmation, like a declared destructive action. When an edit is refused or held for confirmation, the surface is presented the stored state again, undoing any optimistic preview; a confirmed edit then arrives as an ordinary change. - Presence — report where the user is as a
ResourceSelectionfrom the toolkit’sWidget::presence_payload(one line:selection.presence::<R>(app_id)), and draw collaborators from thePresenceCtxevery draw receives, under the same keys. - Effects — work with no document delta (back up now, connect, run a
query) is the surface’s effect vocabulary
E, a#[derive(Effect)]enum: implementResourceSurface<R, E>and answer each effect ineffectwith&mut self, starting a job through theEffectCxwhen it takes time. Every caller — a button (Dispatcher::effect), the palette, an agent — reaches it the same way;effectssays which are unavailable right now. - Run mode — start work that reaches outside the process (a decoder
service, a socket, a probe) only when
RecordEnv::modeis live. A capture readsRecordEnv::fixtureinstead; a past version starts nothing. Work still in flight that the frame shows (a page render, a decode) is reported by the toolkit’sWidget::has_pending_visual_work; a capture waits for it. - One published tree — what the surface offers the palette, agents
and scripts joins the resource’s own publication:
live_rowsfor the live external entities it shows (processes, containers), which carry only view and effect operations. Edits bound to where the user is are the view’s (ViewCx::bind_declarations), and so are search entries for what it shows (Publishes::search_entries). A document action the surface’s ownPublishesResourcesoffers is dropped, so nothing reaches the document beside the resource’s actions.
Required Methods§
Sourcefn present(&mut self, state: &Rc<R::State>)
fn present(&mut self, state: &Rc<R::State>)
The resource state to show.
Keeping state past this call is allowed but not free: while it is
held, the next change brings a copy up to date. A copy shares what
the change did not touch — every Collection
item, untouched Keyed/Ordered fields, the untouched chunks of a
Map, Set or Grid — but plain fields (a Vec, a BTreeMap) are
copied whole on every change, so a large one belongs in one of those,
and a surface keeps the parts it needs rather than the Rc when the
state has large plain ones.
Provided Methods§
fn supports_device_shell(&self) -> bool
Sourcefn device_shell_operation(
&mut self,
_operation: &DeviceShellOperation,
) -> Result<Value, String>
fn device_shell_operation( &mut self, _operation: &DeviceShellOperation, ) -> Result<Value, String>
Answer a private owner operation from the authenticated hosting shell.
Sourcefn request_device_shell(&mut self) -> bool
fn request_device_shell(&mut self) -> bool
A trusted hosting shell owner selected the device-shell target. No grant is implied.
Sourcefn take_host_intent(&mut self) -> Option<AppHostIntent>
fn take_host_intent(&mut self) -> Option<AppHostIntent>
A pending device-local request for the hosting shell, consumed once. The host answers it through its permission flow; this callback lends no document.
Sourcefn attach(&mut self, cx: SurfaceCx<R>)
fn attach(&mut self, cx: SurfaceCx<R>)
The channel edits go through, and whether they will be accepted.
Called once, before the first present.
Sourcefn landed(&mut self, participant: &ParticipantId, place: &Place)
fn landed(&mut self, participant: &ParticipantId, place: &Place)
A participant’s action — an agent’s verb, a collaborator’s edit
taken through the door — left them at place, as the resource says
it lands (Resource::lands).
Called after present showed the state holding it.
Presence draws them there already; a surface that acts at a
participant’s place (typing at an agent’s caret) reads it here, or
any time through Live::place_of, instead
of keeping its own copy.
Sourcefn read_only_changed(&mut self, read_only: bool)
fn read_only_changed(&mut self, read_only: bool)
The participant’s permission to edit changed while the app runs: a role granted or taken away. Present accordingly. The dispatcher already refuses or accepts edits under the new permissions.
Sourcefn stage(&mut self, scenario: Option<&str>)
fn stage(&mut self, scenario: Option<&str>)
Stage view state for a screenshot scenario (None for a plain
--shots): a selection, an open menu, a drag in flight. Called at the
start of the sync after the scenario’s actions applied and were laid
out, so the surface has been presented their result, knows its
geometry, and its own sync follows with the document. Edits it dispatches here are submitted like any other and
applied before the frame is captured. Must be deterministic: the same
scenario stages the same scene on every run. Never called in a live
window.
Sourcefn effect(&mut self, effect: E, cx: &mut EffectCx<R, Self>) -> EffectAnswerwhere
Self: Sized,
fn effect(&mut self, effect: E, cx: &mut EffectCx<R, Self>) -> EffectAnswerwhere
Self: Sized,
Answer effect, invoked by a control, the palette, an agent or a
script: finish now (Effected::done), or
start a job with EffectCx::thread, EffectCx::spawn or
EffectCx::reply and answer Effected::Pending
(only for an effect declared job). A job’s completion runs on the
UI thread with &mut self again, and changes the document through
the context’s dispatcher. Never called in History mode.
§Errors
Returns why the effect failed, which its caller is told.
Sourcefn effects(&self) -> Vec<EffectStatus>
fn effects(&self) -> Vec<EffectStatus>
The effects that differ from their declaration right now, as the surface’s state says: unavailable while the engine is offline, relabelled while recording. Read after every sync, so the published actions follow the surface.