Logo

index : 0x2lib

Library extension for Jai

  • summary
  • about
  • tree
  • log
  • branches
<< path: root/public/0x2lib.git/html/0x2_Rectcut.jai blob: 431ef5d0a95388699d5192ec48aee5ce3afe96c7 [raw] [clear marker]

        
0/** C R E D I T
1 Idea from: https://halt.software/p/rectcut-for-dead-simple-ui-layouts
2 Code from: https://solarium.technology/ (with some modifications by me)
3*/
4
5
6#module_parameters(ASSERTION_ENABLED := true);
7
8
9rcut_from_right :: inline (using rect: *$T/interface Rectangle, percentage: float) -> T {
10 #if ASSERTION_ENABLED then assert_percent();
11 return rcut_from_right_fixed(rect, rect.width * percentage);
12}
13
14rcut_from_left :: inline (using rect: *$T/interface Rectangle, percentage: float) -> T {
15 #if ASSERTION_ENABLED then assert_percent();
16 return rcut_from_left_fixed(rect, rect.width * percentage);
17}
18
19rcut_from_top :: inline (using rect: *$T/interface Rectangle, percentage: float) -> T {
20 #if ASSERTION_ENABLED then assert_percent();
21 return rcut_from_top_fixed (rect, rect.height * percentage);
22}
23
24rcut_from_bottom :: inline (using rect: *$T/interface Rectangle, percentage: float) -> T {
25 #if ASSERTION_ENABLED then assert_percent();
26 return rcut_from_bottom_fixed(rect, rect.height * percentage);
27}
28
29rcut_from_right_fixed :: inline (using rect: *$T/interface Rectangle, n: float) -> T {
30 result := T.{ x + width - n, y, n, height };
31 width = max(width - n, 0);
32 return result;
33}
34
35rcut_from_left_fixed :: inline (using rect: *$T/interface Rectangle, n: float) -> T {
36 result := T.{ x, y, n, height };
37 x += n;
38 width = max(width - n, 0);
39 return result;
40}
41
42rcut_from_top_fixed :: inline (using rect: *$T/interface Rectangle, n: float) -> T {
43 result := T.{ x, y, width, n };
44 y += n;
45 height = max(height - n, 0);
46 return result;
47}
48
49rcut_from_bottom_fixed :: inline (using rect: *$T/interface Rectangle, n: float) -> T {
50 result := T.{ x, y + height - n, width, n };
51 height = max(height - n, 0);
52 return result;
53}
54
55rcut_shrink :: inline (using rect: $T/interface Rectangle, n: float) -> T {
56 return { x + n, y + n, width - n*2, height - n*2 };
57}
58
59
60#scope_file
61
62
63/** From Raylib https://raylib.com */
64Rectangle :: struct {
65 x: float; /** top-left corner position x */
66 y: float; /** top-left corner position y */
67 width: float;
68 height: float;
69}
70
71
72assert_percent :: () #expand {
73 assert(
74 `percentage >= 0.0 && `percentage <= 1.0,
75 "Only values between 0.0 and 1.0 allowed. Your value: %",
76 `percentage
77 );
78}
79
80
81using,only(max, assert) Basic :: #import "Basic";
82
83
84/*
85------------------------------------------------------------------------------
86This software is available under 2 licenses -- choose whichever you prefer.
87------------------------------------------------------------------------------
88ALTERNATIVE A - MIT License
89Copyright (c) 2026 Adam Blazeowsky
90Permission is hereby granted, free of charge, to any person obtaining a copy of
91this software and associated documentation files (the "Software"), to deal in
92the Software without restriction, including without limitation the rights to
93use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
94of the Software, and to permit persons to whom the Software is furnished to do
95so, subject to the following conditions:
96The above copyright notice and this permission notice shall be included in all
97copies or substantial portions of the Software.
98THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
99IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
100FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
101AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
102LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
103OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
104SOFTWARE.
105------------------------------------------------------------------------------
106ALTERNATIVE B - Public Domain (www.unlicense.org)
107This is free and unencumbered software released into the public domain.
108Anyone is free to copy, modify, publish, use, compile, sell, or distribute this
109software, either in source code form or as a compiled binary, for any purpose,
110commercial or non-commercial, and by any means.
111In jurisdictions that recognize copyright laws, the author or authors of this
112software dedicate any and all copyright interest in the software to the public
113domain. We make this dedication for the benefit of the public at large and to
114the detriment of our heirs and successors. We intend this dedication to be an
115overt act of relinquishment in perpetuity of all present and future rights to
116this software under copyright law.
117THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
118IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
119FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
120AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
121ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
122WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
123------------------------------------------------------------------------------
124*/
125
126
Copyright 2026  E766CB298A6D1E64 | Git-Thing heavily inspired by cgit