pub struct Playground { /* private fields */ }Expand description
A place to write code and see what it makes, for documentation, tutorials and tools.
The code is on one side and the result on the other; below 768 pixels they become two
tabs. Run (or Ctrl/Cmd+Enter) hands the code to the Runner. When it has problems,
they are listed under the editor and marked on their lines, and the last result that
worked stays, labeled as such. Examples fill the editor, Restore puts the chosen example
back, and the app can add buttons that receive the code, such as one that copies a link.
use ravenrs_widgets::{AnyView, CodeDiagnostic, Playground, Text, Ui};
let runner = |source: &str| -> Result<AnyView, Vec<CodeDiagnostic>> {
match source.trim().strip_prefix("say ") {
Some(words) => Ok(Box::new(Text::new(words.to_owned()))),
None => Err(vec![CodeDiagnostic::error(1, 1, 3, "Start with `say`")]),
}
};
let playground = Playground::new(runner).example("Hello", "say hello").height(400.0);
let mut ui = Ui::new(playground, ravenrs_style::Theme::raven_dark());
ui.update();Implementations§
Source§impl Playground
impl Playground
Sourcepub fn example(self, name: impl Into<String>, source: impl Into<String>) -> Self
pub fn example(self, name: impl Into<String>, source: impl Into<String>) -> Self
An example to start from, listed in the bar; the first one fills the editor.
Sourcepub fn source(self, source: Binding<String>) -> Self
pub fn source(self, source: Binding<String>) -> Self
Keeps the code in source, so the app can save it, share it or start from it.
While it is empty, or without it, the playground starts from the first example.
Sourcepub fn chosen_example(self, example: Binding<usize>) -> Self
pub fn chosen_example(self, example: Binding<usize>) -> Self
Keeps which example is chosen in example.
Sourcepub fn language(self, language: CodeLanguage) -> Self
pub fn language(self, language: CodeLanguage) -> Self
The language the editor colors; Rust by default.
Sourcepub fn note(self, note: impl Into<String>) -> Self
pub fn note(self, note: impl Into<String>) -> Self
A line under the bar, such as what this playground can and cannot run yet.
Sourcepub fn action(
self,
label: impl Into<String>,
icon: IconName,
then: impl Fn(&str) + 'static,
) -> Self
pub fn action( self, label: impl Into<String>, icon: IconName, then: impl Fn(&str) + 'static, ) -> Self
A button in the bar that gets the code as it is.
Sourcepub fn download(
self,
make: impl Fn(&str) -> Result<(String, Vec<u8>), Vec<CodeDiagnostic>> + 'static,
) -> Self
pub fn download( self, make: impl Fn(&str) -> Result<(String, Vec<u8>), Vec<CodeDiagnostic>> + 'static, ) -> Self
A button that saves what make turns the code into, such as a project to build, with
the system’s dialog on a desktop or as a download in a browser. make gives the file’s
name and bytes, or the problems to mark in the code.
Sourcepub fn output_open(self, open: bool) -> Self
pub fn output_open(self, open: bool) -> Self
Whether the output starts open (it does by default). Folded, the result keeps the room, as on a small page about one example; a problem opens it all the same.
Trait Implementations§
Source§impl Debug for Playground
impl Debug for Playground
Auto Trait Implementations§
impl !RefUnwindSafe for Playground
impl !Send for Playground
impl !Sync for Playground
impl !UnwindSafe for Playground
impl Freeze for Playground
impl Unpin for Playground
impl UnsafeUnpin for Playground
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<T> ErasedDestructor for Twhere
T: 'static,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§impl<V> ViewExt for Vwhere
V: View,
impl<V> ViewExt for Vwhere
V: View,
Source§fn padding(self, padding: impl Into<Insets>) -> Styled<Self>
fn padding(self, padding: impl Into<Insets>) -> Styled<Self>
Source§fn background(self, fill: impl Into<Fill>) -> Styled<Self>
fn background(self, fill: impl Into<Fill>) -> Styled<Self>
Source§fn frame(self, width: Option<f32>, height: Option<f32>) -> Styled<Self>
fn frame(self, width: Option<f32>, height: Option<f32>) -> Styled<Self>
None keeps the content size.