Make iced_core::Button customizable

Now it supports:
  - Any kind of content
  - Custom border radius
  - Custom background
This commit is contained in:
Héctor Ramón Jiménez 2019-10-08 03:13:41 +02:00
parent a0234d5bce
commit 10e10e5e06
35 changed files with 288 additions and 160 deletions

View file

@ -3,6 +3,7 @@
layout(location = 0) in vec4 v_Color;
layout(location = 1) in vec2 v_Pos;
layout(location = 2) in vec2 v_Scale;
layout(location = 3) in flat uint v_BorderRadius;
layout(location = 0) out vec4 o_Color;
@ -26,8 +27,11 @@ float rounded(in vec2 frag_coord, in vec2 position, in vec2 size, float radius,
}
void main() {
o_Color = vec4(
v_Color.xyz,
v_Color.w * rounded(gl_FragCoord.xy, v_Pos, v_Scale, 5.0, 1.0)
);
float radius_alpha = 1.0;
if(v_BorderRadius > 0.0) {
radius_alpha = rounded(gl_FragCoord.xy, v_Pos, v_Scale, v_BorderRadius, 1.0);
}
o_Color = vec4(v_Color.xyz, v_Color.w * radius_alpha);
}

Binary file not shown.

View file

@ -4,6 +4,7 @@ layout(location = 0) in vec2 v_Pos;
layout(location = 1) in vec2 i_Pos;
layout(location = 2) in vec2 i_Scale;
layout(location = 3) in vec4 i_Color;
layout(location = 4) in uint i_BorderRadius;
layout (set = 0, binding = 0) uniform Globals {
mat4 u_Transform;
@ -12,6 +13,7 @@ layout (set = 0, binding = 0) uniform Globals {
layout(location = 0) out vec4 o_Color;
layout(location = 1) out vec2 o_Pos;
layout(location = 2) out vec2 o_Scale;
layout(location = 3) out uint o_BorderRadius;
void main() {
mat4 i_Transform = mat4(
@ -24,6 +26,7 @@ void main() {
o_Color = i_Color;
o_Pos = i_Pos;
o_Scale = i_Scale;
o_BorderRadius = i_BorderRadius;
gl_Position = u_Transform * i_Transform * vec4(v_Pos, 0.0, 1.0);
}

Binary file not shown.