Skip to content

Commit cfc522f

Browse files
committed
deploy: 9d62ab8
1 parent be2a0f7 commit cfc522f

File tree

3 files changed

+44
-44
lines changed

3 files changed

+44
-44
lines changed

first-steps.html

+14-14
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ <h2 id="update-logic"><a class="header" href="#update-logic">Update Logic</a></h
224224
and most idiomatic way to express this logic in Rust is by defining a method named <code>update</code> in our application state.</p>
225225
<p>For our counter interface, we only need to properly increment or decrement the <code>value</code> of our <code>Counter</code> struct based on the <code>Message</code>
226226
we just defined:</p>
227-
<pre><code class="language-rust">impl Counter {
227+
<pre><code class="language-rust ignore">impl Counter {
228228
fn update(&amp;mut self, message: Message) {
229229
match message {
230230
Message::Increment =&gt; {
@@ -237,16 +237,16 @@ <h2 id="update-logic"><a class="header" href="#update-logic">Update Logic</a></h
237237
}
238238
}</code></pre>
239239
<p>Great! Now we are ready to process user interactions. For instance, imagine we initialized our counter like this:</p>
240-
<pre><code class="language-rust">let mut counter = Counter { value: 0 };</code></pre>
240+
<pre><code class="language-rust ignore">let mut counter = Counter { value: 0 };</code></pre>
241241
<p>And let's say we wanted to simulate a user playing with our interface for a bit—pressing the increment button twice
242242
and then the decrement button once. We could easily compute the final state of our counter with our <strong>update logic</strong>:</p>
243-
<pre><code class="language-rust">counter.update(Message::Increment);
243+
<pre><code class="language-rust ignore">counter.update(Message::Increment);
244244
counter.update(Message::Increment);
245245
counter.update(Message::Decrement);</code></pre>
246246
<p>This would cause our <code>Counter</code> to end up with a <code>value</code> of <code>1</code>:</p>
247-
<pre><code class="language-rust">assert_eq!(counter.value, 1);</code></pre>
247+
<pre><code class="language-rust ignore">assert_eq!(counter.value, 1);</code></pre>
248248
<p>In fact, we have just written a simple test for our application logic:</p>
249-
<pre><code class="language-rust">#[test]
249+
<pre><code class="language-rust ignore">#[test]
250250
fn it_counts_properly() {
251251
let mut counter = Counter { value: 0 };
252252

@@ -280,7 +280,7 @@ <h3 id="the-buttons"><a class="header" href="#the-buttons">The Buttons</a></h3>
280280
<p>In iced, widgets are independent values. The same way you can have an integer in a variable, you can have a widget as well.
281281
These values are normally created using a <em>helper function</em> from the <code>widget</code> module.</p>
282282
<p>For our buttons, we can use the <code>button</code> helper:</p>
283-
<pre><code class="language-rust">use iced::widget::button;
283+
<pre><code class="language-rust ignore">use iced::widget::button;
284284

285285
let increment = button("+");
286286
let decrement = button("-");</code></pre>
@@ -292,7 +292,7 @@ <h3 id="the-number"><a class="header" href="#the-number">The Number</a></h3>
292292
for our counter value?</p>
293293
<p>While iced does not really have a <code>number</code> widget, it does have a more generic <code>text</code> widget that can be used
294294
to display any kind of text—numbers included:</p>
295-
<pre><code class="language-rust">use iced::widget::text;
295+
<pre><code class="language-rust ignore">use iced::widget::text;
296296

297297
let counter = text(15);</code></pre>
298298
<p>Sweet! Like <code>button</code>, <code>text</code> also takes an argument used to describe its contents. Since we are just getting started, let's
@@ -302,14 +302,14 @@ <h3 id="the-layout"><a class="header" href="#the-layout">The Layout</a></h3>
302302
<p>Not so fast! The widgets in our counter interface are displayed in a specific <strong>order</strong>. Given our three widgets, there is a total of
303303
<strong>six</strong> different ways to order them! However, the order we want is: <code>increment</code>, <code>counter</code>, and <code>decrement</code>.</p>
304304
<p>A very simple way of describing this order is to create a list with our widgets:</p>
305-
<pre><code class="language-rust">let interface = vec![increment, counter, decrement];</code></pre>
305+
<pre><code class="language-rust ignore">let interface = vec![increment, counter, decrement];</code></pre>
306306
<p>But we are still missing something! It's not only the order that is specific, our interface also has a specific visual <strong>layout</strong>.</p>
307307
<p>The widgets are positioned on top of each other, but they could very well be positioned from left to right instead. There is nothing
308308
in our description so far that talks about the <strong>layout</strong> of our widgets.</p>
309309
<p>In iced, layout is described using... well, more widgets! That's right. Not all widgets produce visual results directly; some may simply
310310
manage the position of existing widgets. And since widgets are just values, they can be nested and composed nicely!</p>
311311
<p>The kind of vertical layout that we need for our counter can be achieved with the <code>column</code> widget:</p>
312-
<pre><code class="language-rust">use iced::widget::column;
312+
<pre><code class="language-rust ignore">use iced::widget::column;
313313

314314
let interface = column![increment, counter, decrement];</code></pre>
315315
<p>This is very similar to our previous snippet! iced provides a <code>column!</code> macro for creating a <code>column</code> out of some widgets in a particular
@@ -323,7 +323,7 @@ <h3 id="the-interactions"><a class="header" href="#the-interactions">The Interac
323323
<p>In iced, every widget has a specific type that enables further configuration using simple builder methods. The <code>button</code>
324324
helper returns an instance of <a href="https://docs.rs/iced/0.12.1/iced/widget/struct.Button.html">the <code>Button</code> type</a>, which has an <code>on_press</code> method we can use to define the message it must
325325
<strong>produce</strong> when a user presses the button:</p>
326-
<pre><code class="language-rust">use iced::widget::button;
326+
<pre><code class="language-rust ignore">use iced::widget::button;
327327

328328
let increment = button("+").on_press(Message::Increment);
329329
let decrement = button("-").on_press(Message::Decrement);</code></pre>
@@ -340,7 +340,7 @@ <h3 id="the-interactions"><a class="header" href="#the-interactions">The Interac
340340
<h3 id="the-view"><a class="header" href="#the-view">The View</a></h3>
341341
<p>We are almost there! There is only one thing left to do: connecting our application <strong>state</strong> to the view logic.</p>
342342
<p>Let's bring together all the view logic we have written so far:</p>
343-
<pre><code class="language-rust">use iced::widget::{button, column, text};
343+
<pre><code class="language-rust ignore">use iced::widget::{button, column, text};
344344

345345
// The buttons
346346
let increment = button("+").on_press(Message::Increment);
@@ -357,7 +357,7 @@ <h3 id="the-view"><a class="header" href="#the-view">The View</a></h3>
357357
we want is to actually display the <code>value</code> field of our <code>Counter</code> state. This way, when a button is pressed and
358358
our update logic is triggered, the text widget will display the new <code>value</code>.</p>
359359
<p>We can easily do this by running our view logic in a method of our <code>Counter</code>—just like we did with our update logic:</p>
360-
<pre><code class="language-rust">use iced::widget::{button, column, text};
360+
<pre><code class="language-rust ignore">use iced::widget::{button, column, text};
361361

362362
impl Counter {
363363
fn view(&amp;self) {
@@ -382,7 +382,7 @@ <h3 id="the-view"><a class="header" href="#the-view">The View</a></h3>
382382
<p>Instead of throwing the <code>interface</code> away, we need to return it. Remember, the purpose of our <strong>view logic</strong> is
383383
to dictate the widgets of our user interface; and the content of the <code>interface</code> variable is precisely the
384384
description of the interface we want:</p>
385-
<pre><code class="language-rust">use iced::widget::{button, column, text, Column};
385+
<pre><code class="language-rust ignore">use iced::widget::{button, column, text, Column};
386386

387387
impl Counter {
388388
fn view(&amp;self) -&gt; Column&lt;Message&gt; {
@@ -413,7 +413,7 @@ <h3 id="the-view"><a class="header" href="#the-view">The View</a></h3>
413413
<div align="center" class="right">
414414
<img alt="A classical counter interface" src="resources/counter-interface.svg" width="50%">
415415
</div>
416-
<pre><code class="language-rust">use iced::widget::{button, column, text, Column};
416+
<pre><code class="language-rust ignore">use iced::widget::{button, column, text, Column};
417417

418418
impl Counter {
419419
fn view(&amp;self) -&gt; Column&lt;Message&gt; {

0 commit comments

Comments
 (0)