@@ -2,34 +2,40 @@ use gtk::prelude::*;
22use gtk:: gdk:: RGBA ;
33use webkitgtk6:: { WebContext , WebView } ;
44use webkitgtk6:: prelude:: WebViewExt ;
5-
5+ use crate :: style :: load_config ;
66pub fn setup_webview ( ) -> WebView {
7+ let config = load_config ( ) ;
8+ let particle_color = config. particle_color . unwrap_or_else ( || "rgba(255, 255, 255, 1)" . to_string ( ) ) ;
9+ let particle_count = config. particle_count . unwrap_or ( 20 ) ; // Reduced for less intense animation
10+ let particle_life_min = config. particle_life_min . unwrap_or ( 40 ) ;
11+ let particle_life_max = config. particle_life_max . unwrap_or ( 70 ) ;
12+ let particle_size_min = config. particle_size_min . unwrap_or ( 2.0 ) ; // Smaller particles
13+ let particle_size_max = config. particle_size_max . unwrap_or ( 5.0 ) ; // Smaller max size
714 let context = WebContext :: default ( ) . unwrap ( ) ;
815 let webview = WebView :: builder ( ) . web_context ( & context) . build ( ) ;
916 webview. set_background_color ( & RGBA :: new ( 0.0 , 0.0 , 0.0 , 0.0 ) ) ; // Fully transparent
1017 webview. set_hexpand ( true ) ;
1118 webview. set_vexpand ( true ) ;
12-
13- // Load enhanced HTML with more advanced particle animations
14- let html = r#"
19+ // Load enhanced HTML with configurable particle animations only on typing at cursor
20+ let html = format ! ( r#"
1521 <html>
1622 <head>
1723 <style>
18- body, html {
24+ body, html {{
1925 margin: 0;
2026 padding: 0;
2127 overflow: hidden;
2228 background: transparent;
23- }
24- canvas {
29+ }}
30+ canvas {{
2531 display: block;
2632 position: absolute;
2733 top: 0;
2834 left: 0;
2935 width: 100%;
3036 height: 100%;
3137 pointer-events: none; /* Allow clicks to pass through */
32- }
38+ }}
3339 </style>
3440 </head>
3541 <body>
@@ -39,74 +45,64 @@ pub fn setup_webview() -> WebView {
3945 const ctx = canvas.getContext('2d');
4046 let particles = [];
4147 let animationFrameId;
42-
43- function resizeCanvas() {
48+ function resizeCanvas() {{
4449 canvas.width = window.innerWidth;
4550 canvas.height = window.innerHeight;
46- }
51+ }}
4752 window.addEventListener('resize', resizeCanvas);
4853 resizeCanvas();
49-
50- class Particle {
51- constructor(x, y) {
54+ class Particle {{
55+ constructor(x, y) {{
5256 this.x = x;
5357 this.y = y;
54- this.size = Math.random() * 6 + 3;
55- this.speedX = Math.random() * 5 - 2 .5;
56- this.speedY = Math.random() * 5 - 2 .5;
57- this.color = `hsl(${Math.random() * 360}, 80%, 60%)` ; // Vibrant colors
58- this.life = 40 + Math.random() * 30;
59- this.rotation = Math.random() * Math.PI * 2 ;
60- this.spin = Math.random() * 0.05 - 0.025 ;
61- }
62- update() {
58+ this.size = Math.random() * {} + {}; // Configurable size
59+ this.speedX = Math.random() * 3 - 1 .5; // Reduced speed
60+ this.speedY = Math.random() * 3 - 1 .5; // Reduced speed
61+ this.color = '{}' ; // Configurable color
62+ this.life = {} + Math.random() * {}; // Configurable life
63+ this.initialLife = this.life ;
64+ this.alpha = 1.0 ;
65+ }}
66+ update() {{
6367 this.x += this.speedX;
6468 this.y += this.speedY;
65- this.speedY += 0.15 ; // Enhanced gravity
69+ this.speedY += 0.1 ; // Reduced gravity
6670 this.life -= 1;
67- this.rotation += this.spin;
68- if (this.size > 0.3) this.size -= 0.12;
69- }
70- draw() {
71+ // Fade out linearly instead of flashing
72+ this.alpha = this.life / this.initialLife;
73+ if (this.size > 0.3) this.size -= 0.08; // Slower size reduction
74+ }}
75+ draw() {{
7176 ctx.save();
72- ctx.translate(this.x, this.y);
73- ctx.rotate(this.rotation);
77+ ctx.globalAlpha = this.alpha;
7478 ctx.fillStyle = this.color;
7579 ctx.beginPath();
76- ctx.moveTo(0, -this.size);
77- for (let i = 0; i < 5; i++) {
78- ctx.lineTo(Math.sin(i * Math.PI * 2 / 5) * this.size, Math.cos(i * Math.PI * 2 / 5) * this.size);
79- }
80- ctx.closePath();
80+ ctx.arc(this.x, this.y, this.size, 0, Math.PI * 2);
8181 ctx.fill();
8282 ctx.restore();
83- }
84- }
85-
86- function animate() {
83+ }}
84+ }}
85+ function animate() {{
8786 ctx.clearRect(0, 0, canvas.width, canvas.height);
88- particles = particles.filter(particle => {
87+ particles = particles.filter(particle => {{
8988 particle.update();
9089 particle.draw();
9190 return particle.life > 0;
92- });
91+ }} );
9392 animationFrameId = requestAnimationFrame(animate);
94- }
93+ }}
9594 animate();
96-
97- // Function to spawn particles (called from Rust on input)
98- function spawnParticles(count = 80) {
99- const x = Math.random() * canvas.width;
100- const y = Math.random() * canvas.height;
101- for (let i = 0; i < count; i++) {
95+ // Function to spawn particles at specific x, y (called from Rust on input)
96+ function spawnParticles(x, y) {{
97+ const count = {};
98+ for (let i = 0; i < count; i++) {{
10299 particles.push(new Particle(x, y));
103- }
104- }
100+ }}
101+ }}
105102 </script>
106103 </body>
107104 </html>
108- "# ;
109- webview. load_html ( html, None ) ;
110-
105+ "# , particle_size_max - particle_size_min, particle_size_min, particle_color, particle_life_min, particle_life_max - particle_life_min, particle_count) ;
106+ webview. load_html ( & html, None ) ;
111107 webview
112108}
0 commit comments