Skip to content

Commit aae38f2

Browse files
committed
2 parents b415369 + 8bc5248 commit aae38f2

11 files changed

Lines changed: 377 additions & 107 deletions

File tree

AGENTS.md

Lines changed: 219 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,219 @@
1+
# AGENTS.md - Agentic Coding Guidelines for tiny_ui
2+
3+
## Project Overview
4+
5+
tiny_ui is a C++17 library for creating simple UIs on Windows and Linux, using SDL2 as the renderer. The project is built with CMake and vcpkg for dependency management.
6+
7+
---
8+
9+
## Build, Lint, and Test Commands
10+
11+
### Building the Project
12+
13+
```bash
14+
# Configure with CMake (uses vcpkg toolchain)
15+
cmake -B build -DCMAKE_BUILD_TYPE=Release
16+
17+
# Build the library and samples
18+
cmake --build build --config Release
19+
```
20+
21+
On Windows with Visual Studio, you can also open `tiny_ui.slnx` or use the `.vcxproj` files.
22+
23+
### Dependencies
24+
25+
The project requires:
26+
- SDL2
27+
- SDL2_image
28+
- SDL2_ttf
29+
- glm
30+
31+
These are managed via vcpkg (see `vcpkg.json`).
32+
33+
### Running the Sample Application
34+
35+
```bash
36+
# After building, run the sample
37+
./bin/release/tiny_ui_sample.exe # Windows
38+
./bin/tiny_ui_sample # Linux
39+
```
40+
41+
### Linting and Formatting
42+
43+
The project uses `.clang-format` for code formatting:
44+
45+
```bash
46+
# Format a single file
47+
clang-format -i src/tinyui.cpp
48+
49+
# Format all source files
50+
find src -name "*.cpp" -o -name "*.h" | xargs clang-format -i
51+
```
52+
53+
### Testing
54+
55+
**Note**: This project currently has no automated tests. The test step in CI (`.github/workflows/cmake.yml`) is commented out. If adding tests:
56+
57+
```bash
58+
# Run tests via CTest (when implemented)
59+
cd build
60+
ctest -C Release
61+
```
62+
63+
To run a single test (when tests exist), use CTest's filtering:
64+
```bash
65+
ctest -R test_name_pattern
66+
```
67+
68+
---
69+
70+
## Code Style Guidelines
71+
72+
### General Style
73+
74+
- **C++ Standard**: C++17
75+
- **Formatting**: Uses `.clang-format` (LLVM-based, see `.clang-format`)
76+
- **Indentation**: 4 spaces, no tabs
77+
- **Column Limit**: 0 (unlimited)
78+
79+
### File Organization
80+
81+
- Header files (`.h`) go in `src/`
82+
- Implementation files (`.cpp`) go in `src/`
83+
- Backend-specific code goes in `src/backends/`
84+
- Samples go in `samples/`
85+
- All source files must include the MIT License header
86+
87+
### Imports and Includes
88+
89+
```cpp
90+
// Order: 1. Project headers, 2. STL/Standard headers, 3. External libraries
91+
#include "tinyui.h"
92+
#include "widgets.h"
93+
#include "backends/sdl2_renderer.h"
94+
95+
#include <iostream>
96+
#include <cstring>
97+
98+
#include "stb_image.h"
99+
```
100+
101+
Include order (per `.clang-format`):
102+
1. Local project headers (`"*.h"`)
103+
2. System headers (`<*.h>`)
104+
3. Other system headers (`<*>`)
105+
106+
### Naming Conventions
107+
108+
- **Types/Structs/Enums**: PascalCase (e.g., `struct Widget`, `enum class Alignment`)
109+
- **Functions**: camelCase (e.g., `createContext()`, `initScreen()`)
110+
- **Member Variables**: `m` prefix (e.g., `mId`, `mType`, `mParent`)
111+
- **Constants**: PascalCase or `k` prefix (e.g., `InvalidHandle`, `kDefaultSize`)
112+
- **Namespaces**: lowercase (e.g., `namespace tinyui`)
113+
114+
### Type Conventions
115+
116+
- Use `int32_t` for explicit-width integers
117+
- Use `ret_code` (defined as `int32_t`) for return codes
118+
- Use `nullptr` instead of `NULL`
119+
- Use `const` extensively for pointer parameters and member functions
120+
- Use `constexpr` for compile-time constants
121+
- Use `static constexpr` for class-level constants
122+
123+
### Return Codes
124+
125+
The library uses a consistent return code pattern:
126+
```cpp
127+
static constexpr ret_code InvalidRenderHandle = -3;
128+
static constexpr ret_code InvalidHandle = -2;
129+
static constexpr ret_code ErrorCode = -1;
130+
static constexpr ret_code ResultOk = 0;
131+
```
132+
133+
### Error Handling
134+
135+
- Return error codes for recoverable errors
136+
- Use `assert()` for programming errors/invariants (development only)
137+
- Validate input parameters at the start of functions
138+
139+
### Enums
140+
141+
Use `enum class` for type-safe enums:
142+
```cpp
143+
enum class Alignment : int32_t {
144+
Invalid = -1,
145+
Left = 0,
146+
Center,
147+
Right,
148+
Count // Use Count for array sizing
149+
};
150+
```
151+
152+
### Structs and Classes
153+
154+
- Use structs for POD (Plain Old Data) types
155+
- Use `= default` for trivial constructors/destructors
156+
- Initialize member variables with default values in class definition
157+
- Use Doxygen-style comments for documentation
158+
159+
### Code Example
160+
161+
```cpp
162+
/// @brief The tiny ui context.
163+
struct Context {
164+
bool mCreated{false};
165+
bool mRequestShutdown{false};
166+
const char *mAppTitle{nullptr};
167+
Widget *mRoot{nullptr};
168+
169+
/// @brief Will create a new tiny ui context.
170+
/// @param title The title of the context.
171+
/// @return The created context.
172+
static Context *create(const char *title);
173+
174+
/// @brief Will destroy a valid tinyui context.
175+
/// @param ctx The context to destroy.
176+
static void destroy(Context *ctx);
177+
};
178+
```
179+
180+
### Common Patterns
181+
182+
```cpp
183+
// Function returning error code
184+
ret_code TinyUi::initScreen(int32_t x, int32_t y, int32_t w, int32_t h) {
185+
if (w <= 0 || h <= 0) {
186+
return ErrorCode;
187+
}
188+
// ... implementation
189+
return ResultOk;
190+
}
191+
192+
// Callback interface
193+
struct CallbackI {
194+
typedef int (*funcCallback) (uint32_t id, void *data);
195+
funcCallback mfuncCallback[Events::NumEvents];
196+
void *mInstance{nullptr};
197+
};
198+
```
199+
200+
---
201+
202+
## CI/CD
203+
204+
The project uses GitHub Actions (see `.github/workflows/cmake.yml`):
205+
- Builds on Ubuntu latest
206+
- Installs SDL2, SDL2-image, SDL2-ttf via apt
207+
- Runs CMake configure and build
208+
209+
---
210+
211+
## Key Files
212+
213+
- `CMakeLists.txt` - Main build configuration
214+
- `vcpkg.json` - Dependency manifest
215+
- `.clang-format` - Code formatting rules
216+
- `.github/workflows/cmake.yml` - CI pipeline
217+
- `src/tinyui.h` - Main header with core types
218+
- `src/widgets.h` - Widget definitions
219+
- `src/backends/` - Platform-specific rendering backends

CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ SET( CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_HOME_DIRECTORY}/lib )
2020
SET( CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_HOME_DIRECTORY}/bin )
2121

2222
INCLUDE_DIRECTORIES(
23-
${CMAKE_CURRENT_BINARY_DIR}/src
24-
${CMAKE_CURRENT_BINARY_DIR}/contrib/stb_image
23+
src
24+
contrib/stb_image
2525
)
2626

2727
find_package(SDL2 CONFIG REQUIRED)

README.md

Lines changed: 44 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -3,83 +3,71 @@
33
</p>
44

55
# tiny_ui
6-
This repo contains a small library to generate simple UIs on different platforms. I am using it for my own games.
7-
8-
Currently this works on Windows and Linux. The renderer is based on SDL2. An OSRE Renderbackend is planned.
9-
10-
# Features
11-
- Elements
12-
- Panel
13-
- Buttons
14-
- Labels
15-
- Progress Bar (experimental)
16-
- Platform support for
17-
- Windows
18-
- Linux
19-
20-
# Planned
21-
- Treeview
22-
- Status Bar
23-
- Default dialogs
24-
25-
# Examples:
26-
## Quickstart
6+
7+
A lightweight C++17 UI library for Windows and Linux, using SDL2 as the renderer.
8+
9+
## Features
10+
11+
- **Widgets**: Panel, Button, Label, Progress Bar (experimental)
12+
- **Platforms**: Windows, Linux
13+
14+
## Build
15+
16+
```bash
17+
# Configure and build
18+
cmake -B build -DCMAKE_BUILD_TYPE=Release
19+
cmake --build build --config Release
20+
```
21+
22+
## Quick Start
2723

