Skip to content

Commit 300cffb

Browse files
committed
fix shadow container overlap
1 parent 7f473f0 commit 300cffb

File tree

3 files changed

+50
-0
lines changed

3 files changed

+50
-0
lines changed

_shadow_test.v

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
module gui
2+
3+
import gg
4+
5+
fn test_render_container_shadow_opacity() {
6+
mut w := Window{
7+
renderers: []Renderer{}
8+
}
9+
// Setup a shape with shadow alpha 128 (approx 0.5)
10+
shadow_alpha := u8(128)
11+
container_color := rgb(100, 100, 100)
12+
13+
mut s := Shape{
14+
shape_type: .rectangle
15+
x: 0
16+
y: 0
17+
width: 100
18+
height: 100
19+
color: container_color
20+
radius: 5
21+
shadow: &BoxShadow{
22+
blur_radius: 10
23+
color: rgba(0, 0, 0, shadow_alpha)
24+
}
25+
}
26+
clip := gg.Rect{0, 0, 200, 200}
27+
28+
render_container(mut s, color_transparent, clip, mut w)
29+
30+
assert w.renderers.len == 2
31+
shadow_r := w.renderers[0]
32+
container_r := w.renderers[1]
33+
34+
if shadow_r is DrawShadow {
35+
assert shadow_r.color.a == shadow_alpha
36+
} else {
37+
assert false, 'Expected DrawShadow first'
38+
}
39+
40+
if container_r is DrawRect {
41+
// Crucial verification: Container color should be opaque (255)
42+
assert container_r.color.a == 255
43+
assert container_r.color.r == 100
44+
} else {
45+
assert false, 'Expected DrawRect second'
46+
}
47+
}

render.v

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -805,6 +805,7 @@ pub fn draw_blur_rect(x f32, y f32, w f32, h f32, radius f32, blur f32, c gg.Col
805805

806806
draw_quad(sx, sy, sw, sh, z_val)
807807
sgl.load_default_pipeline()
808+
sgl.c4b(255, 255, 255, 255) // Reset color state
808809

809810
sgl.pop_matrix()
810811
sgl.matrix_mode_modelview()
@@ -917,6 +918,7 @@ fn draw_gradient_rect(x f32, y f32, w f32, h f32, radius f32, gradient &Gradient
917918
draw_quad(sx, sy, sw, sh, z_val)
918919

919920
sgl.load_default_pipeline()
921+
sgl.c4b(255, 255, 255, 255) // Reset color state
920922
sgl.pop_matrix()
921923
sgl.matrix_mode_modelview()
922924
}

shaders.v

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -755,6 +755,7 @@ pub fn draw_shadow_rect(x f32, y f32, w f32, h f32, radius f32, blur f32, c gg.C
755755

756756
draw_quad(sx, sy, sw, sh, z_val)
757757
sgl.load_default_pipeline()
758+
sgl.c4b(255, 255, 255, 255) // Reset color state
758759

759760
sgl.pop_matrix()
760761
sgl.matrix_mode_modelview()

0 commit comments

Comments
 (0)