Skip to content

Commit

Permalink
book: Disable playground globally (#1518)
Browse files Browse the repository at this point in the history
Also remove annotation from code blocks
  • Loading branch information
Hofer-Julian authored Oct 20, 2023
1 parent b9f3d73 commit d0094d7
Show file tree
Hide file tree
Showing 17 changed files with 128 additions and 127 deletions.
1 change: 1 addition & 0 deletions book/book.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ default-theme = "Rust"
git-repository-url = "https://github.com/gtk-rs/gtk4-rs/tree/master/book"
git-repository-icon = "fa-github"
additional-css = ["theme/style.css"]
playground.runnable = false
24 changes: 12 additions & 12 deletions book/src/actions.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ If that had not been the case, we would have to add the action group manually vi

Filename: <a class=file-link href="https://github.com/gtk-rs/gtk4-rs/blob/master/book/listings/actions/2/main.rs">listings/actions/2/main.rs</a>

```rust ,no_run,noplayground
```rust
{{#rustdoc_include ../listings/actions/2/main.rs:action_group}}
```

Expand All @@ -57,7 +57,7 @@ Let's see how this works.

Filename: <a class=file-link href="https://github.com/gtk-rs/gtk4-rs/blob/master/book/listings/actions/3/main.rs">listings/actions/3/main.rs</a>

```rust ,no_run,noplayground
```rust
{{#rustdoc_include ../listings/actions/3/main.rs:build_ui}}
```

Expand All @@ -83,7 +83,7 @@ With [`ButtonBuilder`](https://gtk-rs.org/gtk4-rs/stable/latest/docs/gtk4/builde

Filename: <a class=file-link href="https://github.com/gtk-rs/gtk4-rs/blob/master/book/listings/actions/4/main.rs">listings/actions/4/main.rs</a>

```rust ,no_run,noplayground
```rust
{{#rustdoc_include ../listings/actions/4/main.rs:button_builder}}
```

Expand All @@ -101,15 +101,15 @@ We will connect the actions and add them to the window in the `Window::setup_act

Filename: <a class=file-link href="https://github.com/gtk-rs/gtk4-rs/blob/master/book/listings/actions/5/window/mod.rs">listings/actions/5/window/mod.rs</a>

```rust ,no_run,noplayground
```rust
{{#rustdoc_include ../listings/actions/5/window/mod.rs:impl_window}}
```

Finally, `setup_actions` will be called within `constructed`.

Filename: <a class=file-link href="https://github.com/gtk-rs/gtk4-rs/blob/master/book/listings/actions/5/window/imp.rs">listings/actions/5/window/imp.rs</a>

```rust ,no_run,noplayground
```rust
{{#rustdoc_include ../listings/actions/5/window/imp.rs:object_impl}}
```

Expand All @@ -135,7 +135,7 @@ This means that the caller can expect the boolean state to toggle after activati

Filename: <a class=file-link href="https://github.com/gtk-rs/gtk4-rs/blob/master/book/listings/actions/6/window/mod.rs">listings/actions/6/window/mod.rs</a>

```rust ,no_run,noplayground
```rust
{{#rustdoc_include ../listings/actions/6/window/mod.rs:action_button_frame}}
```

Expand All @@ -153,7 +153,7 @@ We don't need the action state to implement orientation switching, however it is

Filename: <a class=file-link href="https://github.com/gtk-rs/gtk4-rs/blob/master/book/listings/actions/6/window/mod.rs">listings/actions/6/window/mod.rs</a>

```rust ,no_run,noplayground
```rust
{{#rustdoc_include ../listings/actions/6/window/mod.rs:action_orientation}}
```

Expand Down Expand Up @@ -255,15 +255,15 @@ Since [`gio::Settings`](https://gtk-rs.org/gtk-rs-core/stable/latest/docs/gio/st

Filename: <a class=file-link href="https://github.com/gtk-rs/gtk4-rs/blob/master/book/listings/actions/7/window/imp.rs">listings/actions/7/window/imp.rs</a>

```rust ,no_run,noplayground
```rust
{{#rustdoc_include ../listings/actions/7/window/imp.rs:imp_struct}}
```

Now we create functions to make it easier to access settings.

Filename: <a class=file-link href="https://github.com/gtk-rs/gtk4-rs/blob/master/book/listings/actions/7/window/mod.rs">listings/actions/7/window/mod.rs</a>

```rust ,no_run,noplayground
```rust
{{#rustdoc_include ../listings/actions/7/window/mod.rs:settings}}
```

Expand All @@ -273,7 +273,7 @@ We create actions with the[ `create_action`](https://gtk-rs.org/gtk-rs-core/stab

Filename: <a class=file-link href="https://github.com/gtk-rs/gtk4-rs/blob/master/book/listings/actions/7/window/mod.rs">listings/actions/7/window/mod.rs</a>

```rust ,no_run,noplayground
```rust
{{#rustdoc_include ../listings/actions/7/window/mod.rs:settings_create_actions}}
```

Expand All @@ -285,15 +285,15 @@ For the stateful actions, instead of adding callbacks to their "activate" signal

Filename: <a class=file-link href="https://github.com/gtk-rs/gtk4-rs/blob/master/book/listings/actions/7/window/mod.rs">listings/actions/7/window/mod.rs</a>

```rust ,no_run,noplayground
```rust
{{#rustdoc_include ../listings/actions/7/window/mod.rs:bind_settings}}
```

Finally, we make sure that `bind_settings` is called within `constructed`.

Filename: <a class=file-link href="https://github.com/gtk-rs/gtk4-rs/blob/master/book/listings/actions/7/window/imp.rs">listings/actions/7/window/imp.rs</a>

```rust ,no_run,noplayground
```rust
{{#rustdoc_include ../listings/actions/7/window/imp.rs:object_impl}}
```

Expand Down
32 changes: 16 additions & 16 deletions book/src/composite_templates.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Until now, whenever we constructed pre-defined widgets we relied on the [builder
As a reminder, that is how we used it to build our trusty "Hello World!" app.

Filename: <a class=file-link href="https://github.com/gtk-rs/gtk4-rs/blob/master/book/listings/hello_world/3/main.rs">listings/hello_world/3/main.rs</a>
```rust ,no_run,noplayground
```rust
{{#rustdoc_include ../listings/hello_world/3/main.rs:all}}
```

Expand Down Expand Up @@ -57,7 +57,7 @@ Then, we create a `build.rs` at the root of our package with the following conte
This will compile the resources whenever we trigger a build with cargo and then statically link our executable to them.

Filename: <a class=file-link href="https://github.com/gtk-rs/gtk4-rs/blob/master/book/listings/build.rs">listings/build.rs</a>
```rust ,no_run,noplayground
```rust
fn main() {
glib_build_tools::compile_resources(
&["composite_templates/1/resources"],
Expand All @@ -71,13 +71,13 @@ Finally, we register and include the resources by calling the macro [`gio::resou
In your own apps take care to register the resources before creating the `gtk::Application`.

Filename: <a class=file-link href="https://github.com/gtk-rs/gtk4-rs/blob/master/book/listings/composite_templates/1/main.rs">listings/composite_templates/1/main.rs</a>
```rust ,no_run,noplayground
```rust
{{#rustdoc_include ../listings/composite_templates/1/main.rs}}
```

Within our code we create a custom widget inheriting from `gtk::ApplicationWindow` to make use of our template.
Filename: <a class=file-link href="https://github.com/gtk-rs/gtk4-rs/blob/master/book/listings/composite_templates/1/window/mod.rs">listings/composite_templates/1/window/mod.rs</a>
```rust ,no_run,noplayground
```rust
{{#rustdoc_include ../listings/composite_templates/1/window/mod.rs}}
```

Expand All @@ -90,23 +90,23 @@ You use it by adding a struct member with the same name as one `id` attribute in
This will be useful later, when we want to add a callback to our button.

Filename: <a class=file-link href="https://github.com/gtk-rs/gtk4-rs/blob/master/book/listings/composite_templates/1/window/imp.rs">listings/composite_templates/1/window/imp.rs</a>
```rust ,no_run,noplayground
```rust
{{#rustdoc_include ../listings/composite_templates/1/window/imp.rs:object}}
```

Within the `ObjectSubclass` trait, we make sure that `NAME` corresponds to `class` in the template and `ParentType` corresponds to `parent` in the template.
We also bind and initialize the template in `class_init` and `instance_init`.

Filename: <a class=file-link href="https://github.com/gtk-rs/gtk4-rs/blob/master/book/listings/composite_templates/1/window/imp.rs">listings/composite_templates/1/window/imp.rs</a>
```rust ,no_run,noplayground
```rust
{{#rustdoc_include ../listings/composite_templates/1/window/imp.rs:subclass}}
```

Finally, we connect the callback to the "clicked" signal of `button` within `constructed`.
The button is easily available thanks to the stored reference in `self`.

Filename: <a class=file-link href="https://github.com/gtk-rs/gtk4-rs/blob/master/book/listings/composite_templates/1/window/imp.rs">listings/composite_templates/1/window/imp.rs</a>
```rust ,no_run,noplayground
```rust
{{#rustdoc_include ../listings/composite_templates/1/window/imp.rs:object_impl}}
```

Expand All @@ -118,21 +118,21 @@ As usual, we define the implementation struct within `imp.rs`.
Note the `NAME` we define here, we will need it later to refer to it in the template.

Filename: <a class=file-link href="https://github.com/gtk-rs/gtk4-rs/blob/master/book/listings/composite_templates/2/custom_button/imp.rs">listings/composite_templates/2/custom_button/imp.rs</a>
```rust ,no_run,noplayground
```rust
{{#rustdoc_include ../listings/composite_templates/2/custom_button/imp.rs:imp}}
```

We also define the public struct in `mod.rs`.

Filename: <a class=file-link href="https://github.com/gtk-rs/gtk4-rs/blob/master/book/listings/composite_templates/2/custom_button/mod.rs">listings/composite_templates/2/custom_button/mod.rs</a>
```rust ,no_run,noplayground
```rust
{{#rustdoc_include ../listings/composite_templates/2/custom_button/mod.rs:mod}}
```

Since we want to refer to a `CustomButton` now we also have to change the type of the template child to it.

Filename: <a class=file-link href="https://github.com/gtk-rs/gtk4-rs/blob/master/book/listings/composite_templates/2/window/imp.rs">listings/composite_templates/2/window/imp.rs</a>
```rust ,no_run,noplayground
```rust
{{#rustdoc_include ../listings/composite_templates/2/window/imp.rs:object}}
```

Expand Down Expand Up @@ -162,23 +162,23 @@ It takes a function of type `Fn(&Self)`.
This means that `handle_button_clicked` has a single parameter of type `&CustomButton`.

Filename: <a class=file-link href="https://github.com/gtk-rs/gtk4-rs/blob/master/book/listings/composite_templates/3/window/imp.rs">listings/composite_templates/3/window/imp.rs</a>
```rust ,no_run,noplayground
```rust
{{#rustdoc_include ../listings/composite_templates/3/window/imp.rs:template_callbacks}}
```

Then we have to bind the template callbacks with [`bind_template_callbacks`](https://gtk-rs.org/gtk4-rs/stable/latest/docs/gtk4/subclass/widget/trait.CompositeTemplateCallbacksClass.html#tymethod.bind_template_callbacks).
We also need to remove the `button.connect_clicked` callback implemented in `window/imp.rs`.

Filename: <a class=file-link href="https://github.com/gtk-rs/gtk4-rs/blob/master/book/listings/composite_templates/3/window/imp.rs">listings/composite_templates/3/window/imp.rs</a>
```rust ,no_run,noplayground
```rust
{{#rustdoc_include ../listings/composite_templates/3/window/imp.rs:subclass}}
```

We can also access the state of our widget.
Let's say we want to manipulate a `number` stored in `imp::Window`.

Filename: <a class=file-link href="https://github.com/gtk-rs/gtk4-rs/blob/master/book/listings/composite_templates/4/window/imp.rs">listings/composite_templates/4/window/imp.rs</a>
```rust ,no_run,noplayground
```rust
{{#rustdoc_include ../listings/composite_templates/4/window/imp.rs:object}}
```

Expand All @@ -193,7 +193,7 @@ Now we can add `&self` as first parameter to `handle_button_clicked`.
This lets us access the state of the window and therefore manipulate `number`.

Filename: <a class=file-link href="https://github.com/gtk-rs/gtk4-rs/blob/master/book/listings/composite_templates/4/window/imp.rs">listings/composite_templates/4/window/imp.rs</a>
```rust ,no_run,noplayground
```rust
{{#rustdoc_include ../listings/composite_templates/4/window/imp.rs:template_callbacks}}
```

Expand All @@ -203,7 +203,7 @@ Now that we use template callbacks we don't access the template child anymore.
Let's remove it.

Filename: <a class=file-link href="https://github.com/gtk-rs/gtk4-rs/blob/master/book/listings/composite_templates/5/window/imp.rs">listings/composite_templates/5/window/imp.rs</a>
```rust ,no_run,noplayground
```rust
{{#rustdoc_include ../listings/composite_templates/5/window/imp.rs:object}}
```

Expand All @@ -220,7 +220,7 @@ It also ensures that the widget type is registered.
Luckily we can also do that by ourselves.

Filename: <a class=file-link href="https://github.com/gtk-rs/gtk4-rs/blob/master/book/listings/composite_templates/6/window/imp.rs">listings/composite_templates/6/window/imp.rs</a>
```rust ,no_run,noplayground
```rust
{{#rustdoc_include ../listings/composite_templates/6/window/imp.rs:subclass}}
```

Expand Down
14 changes: 7 additions & 7 deletions book/src/css.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ As usual, the widgets are created during the "activate" step.

Filename: <a class=file-link href="https://github.com/gtk-rs/gtk4-rs/blob/master/book/listings/css/1/main.rs">listings/css/1/main.rs</a>

```rust ,no_run,noplayground
```rust
{{#rustdoc_include ../listings/css/1/main.rs:main}}
```

Expand Down Expand Up @@ -71,7 +71,7 @@ Which is why we add the style class `button-1` to the first one.

Filename: <a class=file-link href="https://github.com/gtk-rs/gtk4-rs/blob/master/book/listings/css/3/main.rs">listings/css/3/main.rs</a>

```rust ,no_run,noplayground
```rust
{{#rustdoc_include ../listings/css/3/main.rs:buttons}}
```

Expand Down Expand Up @@ -100,7 +100,7 @@ We set the name of the first one with [`set_widget_name`](https://gtk-rs.org/gtk

Filename: <a class=file-link href="https://github.com/gtk-rs/gtk4-rs/blob/master/book/listings/css/4/main.rs">listings/css/4/main.rs</a>

```rust ,no_run,noplayground
```rust
{{#rustdoc_include ../listings/css/4/main.rs:buttons}}
```

Expand All @@ -127,7 +127,7 @@ Most widgets will document these rules in their documentation under [CSS nodes](

Filename: <a class=file-link href="https://github.com/gtk-rs/gtk4-rs/blob/master/book/listings/css/5/main.rs">listings/css/5/main.rs</a>

```rust ,no_run,noplayground
```rust
{{#rustdoc_include ../listings/css/5/main.rs:buttons}}
```

Expand Down Expand Up @@ -232,7 +232,7 @@ In our case, the widget `TaskRow` then corresponds to the node `task-row`.

Filename: <a class=file-link href="https://github.com/gtk-rs/gtk4-rs/blob/master/book/listings/todo/3/task_row/imp.rs">listings/todo/3/task_row/imp.rs</a>

```rust ,no_run,noplayground
```rust
{{#rustdoc_include ../listings/todo/3/task_row/imp.rs:object_subclass}}
```

Expand Down Expand Up @@ -274,14 +274,14 @@ Additionally, we call `load_css()` in `connect_startup`.

Filename: <a class=file-link href="https://github.com/gtk-rs/gtk4-rs/blob/master/book/listings/todo/3/main.rs">listings/todo/3/main.rs</a>

```rust ,no_run,noplayground
```rust
{{#rustdoc_include ../listings/todo/3/main.rs:connect_startup}}
```

`load_css()` is very similar to the one shown at the beginning of the chapter.
However, this time we load styles using `load_from_resource()`.

```rust ,no_run,noplayground
```rust
{{#rustdoc_include ../listings/todo/3/main.rs:load_css}}
```

Expand Down
14 changes: 7 additions & 7 deletions book/src/g_object_memory_management.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ We need a data type with interior mutability like [`std::cell::Cell`](https://do
Filename: <a class=file-link href="https://github.com/gtk-rs/gtk4-rs/blob/master/book/listings/g_object_memory_management/2/main.rs">listings/g_object_memory_management/1/main.rs</a>

```rust ,no_run,noplayground
```rust
{{#rustdoc_include ../listings/g_object_memory_management/1/main.rs:build_ui}}
```

Expand All @@ -172,7 +172,7 @@ we can again use the [`Cell`](https://doc.rust-lang.org/std/cell/struct.Cell.htm

Filename: <a class=file-link href="https://github.com/gtk-rs/gtk4-rs/blob/master/book/listings/g_object_memory_management/2/main.rs">listings/g_object_memory_management/2/main.rs</a>

```rust ,no_run,noplayground
```rust
{{#rustdoc_include ../listings/g_object_memory_management/2/main.rs:callback}}
```

Expand All @@ -181,7 +181,7 @@ We can improve that by using the [`glib::clone!`](https://gtk-rs.org/gtk-rs-core

Filename: <a class=file-link href="https://github.com/gtk-rs/gtk4-rs/blob/master/book/listings/g_object_memory_management/3/main.rs">listings/g_object_memory_management/3/main.rs</a>

```rust ,no_run,noplayground
```rust
{{#rustdoc_include ../listings/g_object_memory_management/3/main.rs:callback}}
```

Expand All @@ -190,7 +190,7 @@ Therefore, we can pass the buttons the same way to the closure as we did with `n

Filename: <a class=file-link href="https://github.com/gtk-rs/gtk4-rs/blob/master/book/listings/g_object_memory_management/4/main.rs">listings/g_object_memory_management/4/main.rs</a>

```rust ,no_run,noplayground
```rust
{{#rustdoc_include ../listings/g_object_memory_management/4/main.rs:callback}}
```

Expand All @@ -207,7 +207,7 @@ Since we want our apps to free unneeded memory, we should use weak references fo

Filename: <a class=file-link href="https://github.com/gtk-rs/gtk4-rs/blob/master/book/listings/g_object_memory_management/5/main.rs">listings/g_object_memory_management/5/main.rs</a>

```rust ,no_run,noplayground
```rust
{{#rustdoc_include ../listings/g_object_memory_management/5/main.rs:callback}}
```

Expand All @@ -224,15 +224,15 @@ Who then keeps the buttons alive?

Filename: <a class=file-link href="https://github.com/gtk-rs/gtk4-rs/blob/master/book/listings/g_object_memory_management/5/main.rs">listings/g_object_memory_management/5/main.rs</a>

```rust ,no_run,noplayground
```rust
{{#rustdoc_include ../listings/g_object_memory_management/5/main.rs:box_append}}
```

When we append the buttons to the `gtk_box`, `gtk_box` keeps a strong reference to them.

Filename: <a class=file-link href="https://github.com/gtk-rs/gtk4-rs/blob/master/book/listings/g_object_memory_management/5/main.rs">listings/g_object_memory_management/5/main.rs</a>

```rust ,no_run,noplayground
```rust
{{#rustdoc_include ../listings/g_object_memory_management/5/main.rs:window_child}}
```

Expand Down
Loading

0 comments on commit d0094d7

Please sign in to comment.