diff --git a/masonry/src/doc/01_creating_app.md b/masonry/src/doc/01_creating_app.md index 6ecba075c..855474349 100644 --- a/masonry/src/doc/01_creating_app.md +++ b/masonry/src/doc/01_creating_app.md @@ -11,7 +11,7 @@ The app we'll create is identical to the to-do-list example shown in the README. Let's start with the `main()` function. -```rust +```ignore fn main() { const VERTICAL_WIDGET_SPACING: f64 = 20.0; @@ -53,7 +53,7 @@ During the course of the event loop, the widget tree will be displayed, and upda To handle user interactions, we need to implement the `AppDriver` trait: -```rust +```ignore trait AppDriver { fn on_action(&mut self, ctx: &mut DriverCtx<'_>, widget_id: WidgetId, action: Action); } @@ -65,7 +65,7 @@ That method gives our app a `DriverCtx` context, which we can use to access the We create a `Driver` struct to store a very simple app's state, and we implement the `AppDriver` trait for it: -```rust +```ignore use masonry::app_driver::{AppDriver, DriverCtx}; use masonry::{Action, WidgetId}; use masonry::widget::{Label}; @@ -112,7 +112,7 @@ We use `WidgetMut::add_child()` to add a new `Label` with the text of our In our main function, we create a `Driver` and pass it to `event_loop_runner::run`: -```rust +```ignore // ... let driver = Driver { @@ -133,7 +133,7 @@ In our main function, we create a `Driver` and pass it to `event_loop_runner::ru The last step is to create our Winit window and start our main loop. -```rust +```ignore use masonry::dpi::LogicalSize; use winit::window::Window; @@ -153,7 +153,7 @@ The last step is to create our Winit window and start our main loop. Our complete program therefore looks like this: -```rust +```ignore fn main() { const VERTICAL_WIDGET_SPACING: f64 = 20.0; diff --git a/masonry/src/doc/02_implementing_widget.md b/masonry/src/doc/02_implementing_widget.md index a6c42eaa9..53a8ef7b1 100644 --- a/masonry/src/doc/02_implementing_widget.md +++ b/masonry/src/doc/02_implementing_widget.md @@ -13,7 +13,7 @@ Widgets are types which implement the `masonry::Widget` trait. This trait includes a set of methods that must be implemented to hook into Masonry's internals: -```rust +```ignore trait Widget { fn on_pointer_event(&mut self, ctx: &mut EventCtx, event: &PointerEvent); fn on_text_event(&mut self, ctx: &mut EventCtx, event: &TextEvent); @@ -82,7 +82,7 @@ This methods returns a WidgetMut to the root widget, which you can then project The WidgetMut type only has two fields, both public: -```rust +```ignore pub struct WidgetMut<'a, W: Widget> { pub ctx: MutateCtx<'a>, pub widget: &'a mut W, @@ -106,7 +106,7 @@ This Widget has a size, a color, and emits a `ButtonPressed` action when the use First, let's create our struct: -```rust +```ignore use vello::kurbo::Size; use vello::peniko::Color; @@ -129,7 +129,7 @@ Note that we store a size, and not a position: our widget's position is picked b First we implement event methods: -```rust +```ignore use masonry::{ Widget, EventCtx, PointerEvent, TextEvent, AccessEvent, Action }; @@ -165,7 +165,7 @@ We've also implemented the `on_access_event` method, which emulates the click be Next we can leave the `on_anim_frame` and `update` implementations empty: -```rust +```ignore use masonry::{ UpdateCtx }; @@ -182,7 +182,7 @@ impl Widget for ColorRectangle { Next we implement layout: -```rust +```ignore use masonry::{ LayoutCtx, BoxConstraints }; @@ -202,7 +202,7 @@ Our size is static, and doesn't depend on size constraints passed by our parent Next we write our render methods: -```rust +```ignore use masonry::{ PaintCtx, AccessCtx }; @@ -250,7 +250,7 @@ In `accessibility`, we define a default action of `Click`, which is how we regis Finally, we stub in some additional methods: -```rust +```ignore use masonry::{ RegisterCtx, WidgetId }; @@ -277,7 +277,7 @@ Finally, we want to define some setters for external users: -```rust +```ignore struct ColorRectangle { size: Size, color: Color, diff --git a/masonry/src/doc/03_implementing_container_widget.md b/masonry/src/doc/03_implementing_container_widget.md index bf5a8c22f..5527e38c8 100644 --- a/masonry/src/doc/03_implementing_container_widget.md +++ b/masonry/src/doc/03_implementing_container_widget.md @@ -14,7 +14,7 @@ It stores handles to its children using a type called `WidgetPod`, and its `Widg As an example, let's write a `VerticalStack` widget, which lays out its children in a vertical line: -```rust +```ignore struct VerticalStack { children: Vec>>, gap: f64, @@ -34,7 +34,7 @@ impl VerticalStack { A container widget needs to pay special attention to these methods: -```rust +```ignore trait Widget { // ... @@ -65,7 +65,7 @@ When debug assertions are on, Masonry will actively try to detect cases where yo For our `VerticalStack`, we'll lay out our children in a vertical line, with a gap between each child; we give each child an equal share of the available height: -```rust +```ignore use masonry::{ LayoutCtx, BoxConstraints }; @@ -118,7 +118,7 @@ For instance, if a widget in a list changes size, its siblings and parents must In the case of our `VerticalStack`, we don't implement any transform-only changes, so we don't need to do anything in compose: -```rust +```ignore use masonry::{ LayoutCtx, BoxConstraints }; @@ -134,7 +134,7 @@ impl Widget for VerticalStack { The `register_children` method must call `RegisterCtx::register_child` for each child: -```rust +```ignore use masonry::{ Widget, RegisterCtx }; @@ -161,7 +161,7 @@ Not doing so is a logical bug, and may also trigger debug assertions. "All its children", in this context, means the children whose ids are returned by the `children_ids` method: -```rust +```ignore impl Widget for VerticalStack { // ... @@ -185,7 +185,7 @@ But how do we add them in the first place? Widgets will usually be added or removed through a `WidgetMut` wrapper. Let's write WidgetMut methods for our `VerticalStack`: -```rust +```ignore impl WidgetMut<'_, VerticalStack> { pub fn add_child(&mut self, child: WidgetPod>) { self.widget.children.push(child); @@ -214,7 +214,7 @@ Now that we've implemented our container-specific methods, we should also implem In the case of our `VerticalStack`, all of them can be left empty: -```rust +```ignore impl Widget for VerticalStack { fn on_pointer_event(&mut self, _ctx: &mut EventCtx, _event: &PointerEvent) {} fn on_text_event(&mut self, _ctx: &mut EventCtx, _event: &TextEvent) {} diff --git a/masonry/src/lib.rs b/masonry/src/lib.rs index f693e836a..6b2d9eed1 100644 --- a/masonry/src/lib.rs +++ b/masonry/src/lib.rs @@ -93,6 +93,7 @@ // #![warn(missing_docs)] #![warn(unused_imports)] #![warn(clippy::print_stdout, clippy::print_stderr, clippy::dbg_macro)] +#![allow(clippy::needless_doctest_main)] #![allow(clippy::should_implement_trait)] #![allow(clippy::single_match)] #![cfg_attr(docsrs, feature(doc_cfg))]