Skip to content

Commit

Permalink
book: Check links with lychee (#1499)
Browse files Browse the repository at this point in the history
* book: Check links with lychee

* Update book.yml

* Update book.yml
  • Loading branch information
Hofer-Julian committed Sep 26, 2023
1 parent e7ca908 commit eabd494
Show file tree
Hide file tree
Showing 13 changed files with 62 additions and 56 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/book.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ jobs:

- run: mdbook build -d public
working-directory: book

- name: Link Checker
uses: lycheeverse/lychee-action@v1.8.0
with:
args: book/public
fail: true

- name: Deploy to stable
uses: peaceiris/actions-gh-pages@v3
Expand Down
16 changes: 8 additions & 8 deletions book/src/actions.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ Filename: <a class=file-link href="https://github.com/gtk-rs/gtk4-rs/blob/master
```

One of the most popular reasons to use actions are keyboard accelerators, so we added one here.
With [`set_accels_for_action`](../docs/gtk4/prelude/trait.GtkApplicationExt.html#tymethod.set_accels_for_action) one can assign one or more accelerators to a certain action.
Check the documentation of [`accelerator_parse`](../docs/gtk4/functions/fn.accelerator_parse.html) in order to learn more about its syntax.
With [`set_accels_for_action`](https://gtk-rs.org/gtk4-rs/stable/latest/docs/gtk4/prelude/trait.GtkApplicationExt.html#tymethod.set_accels_for_action) one can assign one or more accelerators to a certain action.
Check the documentation of [`accelerator_parse`](https://gtk-rs.org/gtk4-rs/stable/latest/docs/gtk4/functions/fn.accelerator_parse.html) in order to learn more about its syntax.

Before we move on to other aspects of actions, let's appreciate a few things that are curious here.
The "win" part of "win.close" is the group of the action.
Expand All @@ -47,7 +47,7 @@ However, that also means that we actually define one action per window instance.
If we want to have a single globally accessible action instead, we call `add_action` on our application instead.

> Adding "win.close" was useful as a simple example.
> However, in the future we will use the pre-defined ["window.close"](../docs/gtk4/struct.Window.html#actions) action which does exactly the same thing.
> However, in the future we will use the pre-defined ["window.close"](https://gtk-rs.org/gtk4-rs/stable/latest/docs/gtk4/struct.Window.html#actions) action which does exactly the same thing.
## Parameter and State

Expand Down Expand Up @@ -76,10 +76,10 @@ This is how our app works:

## Actionable

Connecting actions to the "clicked" signal of buttons is a typical use case, which is why all buttons implement the [`Actionable`](../docs/gtk4/struct.Actionable.html) interface.
Connecting actions to the "clicked" signal of buttons is a typical use case, which is why all buttons implement the [`Actionable`](https://gtk-rs.org/gtk4-rs/stable/latest/docs/gtk4/struct.Actionable.html) interface.
This way, the action can be specified by setting the "action-name" property.
If the action accepts a parameter, it can be set via the "action-target" property.
With [`ButtonBuilder`](../docs/gtk4/builders/struct.ButtonBuilder.html), we can set everything up by calling its methods.
With [`ButtonBuilder`](https://gtk-rs.org/gtk4-rs/stable/latest/docs/gtk4/builders/struct.ButtonBuilder.html), we can set everything up by calling its methods.

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>

Expand Down Expand Up @@ -206,8 +206,8 @@ Filename: <a class=file-link href="https://github.com/gtk-rs/gtk4-rs/blob/master
<property name="orientation">vertical</property>
```

Since we connect the menu to the [`gtk::MenuButton`](../docs/gtk4/struct.MenuButton.html) via the [menu-model](../docs/gtk4/struct.MenuButton.html#menu-model) property, the `Menu` is expected to be a [`gtk::PopoverMenu`](../docs/gtk4/struct.PopoverMenu.html).
The [documentation](../docs/gtk4/struct.PopoverMenu.html) for `PopoverMenu` also explains its `xml` syntax for the interface builder.
Since we connect the menu to the [`gtk::MenuButton`](https://gtk-rs.org/gtk4-rs/stable/latest/docs/gtk4/struct.MenuButton.html) via the [menu-model](https://gtk-rs.org/gtk4-rs/stable/latest/docs/gtk4/struct.MenuButton.html#menu-model) property, the `Menu` is expected to be a [`gtk::PopoverMenu`](https://gtk-rs.org/gtk4-rs/stable/latest/docs/gtk4/struct.PopoverMenu.html).
The [documentation](https://gtk-rs.org/gtk4-rs/stable/latest/docs/gtk4/struct.PopoverMenu.html) for `PopoverMenu` also explains its `xml` syntax for the interface builder.

Also note how we specified the target:

Expand All @@ -234,7 +234,7 @@ This is how the app looks in action:
</div>

>We changed the icon of the `MenuButton` by setting its property "icon-name" to "open-menu-symbolic".
>You can find more icons with the [Icon Library](https://apps.gnome.org/app/org.gnome.design.IconLibrary/).
>You can find more icons with the [Icon Library](https://flathub.org/apps/org.gnome.design.IconLibrary).
>They can be embedded with [`gio::Resource`](https://gtk-rs.org/gtk-rs-core/stable/latest/docs/gio/struct.Resource.html) and then be referenced within the composite templates (or other places).
## Settings
Expand Down
16 changes: 8 additions & 8 deletions book/src/composite_templates.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ Filename: <a class=file-link href="https://github.com/gtk-rs/gtk4-rs/blob/master

The most outer tag always has to be the `<interface>`.
Then you start listing the elements you want to describe.
In order to define a composite template, we specify the name `MyGtkAppWindow` of the custom widget we want to create and the parent [`gtk::ApplicationWindow`](../docs/gtk4/struct.ApplicationWindow.html) it derives of.
In order to define a composite template, we specify the name `MyGtkAppWindow` of the custom widget we want to create and the parent [`gtk::ApplicationWindow`](https://gtk-rs.org/gtk4-rs/stable/latest/docs/gtk4/struct.ApplicationWindow.html) it derives of.
These `xml` files are independent of the programming language, which is why the classes have the original names.
Luckily, they all convert like this: `gtk::ApplicationWindow``GtkApplicationWindow`.
Then we can specify properties which are listed [here](../docs/gtk4/struct.ApplicationWindow.html#properties) for `ApplicationWindow`.
Then we can specify properties which are listed [here](https://gtk-rs.org/gtk4-rs/stable/latest/docs/gtk4/struct.ApplicationWindow.html#properties) for `ApplicationWindow`.
Since `ApplicationWindow` can contain other widgets we use the `<child>` tag to add a `gtk::Button`.
We want to be able to refer to the button later on so we also set its `id`.

Expand Down Expand Up @@ -81,12 +81,12 @@ Filename: <a class=file-link href="https://github.com/gtk-rs/gtk4-rs/blob/master
{{#rustdoc_include ../listings/composite_templates/1/window/mod.rs}}
```

In the implementation struct, we then add the derive macro [`gtk::CompositeTemplate`](../docs/gtk4_macros/derive.CompositeTemplate.html).
In the implementation struct, we then add the derive macro [`gtk::CompositeTemplate`](https://gtk-rs.org/gtk4-rs/stable/latest/docs/gtk4_macros/derive.CompositeTemplate.html).
We also specify that the template information comes from a resource of prefix `/org/gtk-rs/example` containing a file `window.ui`.

One very convenient feature of templates is the template child.
You use it by adding a struct member with the same name as one `id` attribute in the template.
[`TemplateChild`](../docs/gtk4/subclass/widget/struct.TemplateChild.html) then stores a reference to the widget for later use.
[`TemplateChild`](https://gtk-rs.org/gtk4-rs/stable/latest/docs/gtk4/subclass/widget/struct.TemplateChild.html) then stores a reference to the widget for later use.
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>
Expand Down Expand Up @@ -154,9 +154,9 @@ Filename: <a class=file-link href="https://github.com/gtk-rs/gtk4-rs/blob/master
{{#rustdoc_include ../listings/composite_templates/3/resources/window.ui}}
```

Then we define the `handle_button_clicked` with the [`template_callbacks`](../docs/gtk4_macros/attr.template_callbacks.html) macro applied to it.
Then we define the `handle_button_clicked` with the [`template_callbacks`](https://gtk-rs.org/gtk4-rs/stable/latest/docs/gtk4_macros/attr.template_callbacks.html) macro applied to it.
We can determine the function signature by having a look at the `connect_*` method of the signal we want to handle.
In our case that would be [`connect_clicked`](../docs/gtk4/prelude/trait.ButtonExt.html#tymethod.connect_clicked).
In our case that would be [`connect_clicked`](https://gtk-rs.org/gtk4-rs/stable/latest/docs/gtk4/prelude/trait.ButtonExt.html#tymethod.connect_clicked).
It takes a function of type `Fn(&Self)`.
`Self` refers to our button.
This means that `handle_button_clicked` has a single parameter of type `&CustomButton`.
Expand All @@ -166,7 +166,7 @@ Filename: <a class=file-link href="https://github.com/gtk-rs/gtk4-rs/blob/master
{{#rustdoc_include ../listings/composite_templates/3/window/imp.rs:template_callbacks}}
```

Then we have to bind the template callbacks with [`bind_template_callbacks`](../docs/gtk4/subclass/widget/trait.CompositeTemplateCallbacksClass.html#tymethod.bind_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>
Expand Down Expand Up @@ -240,7 +240,7 @@ Thanks to composite templates we can
- specify handler functions for signals.

The API involved here is extensive so especially at the beginning you will want to check out the documentation.
The basic syntax of the `ui` files is explained within [`Builder`](../docs/gtk4/struct.Builder.html#gtkbuilder-ui-definitions), syntax specific to widgets within [`Widget`](../docs/gtk4/struct.Widget.html#gtkwidget-as-gtkbuildable).
The basic syntax of the `ui` files is explained within [`Builder`](https://gtk-rs.org/gtk4-rs/stable/latest/docs/gtk4/struct.Builder.html#gtkbuilder-ui-definitions), syntax specific to widgets within [`Widget`](https://gtk-rs.org/gtk4-rs/stable/latest/docs/gtk4/struct.Widget.html#gtkwidget-as-gtkbuildable).
If a certain widget accepts additional element, then they are typically explained in the docs of the widget.

In the following chapter, we will see how composite templates help us to create slightly bigger apps such as a To-Do app.
16 changes: 8 additions & 8 deletions book/src/css.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ We did not specify for which button the rule should apply, so it was applied to
[Class selectors](https://developer.mozilla.org/en-US/docs/Web/CSS/Class_selectors) are one way to choose which specific elements a CSS rule applies to.
GTK adds style classes to many of its widgets, often depending on their content.
A [`gtk::Button`](../docs/gtk4/struct.Button.html#css-nodes), for example, will get the `text-button` style class when its content is a label.
A [`gtk::Button`](https://gtk-rs.org/gtk4-rs/stable/latest/docs/gtk4/struct.Button.html#css-nodes), for example, will get the `text-button` style class when its content is a label.
That is why we create a new CSS rule which only applies to `button` nodes with the style class `text_button`.
Expand All @@ -63,7 +63,7 @@ Now only the font of our button becomes magenta.

## Adding Your Own Style Class

With [`add_css_class`](../docs/gtk4/prelude/trait.WidgetExt.html#tymethod.add_css_class) we can also add our own style classes to widgets.
With [`add_css_class`](https://gtk-rs.org/gtk4-rs/stable/latest/docs/gtk4/prelude/trait.WidgetExt.html#tymethod.add_css_class) we can also add our own style classes to widgets.
One use-case for this is when you want a rule to apply to a hand-picked set of widgets.
For example if we have two buttons, but want only one of them to have magenta font.
Relying on one of the style classes which GTK adds will not help since both will get the same ones.
Expand Down Expand Up @@ -96,7 +96,7 @@ Ideally however, you would give the widget a name and match with that name inste
This way your intentions are more clear, compared to matching with style classes that can apply to multiple widgets.

Again, we have two buttons but want to color only one of them magenta.
We set the name of the first one with [`set_widget_name`](../docs/gtk4/prelude/trait.WidgetExt.html#tymethod.set_widget_name).
We set the name of the first one with [`set_widget_name`](https://gtk-rs.org/gtk4-rs/stable/latest/docs/gtk4/prelude/trait.WidgetExt.html#tymethod.set_widget_name).

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>

Expand All @@ -123,7 +123,7 @@ Again, the style rule only applies to the first button.
Certain styles are common enough that GTK provides CSS rules for them.
For example, if you want to indicate that your button leads to a destructive or suggested action you don't have to provide your own CSS rules.
All you have to do is to add "destructive-action" or "suggested-action" style class to your button.
Most widgets will document these rules in their documentation under [CSS nodes](../docs/gtk4/struct.Button.html#css-nodes).
Most widgets will document these rules in their documentation under [CSS nodes](https://gtk-rs.org/gtk4-rs/stable/latest/docs/gtk4/struct.Button.html#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>

Expand All @@ -137,7 +137,7 @@ Filename: <a class=file-link href="https://github.com/gtk-rs/gtk4-rs/blob/master

We can also add style classes with the interface builder.
Just add the `<style>` element to your widget.
The `<style>` element is documented together with [`gtk::Widget`](../docs/gtk4/struct.Widget.html#gtkwidget-as-gtkbuildable).
The `<style>` element is documented together with [`gtk::Widget`](https://gtk-rs.org/gtk4-rs/stable/latest/docs/gtk4/struct.Widget.html#gtkwidget-as-gtkbuildable).
Adding again destructive and suggested buttons, would then look like this:

Filename: <a class=file-link href="https://github.com/gtk-rs/gtk4-rs/blob/master/book/listings/css/6/window/window.ui">listings/css/6/window/window.ui</a>
Expand Down Expand Up @@ -181,7 +181,7 @@ After we removed the cursor, the button returns to its original state.

In the previous examples, a widget always corresponded to a single CSS node.
This is not always the case.
For example, [`gtk::MenuButton`](../docs/gtk4/struct.MenuButton.html) has multiple CSS nodes.
For example, [`gtk::MenuButton`](https://gtk-rs.org/gtk4-rs/stable/latest/docs/gtk4/struct.MenuButton.html) has multiple CSS nodes.
Let's see how that works.

First, we create a single `MenuButton`.
Expand All @@ -195,7 +195,7 @@ Filename: <a class=file-link href="https://github.com/gtk-rs/gtk4-rs/blob/master
You can make a `MenuButton` show an icon or a label.
If you choose to do neither of those, as we currently do, it shows an image displaying an arrow.

An inheritance tree of [CSS nodes](../docs/gtk4/struct.MenuButton.html#css-nodes) displays this situation:
An inheritance tree of [CSS nodes](https://gtk-rs.org/gtk4-rs/stable/latest/docs/gtk4/struct.MenuButton.html#css-nodes) displays this situation:

```
menubutton
Expand Down Expand Up @@ -227,7 +227,7 @@ Let's see how to deal with this situation by messing with our To-Do app once mor
The class `TaskRow` inherits from `gtk::Box`, so we could just match for the node `box`.
However, in that case we would also match with other instance of `gtk::Box`.
What we will want to do instead is to give `TaskRow` its own CSS name.
When calling [`set_css_name` ](../docs/gtk4/subclass/widget/trait.WidgetClassSubclassExt.html#method.set_css_name), we change the name of the CSS node of the widget class.
When calling [`set_css_name` ](https://gtk-rs.org/gtk4-rs/stable/latest/docs/gtk4/subclass/widget/trait.WidgetClassExt.html#method.set_css_name), we change the name of the CSS node of the widget class.
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>
Expand Down
4 changes: 2 additions & 2 deletions book/src/g_object_properties.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
Properties provide a public API for accessing state of GObjects.

Let's see how this is done by experimenting with the [`Switch`](https://gtk-rs.org/gtk4-rs/stable/latest/docs/gtk4/struct.Switch.html) widget.
One of its properties is called [active](../docs/gtk4/struct.Switch.html#active).
One of its properties is called [active](https://gtk-rs.org/gtk4-rs/stable/latest/docs/gtk4/struct.Switch.html#active).
According to the GTK docs, it can be read and be written to.
That is why `gtk-rs` provides corresponding [`is_active`](../docs/gtk4/struct.Switch.html#method.is_active) and [`set_active`](../docs/gtk4/struct.Switch.html#method.set_active) methods.
That is why `gtk-rs` provides corresponding [`is_active`](https://gtk-rs.org/gtk4-rs/stable/latest/docs/gtk4/struct.Switch.html#method.is_active) and [`set_active`](https://gtk-rs.org/gtk4-rs/stable/latest/docs/gtk4/struct.Switch.html#method.set_active) methods.

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

Expand Down
2 changes: 1 addition & 1 deletion book/src/g_object_signals.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ For example, if we press on a button, the "clicked" signal will be emitted.
The signal then takes care that all the registered callbacks will be executed.

`gtk-rs` provides convenience methods for registering callbacks.
In our "Hello World" example we [connected](../docs/gtk4/prelude/trait.ButtonExt.html#tymethod.connect_clicked) the "clicked" signal to a closure which sets the label of the button to "Hello World" as soon as it gets called.
In our "Hello World" example we [connected](https://gtk-rs.org/gtk4-rs/stable/latest/docs/gtk4/prelude/trait.ButtonExt.html#tymethod.connect_clicked) the "clicked" signal to a closure which sets the label of the button to "Hello World" as soon as it gets called.

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>

Expand Down
4 changes: 2 additions & 2 deletions book/src/hello_world.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Now that we've got a working installation, let's get right into it!

At the very least, we need to create a [`gtk::Application`](../docs/gtk4/struct.Application.html) instance with an [application id](https://developer.gnome.org/documentation/tutorials/application-id.html).
At the very least, we need to create a [`gtk::Application`](https://gtk-rs.org/gtk4-rs/stable/latest/docs/gtk4/struct.Application.html) instance with an [application id](https://developer.gnome.org/documentation/tutorials/application-id.html).
For that we use the [builder pattern](https://rust-unofficial.github.io/patterns/patterns/creational/builder.html) which many `gtk-rs` objects support.
Note that we also import the prelude to bring the necessary traits into scope.

Expand All @@ -20,7 +20,7 @@ and has no handlers connected to the 'activate' signal. It should do one of thes
```

GTK tells us that something should be called in its `activate` step.
So let's create a [`gtk::ApplicationWindow`](../docs/gtk4/struct.ApplicationWindow.html) there.
So let's create a [`gtk::ApplicationWindow`](https://gtk-rs.org/gtk4-rs/stable/latest/docs/gtk4/struct.ApplicationWindow.html) there.

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

Expand Down
Loading

0 comments on commit eabd494

Please sign in to comment.