Linus-Mussmaecher / mooeye

UI library for the the ggez game engine.
MIT License
4 stars 1 forks source link
game game-development rust ui

MooEye - A ggez-based UI library

Docs Status license Crates.io Crates.io

This is a very simple UI library building upon ggez game library. It was originally written for personal use with my own Rust gamedev projets.

UI Features

Additional Features

Maintenance

I am maintaining this project mostly for my own purposes, and by myself. Updates may be far and in between, but Mooeye is in a very usable state right now.

How to use

UI

When using MooEye, your game state struct should contain a gui: UiElement<T>. Initialize this value with any container and create a tree of UIElements representing the state of your UI. In this step, you also define the Interaction of the UI with both user and game state via message handlers and transitions.

Every frame, you want to call gui.draw_to_screen() to draw the Ui within your draw function to draw the UI. T is the type of your extern messages. Collect every change in your game state that you want to represent in the UI and pass them on to the UI in the update step of your game loop using gui.manage_messages(). Your message handlers will then receive these messages and change the UI appropriately (for larger changes, you may also completely rebuild the UI rather than writing enormous handlers). gui.manage_messages() will return a set of internal messages informing you of buttons the user has clicked. This way, your game state can conversely react to interaction with the UI.

Additionally, your update function can interact with your UI by calling gui.add_elements() and gui.remove_elements() to add and remove elements based on their id and change your entire UI layout.

For more extensive explanation and examples see the docs or the examples in the examples folder.

Dynamic sizing rules

The following rules guide how an element in MooEye tries to size itself.

Outer bounds:

Inner bounds:

Preserve ratio:

Elements with the preserve_ratio flag of their layout set to true will only display their content in the ratio of the lower limits of their layout::size. Their background will be drawn as normal, and the element will then scale down in the dimension that would have been stretched more in order to fit onto this background.

Scene Manager

Creating and using a scene manager is as simple as having your scenes implement Scene instead of Event Handler and starting your game via SceneManager::new_and_run instead of event::run.

See also the examples in the examples folder for usage of the SceneManager.

Sprites

Sprites can be created with a path just like any ggez-Image, but can display animation and multiple states of an object. See the respective documentation in the sprite documentation.

The source image file needs to contain the different frames of each animation cycle aligned horizontally, with the different states forming the rows.

See also the relevant examples in the examples folder for usage of Sprite.

Entire folders of sprites can be loaded with a SpritePool, making repeated acceses to the file system unneccessary.

License

MIT License