2824
```cpp
2925
#include <iostream>
3026
#include "widgets.h"
3127

32-
#ifdef main
33-
# undef main
34-
#endif
35-
3628
using namespace tinyui;
3729

38-
static int quit(unsigned int id, void *data) {
39-
if (data == nullptr) {
40-
return ErrorCode;
41-
}
42-
43-
Context *ctx = static_cast<Context*>(data);
30+
static int onQuit(unsigned int id, void *data) {
31+
auto *ctx = static_cast<Context*>(data);
4432
ctx->mRequestShutdown = true;
45-
4633
return ResultOk;
4734
}
4835

49-
int main(int argc, char *argv[]) {
36+
int main() {
5037
Style style = TinyUi::getDefaultStyle();
51-
Context &ctx = Context::create("Sample-Screen", style);
52-
53-
if (TinyUi::initScreen(ctx, 20, 20, 1024, 768) == -1) {
54-
ctx.mLogger(LogSeverity::Error, "Cannot init screen");
55-
return ErrorCode;
56-
}
38+
Context *ctx = Context::create("Sample", style);
5739

58-
Widgets::panel(ctx, RootPanelId, 0, "Sample-Dialog", 90, 5, 120, 300, nullptr);
59-
Widgets::label(ctx, 2, RootPanelId, "Title", 100, 10, 100, 20, Alignment::Center);
60-
Widgets::button(ctx, 3, RootPanelId, "Test 1", nullptr, 100, 50, 100, 40, nullptr);
61-
Widgets::button(ctx, 4, RootPanelId, "Test 2", nullptr, 100, 100, 100, 40, nullptr);
62-
Widgets::button(ctx, 5, RootPanelId, "Test 3", nullptr, 100, 150, 100, 40, nullptr);
63-
Widgets::button(ctx, 6, RootPanelId, nullptr, "button_test.png", 100, 200, 100, 40, nullptr);
40+
TinyUi::initScreen(20, 20, 1024, 768);
6441

65-
CallbackI quit(quit, &ctx);
66-
Widgets::button(ctx, 7, RootPanelId, "Quit", nullptr, 100, 250, 100, 40, &quit);
42+
Widgets::panel(ctx, RootPanelId, 0, "Dialog", 90, 5, 120, 300, nullptr);
43+
Widgets::label(ctx, 1, RootPanelId, "Title", 100, 10, 100, 20, Alignment::Center);
44+
Widgets::button(ctx, 2, RootPanelId, "Quit", nullptr, 100, 50, 100, 40, &onQuit);
6745

68-
while (TinyUi::run(ctx)) {
69-
TinyUi::beginRender(ctx, style.mClearColor);
46+
while (TinyUi::run()) {
47+
TinyUi::beginRender(style.mClearColor);
7048
Widgets::renderWidgets(ctx);
71-
TinyUi::endRender(ctx);
49+
TinyUi::endRender();
7250
}
7351

74-
TinyUi::release(ctx);
75-
52+
TinyUi::release();
7653
return 0;
7754
}
55+
```
7856
57+
## Running the Sample
58+
59+
```bash
60+
./bin/release/tiny_ui_sample.exe # Windows
61+
./bin/tiny_ui_sample # Linux
7962
```
80-
results to
8163

82-
![Sample screen](assets/images/sample1.png "The sample screen").
64+
![Sample](assets/images/sample1.png)
65+
66+
## Planned
67+
68+
- TreeView, Status Bar, Default dialogs
69+
70+
---
8371

84-
Build Status: [![CMake](https://github.com/kimkulling/tiny_ui/actions/workflows/cmake.yml/badge.svg)](https://github.com/kimkulling/tiny_ui/actions/workflows/cmake.yml)
85-
[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=kimkulling_tiny_ui&metric=alert_status)](https://sonarcloud.io/summary/new_code?id=kimkulling_tiny_ui)
72+
[![CMake](https://github.com/kimkulling/tiny_ui/actions/workflows/cmake.yml/badge.svg)](https://github.com/kimkulling/tiny_ui/actions/workflows/cmake.yml)
73+
[![Quality Gate](https://sonarcloud.io/api/project_badges/measure?project=kimkulling_tiny_ui&metric=alert_status)](https://sonarcloud.io/summary/new_code?id=kimkulling_tiny_ui)

contrib/vcpkg

Submodule vcpkg updated 1672 files

0 commit comments

Comments
 (0)