Crates.io | mooeye |
lib.rs | mooeye |
version | 0.4.1 |
source | src |
created_at | 2023-04-08 22:26:29.212251 |
updated_at | 2023-07-31 10:46:51.678618 |
description | A small UI library designed on top of the ggez game library. WORK IN PROGRESS |
homepage | https://github.com/Linus-Mussmaecher/mooeye |
repository | https://github.com/Linus-Mussmaecher/mooeye |
max_upload_size | |
id | 833829 |
size | 600,867 |
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.
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.
When using MooEye, your game state struct should contain a gui: UiElement<T>
. Initialize this value with any container and create a tree of UIElement
s 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.
The following rules guide how an element in MooEye tries to size itself.
layout::size
.draw_to_rectangle
is called with is too small, the element will not display (but may still consume space).layout::size
modifierslayout::size
and instead align as according to its layout::alignment
.layout
, but by the content
of the element. Here, the upper bounds will (so far) be ignored, but the element will try to respect the lower bounds when adjusting its size. These content bounds are mostly used to containers respect the space requirements of their children.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.
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 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.
MIT License