Rename iced_virtual to iced_pure
`virtual` is a reserved keyword in Rust 😬
This commit is contained in:
parent
e03de01988
commit
897188317b
15 changed files with 16 additions and 15 deletions
10
examples/pure/counter/Cargo.toml
Normal file
10
examples/pure/counter/Cargo.toml
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
[package]
|
||||
name = "pure_counter"
|
||||
version = "0.1.0"
|
||||
authors = ["Héctor Ramón Jiménez <hector0193@gmail.com>"]
|
||||
edition = "2021"
|
||||
publish = false
|
||||
|
||||
[dependencies]
|
||||
iced = { path = "../../.." }
|
||||
iced_pure = { path = "../../../pure" }
|
||||
18
examples/pure/counter/README.md
Normal file
18
examples/pure/counter/README.md
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
## Counter
|
||||
|
||||
The classic counter example explained in the [`README`](../../README.md).
|
||||
|
||||
The __[`main`]__ file contains all the code of the example.
|
||||
|
||||
<div align="center">
|
||||
<a href="https://gfycat.com/fairdeadcatbird">
|
||||
<img src="https://thumbs.gfycat.com/FairDeadCatbird-small.gif">
|
||||
</a>
|
||||
</div>
|
||||
|
||||
You can run it with `cargo run`:
|
||||
```
|
||||
cargo run --package counter
|
||||
```
|
||||
|
||||
[`main`]: src/main.rs
|
||||
12
examples/pure/counter/index.html
Normal file
12
examples/pure/counter/index.html
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8" content="text/html; charset=utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
<title>Counter - Iced</title>
|
||||
<base data-trunk-public-url />
|
||||
</head>
|
||||
<body>
|
||||
<link data-trunk rel="rust" href="Cargo.toml" data-wasm-opt="z" data-bin="counter" />
|
||||
</body>
|
||||
</html>
|
||||
54
examples/pure/counter/src/main.rs
Normal file
54
examples/pure/counter/src/main.rs
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
use iced::{Alignment, Element, Sandbox, Settings};
|
||||
use iced_pure::{Button, Column, Pure, State, Text};
|
||||
|
||||
pub fn main() -> iced::Result {
|
||||
Counter::run(Settings::default())
|
||||
}
|
||||
|
||||
struct Counter {
|
||||
value: i32,
|
||||
state: State<Message, iced::Renderer>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
enum Message {
|
||||
IncrementPressed,
|
||||
DecrementPressed,
|
||||
}
|
||||
|
||||
impl Sandbox for Counter {
|
||||
type Message = Message;
|
||||
|
||||
fn new() -> Self {
|
||||
Self {
|
||||
value: 0,
|
||||
state: State::new(),
|
||||
}
|
||||
}
|
||||
|
||||
fn title(&self) -> String {
|
||||
String::from("Counter - Iced")
|
||||
}
|
||||
|
||||
fn update(&mut self, message: Message) {
|
||||
match message {
|
||||
Message::IncrementPressed => {
|
||||
self.value += 1;
|
||||
}
|
||||
Message::DecrementPressed => {
|
||||
self.value -= 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn view(&mut self) -> Element<'_, Message> {
|
||||
let content = Column::new()
|
||||
.padding(20)
|
||||
.align_items(Alignment::Center)
|
||||
.push(Button::new("Increment").on_press(Message::IncrementPressed))
|
||||
.push(Text::new(self.value.to_string()).size(50))
|
||||
.push(Button::new("Decrement").on_press(Message::DecrementPressed));
|
||||
|
||||
Pure::new(&mut self.state, content).into()
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue