Skip to content

Commit

Permalink
Update the rest of the chapters
Browse files Browse the repository at this point in the history
Sorry for the disorganized commits, but it would take too much
time otherwise and I think this it's too critical for this repo.
  • Loading branch information
brianch committed Jan 7, 2024
1 parent 73be7fa commit 7684641
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 11 deletions.
7 changes: 6 additions & 1 deletion src/check_result_dealing.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,14 @@ fn view(&self) -> Element<Message, iced::Renderer<theme::TwentyOneTheme>> {
} else if self.game_stage == GameStage::Tie {
game_result = text("It's a tie!!").size(50);
}
# for card in &self.dealer_hand.cards {
# dealer_row = dealer_row.push(image(String::from("img/") + &card.get_id() + ".png").height(Length::Fixed(200.)));
# }
# dealer_hand_val = self.dealer_hand.value().to_string();
# };
```

With the `Text` ready, we can jsut add it to our table_col:
With the `Text` ready, we can just add it to our table_col:

```rust
let table_col = col![
Expand Down
3 changes: 2 additions & 1 deletion src/conclusion.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ And that's it for this tutorial, I hope it helped you get more familiar with Ice
---------
<br>

[Iced's discord](https://discord.gg/3xZJ65GAhd) is a great place to ask for help if you have questions about the library.
[Iced's discord](https://discord.gg/3xZJ65GAhd) is a place where you can ask quick questions.
[Their discourse](https://discourse.iced.rs/) is a place where you can have longer discussions and is where the developers spend more time.

The docs are also quite good. Iced is split in a number of crates, check especially iced and iced_native:
- [https://docs.rs/iced/latest/iced/](https://docs.rs/iced/latest/iced/)
Expand Down
2 changes: 1 addition & 1 deletion src/face_down.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ fn update(&mut self, message: Self::Message) -> Command<Self::Message> {
But this message has to come from somewhere, so along with changing the card's image and the hand's value, we need to have a button to start the game. These are a lot of changes, so we'll need to separate our `column!` macro call in two.


We'll create the `Column` in a variable, with an `if` to check which version we want:
We'll create the `Column` in a variable, with an `if` to check which version we want, replace the `player_row` and the for below it to this:

```rust
let player_info_col = if self.game_stage == GameStage::Init {
Expand Down
2 changes: 1 addition & 1 deletion src/new_button_style.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Creating a different button style

Remember when I mentioned the Style type inside each StyleSheet at [Chapter 5](./custom_theme.md)? We can try to play with this now.
Remember when we played with the button's StyleSheet at [Chapter 5](./styling.md)? We can try to play with this now.

On our theme.rs, let's add a ButtonStyle enum with 2 variants and set this as our Style type on the stylesheet:

Expand Down
4 changes: 2 additions & 2 deletions src/radio.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ let menu_col = col![
button(text("Restart")).on_press(Message::Restart).style(theme::ButtonStyle::Menu),
Space::with_height(Length::Fixed(30.)),
text("Theme"),
Radio::new(theme::TwentyOneTheme::Green, "Green", self.color_theme, Message::ChangeTheme),
Radio::new(theme::TwentyOneTheme::Burgundy, "Burgundy", self.color_theme, Message::ChangeTheme),
Radio::new("Green", theme::TwentyOneTheme::Green, self.color_theme, Message::ChangeTheme),
Radio::new("Burgundy", theme::TwentyOneTheme::Burgundy, self.color_theme, Message::ChangeTheme),
].spacing(10),
).height(Length::Fill).center_y().width(Length::Fill).center_x().style(theme::ContainerStyle::Menu)
].align_items(iced::Alignment::Center).spacing(10).width(Length::Fixed(200.));
Expand Down
8 changes: 4 additions & 4 deletions src/subscription.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ A `Subscription` is used when you need to listen (without blocking the GUI) to e

Here our use case is super simple, we will have a Subscription that produces a message at a set interval and will deal a new card to the dealer each time until they no longer need more. `iced_futures` has a [`every()`](https://docs.rs/iced_futures/latest/iced_futures/backend/native/smol/time/fn.every.html) function that does just that.

For more normal use cases, you would probably want to use the [`subscription::unfold()`](https://docs.iced.rs/iced/subscription/fn.unfold.html) function that will run your code (which should be an async `Stream`). It's a complicated thing if you're not familiar with `async` code, but on iced's discord you can find a bunch of discussions about this, which might help you.
For more normal use cases, you would probably want to use the [`subscription::channel()`](https://docs.rs/iced/0.10.0/iced/subscription/fn.channel.html) function that will run your code (which should be an async `Stream`). It's a complicated thing if you're not familiar with `async` code, but on iced's [discord](https://discord.gg/3xZJ65GAhd) and [discourse](https://discourse.iced.rs/) you can find a bunch of discussions about this and also get help in case you need.

-----------
But let's prepare the game logic first, we need to define the `Message` the subscription will return to us when it's time to deal another card to the dealer, don't worry about the argument it receives, the `every()` function returns the time that has passed in case we need, but we don't care about it in this case:
Expand Down Expand Up @@ -52,10 +52,10 @@ We're also processing the `DealerDraw(_)` message on our `update()`, no mysterie

```

For `async` stuff Iced has three backends, `tokio`, `async-std`, and `smol`. To use the `every()` function I mentioned before, we need to choose one of these using the feature of the same name. It doesn't really matter much which one, let's go wtih smol, add it to your Cargo.toml:
For `async` stuff Iced has three backends, `tokio`, `async-std`, and `smol`. To use the `every()` function I mentioned before, we need to choose one of these using the feature of the same name. It doesn't really matter much which one, let's go with tokio here, add it to your Cargo.toml:

```sh
iced = {version = "0.8.0", features = ["image", "smol"] }
iced = {version = "0.10.0", features = ["image", "tokio"] }
```

Add these new imports to our main.rs:
Expand All @@ -66,7 +66,7 @@ use std::time::{Duration, Instant};
use iced::time;
```

This will be our `Subscription` function, place it under the `view()`:
This will be our `Subscription` function (it's an optional method of the application trait), place it under the `view()`:

```rust
fn subscription(&self) -> Subscription<Message> {
Expand Down
2 changes: 1 addition & 1 deletion src/window_modes.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Talking about `iced::window`, we can take a look at how to to make the program f

```rust
fn new(_flags: ()) -> (IcedTwentyOne, Command<Self::Message>) {
(IcedBlackjack::default(), iced::window::change_mode(iced::window::Mode::Fullscreen))
(IcedTwentyOne::default(), iced::window::change_mode(iced::window::Mode::Fullscreen))
}
```

Expand Down

0 comments on commit 7684641

Please sign in to comment.