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 new(runner: impl Runner + 'static) -> Playground
pub fn new(runner: impl Runner + 'static) -> Playground
A playground whose code runner runs.
Sourcepub fn example(
self,
name: impl Into<String>,
source: impl Into<String>,
) -> Playground
pub fn example( self, name: impl Into<String>, source: impl Into<String>, ) -> Playground
An example to start from, listed in the bar; the first one fills the editor.
Sourcepub fn source(self, source: Binding<String>) -> Playground
pub fn source(self, source: Binding<String>) -> Playground
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>) -> Playground
pub fn chosen_example(self, example: Binding<usize>) -> Playground
Keeps which example is chosen in example.
Sourcepub fn language(self, language: CodeLanguage) -> Playground
pub fn language(self, language: CodeLanguage) -> Playground
The language the editor colors; Rust by default.
Sourcepub fn title(self, title: impl Into<String>) -> Playground
pub fn title(self, title: impl Into<String>) -> Playground
A title at the start of the bar.
Sourcepub fn note(self, note: impl Into<String>) -> Playground
pub fn note(self, note: impl Into<String>) -> Playground
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,
) -> Playground
pub fn action( self, label: impl Into<String>, icon: IconName, then: impl Fn(&str) + 'static, ) -> Playground
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,
) -> Playground
pub fn download( self, make: impl Fn(&str) -> Result<(String, Vec<u8>), Vec<CodeDiagnostic>> + 'static, ) -> Playground
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) -> Playground
pub fn output_open(self, open: bool) -> Playground
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.
Sourcepub fn height(self, height: f32) -> Playground
pub fn height(self, height: f32) -> Playground
A fixed height; by default it takes the room its parent gives.
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§
impl<T> AutoreleaseSafe for Twhere
T: ?Sized,
impl<T> AutoreleaseSafe for Twhere
T: ?Sized,
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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
impl<S, T> Duplex<S> for Twhere
T: FromSample<S> + ToSample<S>,
impl<T> ErasedDestructor for Twhere
T: 'static,
§impl<S> FromSample<S> for S
impl<S> FromSample<S> for S
fn from_sample_(s: S) -> S
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
§impl<T, U> ToSample<U> for Twhere
U: FromSample<T>,
impl<T, U> ToSample<U> for Twhere
U: FromSample<T>,
fn to_sample_(self) -> U
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.