Commit graph

71 commits

Author SHA1 Message Date
Seintian
038868c32b refactor: simplify ncurses border corner drawing logic by removing redundant conditional checks. 2025-12-30 12:03:15 +01:00
Seintian
8643a5d2d9 Fix Ncurses click handling and restore ncursesw build
This commit addresses issues with mouse interaction reliability and build configuration in the Ncurses renderer and example.

Renderer Changes:
- Enable explicit xterm 1003 mouse tracking (Any Event) via escape sequences to ensure reliable hover sensing from the first frame (though not so portable).
- Refactor `Clay_Ncurses_ProcessInput` to:
  - Correctly order `Clay_SetPointerState` calls to ensure the "Pressed" state is registered before the function returns.
  - Detect and return a new `CLAY_NCURSES_KEY_MOUSE_CLICK` event code for single, double, and triple clicks.
- Make `Clay_Ncurses_OnClick` as a semantic wrapper around `Clay_OnHover`.
- Add empty switch cases for `CLAY_RENDER_COMMAND_TYPE_IMAGE` and `CLAY_RENDER_COMMAND_TYPE_CUSTOM` to prevent unhandled enumeration warnings.

Example Application Changes:
- Update `main.c` to break the input processing loop immediately upon receiving `CLAY_NCURSES_KEY_MOUSE_CLICK`, ensuring the "Pressed" state is processed by the layout engine for that frame.

Build System:
- Update `CMakeLists.txt` to replace `FindCurses` with `find_library` and `find_path` for `ncursesw`.
2025-12-29 21:57:50 +01:00
Seintian
e89f3d15e9 feat(ncurses): event-driven scrolling & font styling
- Update `renderers/ncurses/clay_renderer_ncurses.c`:
  - Export `CLAY_NCURSES_KEY_SCROLL_UP` and `CLAY_NCURSES_KEY_SCROLL_DOWN` key codes.
  - Modify `Clay_Ncurses_ProcessInput` to map mouse wheel events (`BUTTON4`, `BUTTON5`) to these key codes.
  - Update `Clay_Ncurses_OnClick` to trigger on `CLAY_POINTER_DATA_PRESSED_THIS_FRAME` for immediate feedback.

- Update `examples/ncurses-example/main.c`:
  - Handle `CLAY_NCURSES_KEY_SCROLL_UP/DOWN` in `App_ProcessInput` to drive `_appState.scrollDelta`.
  - Simplify `HandleHelpToggleClick` to toggle visibility directly.
  - Apply bold and underline font styles to sidebar items.
  - Convert input processing to a `while` loop to process all pending events per frame.
2025-12-29 20:33:20 +01:00
Seintian
c700104760 feat(ncurses): Add interaction callbacks and improve input handling
Introduces Input Processing and Interaction helpers for the Ncurses renderer, ensuring robust mouse support and simplified event handling.

**Renderer (`renderers/ncurses`):**
- **`Clay_Ncurses_ProcessInput`**: Added a dedicated input processing function that handles both keyboard and mouse events.
  - Implemented persistent `_isMouseDown` state tracking to fix missed "fast clicks" and preserve button state during drag operations.
  - Adjusted `mousemask` to `BUTTON1_PRESSED | BUTTON1_RELEASED | REPORT_MOUSE_POSITION` to bypass Ncurses' internal click resolution delay.
- **`Clay_Ncurses_OnClick`**: Added a helper function to easily attach click listeners.
  - Registers the user's callback directly via `Clay_OnHover` (avoiding allocation/proxies).
  - Matches the standard Clay callback signature pattern.

**Example (`examples/ncurses-example`):**
- **Input Loop**: Migrated main loop to use `Clay_Ncurses_ProcessInput`.
- **Interactions**:
  - Added a "Toggle Help" button to the sidebar.
  - Implemented `HandleHelpToggleClick` callback, which explicitly checks for `CLAY_POINTER_DATA_RELEASED_THIS_FRAME` to validate clicks.
  - Added visual hover effects to sidebar items.

**Documentation (`renderers/ncurses/README.md`):**
- Updated "Usage" section to demonstrate `Clay_Ncurses_ProcessInput`.
- Added "Input & Interaction" section documenting the new helpers.
2025-12-28 22:17:27 +01:00
Seintian
97c1a797c4 [renderers/ncurses] Refactor Ncurses renderer and example with atomic functions and Doxygen docs
Major refactor of the Ncurses renderer and example application to improve code readability, maintainability, and documentation coverage.

**Ncurses Renderer (`renderers/ncurses/clay_renderer_ncurses.c`):**
*   **Atomic Rendering Functions**: Decomposed the monolithic `Clay_Ncurses_Render` function into specialized handlers:
    *   `Clay_Ncurses_RenderRectangle`
    *   `Clay_Ncurses_RenderText`
    *   `Clay_Ncurses_RenderBorder`
*   **Scissor Management**: Encapsulated scissor stack operations into `Clay_Ncurses_PushScissor` and `Clay_Ncurses_PopScissor`.
*   **Visibility Logic**: Extracted visibility/clipping checks into `Clay_Ncurses_GetVisibleRect` for cleaner reuse.
*   **Documentation**: Added comprehensive Doxygen documentation for file headers, internal state, constants, and all functions.

**Ncurses Example (`examples/ncurses-example/main.c`):**
*   **Architecture Refactor**: Implementation split into clear "App State", "Input Processing", and "UI Components" sections.
*   **UI Componentization**: Renamed and organized UI functions with a consistent `UI_` prefix (e.g., `UI_Sidebar`, `UI_FeedPost`, `UI_HelpModal`).
*   **State Management**: Introduced `AppState` struct to centralize application state (sidebar visibility, scroll delta, etc.).
*   **Input Handling**: Centralized input logic in `App_ProcessInput` loop.
*   **Documentation**: Added full Doxygen documentation for the example source.

This refactor maintains identical runtime behavior while significantly improving the codebase's "spoken english" readability and modularity. loop.
*   **Documentation**: Added full Doxygen documentation for the example source.

This refactor maintains identical runtime behavior while significantly improving the codebase's  readability and modularity.
2025-12-28 18:39:25 +01:00
Seintian
de3d63cf61 feat(ncurses): optimize rendering, fix memory leaks, and add rounded corners
Significantly improves the stability, performance, and visual quality of the ncurses renderer.
**Renderer Improvements (`clay_renderer_ncurses.c`):**
*   **Flicker Reduction**:
    *   Removed `erase()` call at the start of the frame to enable differential rendering.
    *   Implemented "Dirty Check" optimizations for Rectangles, Borders, and Text. The renderer now reads the existing screen content (using `mvinch`, `mvin_wch`, `mvin_wchnstr`) and only issues draw commands if the content or color differs.
    *   Hardened Rectangle dirty check to mask out volatile attributes (comparing only `A_CHARTEXT | A_COLOR`), preventing false-positive redraws caused by internal terminal flags.
*   **Memory Safety**:
    *   Fixed internal ncurses memory leaks by calling `delscreen(set_term(NULL))` in `Clay_Ncurses_Terminate` to properly free the default screen wrapper.
*   **Visual Features**:
    *   Added support for **Rounded Corners**: Borders with `cornerRadius > 0` now render using Unicode arc characters (`╭`, `╮`, `╯`, `╰`).
    *   Upgraded standard borders to use full Unicode box-drawing characters.
**Example Application Updates (`ncurses-example/main.c`):**
*   **Layout Stability**:
    *   Refactored all layout dimensions and gaps to use `CLAY_NCURSES_CELL_WIDTH` (8) and `CLAY_NCURSES_CELL_HEIGHT` (16) macros, ensuring strict grid alignment.
    *   Fixed vertical jitter in "Profile Icon" and text headers by enforcing exact height multiples and top-alignment, eliminating sub-pixel rounding errors during scroll.
*   **New UI Elements**:
    *   Added a **Floating Help Modal** (toggled via 'H') to demonstrate Z-ordering and localized input handling.
    *   Added "Server Status" progress bars to the Sidebar to demonstrate percent-based sizing and colored rectangles.
    *   Added "Mixed Border" examples to the Sidebar to showcase the new rounded corner capabilities.
    *   Added "Black" background constant usage for cleaner code.
2025-12-28 18:05:06 +01:00
Seintian
d4a48a07fc feat(ncurses): overhaul renderer with UTF-8, 256-colors, and visual improvements
Significantly enhances the Ncurses renderer capabilities and updates the example application.

Renderer Changes:
- Unicode Support:
  - Implemented automatic UTF-8 locale detection and initialization.
  - Switched to wide-character handling (`wchar_t`, `mvaddnwstr`) for correct rendering of multi-byte characters (e.g., Emojis).
  - Used `wcwidth` for accurate string width measurement.
- Color Support:
  - Upgraded from 3-bit (8 colors) to 256-color support (xterm-256color).
  - Added `Clay_Ncurses_MatchColor` to map arbitrary RGB values to the nearest color in the standard 6x6x6 color cube.
  - Added capability detection to fallback gracefully on simpler terminals.
- Visual Fidelity:
  - Implemented background color inheritance (`Clay_Ncurses_GetBackgroundAt`) to simulate transparency.
  - Text and borders now render on top of existing background colors instead of resetting to the terminal default.
- Build & POSIX:
  - Added `_XOPEN_SOURCE_EXTENDED` and `_XOPEN_SOURCE=700` definitions for standard compliance.

Example Application (clay-ncurses-example):
- Theme:
  - Updated to a modern dark theme (Uniform `{20, 20, 20}` background).
  - Switched to saturated/bright foreground colors for better contrast.
- Fixes:
  - Replaced obsolete `usleep` with POSIX-compliant `nanosleep`.
- Build:
  - Updated CMakeLists.txt to enforce linking against `ncursesw` (wide version).

Verified with `clay-ncurses-example` on Linux (xterm-256color).
2025-12-28 15:19:37 +01:00
Seintian
840606d0c1 feat: Add ncurses renderer and example
- **Renderer**: Implemented `clay_renderer_ncurses.c` supporting rectangles, text, borders, and clipping using standard ncurses plotting.
- **Example**: Added `examples/ncurses-example` demonstrating a scrollable "Social Feed" UI with keyboard navigation.
- **Build**: Added `CLAY_INCLUDE_NCURSES_EXAMPLES` option to root `CMakeLists.txt` and integrated the new example.
- **CompConfig**: Updated `.gitignore` to strictly exclude `build/`, `_deps/`, and other standard CMake artifacts.
2025-12-28 14:01:41 +01:00
Daniel Mayovskiy
fd97d8179e
[Renderers/termbox] fixed horizontal text culling bug (#525)
Some checks failed
CMake on multiple platforms / build (Release, cl, cl, windows-latest) (push) Has been cancelled
CMake on multiple platforms / build (Release, clang, clang++, ubuntu-latest) (push) Has been cancelled
CMake on multiple platforms / build (Release, gcc, g++, ubuntu-latest) (push) Has been cancelled
Odin Bindings Update / check_changes (push) Has been cancelled
Odin Bindings Update / build (macos-latest) (push) Has been cancelled
Odin Bindings Update / build (ubuntu-latest) (push) Has been cancelled
Odin Bindings Update / commit (push) Has been cancelled
2025-10-23 12:58:39 +11:00
rivten
5a0d301c60
[Renderers/Sokol] allow usage of images with sokol renderer (#489)
Co-authored-by: Hugo Viala <h.viala@ganacos.com>
Co-authored-by: Andrew Sampson <1297077+andrewmd5@users.noreply.github.com>
2025-09-08 11:35:18 +10:00
Andrew Sampson
1bc5105272
[Renderers/Sokol] Text measurement/rendering width mismatch in sokol_clay (#480) 2025-08-19 12:14:13 +10:00
Mivirl
a9c1f9a8a7
[Renderers/termbox2] Termbox2 renderer & examples (#419) 2025-06-27 08:26:38 +10:00
wolfee
4a91cac1b2
[Renderers/SDL3] Fix border position calculated incorrectly (#446) 2025-06-23 10:43:08 +10:00
wolfee
f97cb9ea10
[Renderers/SDL] Font sizing is ignored (#444) 2025-06-23 09:30:14 +10:00
Alan
58491394ca
[Renderers/Raylib] Fix element float distortion (#430) 2025-06-05 10:49:26 +10:00
Nic Barker
87575cb7c3 [Core] Fix handling of letter spacing 2025-06-05 10:38:53 +10:00
Nic Barker
0431f862f4 [Core] Improve handling of aspect ratio scaling 2025-06-02 12:14:09 +10:00
Emmanuel
65e813d4df
[Renderers/Terminal] Add initial implementation of terminal renderer (#91) 2025-05-22 12:45:52 +12:00
Matt Jennings
e2f94f17f6
[Renderers/Playdate] Playdate console example (#404) 2025-05-19 11:46:39 +12:00
Zordan
eb1d85f2a6
[Renderers/Cairo] Fix cairo renderer and example (#416) 2025-05-19 11:36:08 +12:00
David Delassus
fb4eec93b2
[Renderers/SDL3] Use SDL_Texture instead of SDL_Surface for images (#402) 2025-05-05 12:27:41 +12:00
Tim Lügger
5391a259f3
[Renderers/Raylib] Fix raylib renderer border bottom left corner radius (#378) 2025-04-14 14:26:12 +12:00
Lily Nikitin
fe2d44a888
[Renderers/Raylib] Add explicit type cast for malloc (#379) 2025-04-14 14:23:13 +12:00
Nathan Korth
eb46688b82
[Renderers/Sokol] Sokol renderer & examples (#373) 2025-04-09 13:40:22 +12:00
Philosoph228
87efc49f52
[Renderers/WinGDI] Working on Win32 GDI renderer and example (#344) 2025-04-09 11:31:33 +12:00
Emerald-Ruby
6186596b41
math.h include missing cause lots of warning logs 2025-03-15 21:51:36 +00:00
Nic Barker
a7d46629b1
[Renderers/SDL2] Fix rounded corner border index 2025-03-13 09:52:16 +13:00
Nic Barker
bee93bc7ba
[Renderers/Raylib] Reuse memory in raylib renderer for temporary string allocations 2025-03-13 09:51:44 +13:00
Nic Barker
3e39e444db Update README 2025-03-13 09:21:09 +13:00
hailey
6567f85eb3 Updated rectangle border rendering 2025-03-10 10:29:55 -05:00
hailey
a92ec772e1 [Renderers/Win32_GDI] first pass, fixed build errors and added build script 2025-03-10 09:33:12 -05:00
__hexmaster111
a782df73a1
Added win32 samples (first pass) 2025-03-10 09:23:36 -05:00
__hexmaster111
3a9172ec4c
Merge branch 'nicbarker:main' into main 2025-03-10 09:12:52 -05:00
__hexmaster111
12319fc240
Updated measure text to support the defualt raylib font if the user spesfied font failed to load. (#305) 2025-03-05 10:13:42 +13:00
__hexmaster111
ad363f986c
Added missing CloseWindow() call for raylib as well 2025-03-03 16:08:34 -06:00
__hexmaster111
3612431e82
[Raylib Render] Dont call malloc and Free every frame so much 2025-03-03 16:04:07 -06:00
mizmar
375501fb89
[Renderers/SDL2] Fix rounded corner border index 2025-03-03 18:36:04 +01:00
Timothy Hoyt
47c8e9178e
[Renderers/SDL2] Make SDL_RenderCornerBorder static (#263) 2025-02-17 08:49:05 +13:00
irfan-zahir
a62ee15758
[Renderers/SDL3] Enable sdl3 alpha blending (#261) 2025-02-17 08:48:19 +13:00
Timothy Hoyt
eb553962e8
[Renderers/SDL2] Added rounded corner borders and fixed other issues (#258) 2025-02-14 10:14:11 +13:00
tomat
bc2548e3ec
[Renderers/SDL3] Add image rendering and scissor support to SDL3 renderer (#246) 2025-02-13 10:02:06 +13:00
Julio Ernesto Rodríguez Cabañas
eeb4520f48
[Renderers/SDL3] Use text engine to render text on the SDL3 renderer (#256) 2025-02-13 09:19:36 +13:00
Nic Barker
72af2a4020 [Compilers] Fix missing initializer warnings under -Wextra 2025-02-12 09:12:11 +13:00
tomat
e7bc3869f7
[Renderers/SDL2] Add rounded rectangle support to sdl2 renderer; feature-completes sdl2 renderer (#245) 2025-02-07 11:26:49 +13:00
Nic Barker
9d940c1f8e
[Core] Replace config macros with a single unified configuration struct (#240) 2025-02-04 17:00:19 +13:00
Nic Barker
1bcf256e4d
[Core] Replace generated arrays with macro declarations, align cache lines to 64 bytes (#235) 2025-01-29 17:14:01 +13:00
Martin Evald
e9f2e6c4f1
[Renderers/SDL2] Don't take addresses of temporaries. (#232) 2025-01-29 13:09:41 +13:00
Nic Barker
0a703de69a
[Core] Add z-index and string base to Render Commands (#227) 2025-01-26 15:28:35 +13:00
arnauNau
c0dac38c87
[Renderers/SDL3] Add borders and rounded borders functionality. (#220) 2025-01-26 14:39:34 +13:00
arnauNau
aba846a446
[Renderers/SDL3] Add rounded corners rectangle functionality (#219) 2025-01-23 09:30:24 +13:00