Skip to content

Commit

Permalink
zgui: Add Err enum to examples
Browse files Browse the repository at this point in the history
  • Loading branch information
ozkriff committed Jun 6, 2021
1 parent 77a0da6 commit d603e6a
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 12 deletions.
2 changes: 1 addition & 1 deletion zgui/examples/absolute_coordinates.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ fn draw_scene() {
#[mq::main("ZGui: Absolute Coordinates Demo")]
#[macroquad(crate_rename = "mq")]
async fn main() {
let assets = common::Assets::load().await;
let assets = common::Assets::load().await.expect("Can't load assets");
let mut gui = make_gui(assets.font).expect("Can't create the gui");
loop {
// Update the camera and the GUI.
Expand Down
28 changes: 22 additions & 6 deletions zgui/examples/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,24 @@ use mq::{
texture::{self, Texture2D},
};

#[derive(Debug)]
pub enum Err {
File(mq::file::FileError),
Font(mq::text::FontError),
}

impl From<mq::file::FileError> for Err {
fn from(err: mq::file::FileError) -> Self {
Err::File(err)
}
}

impl From<mq::text::FontError> for Err {
fn from(err: mq::text::FontError) -> Self {
Err::Font(err)
}
}

pub fn aspect_ratio() -> f32 {
mq::window::screen_width() / mq::window::screen_height()
}
Expand All @@ -33,11 +51,9 @@ pub struct Assets {
}

impl Assets {
pub async fn load() -> Self {
let font = load_ttf_font("zgui/assets/Karla-Regular.ttf")
.await
.unwrap();
let texture = texture::load_texture("zgui/assets/fire.png").await.unwrap();
Self { font, texture }
pub async fn load() -> Result<Self, Err> {
let font = load_ttf_font("zgui/assets/Karla-Regular.ttf").await?;
let texture = texture::load_texture("zgui/assets/fire.png").await?;
Ok(Self { font, texture })
}
}
2 changes: 1 addition & 1 deletion zgui/examples/layers_layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ fn make_gui(assets: common::Assets) -> ui::Result<ui::Gui<Message>> {
#[mq::main("ZGui: Layers Layout Demo")]
#[macroquad(crate_rename = "mq")]
async fn main() {
let assets = common::Assets::load().await;
let assets = common::Assets::load().await.expect("Can't load assets");
let mut gui = make_gui(assets).expect("Can't create the gui");
loop {
// Update the camera and the GUI.
Expand Down
2 changes: 1 addition & 1 deletion zgui/examples/nested.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ fn make_gui(assets: common::Assets) -> ui::Result<ui::Gui<Message>> {
#[mq::main("ZGui: Nested Layouts Demo")]
#[macroquad(crate_rename = "mq")]
async fn main() {
let assets = common::Assets::load().await;
let assets = common::Assets::load().await.expect("Can't load assets");
let mut gui = make_gui(assets).expect("Can't create the gui");
loop {
// Update the camera and the GUI.
Expand Down
2 changes: 1 addition & 1 deletion zgui/examples/pixel_coordinates.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ fn draw_scene() {
#[mq::main("ZGui: Pixel Coordinates Demo")]
#[macroquad(crate_rename = "mq")]
async fn main() {
let assets = common::Assets::load().await;
let assets = common::Assets::load().await.expect("Can't load assets");
let mut gui = make_gui(assets.font).expect("Can't create the gui");
loop {
// Update the camera and the GUI.
Expand Down
2 changes: 1 addition & 1 deletion zgui/examples/remove.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ impl State {
#[mq::main("ZGui: Remove Widget Demo")]
#[macroquad(crate_rename = "mq")]
async fn main() {
let assets = common::Assets::load().await;
let assets = common::Assets::load().await.expect("Can't load assets");
let mut state = State::new(assets).expect("Can't create the game state");
loop {
// Update the camera and the GUI.
Expand Down
2 changes: 1 addition & 1 deletion zgui/examples/text_button.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ fn make_gui(font: mq::text::Font) -> ui::Result<ui::Gui<Message>> {
#[mq::main("ZGui: Text Button Demo")]
#[macroquad(crate_rename = "mq")]
async fn main() {
let assets = common::Assets::load().await;
let assets = common::Assets::load().await.expect("Can't load assets");
let mut gui = make_gui(assets.font).expect("Can't create the gui");
loop {
// Update the camera and the GUI.
Expand Down

0 comments on commit d603e6a

Please sign in to comment.