https://github.com/compufox/trivial-gamekit-ui
trivial-gamekit module for making lightweight UI
https://github.com/compufox/trivial-gamekit-ui
Last synced: 5 months ago
JSON representation
trivial-gamekit module for making lightweight UI
- Host: GitHub
- URL: https://github.com/compufox/trivial-gamekit-ui
- Owner: compufox
- Created: 2021-02-24T17:51:29.000Z (over 5 years ago)
- Default Branch: main
- Last Pushed: 2021-03-19T20:53:56.000Z (over 5 years ago)
- Last Synced: 2026-02-24T00:39:29.175Z (5 months ago)
- Language: Common Lisp
- Size: 21.5 KB
- Stars: 9
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# trivial-gamekit-ui
### _ava fox_
trivial-gamekit module for creating common user interface widgets quickly
## Installing
```shell
$ git clone https://github.com/compufox/trivial-gamekit-ui ~/common-lisp/
$ ros run # (or run whichever lisp you use)
* ;; install the quicklisp distro that houses trivial-gamekit
* (ql-dist:install-dist "http://bodge.borodust.org/dist/org.borodust.bodge.txt")
* ;; ready to go!
```
## Usage
Define your game with the `with-ui` superclass
```lisp
(gamekit:defgame your-game (with-ui) ()
...)
```
in your `gamekit:post-initialize`:
```lisp
(defmethod gamekit:post-initialize ((this your-game))
...
(initalize-ui this
(:label (make-label "Hello World!" (vec2 50 50) :color gamekit.colors:+black+)))
...)
```
then in your `gamekit:draw`
```lisp
(defmethod gamekit:draw ((this your-game))
...
(draw-ui this)
...)
```
please see `example.lisp` for a more detailed example
## API
`(make-label (text &key (position (vec2 0 0)) (font :default) (size 12) (color gamekit.colors:+black+) (justification :left))`
creates and returns a label
---
`(make-button &key (position (vec2 0 0)) label (fill-color gamekit.colors:+black+) (hover-color gamekit.colors:+black+) (pressed-color gamekit.colors:+black+) (stroke-color gamekit.colors:+transparent+) (stroke-thickness 0) (rounding 0) image hover-image pressed-image on-click)`
creates and returns a button
---
`(make-panel &key (position (vec2 0 0)) width height children (fill-color gamekit.colors:+black+) (stroke-color gamekit.colors:+transparent+) (stroke-thickness 0) (rounding 0) image)`
creates and returns a panel
---
`(make-progress-bar width height &key (position (vec2 0 0)) (fill-color gamekit.colors:+white+) (stroke-color gamekit.colors:+transparent+) (stroke-thickness 0) (inner-color gamekit.colors:+black+) (rounding 0) (percent 0) show-percent (font :default) (font-size 12) (font-color gamekit.colors:+black+))`
creates and returns a progress-bar
---
`(draw-widget this)`
draws a UI widget on the screen
---
`(ui-element state-or-game element)`
returns a UI widget from STATE-OR-GAME identified by ELEMENT
ex: `(ui-element (gamekit.fistmachine:current-state) :score-label)`
---
`(setf (ui-element state-or-game element) widget)`
sets a UI widget in STATE-OR-GAME, identified by ELEMENT
---
`(draw-ui state-or-game)`
draws all ui elements of state-or-game
---
`(initialize-ui state-or-game &rest forms)`
macro that allows you to set multiple widgets in STATE-OR-GAME at once
each form in FORMS should be (IDENTIFIER WIDGET)
---
`(text-width text &optional (font gamekit::*font*))`
returns the width of TEXT using FONT
---
`(text-height text &optional (font gamekit::*font*))`
returns the height of TEXT using FONT
---
`(text-dimensions text &optional (font gamekit::*font*))`
returns a vec2 of the width and height of TEXT using FONT
---
accessors exported: `text` `size` `widget-position` `text-color` `image` `stroke` `hover-color` `pressed-color` `on-click` `stroke-thickness` `hover-image` `pressed-image` `stroke-color` `children` `width` `height` `label` `rounding` `justification` `render`
---
## License
MIT