@@ -20,6 +20,41 @@ local function convertZ(z)
2020 return 1 - math.min (z or 0 , 100000 ) / 1000000
2121end
2222
23+ --- @param z number
24+ --- @param windowWidth number
25+ --- @param windowHeight number
26+ --- @param vertices number[]
27+ --- @param indices number[]
28+ local function addBorderQuad (bx , by , bw , bh , color , z , windowWidth , windowHeight , vertices , indices )
29+ if bw <= 0 or bh <= 0 then
30+ return
31+ end
32+
33+ local baseIdx = # vertices / 10
34+ local left = toNDC (bx , windowWidth )
35+ local right = toNDC (bx + bw , windowWidth )
36+ local top = - toNDC (by , windowHeight )
37+ local bottom = - toNDC (by + bh , windowHeight )
38+
39+ -- stylua: ignore
40+ for _ , v in ipairs ({
41+ left , top , convertZ (z + 1 ), color .r , color .g , color .b , color .a , 0 , 0 , 0 ,
42+ right , top , convertZ (z + 1 ), color .r , color .g , color .b , color .a , 0 , 0 , 0 ,
43+ right , bottom , convertZ (z + 1 ), color .r , color .g , color .b , color .a , 0 , 0 , 0 ,
44+ left , bottom , convertZ (z + 1 ), color .r , color .g , color .b , color .a , 0 , 0 , 0 ,
45+ }) do
46+ table.insert (vertices , v )
47+ end
48+
49+ -- stylua: ignore
50+ for _ , idx in ipairs ({
51+ baseIdx , baseIdx + 1 , baseIdx + 2 ,
52+ baseIdx , baseIdx + 2 , baseIdx + 3 ,
53+ }) do
54+ table.insert (indices , idx )
55+ end
56+ end
57+
2358--- @param layout ComputedLayout
2459local function generateLayoutQuads (layout , parentX , parentY , vertices , indices , windowWidth , windowHeight )
2560 local x = (parentX or 0 ) + (layout .x or 0 )
@@ -74,54 +109,28 @@ local function generateLayoutQuads(layout, parentX, parentY, vertices, indices,
74109 local borderLeft = layout .border .left
75110 local borderRight = layout .border .right
76111
77- local function addBorderQuad (bx , by , bw , bh , color )
78- if bw <= 0 or bh <= 0 then
79- return
80- end
81-
82- local baseIdx = # vertices / 10
83- local left = toNDC (bx , windowWidth )
84- local right = toNDC (bx + bw , windowWidth )
85- local top = - toNDC (by , windowHeight )
86- local bottom = - toNDC (by + bh , windowHeight )
87-
88- -- stylua: ignore
89- for _ , v in ipairs ({
90- left , top , convertZ (z + 1 ), color .r , color .g , color .b , color .a , 0 , 0 , 0 ,
91- right , top , convertZ (z + 1 ), color .r , color .g , color .b , color .a , 0 , 0 , 0 ,
92- right , bottom , convertZ (z + 1 ), color .r , color .g , color .b , color .a , 0 , 0 , 0 ,
93- left , bottom , convertZ (z + 1 ), color .r , color .g , color .b , color .a , 0 , 0 , 0 ,
94- }) do
95- table.insert (vertices , v )
96- end
97-
98- -- stylua: ignore
99- for _ , idx in ipairs ({
100- baseIdx , baseIdx + 1 , baseIdx + 2 ,
101- baseIdx , baseIdx + 2 , baseIdx + 3 ,
102- }) do
103- table.insert (indices , idx )
104- end
105- end
106-
107112 -- Top border
108113 if borderTop and borderTop .width and borderTop .width > 0 and borderTop .style ~= " none" then
109- addBorderQuad (x , y , width , borderTop .width , borderTop .color )
114+ addBorderQuad (x , y , width , borderTop .width , borderTop .color , z , windowWidth , windowHeight , vertices , indices )
110115 end
111116
112117 -- Bottom border
113118 if borderBottom and borderBottom .width and borderBottom .width > 0 and borderBottom .style ~= " none" then
114- addBorderQuad (x , y + height - borderBottom .width , width , borderBottom .width , borderBottom .color )
119+ addBorderQuad (x , y + height - borderBottom .width , width , z , borderBottom .width , borderBottom .color ,
120+ windowWidth ,
121+ windowHeight , vertices , indices )
115122 end
116123
117124 -- Left border
118125 if borderLeft and borderLeft .width and borderLeft .width > 0 and borderLeft .style ~= " none" then
119- addBorderQuad (x , y , borderLeft .width , height , borderLeft .color )
126+ addBorderQuad (x , y , borderLeft .width , height , borderLeft .color , z , windowWidth , windowHeight , vertices ,
127+ indices )
120128 end
121129
122130 -- Right border
123131 if borderRight and borderRight .width and borderRight .width > 0 and borderRight .style ~= " none" then
124- addBorderQuad (x + width - borderRight .width , y , borderRight .width , height , borderRight .color )
132+ addBorderQuad (x + width - borderRight .width , y , borderRight .width , height , borderRight .color , z , windowWidth ,
133+ windowHeight , vertices , indices )
125134 end
126135 end
127136
0 commit comments