Nuklear/Readme.md

128 lines
5.3 KiB
Markdown
Raw Normal View History

2015-03-11 16:00:59 +03:00
# GUI
2015-04-16 17:20:00 +03:00
2015-04-16 23:04:34 +03:00
WORK IN PROGRESS: I do not garantee that everything works right now
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-04-19 23:12:37 +03:00
- Small codebase with roughly 2kLOC
2015-04-07 04:24:31 +03:00
- Focus on portability and minimal internal state
- Suited for embedding into graphical applications
2015-03-31 19:29:45 +03:00
- No global hidden state
- No direct dependencies (not even libc!)
2015-04-19 23:12:37 +03:00
- No memory allocation
2015-03-25 16:32:43 +03:00
- Renderer and platform independent
2015-03-14 19:05:30 +03:00
- Configurable
2015-03-25 16:32:43 +03:00
- UTF-8 supported
2015-03-24 15:08:42 +03:00
2015-04-16 21:05:43 +03:00
## Limitations
2015-04-19 23:12:37 +03:00
- Does NOT provide window management
- Does NOT provide input handling
2015-04-16 21:05:43 +03:00
- Does NOT provide a renderer backend
2015-04-17 23:30:43 +03:00
- Does NOT implement a font library
2015-04-16 21:05:43 +03:00
Summary: It is only responsible for the actual user interface
2015-04-16 17:20:00 +03:00
2015-04-17 23:28:00 +03:00
#### Widgets
```c
2015-04-19 23:12:37 +03:00
struct gui_input in = {0};
struct gui_canvas canvas = {...};
struct gui_button style = {...};
gui_default_config(&config);
2015-04-17 23:28:00 +03:00
while (1) {
gui_input_begin(&input);
/* record input */
gui_input_end(&input);
2015-04-19 23:12:37 +03:00
if (gui_button_text(&canvas, 50, 50, 100, 30, &style, "button", GUI_BUTTON_DEFAULT, &input))
2015-04-17 23:28:00 +03:00
fprintf(stdout, "button pressed!\n");
}
```
#### Panels
```c
2015-04-19 23:12:37 +03:00
struct gui_input in = {0};
2015-04-17 23:28:00 +03:00
struct gui_config config;
struct gui_panel panel = {0};
2015-04-19 23:12:37 +03:00
struct gui_canvas canvas = {...};
2015-04-17 23:28:00 +03:00
gui_default_config(&config);
while (1) {
gui_input_begin(&input);
/* record input */
gui_input_end(&input);
2015-04-19 23:12:37 +03:00
gui_panel_begin(&panel, "Demo", panel.x, panel.y, panel.width, panel.height,
GUI_PANEL_CLOSEABLE|GUI_PANEL_MINIMIZABLE|GUI_PANEL_BORDER|
GUI_PANEL_MOVEABLE|GUI_PANEL_SCALEABLE, &config, &canvas, &in);
2015-04-17 23:28:00 +03:00
gui_panel_layout(&panel, 30, 1);
if (gui_panel_button_text(&panel, "button", GUI_BUTTON_DEFAULT))
fprintf(stdout, "button pressed!\n");
gui_panel_end(&panel);
}
```
2015-04-12 16:40:42 +03:00
## Configuration
2015-04-16 21:05:43 +03:00
The gui toolkit provides a number of different attributes that can be
configured, like spacing, padding, size and color.
While the widget API even expects you to provide the configuration
for each and every widget the higher layers provide you with a set of
attributes in the `gui_config` structure. The structure either needs to be
filled by the user or can be setup with some default values by the function
`gui_default_config`. Modification on the fly to the `gui_config` is in
true immedate mode fashion possible and supported.
2015-04-12 16:40:42 +03:00
## FAQ
2015-04-16 21:05:43 +03:00
#### Where is Widget X?
2015-04-12 16:40:42 +03:00
A number of basic widgets are provided but some of the more complex widgets like
2015-04-16 21:05:43 +03:00
comboboxes, tables and trees are not yet implemented. Maybe if I have more
2015-04-12 16:40:42 +03:00
time I will look into adding them, except for comboboxes which are just
2015-04-16 17:20:00 +03:00
really hard to implement.
2015-04-12 16:40:42 +03:00
2015-04-16 21:05:43 +03:00
#### Why did you use ANSI C and not C99 or C++?
2015-04-12 16:40:42 +03:00
Personally I stay out of all "discussions" about C vs C++ since they are totally
worthless and never brought anything good with it. The simple answer is I
2015-04-16 17:20:00 +03:00
personally love C and have nothing against people using C++ exspecially the new
iterations with C++11 and C++14.
2015-04-12 16:40:42 +03:00
While this hopefully settles my view on C vs C++ there is still ANSI C vs C99.
2015-04-16 21:05:43 +03:00
While for personal projects I only use C99 with all its niceties, libraries are
2015-04-16 17:20:00 +03:00
a little bit different. Libraries are designed to reach the highest number of
2015-04-17 23:28:00 +03:00
users possible which brings me to ANSI C as the most portable version.
2015-04-16 21:05:43 +03:00
In addition not all C compiler like the MSVC
2015-04-16 17:20:00 +03:00
compiler fully support C99, which finalized my decision to use ANSI C.
2015-04-12 16:40:42 +03:00
2015-04-16 21:05:43 +03:00
#### Why do you typedef our own types instead of using the standard types
This Project uses ANSI C which does not have the header file `<stdint.h>`
and therefore does not provide the fixed sized types that I need. Therefore
2015-04-12 16:40:42 +03:00
I defined my own types which need to be set to the correct size for each
2015-04-16 17:20:00 +03:00
plaform. But if your development environment provides the header file you can define
2015-04-12 16:40:42 +03:00
`GUI_USE_FIXED_SIZE_TYPES` to directly use the correct types.
2015-04-17 23:29:40 +03:00
#### Why is font/input/window management not provided
2015-04-17 23:28:00 +03:00
As for window and input management it is a ton of work to abstract over
all possible platforms and there are already libraries like SDL or SFML or even
the platform itself which provide you with the functionality.
So instead of reinventing the wheel and trying to do everything the project tries
to be as indepenedent and out of the users way as possible.
This means in practice a litte bit more work on the users behalf but grants a
lot more freedom especially because the toolkit is designed to be embeddable.
The font management on the other hand is a more tricky subject. In the beginning
the toolkit had some basic font handling but it got later removed. This is mainly
a question of if font handling should be part of a gui toolkit or not. As for a
framework the question would definitely be yes but for a toolkit library the
question is not as easy. In the end the project does not have font handling
since there are already a number of font handling libraries in existence or even the
platform (Xlib, Win32) itself already provides a solution.
2015-03-14 19:05:30 +03:00
## References
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-04-12 16:40:42 +03:00
- [Casey Muratori's original introduction to imgui's](http:://mollyrocket.com/861?node=861)
2015-04-16 23:04:34 +03:00
- [Casey Muratori's imgui panel design 1/2](http://mollyrocket.com/casey/stream_0019.html)
- [Casey Muratori's imgui panel design 2/2](http://mollyrocket.com/casey/stream_0020.html)
2015-04-12 16:40:42 +03:00
- [ImGui: The inspiration for this project](https://github.com/ocornut/imgui)
2015-03-14 19:05:30 +03:00
2015-03-03 19:24:02 +03:00
# License
(The MIT License)