Complete examples README
This commit is contained in:
parent
ced3ffc225
commit
b81ab91e67
4 changed files with 61 additions and 12 deletions
|
|
@ -15,6 +15,16 @@ The example is built on top of [`ggez`], a game library for Rust. Currently, it
|
|||
is using a [personal fork] to [add a `FontCache` type] and
|
||||
[fix some issues with HiDPI].
|
||||
|
||||
The implementation consists of different modules:
|
||||
- __[`tour`]__ contains the actual GUI code: __state__, __messages__,
|
||||
__update logic__ and __view logic__.
|
||||
- __[`renderer`]__ implements a simple renderer for each of the used widgets on
|
||||
top of the graphics module of [`ggez`].
|
||||
- __[`widget`]__ re-exposes Iced's built-in widgets with the renderer type parameter
|
||||
replaced with the implemented [`renderer`], for convenience.
|
||||
- __[`main`]__ integrates Iced with [`ggez`] and connects the [`tour`] with
|
||||
the [`renderer`].
|
||||
|
||||
```
|
||||
cargo run --example tour
|
||||
```
|
||||
|
|
@ -22,6 +32,10 @@ cargo run --example tour
|
|||
[![Tour - Iced][gui_gif]][gui_gfycat]
|
||||
|
||||
[`ggez`]: https://github.com/ggez/ggez
|
||||
[`tour`]: tour/tour.rs
|
||||
[`renderer`]: tour/renderer
|
||||
[`widget`]: tour/widget.rs
|
||||
[`main`]: tour/main.rs
|
||||
[personal fork]: https://github.com/hecrj/ggez
|
||||
[add a `FontCache` type]: https://github.com/ggez/ggez/pull/679
|
||||
[fix some issues with HiDPI]: https://github.com/hecrj/ggez/commit/dfe2fd2423c51a6daf42c75f66dfaeaacd439fb1
|
||||
|
|
@ -35,7 +49,7 @@ Since [Iced was born in May], it has been powering the user interfaces in
|
|||
[Coffee], an experimental 2D game engine.
|
||||
|
||||
If you want to give Iced a try without having to write your own renderer,
|
||||
the [`ui` module] in [Coffee] is probably your best choice as of now.
|
||||
the __[`ui` module]__ in [Coffee] is probably your best choice as of now.
|
||||
|
||||
[![Tour - Coffee][coffee_gui_gif]][coffee_gui_gfycat]
|
||||
|
||||
|
|
|
|||
35
examples/tour/README.md
Normal file
35
examples/tour/README.md
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
# Tour
|
||||
|
||||
A simple UI tour showcasing different widgets that can be built using Iced. It
|
||||
also shows how the library can be integrated into an existing system.
|
||||
|
||||
The example is built on top of [`ggez`], a game library for Rust. Currently, it
|
||||
is using a [personal fork] to [add a `FontCache` type] and
|
||||
[fix some issues with HiDPI].
|
||||
|
||||
The implementation consists of different modules:
|
||||
- __[`tour`]__ contains the actual GUI code: __state__, __messages__,
|
||||
__update logic__ and __view logic__.
|
||||
- __[`renderer`]__ implements a simple renderer for each of the used widgets on
|
||||
top of the graphics module of [`ggez`].
|
||||
- __[`widget`]__ re-exposes Iced's built-in widgets with the renderer type parameter
|
||||
replaced with the implemented [`renderer`], for convenience.
|
||||
- __[`main`]__ integrates Iced with [`ggez`] and connects the [`tour`] with
|
||||
the [`renderer`].
|
||||
|
||||
```
|
||||
cargo run --example tour
|
||||
```
|
||||
|
||||
[![Tour - Iced][gui_gif]][gui_gfycat]
|
||||
|
||||
[`ggez`]: https://github.com/ggez/ggez
|
||||
[`tour`]: tour/tour.rs
|
||||
[`renderer`]: tour/renderer
|
||||
[`widget`]: tour/widget.rs
|
||||
[`main`]: tour/main.rs
|
||||
[personal fork]: https://github.com/hecrj/ggez
|
||||
[add a `FontCache` type]: https://github.com/ggez/ggez/pull/679
|
||||
[fix some issues with HiDPI]: https://github.com/hecrj/ggez/commit/dfe2fd2423c51a6daf42c75f66dfaeaacd439fb1
|
||||
[gui_gif]: https://thumbs.gfycat.com/VeneratedSourAurochs-small.gif
|
||||
[gui_gfycat]: https://gfycat.com/veneratedsouraurochs
|
||||
|
|
@ -16,8 +16,8 @@ pub fn main() -> ggez::GameResult {
|
|||
let (context, event_loop) = {
|
||||
&mut ggez::ContextBuilder::new("iced", "ggez")
|
||||
.window_mode(ggez::conf::WindowMode {
|
||||
width: 850.0,
|
||||
height: 850.0,
|
||||
width: 1280.0,
|
||||
height: 1024.0,
|
||||
..ggez::conf::WindowMode::default()
|
||||
})
|
||||
.build()?
|
||||
|
|
@ -133,14 +133,14 @@ impl event::EventHandler for Game {
|
|||
let screen = graphics::screen_coordinates(context);
|
||||
|
||||
let (messages, cursor) = {
|
||||
let layout = self.tour.layout();
|
||||
let view = self.tour.view();
|
||||
|
||||
let content = Column::new()
|
||||
.width(screen.w as u16)
|
||||
.height(screen.h as u16)
|
||||
.align_items(iced::Align::Center)
|
||||
.justify_content(iced::Justify::Center)
|
||||
.push(layout);
|
||||
.push(view);
|
||||
|
||||
let renderer = &mut Renderer::new(
|
||||
context,
|
||||
|
|
@ -165,7 +165,7 @@ impl event::EventHandler for Game {
|
|||
};
|
||||
|
||||
for message in messages {
|
||||
self.tour.react(message);
|
||||
self.tour.update(message);
|
||||
}
|
||||
|
||||
mouse::set_cursor_type(context, into_cursor_type(cursor));
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ impl Tour {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn react(&mut self, event: Message) {
|
||||
pub fn update(&mut self, event: Message) {
|
||||
match event {
|
||||
Message::BackPressed => {
|
||||
self.steps.go_back();
|
||||
|
|
@ -38,7 +38,7 @@ impl Tour {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn layout(&mut self) -> Element<Message> {
|
||||
pub fn view(&mut self) -> Element<Message> {
|
||||
let Tour {
|
||||
steps,
|
||||
back_button,
|
||||
|
|
@ -67,7 +67,7 @@ impl Tour {
|
|||
let element: Element<_> = Column::new()
|
||||
.max_width(500)
|
||||
.spacing(20)
|
||||
.push(steps.layout(self.debug).map(Message::StepMessage))
|
||||
.push(steps.view(self.debug).map(Message::StepMessage))
|
||||
.push(controls)
|
||||
.into();
|
||||
|
||||
|
|
@ -136,8 +136,8 @@ impl Steps {
|
|||
self.steps[self.current].update(msg, debug);
|
||||
}
|
||||
|
||||
fn layout(&mut self, debug: bool) -> Element<StepMessage> {
|
||||
self.steps[self.current].layout(debug)
|
||||
fn view(&mut self, debug: bool) -> Element<StepMessage> {
|
||||
self.steps[self.current].view(debug)
|
||||
}
|
||||
|
||||
fn advance(&mut self) {
|
||||
|
|
@ -262,7 +262,7 @@ impl<'a> Step {
|
|||
}
|
||||
}
|
||||
|
||||
fn layout(&mut self, debug: bool) -> Element<StepMessage> {
|
||||
fn view(&mut self, debug: bool) -> Element<StepMessage> {
|
||||
match self {
|
||||
Step::Welcome => Self::welcome().into(),
|
||||
Step::Radio { selection } => Self::radio(*selection).into(),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue