2015-09-09 20:33:32 +03:00
|
|
|
# Zahnrad
|
2015-07-25 23:16:35 +03:00
|
|
|
[![Coverity Status](https://scan.coverity.com/projects/5863/badge.svg)](https://scan.coverity.com/projects/5863)
|
2015-07-25 22:32:37 +03:00
|
|
|
|
2015-05-21 14:06:29 +03:00
|
|
|
This is a bloat free minimal state immediate mode graphical user interface toolkit
|
2015-08-27 20:25:13 +03:00
|
|
|
written in ANSI C. It was designed as a simple embeddable user interface for
|
2015-09-17 18:31:43 +03:00
|
|
|
application and does not have any direct dependencies. It does not have
|
|
|
|
a default renderbackend, os window and input handling but instead provides a very modular
|
|
|
|
library approach by providing a simple input state storage for input and draw
|
|
|
|
commands describing primitive shapes as output. So instead of providing a
|
|
|
|
layered library that tries to abstract over a number of platform and
|
|
|
|
render backends it only focuses on the actual GUI.
|
2015-03-11 16:00:59 +03:00
|
|
|
|
2015-03-14 19:05:30 +03:00
|
|
|
## Features
|
2015-04-16 17:20:00 +03:00
|
|
|
- Immediate mode graphical user interface toolkit
|
2015-03-14 19:05:30 +03:00
|
|
|
- Written in C89 (ANSI C)
|
2015-09-15 19:13:43 +03:00
|
|
|
- Small codebase (~8kLOC)
|
2015-05-17 15:39:02 +03:00
|
|
|
- Focus on portability, efficiency, simplicity and minimal internal state
|
|
|
|
- No global or hidden state
|
2015-09-15 19:13:43 +03:00
|
|
|
- No direct dependencies
|
2015-05-11 13:45:22 +03:00
|
|
|
- Configurable style and colors
|
2015-04-30 17:12:21 +03:00
|
|
|
- UTF-8 support
|
2015-09-16 11:41:14 +03:00
|
|
|
- Optional vertex buffer output and font handling
|
2015-03-24 15:08:42 +03:00
|
|
|
|
2015-09-18 00:09:49 +03:00
|
|
|
The library is self-contained within four different files that only have to be
|
|
|
|
copied and compiled into your application. Files zahnrad.c and zahnrad.h make up
|
2015-09-17 18:31:43 +03:00
|
|
|
the core of the library, while stb_rect_pack.h and stb_truetype.h are
|
|
|
|
for a optional font handling implementation and can be removed if not needed.
|
2015-09-18 00:09:49 +03:00
|
|
|
- zahnrad.c
|
|
|
|
- zahnrad.h
|
2015-09-17 18:31:43 +03:00
|
|
|
- stb_rect_pack.h
|
|
|
|
- stb_truetype.h
|
2015-09-17 18:35:45 +03:00
|
|
|
|
2015-09-18 00:09:49 +03:00
|
|
|
There are no dependencies or a particular building process required. You just have
|
|
|
|
to compile the .c file and #include zahnrad.h into your project. To actually
|
2015-09-17 18:31:43 +03:00
|
|
|
run you have to provide the input state, configuration style and memory
|
|
|
|
for draw commands to the library. After the GUI was executed all draw commands
|
|
|
|
have to be either executed or optionally converted into a vertex buffer to
|
|
|
|
draw the GUI.
|
|
|
|
|
2015-05-09 16:22:23 +03:00
|
|
|
## Gallery
|
2015-11-09 15:26:25 +03:00
|
|
|
![1](https://cloud.githubusercontent.com/assets/8057201/11033668/59ab5d04-86e5-11e5-8091-c56f16411565.png)
|
|
|
|
![2](https://cloud.githubusercontent.com/assets/8057201/11033664/5074a588-86e5-11e5-8308-8e1f4724ae85.png)
|
|
|
|
![3](https://cloud.githubusercontent.com/assets/8057201/11033654/3f0c5a5c-86e5-11e5-8529-4bb5ac3b357a.png)
|
2015-10-26 00:52:40 +03:00
|
|
|
![explorer](https://cloud.githubusercontent.com/assets/8057201/10718115/02a9ba08-7b6b-11e5-950f-adacdd637739.png)
|
2015-09-19 18:59:10 +03:00
|
|
|
![node](https://cloud.githubusercontent.com/assets/8057201/9976995/e81ac04a-5ef7-11e5-872b-acd54fbeee03.gif)
|
2015-05-09 16:22:23 +03:00
|
|
|
|
2015-04-25 17:44:43 +03:00
|
|
|
## Example
|
|
|
|
```c
|
2015-10-28 12:36:17 +03:00
|
|
|
/* allocate memory to hold draw commands */
|
|
|
|
struct zr_command_queue queue;
|
|
|
|
zr_command_queue_init_fixed(&queue, malloc(MEMORY_SIZE), MEMORY_SIZE);
|
|
|
|
|
2015-08-10 21:34:47 +03:00
|
|
|
/* setup configuration */
|
2015-09-18 00:09:49 +03:00
|
|
|
struct zr_style style;
|
|
|
|
struct zr_user_font font = {...};
|
|
|
|
zr_style_default(&style, ZR_DEFAULT_ALL, &font);
|
2015-05-29 15:47:42 +03:00
|
|
|
|
2015-09-17 18:31:43 +03:00
|
|
|
/* initialize window */
|
2015-09-18 00:09:49 +03:00
|
|
|
struct zr_window window;
|
2015-09-30 11:40:53 +03:00
|
|
|
zr_window_init(&window, zr_rect(50, 50, 220, 180),
|
2015-09-18 00:09:49 +03:00
|
|
|
ZR_WINDOW_BORDER|ZR_WINDOW_MOVEABLE|ZR_WINDOW_SCALEABLE,
|
2015-09-16 16:04:26 +03:00
|
|
|
&queue, &style, &input);
|
2015-04-25 17:44:43 +03:00
|
|
|
|
2015-06-28 11:09:53 +03:00
|
|
|
/* setup widget data */
|
2015-08-05 13:48:01 +03:00
|
|
|
enum {EASY, HARD};
|
2015-09-18 00:09:49 +03:00
|
|
|
zr_size option = EASY;
|
2015-09-30 11:19:19 +03:00
|
|
|
zr_float value = 0.6f;
|
2015-06-28 11:09:53 +03:00
|
|
|
|
2015-09-18 00:09:49 +03:00
|
|
|
struct zr_input input = {0};
|
2015-04-25 17:44:43 +03:00
|
|
|
while (1) {
|
2015-09-18 00:09:49 +03:00
|
|
|
zr_input_begin(&input);
|
2015-04-25 17:44:43 +03:00
|
|
|
/* record input */
|
2015-09-18 00:09:49 +03:00
|
|
|
zr_input_end(&input);
|
2015-04-25 17:44:43 +03:00
|
|
|
|
2015-05-14 16:14:15 +03:00
|
|
|
/* GUI */
|
2015-09-18 00:09:49 +03:00
|
|
|
struct zr_context context;
|
|
|
|
zr_begin(&context, &window);
|
2015-08-06 17:36:28 +03:00
|
|
|
{
|
2015-09-18 00:09:49 +03:00
|
|
|
zr_header(&context, "Show", ZR_CLOSEABLE, 0, ZR_HEADER_LEFT);
|
|
|
|
zr_layout_row_static(&context, 30, 80, 1);
|
|
|
|
if (zr_button_text(&context, "button", ZR_BUTTON_DEFAULT)) {
|
2015-08-06 17:36:28 +03:00
|
|
|
/* event handling */
|
|
|
|
}
|
2015-09-18 00:09:49 +03:00
|
|
|
zr_layout_row_dynamic(&context, 30, 2);
|
|
|
|
if (zr_option(&context, "easy", option == EASY)) option = EASY;
|
|
|
|
if (zr_option(&context, "hard", option == HARD)) option = HARD;
|
2015-09-30 11:19:19 +03:00
|
|
|
zr_layout_row_begin(&context, ZR_STATIC, 30, 2);
|
|
|
|
{
|
|
|
|
zr_layout_row_push(&context, 50);
|
|
|
|
zr_label(&context, "Volume:", ZR_TEXT_LEFT);
|
|
|
|
zr_layout_row_push(&context, 110);
|
2015-11-13 11:40:28 +03:00
|
|
|
zr_slider_float(&context, 0, &value, 1.0f, 0.1f);
|
2015-09-30 11:19:19 +03:00
|
|
|
}
|
|
|
|
zr_layout_row_end(&context);
|
2015-04-25 17:44:43 +03:00
|
|
|
}
|
2015-09-18 00:09:49 +03:00
|
|
|
zr_end(&context, &window);
|
2015-04-25 17:44:43 +03:00
|
|
|
|
2015-05-14 16:14:15 +03:00
|
|
|
/* draw */
|
2015-09-18 00:09:49 +03:00
|
|
|
const struct zr_command *cmd;
|
|
|
|
zr_foreach_command(cmd, &queue) {
|
2015-05-29 15:47:42 +03:00
|
|
|
/* execute draw call command */
|
2015-04-25 17:44:43 +03:00
|
|
|
}
|
2015-09-18 00:09:49 +03:00
|
|
|
zr_command_queue_clear(&queue);
|
2015-04-25 17:44:43 +03:00
|
|
|
}
|
|
|
|
```
|
2015-09-30 11:23:45 +03:00
|
|
|
![example](https://cloud.githubusercontent.com/assets/8057201/10187981/584ecd68-675c-11e5-897c-822ef534a876.png)
|
2015-04-25 17:44:43 +03:00
|
|
|
|
2015-03-14 19:05:30 +03:00
|
|
|
## References
|
2015-09-17 18:31:43 +03:00
|
|
|
- [stb_rect_pack.h and stb_truetype.h by Sean Barret (public domain)](https:://github.com/nothings/stb/)
|
2015-04-12 16:40:42 +03:00
|
|
|
- [Tutorial from Jari Komppa about imgui libraries](http://www.johno.se/book/imgui.html)
|
2015-03-25 16:32:43 +03:00
|
|
|
- [Johannes 'johno' Norneby's article](http://iki.fi/sol/imgui/)
|
2015-09-15 19:13:43 +03:00
|
|
|
- [ImGui: The inspiration for this project from ocornut](https://github.com/ocornut/imgui)
|
2015-04-20 22:36:16 +03:00
|
|
|
- [Nvidia's imgui toolkit](https://code.google.com/p/nvidia-widgets/)
|
2015-03-14 19:05:30 +03:00
|
|
|
|
2015-03-03 19:24:02 +03:00
|
|
|
# License
|
2015-09-21 18:16:23 +03:00
|
|
|
(The zlib License)
|