Skip to content

Commit

Permalink
Fix build errors
Browse files Browse the repository at this point in the history
  • Loading branch information
PoignardAzur committed Oct 22, 2024
1 parent a2e4329 commit 8b8edb4
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 23 deletions.
12 changes: 6 additions & 6 deletions masonry/src/doc/01_creating_app.md
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
Expand All @@ -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};
Expand Down Expand Up @@ -112,7 +112,7 @@ We use `WidgetMut<Flex>::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 {
Expand All @@ -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;
Expand All @@ -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;
Expand Down
18 changes: 9 additions & 9 deletions masonry/src/doc/02_implementing_widget.md
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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,
Expand All @@ -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;
Expand All @@ -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
};
Expand Down Expand Up @@ -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
};
Expand All @@ -182,7 +182,7 @@ impl Widget for ColorRectangle {

Next we implement layout:

```rust
```ignore
use masonry::{
LayoutCtx, BoxConstraints
};
Expand All @@ -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
};
Expand Down Expand Up @@ -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
};
Expand All @@ -277,7 +277,7 @@ Finally, we want to define some setters for external users:

<!-- TODO - Rewrite once we've decided how WidgetMut should be implemented. -->

```rust
```ignore
struct ColorRectangle {
size: Size,
color: Color,
Expand Down
16 changes: 8 additions & 8 deletions masonry/src/doc/03_implementing_container_widget.md
Original file line number Diff line number Diff line change
Expand Up @@ -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<WidgetPod<Box<dyn Widget>>>,
gap: f64,
Expand All @@ -34,7 +34,7 @@ impl VerticalStack {

A container widget needs to pay special attention to these methods:

```rust
```ignore
trait Widget {
// ...
Expand Down Expand Up @@ -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
};
Expand Down Expand Up @@ -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
};
Expand All @@ -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
};
Expand All @@ -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 {
// ...
Expand All @@ -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<Box<dyn Widget>>) {
self.widget.children.push(child);
Expand Down Expand Up @@ -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) {}
Expand Down
1 change: 1 addition & 0 deletions masonry/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))]
Expand Down

0 comments on commit 8b8edb4

Please sign in to comment.