Skip to content

Commit

Permalink
Draft 'add_text' is ready
Browse files Browse the repository at this point in the history
  • Loading branch information
richelbilderbeek committed Aug 10, 2024
1 parent ed57907 commit 06eba8a
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions docs/chapters/add_text.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,17 @@ Where [the previous chapter](add_player_sprite_with_texture.md)
needed to have `app.update()` to prevent a panic,
here we have a different reason:
would we add `app.update()` in the `create_app` function,
our text will not be shown in a regular run!
our text will not be shown in a regular run:

![This game when `app.update()` is added to `create_app`](add_text_no_text_shown.png)

> This game when `app.update()` is added to `create_app`: no text is visible
The reason is, again, that calling `app.update()` finalizes the `App`'s
currents state. When then, in the `main` function, the default plugins
are added, something happens to the already initialized text
making it not appear.

## 2.6.6. Third fix

To make this test pass, we need to:
Expand Down Expand Up @@ -148,7 +153,8 @@ fn add_text(mut commands: Commands, str: &String) {

Most of this function is similar to adding a `SpriteBundle`.
It may come as a surprise that the `text` field is more than just
a `String`: a `Text` contains multiple `TextSection`s.
a `String`: a `Text` contains multiple `TextSection`s,
of which each `TextSection` can have its own text and style.

## 2.6.7. Fourth test: an `App` has the correct text

Expand All @@ -164,6 +170,9 @@ fn test_app_uses_text() {
}
```

In ths test, our `text` string needs to be cloned
and the Rust compiler will remind us of that.

## 2.6.8. Fourth fix

If your implementations matched the earlier fixes, this test would already
Expand Down

0 comments on commit 06eba8a

Please sign in to comment.