123 lines
4.1 KiB
Markdown
123 lines
4.1 KiB
Markdown
# Design Document
|
|
|
|
## Overview
|
|
|
|
This design outlines a simple, cross-platform demo application built with GLFW3 for window management and Nuklear for immediate mode GUI rendering. The application is designed to be minimal and straightforward, serving as a basic example of integrating these technologies.
|
|
|
|
The core design principle is simplicity - create a working demo that shows basic Nuklear GUI elements in a GLFW window with minimal code complexity.
|
|
|
|
## Architecture
|
|
|
|
The application uses a simple, single-file architecture:
|
|
|
|
```
|
|
┌─────────────────────────────────┐
|
|
│ Main Application │ ← Single main.c file
|
|
│ ┌─────────────────────────────┐ │
|
|
│ │ GLFW3 Window Setup │ │ ← Window creation & events
|
|
│ ├─────────────────────────────┤ │
|
|
│ │ Nuklear Integration │ │ ← GUI context & rendering
|
|
│ ├─────────────────────────────┤ │
|
|
│ │ Simple UI Demo │ │ ← Basic UI components
|
|
│ └─────────────────────────────┘ │
|
|
└─────────────────────────────────┘
|
|
```
|
|
|
|
### Key Design Decisions
|
|
|
|
1. **Single File**: Everything in one main.c file for simplicity
|
|
2. **OpenGL Backend**: Using Nuklear's OpenGL3 backend for cross-platform compatibility
|
|
3. **Minimal Dependencies**: Only GLFW3, OpenGL, and Nuklear (header-only)
|
|
4. **Basic UI Elements**: Simple buttons, text, and input fields for demonstration
|
|
|
|
## Components and Interfaces
|
|
|
|
### Main Application Structure
|
|
The application consists of simple functions organized in a single file:
|
|
|
|
```c
|
|
// Core application functions
|
|
int main(int argc, char** argv);
|
|
void init_glfw(void);
|
|
void init_nuklear(void);
|
|
void render_ui(struct nk_context* ctx);
|
|
void cleanup(void);
|
|
|
|
// Simple state variables
|
|
static GLFWwindow* window;
|
|
static struct nk_context* ctx;
|
|
static int window_width = 800;
|
|
static int window_height = 600;
|
|
```
|
|
|
|
### Basic UI Demo Functions
|
|
Simple functions to demonstrate different Nuklear UI elements:
|
|
|
|
```c
|
|
// Demo UI functions
|
|
void demo_basic_widgets(struct nk_context* ctx);
|
|
void demo_text_input(struct nk_context* ctx);
|
|
void demo_buttons(struct nk_context* ctx);
|
|
```
|
|
|
|
## Data Models
|
|
|
|
### Simple State Variables
|
|
The demo uses minimal global state:
|
|
|
|
```c
|
|
// UI state for demo
|
|
static char text_buffer[256] = "Hello World!";
|
|
static float slider_value = 0.5f;
|
|
static int checkbox_value = 1;
|
|
static int option_selected = 0;
|
|
```
|
|
|
|
## Error Handling
|
|
|
|
### Simple Error Handling
|
|
Basic error checking with immediate exit on failure:
|
|
|
|
```c
|
|
// Simple error checking pattern
|
|
if (!glfwInit()) {
|
|
fprintf(stderr, "Failed to initialize GLFW\n");
|
|
exit(EXIT_FAILURE);
|
|
}
|
|
|
|
if (!window) {
|
|
fprintf(stderr, "Failed to create window\n");
|
|
glfwTerminate();
|
|
exit(EXIT_FAILURE);
|
|
}
|
|
```
|
|
|
|
## Testing Strategy
|
|
|
|
### Manual Testing
|
|
- **Build Testing**: Verify compilation on Windows, Linux, and macOS
|
|
- **Visual Testing**: Ensure UI elements render correctly
|
|
- **Interaction Testing**: Test basic button clicks, text input, and sliders
|
|
- **Window Testing**: Test window resize and close functionality
|
|
|
|
## Implementation Notes
|
|
|
|
### Build System
|
|
- **Simple Makefile or CMake**: Basic build configuration
|
|
- **Dependencies**: GLFW3, OpenGL, Nuklear (single header file)
|
|
- **Compiler**: C99 standard for maximum compatibility
|
|
|
|
### File Structure
|
|
```
|
|
project/
|
|
├── main.c # Single source file
|
|
├── nuklear.h # Nuklear header (downloaded)
|
|
├── nuklear_glfw_gl3.h # Nuklear GLFW+OpenGL3 backend
|
|
├── CMakeLists.txt # Build configuration
|
|
└── README.md # Build instructions
|
|
```
|
|
|
|
### Cross-Platform Notes
|
|
- Use GLFW3 for consistent window management across platforms
|
|
- OpenGL 3.3 core profile for modern graphics support
|
|
- Standard C library functions only for maximum portability |