Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Basic GUI support #35

Merged
merged 82 commits into from
Jun 9, 2019
Merged

Basic GUI support #35

merged 82 commits into from
Jun 9, 2019

Conversation

hecrj
Copy link
Owner

@hecrj hecrj commented May 27, 2019

Demo
Watch in higher quality / Code

This PR implements a basic UI runtime and integrates it with Coffee.

Features / Goals

  • Responsive UI layout based on flexbox, built on top of stretch.
  • Generic Widget trait with a Renderer associated type, allowing users to build their own custom widgets and UI renderers.
  • Type-safety. No weak references.
  • Simple design, heavily inspired by Elm and elm-ui. Users define a function describing their UI layout. The resulting UI produces messages on user interaction. Produced messages are processed by another user-defined function, changing state as desired.
  • Simple integration. GUI can easily be added by simply extending your Game with the UserInterface trait.

Built-in widgets

Example

This branch includes an example that showcases all the built-in widgets so far (code). If you want to check it out simply run:

cargo run --example ui --features opengl,debug --release

Limitations

This is a first iteration. The current implementation is still missing some basic features like:

Also, there is no way to overlay elements as of now and there are probably many performance optimizations that we could make. However, I would like to wait a bit and gather use cases before implementing these.

Breaking changes

This PR contains breaking changes that affect the architecture of the engine for the better:

  • The View associated type has been removed. Thus, implementors of the Game trait are also meant to hold the game assets. This simplifies the API considerably, and it helps model your game state-view relationship with precision, avoiding inconsistencies.
  • The Game::Input associated type now has to implement the new Input trait. This splits code quite nicely, as the on_input method moves away from Game. It also makes Input implementors reusable. For instance, a KeyboardAndMouse type has been implemented that can be used out of the box!
  • The Game::LoadingScreen associated type has been introduced. Given that all the Game associated types implement a trait with a load method, wiring a loading screen now is as simple as writing its name. Because of this, the Game::new method is no longer necessary and it is dropped.

Additional implemented features

  • Text alignment, using HorizontalAlignment and VerticalAlignment
  • Font::measure, which allows to measure any Text
  • Rectangle::contains, returns whether or not it contains the given Point
  • Sprite::scale
  • Default implementation for Sprite

Pending work

  • Rename UserInterface::Event to UserInterface::Message
  • Move runtime concepts and customization into a (public) module inside ui
  • Expose simple concepts using the basic renderer directly on the ui module
  • Implement ProgressBar widget Implement a ProgressBar widget #45
  • Debug some weird stretch behavior (maybe contact maintainers and/or open an issue) stretch seems to ignore Text measurements #44
  • Debug glyph_brush measuring functions (they seem to be off) Font::measure returns wrong values #43
  • Rethink alignment API
  • Support renderer configuration
  • Control event propagation
  • Remove debug code (maybe split it into another renderer)
  • Update examples
  • Review API consistency
  • Give proper credits (Kenney and stretch)
  • Update documentation
  • Update README
  • Update CHANGELOG

@hecrj
Copy link
Owner Author

hecrj commented Jun 8, 2019

I have uploaded the new docs here: http://coffee-rs.surge.sh/coffee/index.html

I am quite happy with how it's turning out. Any feedback is appreciated!

@hecrj
Copy link
Owner Author

hecrj commented Jun 9, 2019

There is still some work to be done: debugging some weird behavior and implementing a ProgressBar widget. However, this PR is already almost as big as the entire engine in master... 😅

I think we should open issues so we can properly track the remaining work and deal with them in separate PRs.

So, let's merge this! 🎉

@hecrj hecrj changed the title [WIP] Basic GUI support Basic GUI support Jun 9, 2019
@PvdBerg1998
Copy link
Contributor

I think you forgot to document the removal of State in the changelog

@hecrj
Copy link
Owner Author

hecrj commented Jun 9, 2019

@PvdBerg1998 State was added in this PR, it doesn't exist in the current release. The actual change you may be referring to is the removal of the View associated type, which I think I have added to the changelog under the "Changed" section.

In any case, we will review/rewrite the changelog a bit before releasing 0.3.0.

And thank you for taking a look!

@hecrj hecrj merged commit ac9cd91 into master Jun 9, 2019
@hecrj hecrj deleted the feature/ui branch June 9, 2019 14:36
@PvdBerg1998
Copy link
Contributor

No sorry, I didn't see it was only added in this PR. Nice work! 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants