mirror of
https://github.com/nicbarker/clay.git
synced 2025-11-03 08:06:17 +00:00
Compare commits
9 commits
de0b4b8739
...
83bdaa4dbc
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
83bdaa4dbc | ||
|
|
fd97d8179e | ||
|
|
7216815536 | ||
|
|
83129995f7 | ||
|
|
500fab288e | ||
|
|
7af4d9d3f0 | ||
|
|
838bfae80a | ||
|
|
e1a4fb9810 | ||
|
|
e465d05284 |
4
.gitignore
vendored
4
.gitignore
vendored
|
|
@ -5,3 +5,7 @@ cmake-build-release/
|
||||||
node_modules/
|
node_modules/
|
||||||
*.dSYM
|
*.dSYM
|
||||||
.vs/
|
.vs/
|
||||||
|
.direnv/
|
||||||
|
.envrc
|
||||||
|
/build/
|
||||||
|
/result/
|
||||||
|
|
|
||||||
|
|
@ -15,5 +15,5 @@ mkdir -p build/clay \
|
||||||
-Wl,--initial-memory=6553600 \
|
-Wl,--initial-memory=6553600 \
|
||||||
-o build/clay/index.wasm \
|
-o build/clay/index.wasm \
|
||||||
main.c \
|
main.c \
|
||||||
&& cp index.html build/clay/index.html && cp -r fonts/ build/clay/fonts \
|
&& cp index.html build/index.html && cp -r fonts/ build/clay/fonts \
|
||||||
&& cp index.html build/clay/index.html && cp -r images/ build/clay/images
|
&& cp -r images/ build/clay/images
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ set(FETCHCONTENT_QUIET FALSE)
|
||||||
FetchContent_Declare(
|
FetchContent_Declare(
|
||||||
termbox2
|
termbox2
|
||||||
GIT_REPOSITORY "https://github.com/termbox/termbox2.git"
|
GIT_REPOSITORY "https://github.com/termbox/termbox2.git"
|
||||||
GIT_TAG "9c9281a9a4c971a2be57f8645e828ec99fd555e8"
|
GIT_TAG "ffd159c2a6106dd5eef338a6702ad15d4d4aa809"
|
||||||
GIT_PROGRESS TRUE
|
GIT_PROGRESS TRUE
|
||||||
GIT_SHALLOW TRUE
|
GIT_SHALLOW TRUE
|
||||||
)
|
)
|
||||||
|
|
@ -17,7 +17,7 @@ FetchContent_MakeAvailable(termbox2)
|
||||||
FetchContent_Declare(
|
FetchContent_Declare(
|
||||||
stb
|
stb
|
||||||
GIT_REPOSITORY "https://github.com/nothings/stb.git"
|
GIT_REPOSITORY "https://github.com/nothings/stb.git"
|
||||||
GIT_TAG "f58f558c120e9b32c217290b80bad1a0729fbb2c"
|
GIT_TAG "fede005abaf93d9d7f3a679d1999b2db341b360f"
|
||||||
GIT_PROGRESS TRUE
|
GIT_PROGRESS TRUE
|
||||||
GIT_SHALLOW TRUE
|
GIT_SHALLOW TRUE
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -90,7 +90,7 @@ void component_text_pair(const char *key, const char *value)
|
||||||
|
|
||||||
void component_termbox_settings(void)
|
void component_termbox_settings(void)
|
||||||
{
|
{
|
||||||
CLAY_AUTO_ID({
|
CLAY(CLAY_ID("Termbox Settings"), {
|
||||||
.floating = {
|
.floating = {
|
||||||
.attachTo = CLAY_ATTACH_TO_PARENT,
|
.attachTo = CLAY_ATTACH_TO_PARENT,
|
||||||
.zIndex = 1,
|
.zIndex = 1,
|
||||||
|
|
@ -509,13 +509,18 @@ Clay_RenderCommandArray CreateLayout(clay_tb_image *image1, clay_tb_image *image
|
||||||
{
|
{
|
||||||
Clay_BeginLayout();
|
Clay_BeginLayout();
|
||||||
CLAY_AUTO_ID({
|
CLAY_AUTO_ID({
|
||||||
|
.clip = {
|
||||||
|
.vertical = false,
|
||||||
|
.horizontal = true,
|
||||||
|
.childOffset = Clay_GetScrollOffset(),
|
||||||
|
},
|
||||||
.layout = {
|
.layout = {
|
||||||
.sizing = {
|
.sizing = {
|
||||||
.width = CLAY_SIZING_GROW(),
|
.width = CLAY_SIZING_GROW(),
|
||||||
.height = CLAY_SIZING_GROW()
|
.height = CLAY_SIZING_GROW()
|
||||||
},
|
},
|
||||||
.childAlignment = {
|
.childAlignment = {
|
||||||
.x = CLAY_ALIGN_X_CENTER,
|
.x = CLAY_ALIGN_X_LEFT,
|
||||||
.y = CLAY_ALIGN_Y_CENTER
|
.y = CLAY_ALIGN_Y_CENTER
|
||||||
},
|
},
|
||||||
.childGap = 64
|
.childGap = 64
|
||||||
|
|
@ -714,12 +719,12 @@ void handle_termbox_events(void)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case TB_KEY_MOUSE_WHEEL_UP: {
|
case TB_KEY_MOUSE_WHEEL_UP: {
|
||||||
Clay_Vector2 scrollDelta = { 0, 1 * Clay_Termbox_Cell_Height() };
|
Clay_Vector2 scrollDelta = { 0.5 * Clay_Termbox_Cell_Width(), 0 };
|
||||||
Clay_UpdateScrollContainers(false, scrollDelta, 1);
|
Clay_UpdateScrollContainers(false, scrollDelta, 1);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case TB_KEY_MOUSE_WHEEL_DOWN: {
|
case TB_KEY_MOUSE_WHEEL_DOWN: {
|
||||||
Clay_Vector2 scrollDelta = { 0, -1 * Clay_Termbox_Cell_Height() };
|
Clay_Vector2 scrollDelta = { -0.5 * Clay_Termbox_Cell_Width(), 0 };
|
||||||
Clay_UpdateScrollContainers(false, scrollDelta, 1);
|
Clay_UpdateScrollContainers(false, scrollDelta, 1);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
27
flake.lock
Normal file
27
flake.lock
Normal file
|
|
@ -0,0 +1,27 @@
|
||||||
|
{
|
||||||
|
"nodes": {
|
||||||
|
"nixpkgs": {
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1749285348,
|
||||||
|
"narHash": "sha256-frdhQvPbmDYaScPFiCnfdh3B/Vh81Uuoo0w5TkWmmjU=",
|
||||||
|
"owner": "NixOS",
|
||||||
|
"repo": "nixpkgs",
|
||||||
|
"rev": "3e3afe5174c561dee0df6f2c2b2236990146329f",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "NixOS",
|
||||||
|
"ref": "nixos-unstable",
|
||||||
|
"repo": "nixpkgs",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"root": {
|
||||||
|
"inputs": {
|
||||||
|
"nixpkgs": "nixpkgs"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"root": "root",
|
||||||
|
"version": 7
|
||||||
|
}
|
||||||
167
flake.nix
Normal file
167
flake.nix
Normal file
|
|
@ -0,0 +1,167 @@
|
||||||
|
{
|
||||||
|
description = "Clay (short for C Layout) is a high performance 2D UI layout library.";
|
||||||
|
|
||||||
|
inputs = {
|
||||||
|
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
|
||||||
|
};
|
||||||
|
|
||||||
|
outputs = {
|
||||||
|
self,
|
||||||
|
nixpkgs,
|
||||||
|
}: let
|
||||||
|
inherit (nixpkgs) lib;
|
||||||
|
|
||||||
|
systems = lib.systems.flakeExposed;
|
||||||
|
forAllSystems = lib.genAttrs systems;
|
||||||
|
nixpkgsFor = forAllSystems (system: nixpkgs.legacyPackages.${system});
|
||||||
|
|
||||||
|
date = let
|
||||||
|
# YYYYMMDD
|
||||||
|
date' = lib.substring 0 8 self.lastModifiedDate;
|
||||||
|
year = lib.substring 0 4 date';
|
||||||
|
month = lib.substring 4 2 date';
|
||||||
|
day = lib.substring 6 2 date';
|
||||||
|
in
|
||||||
|
if (self ? lastModifiedDate)
|
||||||
|
then lib.concatStringsSep "-" [year month day]
|
||||||
|
else "unknown";
|
||||||
|
|
||||||
|
mkClayPackage = {
|
||||||
|
system,
|
||||||
|
version,
|
||||||
|
src,
|
||||||
|
suffix,
|
||||||
|
}:
|
||||||
|
nixpkgsFor.${system}.stdenv.mkDerivation {
|
||||||
|
pname = "clay";
|
||||||
|
version = "${version}${suffix}";
|
||||||
|
inherit src;
|
||||||
|
|
||||||
|
dontBuild = true;
|
||||||
|
|
||||||
|
postInstall = ''
|
||||||
|
mkdir -p $out/include
|
||||||
|
mkdir -p $out/lib/pkgconfig
|
||||||
|
|
||||||
|
cp clay.h $out/include
|
||||||
|
|
||||||
|
cat <<EOF >$out/lib/pkgconfig/clay.pc
|
||||||
|
prefix=$out
|
||||||
|
includedir=$out/include
|
||||||
|
Name: Clay
|
||||||
|
Description: Clay (short for C Layout) is a high performance 2D UI layout library.
|
||||||
|
Version: ${version}
|
||||||
|
Cflags: -I$out/include
|
||||||
|
EOF
|
||||||
|
'';
|
||||||
|
|
||||||
|
passthru.tests.pkg-config = nixpkgs.lib.testing.testMetaPkgConfig self.packages.${system}.${version};
|
||||||
|
|
||||||
|
meta = with lib; {
|
||||||
|
description = "Clay (short for C Layout) is a high performance 2D UI layout library.";
|
||||||
|
homepage = "https://github.com/nicbarker/clay";
|
||||||
|
license = licenses.zlib;
|
||||||
|
maintainers = with maintainers; [nicbarker];
|
||||||
|
pkgConfigModules = ["clay"];
|
||||||
|
platforms = platforms.all;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
in {
|
||||||
|
checks = forAllSystems (
|
||||||
|
system: let
|
||||||
|
pkgs = nixpkgsFor.${system};
|
||||||
|
in {
|
||||||
|
formatting =
|
||||||
|
pkgs.runCommand "format-flake" {
|
||||||
|
nativeBuildInputs = with pkgs; [
|
||||||
|
alejandra
|
||||||
|
deadnix
|
||||||
|
statix
|
||||||
|
];
|
||||||
|
} ''
|
||||||
|
cd ${self}
|
||||||
|
|
||||||
|
echo "Checking nix formatting"
|
||||||
|
alejandra --check .
|
||||||
|
|
||||||
|
echo "Checking dead code"
|
||||||
|
deadnix --fail .
|
||||||
|
|
||||||
|
echo "Checking statix"
|
||||||
|
statix check .
|
||||||
|
|
||||||
|
touch $out
|
||||||
|
'';
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
devShells = forAllSystems (
|
||||||
|
system: let
|
||||||
|
pkgs = nixpkgsFor.${system};
|
||||||
|
in {
|
||||||
|
default = pkgs.mkShell {
|
||||||
|
# For testing renderers and examples, aswell as tests
|
||||||
|
packages = with pkgs; [
|
||||||
|
cmake # this is needed for building examples and tests
|
||||||
|
clang-tools # for clangd and clang-tidy (optional)
|
||||||
|
pkg-config
|
||||||
|
alejandra # for formatting nix
|
||||||
|
|
||||||
|
lld # for wasm
|
||||||
|
];
|
||||||
|
|
||||||
|
buildInputs = with pkgs; [
|
||||||
|
SDL2
|
||||||
|
SDL2_image
|
||||||
|
SDL2_ttf
|
||||||
|
|
||||||
|
sdl3
|
||||||
|
sdl3-ttf
|
||||||
|
sdl3-image
|
||||||
|
|
||||||
|
cairo
|
||||||
|
raylib
|
||||||
|
sokol
|
||||||
|
|
||||||
|
# dependencies for examples and tests
|
||||||
|
xorg.libXrandr
|
||||||
|
xorg.libXinerama
|
||||||
|
xorg.libXcursor
|
||||||
|
xorg.libXi
|
||||||
|
];
|
||||||
|
};
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
formatter = forAllSystems (system: nixpkgsFor.${system}.alejandra);
|
||||||
|
|
||||||
|
packages = forAllSystems (system: let
|
||||||
|
pkgs = nixpkgsFor.${system};
|
||||||
|
inherit (pkgs) fetchFromGitHub;
|
||||||
|
in {
|
||||||
|
stable = mkClayPackage {
|
||||||
|
inherit system;
|
||||||
|
version = "0.14";
|
||||||
|
# To update this use nurl https://github.com/nicbarker/clay {tag}
|
||||||
|
src = fetchFromGitHub {
|
||||||
|
owner = "nicbarker";
|
||||||
|
repo = "clay";
|
||||||
|
rev = "v0.14"; # This will need to be updated when a new version is released
|
||||||
|
hash = "sha256-6h1aQXqwzPc4oPuid3RfV7W0WzQFUiddjW7OtkKM0P8="; # This too likely
|
||||||
|
};
|
||||||
|
suffix = "";
|
||||||
|
};
|
||||||
|
|
||||||
|
unstable = mkClayPackage {
|
||||||
|
inherit system;
|
||||||
|
version = "0.14";
|
||||||
|
src = ./.;
|
||||||
|
suffix = "-master-${date}";
|
||||||
|
};
|
||||||
|
|
||||||
|
# I have no idea how to expose both unstable and stable at the same time
|
||||||
|
# so I'm going to just expose the unstable version for now
|
||||||
|
default = self.packages.${system}.unstable;
|
||||||
|
});
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
@ -3,6 +3,8 @@
|
||||||
|
|
||||||
Copyright (c) 2025 Mivirl
|
Copyright (c) 2025 Mivirl
|
||||||
|
|
||||||
|
altered by Godje (Sep 2025)
|
||||||
|
|
||||||
This software is provided 'as-is', without any express or implied warranty.
|
This software is provided 'as-is', without any express or implied warranty.
|
||||||
In no event will the authors be held liable for any damages arising from the
|
In no event will the authors be held liable for any damages arising from the
|
||||||
use of this software.
|
use of this software.
|
||||||
|
|
@ -1616,6 +1618,20 @@ void Clay_Termbox_Render(Clay_RenderCommandArray commands)
|
||||||
|
|
||||||
Clay_StringSlice *text = &render_data.stringContents;
|
Clay_StringSlice *text = &render_data.stringContents;
|
||||||
int32_t i = 0;
|
int32_t i = 0;
|
||||||
|
|
||||||
|
// culling text characters that are outside of the layout
|
||||||
|
int h_clip = 0 - cell_box.x;
|
||||||
|
while(h_clip > 0 && i < text->length){
|
||||||
|
uint32_t ch = ' ';
|
||||||
|
int codepoint_length = tb_utf8_char_to_unicode(&ch, text->chars + i);
|
||||||
|
if (0 > codepoint_length) {
|
||||||
|
clay_tb_assert(false, "Invalid utf8");
|
||||||
|
}
|
||||||
|
i += codepoint_length;
|
||||||
|
h_clip -= 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// printing the rest of the characters
|
||||||
for (int y = box_begin_y; y < box_end_y; ++y) {
|
for (int y = box_begin_y; y < box_end_y; ++y) {
|
||||||
for (int x = box_begin_x; x < box_end_x;) {
|
for (int x = box_begin_x; x < box_end_x;) {
|
||||||
uint32_t ch = ' ';
|
uint32_t ch = ' ';
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue