Skip to content

Commit fcb6a7f

Browse files
authored
chore: Use custom paint icons to replace png icons (#467)
1 parent 2006a44 commit fcb6a7f

File tree

7 files changed

+295
-38
lines changed

7 files changed

+295
-38
lines changed

example/lib/pages/home.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ class _HomePageState extends State<HomePage> with TrayListener, WindowListener {
133133
? Brightness.light
134134
: Brightness.dark,
135135
);
136+
setState(() {});
136137
},
137138
),
138139
],

images/ic_chrome_close.png

-298 Bytes
Binary file not shown.

images/ic_chrome_maximize.png

-271 Bytes
Binary file not shown.

images/ic_chrome_minimize.png

-166 Bytes
Binary file not shown.

images/ic_chrome_unmaximize.png

-366 Bytes
Binary file not shown.

lib/src/widgets/window_caption_button.dart

Lines changed: 294 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,274 @@
22

33
import 'package:flutter/material.dart';
44

5+
const _kIconChromeClose = 'icon_chrome_close';
6+
const _kIconChromeMaximize = 'icon_chrome_maximize';
7+
const _kIconChromeMinimize = 'icon_chrome_minimize';
8+
const _kIconChromeUnmaximize = 'icon_chrome_unmaximize';
9+
10+
class _IconChromeMinimizePainter extends CustomPainter {
11+
_IconChromeMinimizePainter(this.color);
12+
13+
final Color color;
14+
15+
@override
16+
void paint(Canvas canvas, Size size) {
17+
final paint = Paint()
18+
..color = color
19+
..style = PaintingStyle.fill;
20+
21+
final path = Path()
22+
..moveTo(3.49805, 8)
23+
..cubicTo(3.42969, 8, 3.36458, 7.98698, 3.30273, 7.96094)
24+
..cubicTo(3.24414, 7.9349, 3.19206, 7.89909, 3.14648, 7.85352)
25+
..cubicTo(3.10091, 7.80794, 3.0651, 7.75586, 3.03906, 7.69727)
26+
..cubicTo(3.01302, 7.63542, 3, 7.57031, 3, 7.50195)
27+
..cubicTo(3, 7.43359, 3.01302, 7.37012, 3.03906, 7.31152)
28+
..cubicTo(3.0651, 7.24967, 3.10091, 7.19596, 3.14648, 7.15039)
29+
..cubicTo(3.19206, 7.10156, 3.24414, 7.06413, 3.30273, 7.03809)
30+
..cubicTo(3.36458, 7.01204, 3.42969, 6.99902, 3.49805, 6.99902)
31+
..lineTo(12.502, 6.99902)
32+
..cubicTo(12.5703, 6.99902, 12.6338, 7.01204, 12.6924, 7.03809)
33+
..cubicTo(12.7542, 7.06413, 12.8079, 7.10156, 12.8535, 7.15039)
34+
..cubicTo(12.8991, 7.19596, 12.9349, 7.24967, 12.9609, 7.31152)
35+
..cubicTo(12.987, 7.37012, 13, 7.43359, 13, 7.50195)
36+
..cubicTo(13, 7.57031, 12.987, 7.63542, 12.9609, 7.69727)
37+
..cubicTo(12.9349, 7.75586, 12.8991, 7.80794, 12.8535, 7.85352)
38+
..cubicTo(12.8079, 7.89909, 12.7542, 7.9349, 12.6924, 7.96094)
39+
..cubicTo(12.6338, 7.98698, 12.5703, 8, 12.502, 8)
40+
..close();
41+
42+
canvas.drawPath(path, paint);
43+
}
44+
45+
@override
46+
bool shouldRepaint(covariant CustomPainter oldDelegate) {
47+
return false;
48+
}
49+
}
50+
51+
class _IconChromeMaximizePainter extends CustomPainter {
52+
_IconChromeMaximizePainter(this.color);
53+
54+
final Color color;
55+
56+
@override
57+
void paint(Canvas canvas, Size size) {
58+
final paint = Paint()
59+
..color = color
60+
..style = PaintingStyle.fill;
61+
62+
Path path = Path()
63+
..moveTo(4.47461, 13)
64+
..cubicTo(4.2793, 13, 4.09212, 12.9609, 3.91309, 12.8828)
65+
..cubicTo(3.73405, 12.8014, 3.57617, 12.694, 3.43945, 12.5605)
66+
..cubicTo(3.30599, 12.4238, 3.19857, 12.266, 3.11719, 12.0869)
67+
..cubicTo(3.03906, 11.9079, 3, 11.7207, 3, 11.5254)
68+
..lineTo(3, 4.47461)
69+
..cubicTo(3, 4.2793, 3.03906, 4.09212, 3.11719, 3.91309)
70+
..cubicTo(3.19857, 3.73405, 3.30599, 3.5778, 3.43945, 3.44434)
71+
..cubicTo(3.57617, 3.30762, 3.73405, 3.2002, 3.91309, 3.12207)
72+
..cubicTo(4.09212, 3.04069, 4.2793, 3, 4.47461, 3)
73+
..lineTo(11.5254, 3)
74+
..cubicTo(11.7207, 3, 11.9079, 3.04069, 12.0869, 3.12207)
75+
..cubicTo(12.266, 3.2002, 12.4222, 3.30762, 12.5557, 3.44434)
76+
..cubicTo(12.6924, 3.5778, 12.7998, 3.73405, 12.8779, 3.91309)
77+
..cubicTo(12.9593, 4.09212, 13, 4.2793, 13, 4.47461)
78+
..lineTo(13, 11.5254)
79+
..cubicTo(13, 11.7207, 12.9593, 11.9079, 12.8779, 12.0869)
80+
..cubicTo(12.7998, 12.266, 12.6924, 12.4238, 12.5557, 12.5605)
81+
..cubicTo(12.4222, 12.694, 12.266, 12.8014, 12.0869, 12.8828)
82+
..cubicTo(11.9079, 12.9609, 11.7207, 13, 11.5254, 13)
83+
..lineTo(4.47461, 13)
84+
..moveTo(11.501, 11.999)
85+
..cubicTo(11.5693, 11.999, 11.6328, 11.986, 11.6914, 11.96)
86+
..cubicTo(11.7533, 11.9339, 11.807, 11.8981, 11.8525, 11.8525)
87+
..cubicTo(11.8981, 11.807, 11.9339, 11.7549, 11.96, 11.6963)
88+
..cubicTo(11.986, 11.6344, 11.999, 11.5693, 11.999, 11.501)
89+
..lineTo(11.999, 4.49902)
90+
..cubicTo(11.999, 4.43066, 11.986, 4.36719, 11.96, 4.30859)
91+
..cubicTo(11.9339, 4.24674, 11.8981, 4.19303, 11.8525, 4.14746)
92+
..cubicTo(11.807, 4.10189, 11.7533, 4.06608, 11.6914, 4.04004)
93+
..cubicTo(11.6328, 4.014, 11.5693, 4.00098, 11.501, 4.00098)
94+
..lineTo(4.49902, 4.00098)
95+
..cubicTo(4.43066, 4.00098, 4.36556, 4.014, 4.30371, 4.04004)
96+
..cubicTo(4.24512, 4.06608, 4.19303, 4.10189, 4.14746, 4.14746)
97+
..cubicTo(4.10189, 4.19303, 4.06608, 4.24674, 4.04004, 4.30859)
98+
..cubicTo(4.014, 4.36719, 4.00098, 4.43066, 4.00098, 4.49902)
99+
..lineTo(4.00098, 11.501)
100+
..cubicTo(4.00098, 11.5693, 4.014, 11.6344, 4.04004, 11.6963)
101+
..cubicTo(4.06608, 11.7549, 4.10189, 11.807, 4.14746, 11.8525)
102+
..cubicTo(4.19303, 11.8981, 4.24512, 11.9339, 4.30371, 11.96)
103+
..cubicTo(4.36556, 11.986, 4.43066, 11.999, 4.49902, 11.999)
104+
..lineTo(11.501, 11.999)
105+
..close();
106+
107+
canvas.drawPath(path, paint);
108+
}
109+
110+
@override
111+
bool shouldRepaint(covariant CustomPainter oldDelegate) {
112+
return false;
113+
}
114+
}
115+
116+
class _IconChromeUnmaximizePainter extends CustomPainter {
117+
_IconChromeUnmaximizePainter(this.color);
118+
119+
final Color color;
120+
121+
@override
122+
void paint(Canvas canvas, Size size) {
123+
final paint = Paint()
124+
..color = color
125+
..style = PaintingStyle.fill;
126+
127+
final path = Path()
128+
..moveTo(11.999, 5.96387)
129+
..cubicTo(11.999, 5.69368, 11.9453, 5.43978, 11.8379, 5.20215)
130+
..cubicTo(11.7305, 4.96126, 11.584, 4.75293, 11.3984, 4.57715)
131+
..cubicTo(11.2161, 4.39811, 11.0029, 4.25814, 10.7588, 4.15723)
132+
..cubicTo(10.5179, 4.05306, 10.264, 4.00098, 9.99707, 4.00098)
133+
..lineTo(5.08496, 4.00098)
134+
..cubicTo(5.13704, 3.85124, 5.21029, 3.71452, 5.30469, 3.59082)
135+
..cubicTo(5.39909, 3.46712, 5.50814, 3.36133, 5.63184, 3.27344)
136+
..cubicTo(5.75553, 3.18555, 5.89062, 3.11882, 6.03711, 3.07324)
137+
..cubicTo(6.18685, 3.02441, 6.34147, 3, 6.50098, 3)
138+
..lineTo(9.99707, 3)
139+
..cubicTo(10.4105, 3, 10.7995, 3.07975, 11.1641, 3.23926)
140+
..cubicTo(11.5286, 3.39551, 11.846, 3.60872, 12.1162, 3.87891)
141+
..cubicTo(12.3896, 4.14909, 12.6045, 4.46647, 12.7607, 4.83105)
142+
..cubicTo(12.9202, 5.19564, 13, 5.58464, 13, 5.99805)
143+
..lineTo(13, 9.49902)
144+
..cubicTo(13, 9.65853, 12.9756, 9.81315, 12.9268, 9.96289)
145+
..cubicTo(12.8812, 10.1094, 12.8145, 10.2445, 12.7266, 10.3682)
146+
..cubicTo(12.6387, 10.4919, 12.5329, 10.6009, 12.4092, 10.6953)
147+
..cubicTo(12.2855, 10.7897, 12.1488, 10.863, 11.999, 10.915)
148+
..lineTo(11.999, 5.96387)
149+
..close()
150+
..moveTo(4.47461, 13)
151+
..cubicTo(4.2793, 13, 4.09212, 12.9609, 3.91309, 12.8828)
152+
..cubicTo(3.73405, 12.8014, 3.57617, 12.694, 3.43945, 12.5605)
153+
..cubicTo(3.30599, 12.4238, 3.19857, 12.266, 3.11719, 12.0869)
154+
..cubicTo(3.03906, 11.9079, 3, 11.7207, 3, 11.5254)
155+
..lineTo(3, 6.47656)
156+
..cubicTo(3, 6.27799, 3.03906, 6.09082, 3.11719, 5.91504)
157+
..cubicTo(3.19857, 5.736, 3.30599, 5.57975, 3.43945, 5.44629)
158+
..cubicTo(3.57617, 5.30957, 3.73242, 5.20215, 3.9082, 5.12402)
159+
..cubicTo(4.08724, 5.04264, 4.27604, 5.00195, 4.47461, 5.00195)
160+
..lineTo(9.52344, 5.00195)
161+
..cubicTo(9.72201, 5.00195, 9.91081, 5.04264, 10.0898, 5.12402)
162+
..cubicTo(10.2689, 5.20215, 10.4251, 5.30794, 10.5586, 5.44141)
163+
..cubicTo(10.6921, 5.57487, 10.7979, 5.73112, 10.876, 5.91016)
164+
..cubicTo(10.9574, 6.08919, 10.998, 6.27799, 10.998, 6.47656)
165+
..lineTo(10.998, 11.5254)
166+
..cubicTo(10.998, 11.724, 10.9574, 11.9128, 10.876, 12.0918)
167+
..cubicTo(10.7979, 12.2676, 10.6904, 12.4238, 10.5537, 12.5605)
168+
..cubicTo(10.4202, 12.694, 10.264, 12.8014, 10.085, 12.8828)
169+
..cubicTo(9.90918, 12.9609, 9.72201, 13, 9.52344, 13)
170+
..lineTo(4.47461, 13)
171+
..close()
172+
..moveTo(9.49902, 11.999)
173+
..cubicTo(9.56738, 11.999, 9.63086, 11.986, 9.68945, 11.96)
174+
..cubicTo(9.7513, 11.9339, 9.80501, 11.8981, 9.85059, 11.8525)
175+
..cubicTo(9.89941, 11.807, 9.93685, 11.7549, 9.96289, 11.6963)
176+
..cubicTo(9.98893, 11.6344, 10.002, 11.5693, 10.002, 11.501)
177+
..lineTo(10.002, 6.50098)
178+
..cubicTo(10.002, 6.43262, 9.98893, 6.36751, 9.96289, 6.30566)
179+
..cubicTo(9.93685, 6.24382, 9.90104, 6.1901, 9.85547, 6.14453)
180+
..cubicTo(9.8099, 6.09896, 9.75618, 6.06315, 9.69434, 6.03711)
181+
..cubicTo(9.63249, 6.01107, 9.56738, 5.99805, 9.49902, 5.99805)
182+
..lineTo(4.49902, 5.99805)
183+
..cubicTo(4.43066, 5.99805, 4.36556, 6.01107, 4.30371, 6.03711)
184+
..cubicTo(4.24512, 6.06315, 4.19303, 6.10059, 4.14746, 6.14941)
185+
..cubicTo(4.10189, 6.19499, 4.06608, 6.2487, 4.04004, 6.31055)
186+
..cubicTo(4.014, 6.36914, 4.00098, 6.43262, 4.00098, 6.50098)
187+
..lineTo(4.00098, 11.501)
188+
..cubicTo(4.00098, 11.5693, 4.014, 11.6344, 4.04004, 11.6963)
189+
..cubicTo(4.06608, 11.7549, 4.10189, 11.807, 4.14746, 11.8525)
190+
..cubicTo(4.19303, 11.8981, 4.24512, 11.9339, 4.30371, 11.96)
191+
..cubicTo(4.36556, 11.986, 4.43066, 11.999, 4.49902, 11.999)
192+
..lineTo(9.49902, 11.999)
193+
..close();
194+
195+
canvas.drawPath(path, paint);
196+
}
197+
198+
@override
199+
bool shouldRepaint(covariant CustomPainter oldDelegate) {
200+
return false;
201+
}
202+
}
203+
204+
class _IconChromeClosePainter extends CustomPainter {
205+
_IconChromeClosePainter(this.color);
206+
207+
final Color color;
208+
209+
@override
210+
void paint(Canvas canvas, Size size) {
211+
final paint = Paint()
212+
..color = color
213+
..style = PaintingStyle.fill;
214+
215+
final path = Path()
216+
..moveTo(8, 8.70801)
217+
..lineTo(3.85449, 12.8535)
218+
..cubicTo(3.75684, 12.9512, 3.63965, 13, 3.50293, 13)
219+
..cubicTo(3.3597, 13, 3.23926, 12.9528, 3.1416, 12.8584)
220+
..cubicTo(3.0472, 12.7607, 3, 12.6403, 3, 12.4971)
221+
..cubicTo(3, 12.3604, 3.04883, 12.2432, 3.14648, 12.1455)
222+
..lineTo(7.29199, 8)
223+
..lineTo(3.14648, 3.85449)
224+
..cubicTo(3.04883, 3.75684, 3, 3.63802, 3, 3.49805)
225+
..cubicTo(3, 3.42969, 3.01302, 3.36458, 3.03906, 3.30273)
226+
..cubicTo(3.0651, 3.24089, 3.10091, 3.1888, 3.14648, 3.14648)
227+
..cubicTo(3.19206, 3.10091, 3.24577, 3.0651, 3.30762, 3.03906)
228+
..cubicTo(3.36947, 3.01302, 3.43457, 3, 3.50293, 3)
229+
..cubicTo(3.63965, 3, 3.75684, 3.04883, 3.85449, 3.14648)
230+
..lineTo(8, 7.29199)
231+
..lineTo(12.1455, 3.14648)
232+
..cubicTo(12.2432, 3.04883, 12.362, 3, 12.502, 3)
233+
..cubicTo(12.5703, 3, 12.6338, 3.01302, 12.6924, 3.03906)
234+
..cubicTo(12.7542, 3.0651, 12.8079, 3.10091, 12.8535, 3.14648)
235+
..cubicTo(12.8991, 3.19206, 12.9349, 3.24577, 12.9609, 3.30762)
236+
..cubicTo(12.987, 3.36621, 13, 3.42969, 13, 3.49805)
237+
..cubicTo(13, 3.63802, 12.9512, 3.75684, 12.8535, 3.85449)
238+
..lineTo(8.70801, 8)
239+
..lineTo(12.8535, 12.1455)
240+
..cubicTo(12.9512, 12.2432, 13, 12.3604, 13, 12.4971)
241+
..cubicTo(13, 12.5654, 12.987, 12.6305, 12.9609, 12.6924)
242+
..cubicTo(12.9349, 12.7542, 12.8991, 12.8079, 12.8535, 12.8535)
243+
..cubicTo(12.8112, 12.8991, 12.7591, 12.9349, 12.6973, 12.9609)
244+
..cubicTo(12.6354, 12.987, 12.5703, 13, 12.502, 13)
245+
..cubicTo(12.362, 13, 12.2432, 12.9512, 12.1455, 12.8535)
246+
..lineTo(8, 8.70801)
247+
..close();
248+
249+
canvas.drawPath(path, paint);
250+
}
251+
252+
@override
253+
bool shouldRepaint(covariant CustomPainter oldDelegate) {
254+
return false;
255+
}
256+
}
257+
5258
class WindowCaptionButtonIcon extends StatelessWidget {
6259
const WindowCaptionButtonIcon({
7260
super.key,
8-
required this.name,
9261
this.color,
10-
this.package = 'window_manager',
262+
required this.createPainter,
11263
});
12264

13-
final String name;
14265
final Color? color;
15-
final String package;
266+
final CustomPainter Function(Color? color) createPainter;
16267

17268
@override
18269
Widget build(BuildContext context) {
19-
return Image.asset(
20-
name,
21-
package: package,
22-
width: 15,
23-
color: color,
24-
filterQuality: FilterQuality.high,
270+
return CustomPaint(
271+
painter: createPainter(color),
272+
size: const Size(16, 16),
25273
);
26274
}
27275
}
@@ -36,12 +284,33 @@ class WindowCaptionButton extends StatefulWidget {
36284
required this.onPressed,
37285
});
38286

