pub struct Context { /* private fields */ }Expand description
What a plugin is called with besides a frame: its configuration, and handles to every interface.
Implementations§
Source§impl Context
impl Context
pub const fn new() -> Self
Sourcepub fn config_json(&self) -> Json
pub fn config_json(&self) -> Json
The configuration document activate was called with.
Sourcepub fn config<T: DeserializeOwned>(&self) -> Result<T>
pub fn config<T: DeserializeOwned>(&self) -> Result<T>
The configuration, deserialized (an empty document is null).
pub fn live(&self) -> Live
Sourcepub fn calls(&self) -> Calls
pub fn calls(&self) -> Calls
Examples found in repository?
83 fn event(&mut self, event: Event, cx: &mut Context) {
84 match event {
85 Event::Plugin { name, .. } if name == "together.changed" => {
86 self.reload(cx);
87 self.paint();
88 // A commit from an event is sampled on the next frame;
89 // ask for one.
90 cx.request_frame();
91 }
92 Event::Resize { .. } => {
93 self.paint();
94 cx.request_frame();
95 }
96 Event::Pointer(pointer) if pointer.kind == PointerKind::Down => {
97 // Side-effect free unless this viewer is the one the user
98 // is driving, and then exactly once across viewers.
99 if !view::is_driving() {
100 return;
101 }
102 // `send` returns at once: the companion's answer arrives as
103 // the value it writes, not here.
104 let _ = claims().once("together.rebuild", 5_000, || {
105 let _ = cx.calls().send("rebuild", &(), Target::Singleton);
106 });
107 }
108 _ => {}
109 }
110 }pub fn claims(&self) -> Claims
pub fn is_driving(&self) -> bool
pub fn capabilities(&self) -> Capabilities
Sourcepub fn request_frame(&self)
pub fn request_frame(&self)
Asks for a frame on the next paced frame, from an event handler
(inside UiPlugin::frame, use Frame::request_frame). A commit
in event is otherwise sampled on the next frame something else
causes.
Examples found in repository?
83 fn event(&mut self, event: Event, cx: &mut Context) {
84 match event {
85 Event::Plugin { name, .. } if name == "together.changed" => {
86 self.reload(cx);
87 self.paint();
88 // A commit from an event is sampled on the next frame;
89 // ask for one.
90 cx.request_frame();
91 }
92 Event::Resize { .. } => {
93 self.paint();
94 cx.request_frame();
95 }
96 Event::Pointer(pointer) if pointer.kind == PointerKind::Down => {
97 // Side-effect free unless this viewer is the one the user
98 // is driving, and then exactly once across viewers.
99 if !view::is_driving() {
100 return;
101 }
102 // `send` returns at once: the companion's answer arrives as
103 // the value it writes, not here.
104 let _ = claims().once("together.rebuild", 5_000, || {
105 let _ = cx.calls().send("rebuild", &(), Target::Singleton);
106 });
107 }
108 _ => {}
109 }
110 }Sourcepub fn open(&self, surface: &str) -> Result<()>
pub fn open(&self, surface: &str) -> Result<()>
Opens a stage surface. Only while handling a user gesture: a key,
a paste, a pointer press on one of the plugin’s surfaces, or one of
its commands.
Sourcepub fn focus_pane(&self, pane: &str) -> Result<()>
pub fn focus_pane(&self, pane: &str) -> Result<()>
Shows a pane in this viewer’s workspace and gives it focus, as a
click on its sidebar row does. Only while handling a user gesture,
as Context::open; a pane the viewer does not know is ignored.
Sourcepub fn open_url(&self, url: &str) -> Result<()>
pub fn open_url(&self, url: &str) -> Result<()>
Opens an https:// URL in the user’s browser (crate::url::open):
while handling user input, or within a second after it.
Sourcepub fn request_size(&self, surface: &str, cols: u32, rows: u32) -> Result<()>
pub fn request_size(&self, surface: &str, cols: u32, rows: u32) -> Result<()>
Asks for surface to be cols by rows cells (0: the viewer’s
choice in that dimension) instead of the manifest’s size. The
viewer clamps it where it places the surface and sends
Event::Resize when the size changes. A card grows to show more
rows; a popover fits its content.
Sourcepub fn set_label(&self, surface: &str, label: Option<&str>) -> Result<()>
pub fn set_label(&self, surface: &str, label: Option<&str>) -> Result<()>
Sets a short label the viewer shows at the right end of surface’s
chrome title: a boxed card’s top border, a pane’s header, a column’s
title row. None removes it. At most 48 characters with no control
characters.
Sourcepub fn set_caret(&self, surface: &str, caret: Option<(u32, u32)>) -> Result<()>
pub fn set_caret(&self, surface: &str, caret: Option<(u32, u32)>) -> Result<()>
Places the viewer’s own text cursor at (col, row) of surface
while the surface takes keys (an open stage, popover or pane
overlay, or the surface a click or open gave input focus), so a
text field draws no cursor of its own; the cursor trail moves to it.
None removes it. Stays until set again.