287+
WindowCaptionButton.minimize({
288+
super.key,
289+
this.brightness,
290+
this.icon,
291+
this.onPressed,
292+
}) : iconName = _kIconChromeMinimize;
293+
294+
WindowCaptionButton.maximize({
295+
super.key,
296+
this.brightness,
297+
this.icon,
298+
this.onPressed,
299+
}) : iconName = _kIconChromeMaximize;
300+
301+
WindowCaptionButton.unmaximize({
302+
super.key,
303+
this.brightness,
304+
this.icon,
305+
this.onPressed,
306+
}) : iconName = _kIconChromeUnmaximize;
307+
39308
WindowCaptionButton.close({
40309
super.key,
41310
this.brightness,
42311
this.icon,
43312
this.onPressed,
44-
}) : iconName = 'images/ic_chrome_close.png',
313+
}) : iconName = _kIconChromeClose,
45314
_lightButtonBgColorScheme = _ButtonBgColorScheme(
46315
normal: Colors.transparent,
47316
hovered: const Color(0xffC42B1C),
@@ -65,27 +334,6 @@ class WindowCaptionButton extends StatefulWidget {
65334
disabled: Colors.black.withOpacity(0.3628),
66335
);
67336

68-
WindowCaptionButton.unmaximize({
69-
super.key,
70-
this.brightness,
71-
this.icon,
72-
this.onPressed,
73-
}) : iconName = 'images/ic_chrome_unmaximize.png';
74-
75-
WindowCaptionButton.maximize({
76-
super.key,
77-
this.brightness,
78-
this.icon,
79-
this.onPressed,
80-
}) : iconName = 'images/ic_chrome_maximize.png';
81-
82-
WindowCaptionButton.minimize({
83-
super.key,
84-
this.brightness,
85-
this.icon,
86-
this.onPressed,
87-
}) : iconName = 'images/ic_chrome_minimize.png';
88-
89337
final Brightness? brightness;
90338
final Widget? icon;
91339
final String? iconName;
@@ -169,8 +417,21 @@ class _WindowCaptionButtonState extends State<WindowCaptionButton> {
169417
),
170418
child: Center(
171419
child: WindowCaptionButtonIcon(
172-
name: widget.iconName!,
173420
color: iconColor,
421+
createPainter: (color) {
422+
switch (widget.iconName) {
423+
case _kIconChromeMinimize:
424+
return _IconChromeMinimizePainter(color!);
425+
case _kIconChromeMaximize:
426+
return _IconChromeMaximizePainter(color!);
427+
case _kIconChromeUnmaximize:
428+
return _IconChromeUnmaximizePainter(color!);
429+
case _kIconChromeClose:
430+
return _IconChromeClosePainter(color!);
431+
default:
432+
return _IconChromeClosePainter(color!);
433+
}
434+
},
174435
),
175436
),
176437
),

pubspec.yaml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,3 @@ flutter:
4040
pluginClass: WindowManagerPlugin
4141
windows:
4242
pluginClass: WindowManagerPlugin
43-
assets:
44-
- images/ic_chrome_close.png
45-
- images/ic_chrome_maximize.png
46-
- images/ic_chrome_minimize.png
47-
- images/ic_chrome_unmaximize.png

0 commit comments

Comments
 (0)