rupl 0.1.2

a complex graphing library
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
#[cfg(feature = "serde")]
use base64::Engine;
#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};
use std::f64::consts::PI;
use std::iter::Sum;
use std::ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Sub, SubAssign};
#[derive(PartialEq, Debug, Clone, Copy, Default)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub enum GraphMode {
    ///given a 3d data set maps in 3d, given a 2d data set maps in 2d
    #[default]
    Normal,
    ///takes a slice of the 3d data set and displays it in 2d,
    ///what slice is depended on Graph.view_x and Graph.slice
    Slice,
    ///graphs the 3d data set as a domain coloring plot, explained more in Graph.domain_alternate
    DomainColoring,
    ///maps the real part to the x axis and imaginary part to the y axis
    ///in 3d takes a slice and applys the above logic
    Flatten,
    ///maps the real part to the x axis and imaginary part to the y axis
    ///and the input variable to the z axis
    ///in 3d takes a slice and applys the above logic
    Depth,
    ///turns a 2d function into a polar graph by mapping the x axis to angle of rotation and the y axis to radius,
    ///given a 3d function it maps the z to radius, x to the polar angle, y to the azimuthal angle
    Polar,
    ///takes a slice of a 3d function and applys polar logic
    SlicePolar,
}
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[derive(Clone, Debug)]
pub enum GraphType {
    ///2d data set where the first element in the vector maps to the first float on the x axis,
    ///and the last element in the vector maps to the last float on the x axis, with even spacing
    Width(Vec<Complex>, f64, f64),
    ///each complex number is mapped to the first element in the tuple on the x axis
    Coord(Vec<(f64, Complex)>),
    ///3d data set where the first 2 floats are the starting x/y positions and the last 2 floats are
    ///the ending x/y positions,
    ///
    ///the ith element in the vector corrosponds to the (i % len)th element down the x axis
    ///and the (i / len)th element down the y axis
    ///
    ///expects square vector size
    Width3D(Vec<Complex>, f64, f64, f64, f64),
    ///each complex number is mapped to the first element in the tuple on the x axis
    ///and the second element in the tuple on the y axis
    Coord3D(Vec<(f64, f64, Complex)>),
    ///a constant value, in 2d second value determines weather its on the x or y axis
    Constant(Complex, bool),
    ///a point, 2d only
    Point(Vec2),
    ///a list of graphs, so that all graphs will be the same color
    List(Vec<GraphType>),
    None,
}
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[derive(Clone, Debug)]
pub struct Name {
    pub vars: Vec<String>,
    ///name of the function
    pub name: String,
    ///if the function has an imaginary part or not
    pub show: Show,
}
impl Name {
    pub fn new(name: String) -> Self {
        Name {
            vars: Vec::new(),
            name,
            show: Show::Real,
        }
    }
}
#[derive(Copy, Clone)]
pub(crate) enum Draw {
    Line(Pos, Pos, f32),
    Point(Pos),
}
pub enum Prec {
    ///a multiplier on the precision of the graph to update data on, potentially note Graph.prec
    Mult(f64),
    ///a multiplier on the precision of the graph to update data on, potentially note Graph.prec
    ///
    ///expecting you to only get the slice data
    Slice(f64),
    ///the amount of x/y data is requested for domain coloring
    Dimension(usize, usize),
}
pub enum Bound {
    ///a 2d data set is requested
    Width(f64, f64, Prec),
    ///a 3d data set is requested
    Width3D(f64, f64, f64, f64, Prec),
}
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[derive(Clone, Copy, Debug, Default)]
pub enum Show {
    Real,
    Imag,
    #[default]
    Complex,
    None,
}
impl Show {
    pub fn real(&self) -> bool {
        matches!(self, Self::Complex | Self::Real)
    }
    pub fn imag(&self) -> bool {
        matches!(self, Self::Complex | Self::Imag)
    }
}
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[derive(Clone, Debug, Copy, Default)]
pub enum Lines {
    Points,
    LinesPoints,
    #[default]
    Lines,
}
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[derive(Clone, Debug, Copy, Default)]
pub enum DepthColor {
    ///colors based off of how far on the z axis the value is
    Vertical,
    ///colors based off of how close to the camera it is
    Depth,
    #[default]
    None,
}
#[cfg(feature = "egui")]
pub(crate) struct Image(pub egui::TextureHandle);
#[cfg(feature = "egui")]
impl std::fmt::Debug for Image {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        write!(f, "eguiimage")
    }
}
#[cfg(feature = "skia")]
#[derive(Debug)]
pub(crate) struct Image(pub skia_safe::Image);
#[cfg(feature = "skia")]
impl AsRef<skia_safe::Image> for Image {
    fn as_ref(&self) -> &skia_safe::Image {
        &self.0
    }
}
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[derive(Clone, Debug, Copy, Default)]
pub enum Angle {
    #[default]
    Radian,
    Degree,
    Gradian,
}
#[derive(Clone, Debug, Copy)]
pub(crate) enum Dragable {
    Point(Pos),
    Points((usize, Pos)),
    X(f32),
    Y(f32),
}
impl Angle {
    pub(crate) fn to_val(self, t: f64) -> f64 {
        match self {
            Angle::Radian => t,
            Angle::Degree => 180.0 * t / PI,
            Angle::Gradian => 200.0 * t / PI,
        }
    }
}
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[derive(Clone, Debug)]
pub(crate) enum Change {
    Char((usize, usize), char, bool),
    Str((usize, usize), String, bool),
    Line(usize, bool, bool),
    None,
}
#[cfg(feature = "arboard")]
pub(crate) struct Clipboard(pub arboard::Clipboard);
#[cfg(feature = "arboard")]
impl std::fmt::Debug for Clipboard {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        write!(f, "arboard")
    }
}
#[cfg(not(feature = "arboard"))]
#[derive(Debug)]
pub(crate) struct Clipboard(pub(crate) String);
impl Clipboard {
    #[cfg(feature = "arboard")]
    pub(crate) fn set_text(&mut self, text: &str) {
        self.0.set_text(text).unwrap_or_default()
    }
    #[cfg(feature = "arboard")]
    pub(crate) fn set_image(&mut self, width: usize, height: usize, bytes: &[u8]) {
        self.0
            .set_image(arboard::ImageData {
                width,
                height,
                bytes: bytes.into(),
            })
            .unwrap()
    }
    #[cfg(not(feature = "arboard"))]
    pub(crate) fn set_text(&mut self, text: &str) {
        self.0 = text.to_string();
    }
    #[cfg(feature = "arboard")]
    pub(crate) fn get_text(&mut self) -> String {
        self.0.get_text().unwrap_or_default()
    }
    #[cfg(not(feature = "arboard"))]
    pub(crate) fn get_text(&mut self) -> String {
        self.0.clone()
    }
}
#[cfg(feature = "tiny-skia")]
pub(crate) struct Image(pub tiny_skia::Pixmap);
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct Graph {
    #[cfg(feature = "skia-vulkan")]
    #[cfg_attr(feature = "serde", serde(skip))]
    pub(crate) render_ctx: crate::skia_vulkan::context::VulkanRenderContext,
    ///vulkan surface
    #[cfg(feature = "skia-vulkan")]
    #[cfg_attr(feature = "serde", serde(skip))]
    pub renderer: Option<crate::skia_vulkan::renderer::VulkanRenderer>,
    ///current data sets
    #[cfg_attr(feature = "serde", serde(skip))]
    pub data: Vec<GraphType>,
    ///current data sets names for labeling, ordered by data
    #[cfg_attr(feature = "serde", serde(default))]
    pub names: Vec<Name>,
    #[cfg_attr(feature = "serde", serde(skip))]
    pub(crate) cache: Option<Image>,
    #[cfg_attr(feature = "serde", serde(default))]
    pub(crate) name_updated: Option<usize>,
    #[cfg(feature = "skia")]
    #[cfg_attr(feature = "serde", serde(skip))]
    pub(crate) font: Option<skia_safe::Font>,
    #[cfg_attr(feature = "serde", serde(skip))]
    #[cfg(feature = "tiny-skia")]
    pub(crate) font: Option<bdf2::Font>,
    #[cfg_attr(feature = "serde", serde(default))]
    pub(crate) font_size: f32,
    #[cfg_attr(feature = "serde", serde(default))]
    pub(crate) font_width: f32,
    #[allow(clippy::type_complexity)]
    #[cfg_attr(feature = "serde", serde(skip))]
    ///for tab completion,will tab complete upto a "(" if it exists,
    /// so you may give info about which variables will be accepted
    pub tab_complete: Option<Box<dyn Fn(&str) -> Vec<String>>>,
    ///width of function lines
    #[cfg_attr(feature = "serde", serde(default))]
    pub line_width: f32,
    #[cfg(feature = "skia")]
    ///if Some, then returns bytes of an image format from update
    #[cfg_attr(feature = "serde", serde(default))]
    pub image_format: crate::ui::ImageFormat,
    ///a fast 3d mode ignoring depth
    #[cfg_attr(feature = "serde", serde(default))]
    pub fast_3d: bool,
    ///enable fast 3d only when moving with a mouse
    #[cfg_attr(feature = "serde", serde(default))]
    pub fast_3d_move: bool,
    ///request less data when moving with a mouse
    #[cfg_attr(feature = "serde", serde(default))]
    pub reduced_move: bool,
    ///current initial bound of window
    #[cfg_attr(feature = "serde", serde(default))]
    pub bound: Vec2,
    ///weather data is complex or not, changes graph mode options from keybinds
    #[cfg_attr(feature = "serde", serde(default))]
    pub is_complex: bool,
    ///offset in 3d mode
    #[cfg_attr(feature = "serde", serde(default))]
    pub offset3d: Vec3,
    ///offset in 2d mode
    #[cfg_attr(feature = "serde", serde(default))]
    pub offset: Vec2,
    ///view angle in 3d mode
    #[cfg_attr(feature = "serde", serde(default))]
    pub angle: Vec2,
    ///weather bounds should be ignored in 3d mode
    #[cfg_attr(feature = "serde", serde(default))]
    pub ignore_bounds: bool,
    ///current zoom
    #[cfg_attr(feature = "serde", serde(default))]
    pub zoom: Vec2,
    ///current zoom for 3d
    #[cfg_attr(feature = "serde", serde(default))]
    pub zoom_3d: Vec3,
    ///what slice we are currently at in any slice mode
    #[cfg_attr(feature = "serde", serde(default))]
    pub slice: isize,
    ///var range used for flatten or depth
    #[cfg_attr(feature = "serde", serde(default))]
    pub var: Vec2,
    ///log scale for domain coloring
    #[cfg_attr(feature = "serde", serde(default))]
    pub log_scale: bool,
    ///how large the box should be in 3d
    #[cfg_attr(feature = "serde", serde(default))]
    pub box_size: f64,
    ///alternate domain coloring mode
    #[cfg_attr(feature = "serde", serde(default))]
    pub domain_alternate: bool,
    #[cfg_attr(feature = "serde", serde(default))]
    pub(crate) screen: Vec2,
    #[cfg_attr(feature = "serde", serde(default))]
    pub(crate) screen_offset: Vec2,
    #[cfg_attr(feature = "serde", serde(default))]
    pub(crate) delta: f64,
    ///if real/imag should be displayed
    #[cfg_attr(feature = "serde", serde(default))]
    pub show: Show,
    ///weather some elements should be anti aliased or not
    #[cfg_attr(feature = "serde", serde(default))]
    pub anti_alias: bool,
    ///what color depth mode is currently enabled for 3d
    #[cfg_attr(feature = "serde", serde(default))]
    pub color_depth: DepthColor,
    ///weather all box lines should be displayed
    #[cfg_attr(feature = "serde", serde(default))]
    pub show_box: bool,
    ///colors of data sets for real part, ordered by data
    #[cfg_attr(feature = "serde", serde(default))]
    pub main_colors: Vec<Color>,
    ///colors of data sets for imag part, ordered by data
    #[cfg_attr(feature = "serde", serde(default))]
    pub alt_colors: Vec<Color>,
    ///major ticks axis color
    #[cfg_attr(feature = "serde", serde(default))]
    pub axis_color: Color,
    ///do not show graph with these indices
    #[cfg_attr(feature = "serde", serde(default))]
    pub blacklist_graphs: Vec<usize>,
    ///minor ticks axis color
    #[cfg_attr(feature = "serde", serde(default))]
    pub axis_color_light: Color,
    ///background color
    #[cfg_attr(feature = "serde", serde(default))]
    pub background_color: Color,
    ///text color
    #[cfg_attr(feature = "serde", serde(default))]
    pub(crate) text_color: Color,
    #[cfg_attr(feature = "serde", serde(default))]
    pub(crate) mouse_position: Option<Vec2>,
    #[cfg_attr(feature = "serde", serde(default))]
    pub(crate) mouse_moved: bool,
    ///weather non origin lines are disabled or not
    #[cfg_attr(feature = "serde", serde(default))]
    pub disable_lines: bool,
    ///weather axis text is disabled or not
    #[cfg_attr(feature = "serde", serde(default))]
    pub disable_axis: bool,
    ///weather mouse position is disabled or not
    #[cfg_attr(feature = "serde", serde(default))]
    pub disable_coord: bool,
    ///is slice viewing the x part or y part
    #[cfg_attr(feature = "serde", serde(default))]
    pub view_x: bool,
    ///current graph mode
    #[cfg_attr(feature = "serde", serde(default))]
    pub graph_mode: GraphMode,
    ///weather we are displaying a 3d plot or 2d
    #[cfg_attr(feature = "serde", serde(default))]
    pub is_3d: bool,
    ///weather the data type supplied is naturally 3d or not
    #[cfg_attr(feature = "serde", serde(default))]
    pub is_3d_data: bool,
    ///what angle type will be displayed
    #[cfg_attr(feature = "serde", serde(default))]
    pub angle_type: Angle,
    #[cfg_attr(feature = "serde", serde(default))]
    pub(crate) last_interact: Option<Vec2>,
    #[cfg_attr(feature = "serde", serde(default))]
    pub(crate) last_right_interact: Option<Vec2>,
    #[cfg_attr(feature = "serde", serde(default))]
    pub(crate) recalculate: bool,
    #[cfg_attr(feature = "serde", serde(default))]
    pub(crate) name_modified: bool,
    ///current line style
    #[cfg_attr(feature = "serde", serde(default))]
    pub lines: Lines,
    ///current ruler position
    #[cfg_attr(feature = "serde", serde(default))]
    pub ruler_pos: Option<Vec2>,
    #[cfg_attr(feature = "serde", serde(default))]
    pub(crate) prec: f64,
    #[cfg_attr(feature = "serde", serde(default))]
    pub(crate) mouse_held: bool,
    ///how much extra reduced precision domain coloring should have
    #[cfg_attr(feature = "serde", serde(default))]
    pub mult: f64,
    ///how many major lines to display
    #[cfg_attr(feature = "serde", serde(default))]
    pub line_major: usize,
    ///how many minor lines inbetween major lines to display
    #[cfg_attr(feature = "serde", serde(default))]
    pub line_minor: usize,
    #[cfg_attr(feature = "serde", serde(default))]
    pub(crate) draw_offset: Pos,
    #[cfg_attr(feature = "serde", serde(default))]
    pub(crate) cos_phi: f64,
    #[cfg_attr(feature = "serde", serde(default))]
    pub(crate) sin_phi: f64,
    #[cfg_attr(feature = "serde", serde(default))]
    pub(crate) cos_theta: f64,
    #[cfg_attr(feature = "serde", serde(default))]
    pub(crate) sin_theta: f64,
    #[cfg_attr(feature = "serde", serde(default))]
    pub(crate) select: Option<(usize, usize, Option<bool>)>,
    ///where in side panel the cursor is at
    #[cfg_attr(feature = "serde", serde(default))]
    pub text_box: Option<(usize, usize)>,
    #[cfg_attr(feature = "serde", serde(default))]
    pub(crate) side_slider: Option<usize>,
    #[cfg_attr(feature = "serde", serde(default))]
    pub(crate) side_drag: Option<(usize, Option<usize>)>,
    #[cfg_attr(feature = "serde", serde(default))]
    pub(crate) last_multi: bool,
    #[cfg_attr(feature = "serde", serde(default))]
    pub(crate) side_bar_width: f64,
    #[cfg_attr(feature = "serde", serde(skip))]
    pub(crate) clipboard: Option<Clipboard>,
    #[cfg_attr(feature = "serde", serde(default))]
    pub(crate) history: Vec<Change>,
    #[cfg_attr(feature = "serde", serde(default))]
    pub(crate) history_pos: usize,
    #[cfg_attr(feature = "serde", serde(default))]
    pub(crate) text_scroll_pos: (usize, usize),
    ///do not show anything if it contains an imaginary part
    #[cfg_attr(feature = "serde", serde(default))]
    pub only_real: bool,
    ///what menu should be drawn
    #[cfg_attr(feature = "serde", serde(default))]
    pub menu: Menu,
    ///current keybinds, always some, besides during deserialization
    #[cfg_attr(feature = "serde", serde(skip))]
    pub keybinds: Option<Keybinds>,
    ///side bar height per line
    #[cfg_attr(feature = "serde", serde(default))]
    pub side_height: f32,
    ///in horizontal view, minimum width side bar will be in pixels
    #[cfg_attr(feature = "serde", serde(default))]
    pub min_side_width: f64,
    ///in horizontal view, maximum width main graph will be in pixels in side bar view
    #[cfg_attr(feature = "serde", serde(default))]
    pub min_screen_width: f64,
    ///in horizontal view, minimum ratio of the main screen will be targeted
    #[cfg_attr(feature = "serde", serde(default))]
    pub target_side_ratio: f64,
    /// bracket color based on depth of brackets
    #[cfg_attr(feature = "serde", serde(default))]
    pub bracket_color: Vec<Color>,
    /// what color the text drag select will be
    #[cfg_attr(feature = "serde", serde(default))]
    pub select_color: Color,
    #[cfg(feature = "arboard")]
    #[cfg_attr(feature = "serde", serde(default))]
    pub(crate) wait_frame: bool,
    #[cfg(feature = "serde")]
    /// which file will save the serialization data
    #[cfg_attr(feature = "serde", serde(default))]
    pub save_file: String,
    #[cfg(feature = "serde")]
    #[cfg_attr(feature = "serde", serde(default))]
    pub(crate) save_num: Option<usize>,
    #[cfg(feature = "serde")]
    #[cfg_attr(feature = "serde", serde(skip))]
    pub(crate) file_data: Option<Vec<(String, usize, String)>>,
    #[cfg(feature = "serde")]
    #[cfg_attr(feature = "serde", serde(skip))]
    pub(crate) file_data_raw: Option<Vec<String>>,
    #[cfg_attr(feature = "serde", serde(skip))]
    pub(crate) constant_eval: Vec<(usize, String)>,
    #[cfg(any(feature = "skia", feature = "tiny-skia"))]
    #[cfg_attr(feature = "serde", serde(skip))]
    pub request_redraw: bool,
    #[cfg_attr(feature = "serde", serde(skip))]
    #[cfg(feature = "tiny-skia")]
    pub(crate) font_cache: std::collections::HashMap<char, tiny_skia::Pixmap>,
}
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[derive(Clone, Debug, Copy, PartialEq, Default)]
pub enum Menu {
    #[default]
    Normal,
    Side,
    Settings,
    #[cfg(feature = "serde")]
    Load,
}
impl Default for Graph {
    fn default() -> Self {
        #[cfg(feature = "skia")]
        let typeface = skia_safe::FontMgr::default()
            .new_from_data(include_bytes!("../terminus.bdf"), None)
            .unwrap();
        let text_color = Color::splat(0);
        let font_size = 18.0;
        #[cfg(feature = "tiny-skia")]
        let font = bdf2::read(&include_bytes!("../terminus.bdf")[..]).ok();
        #[cfg(feature = "skia")]
        let font = Some(skia_safe::Font::new(typeface, font_size));
        #[cfg(feature = "arboard")]
        let clipboard = None;
        #[cfg(not(feature = "arboard"))]
        let clipboard = Some(Clipboard(String::new()));
        Self {
            #[cfg(feature = "tiny-skia")]
            font_cache: crate::build_cache(&font, text_color),
            #[cfg(feature = "skia-vulkan")]
            render_ctx: Default::default(),
            #[cfg(feature = "skia-vulkan")]
            renderer: None,
            name_updated: None,
            is_3d: false,
            clipboard,
            #[cfg(feature = "arboard")]
            wait_frame: true,
            #[cfg(feature = "serde")]
            file_data: None,
            #[cfg(feature = "serde")]
            file_data_raw: None,
            history: Vec::new(),
            tab_complete: None,
            history_pos: 0,
            is_3d_data: false,
            constant_eval: Vec::new(),
            zoom_3d: Vec3::splat(1.0),
            names: Vec::new(),
            fast_3d: false,
            text_scroll_pos: (0, 0),
            data: Vec::new(),
            #[cfg(feature = "serde")]
            save_file: String::new(),
            #[cfg(feature = "serde")]
            save_num: None,
            cache: None,
            blacklist_graphs: Vec::new(),
            line_width: 3.0,
            #[cfg(any(feature = "skia", feature = "tiny-skia"))]
            font,
            font_size,
            font_width: 0.0,
            #[cfg(feature = "skia")]
            image_format: crate::ui::ImageFormat::Png,
            fast_3d_move: false,
            reduced_move: false,
            bound: Vec2::new(-2.0, 2.0),
            offset3d: Vec3::splat(0.0),
            offset: Vec2::splat(0.0),
            angle: Vec2::splat(PI / 6.0),
            slice: 0,
            mult: 1.0,
            text_box: None,
            line_major: 8,
            line_minor: 4,
            is_complex: false,
            show: Show::Complex,
            ignore_bounds: false,
            zoom: Vec2::splat(1.0),
            name_modified: false,
            draw_offset: Pos::new(0.0, 0.0),
            angle_type: Angle::Radian,
            mouse_held: false,
            menu: Menu::Normal,
            screen: Vec2::splat(0.0),
            screen_offset: Vec2::splat(0.0),
            delta: 0.0,
            show_box: true,
            select: None,
            log_scale: false,
            view_x: true,
            color_depth: DepthColor::None,
            box_size: 3.0f64.sqrt(),
            anti_alias: true,
            lines: Lines::Lines,
            domain_alternate: true,
            var: Vec2::new(-2.0, 2.0),
            #[cfg(any(feature = "skia", feature = "tiny-skia"))]
            request_redraw: false,
            last_interact: None,
            last_right_interact: None,
            min_screen_width: 256.0,
            main_colors: vec![
                Color::new(255, 85, 85),
                Color::new(85, 85, 255),
                Color::new(255, 85, 255),
                Color::new(85, 255, 85),
                Color::new(85, 255, 255),
                Color::new(255, 255, 85),
            ],
            alt_colors: vec![
                Color::new(170, 0, 0),
                Color::new(0, 0, 170),
                Color::new(170, 0, 170),
                Color::new(0, 170, 0),
                Color::new(0, 170, 170),
                Color::new(170, 170, 0),
            ],
            axis_color: Color::splat(0),
            axis_color_light: Color::splat(220),
            text_color,
            background_color: Color::splat(255),
            mouse_position: None,
            mouse_moved: false,
            disable_lines: false,
            disable_axis: false,
            disable_coord: true,
            side_slider: None,
            side_drag: None,
            graph_mode: GraphMode::Normal,
            last_multi: false,
            prec: 1.0,
            side_bar_width: 0.0,
            side_height: 1.875,
            recalculate: false,
            ruler_pos: None,
            bracket_color: vec![
                Color::new(255, 85, 85),
                //Color::new(85, 255, 85),
                //Color::new(255, 255, 85),
                Color::new(85, 85, 255),
                Color::new(255, 85, 255),
                //Color::new(85, 255, 255),
            ],
            cos_phi: 0.0,
            sin_phi: 0.0,
            cos_theta: 0.0,
            sin_theta: 0.0,
            only_real: false,
            keybinds: Some(Keybinds::default()),
            target_side_ratio: 3.0 / 2.0,
            min_side_width: 256.0,
            select_color: Color::new(191, 191, 255),
        }
    }
}
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[derive(Copy, Debug, Clone, PartialEq)]
pub struct Keybinds {
    ///moves left on the x axis in 2d, rotates left in 3d
    pub left: Option<Keys>,
    ///moves right on the x axis in 2d, rotates right in 3d
    pub right: Option<Keys>,
    ///moves up on the y axis in 2d, rotates up in 3d
    pub up: Option<Keys>,
    ///moves down on the y axis in 2d, rotates down in 3d
    pub down: Option<Keys>,
    ///moves viewport left in 3d
    pub left_3d: Option<Keys>,
    ///moves viewport right in 3d
    pub right_3d: Option<Keys>,
    ///moves viewport up in 3d
    pub up_3d: Option<Keys>,
    ///moves viewport down in 3d
    pub down_3d: Option<Keys>,
    ///in 3d, moves up on the z axis
    pub in_3d: Option<Keys>,
    ///in 3d, moves down on the z axis
    pub out_3d: Option<Keys>,
    ///zooms the into the data set, in 2d, towards the cursor if moved since last reset,
    ///otherwise towards center of screen
    pub zoom_in: Option<Keys>,
    ///zooms the out of the data set, in 2d, away from cursor if moved since last reset,
    ///otherwise towards center of screen
    pub zoom_out: Option<Keys>,
    pub zoom_in_x: Option<Keys>,
    pub zoom_out_x: Option<Keys>,
    pub zoom_in_y: Option<Keys>,
    pub zoom_out_y: Option<Keys>,
    pub zoom_in_z: Option<Keys>,
    pub zoom_out_z: Option<Keys>,
    ///toggles non center lines in 2d, or all lines with axis aditionally disabled
    pub lines: Option<Keys>,
    ///toggles display of axis numbers, or all lines with axis aditionally disabled
    pub axis: Option<Keys>,
    ///toggles current coordonate of mouse in bottom left, or angle in 3d
    pub coord: Option<Keys>,
    ///toggles anti alias for some things
    pub anti_alias: Option<Keys>,
    ///in 3d, ignores the bounds of the box and displays all data points
    pub ignore_bounds: Option<Keys>,
    ///in 3d, toggles the color depth enum
    pub color_depth: Option<Keys>,
    ///makes viewport larger in 3d
    pub zoom_in_3d: Option<Keys>,
    ///makes viewport smaller in 3d
    pub zoom_out_3d: Option<Keys>,
    ///in 3d, shows the full box instead of just the axis lines,
    ///or none if additionally axis is disabled
    pub show_box: Option<Keys>,
    ///toggles domain alternate mode, see Graph.domain_alternate for more info
    pub domain_alternate: Option<Keys>,
    ///iterates Graph.slice foward
    pub slice_up: Option<Keys>,
    ///iterates Graph.slice backward
    pub slice_down: Option<Keys>,
    ///toggles Graph.view_x
    pub slice_view: Option<Keys>,
    ///log scale, currently only for domain coloring
    pub log_scale: Option<Keys>,
    ///toggles line style enum
    pub line_style: Option<Keys>,
    ///for flatten or depth graph modes, move the input variables range foward
    pub var_up: Option<Keys>,
    ///for flatten or depth graph modes, move the input variables range backward
    pub var_down: Option<Keys>,
    ///for flatten or depth graph modes, decrease range of input variables range
    pub var_in: Option<Keys>,
    ///for flatten or depth graph modes, incrase range of input variables range
    pub var_out: Option<Keys>,
    ///increases amount of data asked for
    pub prec_up: Option<Keys>,
    ///decreases amount of data asked for
    pub prec_down: Option<Keys>,
    ///toggles a ruler at current mouse position, in bottom right will have the following info,
    ///delta x of ruler
    ///delta y of ruler
    ///norm of ruler
    ///angle of ruler in degrees
    pub ruler: Option<Keys>,
    ///toggles showing real/imag parts of graphs
    pub view: Option<Keys>,
    ///toggles the current graph mode enum foward
    pub mode_up: Option<Keys>,
    ///toggles the current graph mode enum backward
    pub mode_down: Option<Keys>,
    ///resets most settings to default
    pub reset: Option<Keys>,
    ///toggles up the side menu
    pub side: Option<Keys>,
    ///toggles using faster logic in 2d/3d
    pub fast: Option<Keys>,
    #[cfg(feature = "serde")]
    ///copys tiny serialized data to clipboard
    pub save: Option<Keys>,
    #[cfg(feature = "serde")]
    ///full saves the graph into the Graph.save_file directory
    pub full_save: Option<Keys>,
    #[cfg(feature = "serde")]
    ///applys tiny serialized data from clipboard
    pub paste: Option<Keys>,
    ///settings menu
    pub settings: Option<Keys>,
    #[cfg(feature = "serde")]
    ///load from full saves
    pub load: Option<Keys>,
    #[cfg(any(feature = "skia", feature = "tiny-skia"))]
    ///save screen to clipboard
    pub save_png: Option<Keys>,
    ///only shows real values, and ignores real values if they have an imaginary part
    pub only_real: Option<Keys>,
    ///toggles dark mode
    pub toggle_dark_mode: Option<Keys>,
}
#[cfg(feature = "serde")]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "serde", serde(default))]
#[derive(Clone, Debug, Default)]
pub struct GraphTiny {
    pub names: Vec<Name>,
    pub bound: (f32, f32),
    pub prec: f32,
    pub is_complex: bool,
    pub offset3d: Option<(f32, f32, f32)>,
    pub offset: Option<(f32, f32)>,
    pub zoom: Option<(f32, f32)>,
    pub zoom_3d: Option<(f32, f32, f32)>,
    pub slice: i8,
    pub var: (f32, f32),
    pub log_scale: bool,
    pub domain_alternate: bool,
    pub color_depth: DepthColor,
    pub blacklist_graphs: Vec<u8>,
    pub view_x: bool,
    pub graph_mode: GraphMode,
    pub only_real: bool,
}
#[cfg(feature = "serde")]
impl Graph {
    pub fn to_tiny(&self) -> GraphTiny {
        let (a, b) = self.to_coord((self.screen / 2.0).to_pos());
        GraphTiny {
            names: self
                .names
                .iter()
                .filter_map(|n| {
                    if n.vars.is_empty() && n.name.is_empty() {
                        None
                    } else {
                        Some(n.clone())
                    }
                })
                .collect(),
            bound: self.bound.to_tuple(),
            prec: self.prec as f32,
            is_complex: self.is_complex,
            offset3d: self.is_3d.then_some(self.offset3d.to_tuple()),
            offset: (!self.is_3d).then_some((a as f32, b as f32)),
            zoom: (!self.is_3d).then_some(self.zoom.to_tuple()),
            zoom_3d: self.is_3d.then_some(self.zoom_3d.to_tuple()),
            slice: self.slice as i8,
            var: self.var.to_tuple(),
            log_scale: self.log_scale,
            domain_alternate: self.domain_alternate,
            color_depth: self.color_depth,
            blacklist_graphs: self.blacklist_graphs.iter().map(|i| *i as u8).collect(),
            view_x: self.view_x,
            graph_mode: self.graph_mode,
            only_real: self.only_real,
        }
    }
    pub fn apply_tiny(&mut self, tiny: GraphTiny) {
        self.names = tiny.names;
        self.bound = tiny.bound.into();
        self.is_complex = tiny.is_complex;
        self.prec = tiny.prec as f64;
        self.offset3d = tiny.offset3d.unwrap_or_default().into();
        self.zoom = tiny.zoom.unwrap_or((1.0, 1.0)).into();
        self.zoom_3d = tiny.zoom_3d.unwrap_or((1.0, 1.0, 1.0)).into();
        let o: Vec2 = tiny.offset.unwrap_or_default().into();
        self.offset = self.get_new_offset(o);
        self.slice = tiny.slice as isize;
        self.var = tiny.var.into();
        self.log_scale = tiny.log_scale;
        self.domain_alternate = tiny.domain_alternate;
        self.color_depth = tiny.color_depth;
        self.blacklist_graphs = tiny.blacklist_graphs.iter().map(|i| *i as usize).collect();
        self.view_x = tiny.view_x;
        self.graph_mode = tiny.graph_mode;
        self.only_real = tiny.only_real;
        self.recalculate(None);
        self.name_modified(None);
        self.text_box = Some((0, 0));
    }
}
#[cfg(feature = "serde")]
impl TryFrom<&String> for GraphTiny {
    type Error = ();
    fn try_from(value: &String) -> Result<Self, Self::Error> {
        let (a, b) = value.rsplit_once('@').ok_or(())?;
        let l = base64::prelude::BASE64_URL_SAFE_NO_PAD
            .decode(a)
            .map_err(|_| ())?;
        let l = String::from_utf8(l)
            .map_err(|_| ())?
            .parse::<usize>()
            .map_err(|_| ())?;
        let comp = base64::prelude::BASE64_URL_SAFE_NO_PAD
            .decode(b)
            .map_err(|_| ())?;
        let seri = zstd::bulk::decompress(&comp, l).map_err(|_| ())?;
        bitcode::deserialize(&seri).map_err(|_| ())
    }
}
impl Default for Keybinds {
    fn default() -> Self {
        Self {
            left: Some(Keys::new(Key::ArrowLeft)),
            right: Some(Keys::new(Key::ArrowRight)),
            up: Some(Keys::new(Key::ArrowUp)),
            down: Some(Keys::new(Key::ArrowDown)),
            zoom_in: Some(Keys::new(Key::Equals)),
            zoom_out: Some(Keys::new(Key::Minus)),
            zoom_in_x: Some(Keys::new_with_modifier(
                Key::Equals,
                Modifiers::default().ctrl(),
            )),
            zoom_out_x: Some(Keys::new_with_modifier(
                Key::Minus,
                Modifiers::default().ctrl(),
            )),
            zoom_in_y: Some(Keys::new_with_modifier(
                Key::Plus,
                Modifiers::default().shift(),
            )),
            zoom_out_y: Some(Keys::new_with_modifier(
                Key::Underscore,
                Modifiers::default().shift(),
            )),
            zoom_in_z: Some(Keys::new_with_modifier(
                Key::Plus,
                Modifiers::default().shift().ctrl(),
            )),
            zoom_out_z: Some(Keys::new_with_modifier(
                Key::Underscore,
                Modifiers::default().shift().ctrl(),
            )),
            lines: Some(Keys::new(Key::Z)),
            axis: Some(Keys::new(Key::X)),
            left_3d: Some(Keys::new_with_modifier(
                Key::ArrowLeft,
                Modifiers::default().ctrl(),
            )),
            right_3d: Some(Keys::new_with_modifier(
                Key::ArrowRight,
                Modifiers::default().ctrl(),
            )),
            up_3d: Some(Keys::new_with_modifier(
                Key::ArrowUp,
                Modifiers::default().ctrl(),
            )),
            down_3d: Some(Keys::new_with_modifier(
                Key::ArrowDown,
                Modifiers::default().ctrl(),
            )),
            in_3d: Some(Keys::new_with_modifier(
                Key::ArrowDown,
                Modifiers::default().ctrl().alt(),
            )),
            out_3d: Some(Keys::new_with_modifier(
                Key::ArrowUp,
                Modifiers::default().ctrl().alt(),
            )),
            #[cfg(feature = "serde")]
            save: Some(Keys::new_with_modifier(Key::S, Modifiers::default().ctrl())),
            #[cfg(feature = "serde")]
            full_save: Some(Keys::new_with_modifier(
                Key::S,
                Modifiers::default().ctrl().shift(),
            )),
            #[cfg(feature = "serde")]
            paste: Some(Keys::new_with_modifier(Key::P, Modifiers::default().ctrl())),
            coord: Some(Keys::new(Key::C)),
            anti_alias: Some(Keys::new(Key::R)),
            ignore_bounds: Some(Keys::new(Key::P)),
            color_depth: Some(Keys::new(Key::O)),
            zoom_in_3d: Some(Keys::new(Key::Semicolon)),
            zoom_out_3d: Some(Keys::new(Key::Quote)),
            show_box: Some(Keys::new(Key::U)),
            domain_alternate: Some(Keys::new(Key::Y)),
            slice_up: Some(Keys::new(Key::Period)),
            slice_down: Some(Keys::new(Key::Comma)),
            slice_view: Some(Keys::new(Key::Slash)),
            log_scale: Some(Keys::new_with_modifier(Key::L, Modifiers::default().ctrl())),
            line_style: Some(Keys::new(Key::L)),
            var_up: Some(Keys::new_with_modifier(
                Key::ArrowRight,
                Modifiers::default().shift(),
            )),
            var_down: Some(Keys::new_with_modifier(
                Key::ArrowLeft,
                Modifiers::default().shift(),
            )),
            var_in: Some(Keys::new_with_modifier(
                Key::ArrowUp,
                Modifiers::default().shift(),
            )),
            var_out: Some(Keys::new_with_modifier(
                Key::ArrowDown,
                Modifiers::default().shift(),
            )),
            prec_up: Some(Keys::new(Key::OpenBracket)),
            prec_down: Some(Keys::new(Key::CloseBracket)),
            ruler: Some(Keys::new(Key::N)),
            view: Some(Keys::new(Key::I)),
            mode_up: Some(Keys::new(Key::B)),
            mode_down: Some(Keys::new_with_modifier(
                Key::B,
                Modifiers::default().shift(),
            )),
            reset: Some(Keys::new(Key::T)),
            side: Some(Keys::new(Key::Escape)),
            fast: Some(Keys::new(Key::F)),
            settings: None, /*Some(Keys::new_with_modifier( TODO
                                Key::Escape,
                                Modifiers::default().ctrl(),
                            ))*/
            #[cfg(feature = "serde")]
            load: Some(Keys::new_with_modifier(
                Key::Escape,
                Modifiers::default().shift(),
            )),
            #[cfg(any(feature = "skia", feature = "tiny-skia"))]
            save_png: Some(Keys::new_with_modifier(Key::S, Modifiers::default().alt())),
            toggle_dark_mode: Some(Keys::new_with_modifier(
                Key::D,
                Modifiers::default().shift().ctrl(),
            )),
            only_real: Some(Keys::new_with_modifier(
                Key::O,
                Modifiers::default().shift().ctrl(),
            )),
        }
    }
}
pub struct Multi {
    ///how much touch input has zoomed in this frame
    pub zoom_delta: f64,
    ///how much touch input translated in this frame
    pub translation_delta: Vec2,
}
pub struct InputState {
    ///which keys have been pressed this frame
    pub keys_pressed: Vec<Key>,
    ///which modifiers are pressed
    pub modifiers: Modifiers,
    ///how much scroll wheel has scrolled
    pub raw_scroll_delta: Vec2,
    ///where the pointer is currently
    pub pointer_pos: Option<Vec2>,
    ///some if pointer is down, true if this frame pointer was pressed
    pub pointer: Option<bool>,
    ///some if pointer is down, true if this frame pointer was pressed
    pub pointer_right: Option<bool>,
    ///Some if multiple touch inputs have been detected
    pub multi: Option<Multi>,
    #[cfg(feature = "egui")]
    pub(crate) clipboard_override: Option<String>,
}
impl Default for InputState {
    fn default() -> Self {
        Self {
            keys_pressed: Vec::new(),
            modifiers: Modifiers::default(),
            raw_scroll_delta: Vec2::splat(0.0),
            pointer_pos: None,
            pointer: None,
            pointer_right: None,
            multi: None,
            #[cfg(feature = "egui")]
            clipboard_override: None,
        }
    }
}
impl InputState {
    ///resets raw_scroll_delta, keys_pressed, pointer_just_down, multi,
    ///expected to happen after update()
    pub fn reset(&mut self) {
        self.raw_scroll_delta = Vec2::splat(0.0);
        self.keys_pressed = Vec::new();
        if self.pointer.is_some() {
            self.pointer = Some(false);
        }
        if self.pointer_right.is_some() {
            self.pointer_right = Some(false);
        }
        self.multi = None;
    }
}
#[cfg(feature = "egui")]
impl From<&egui::InputState> for InputState {
    fn from(val: &egui::InputState) -> Self {
        let pointer = if val.pointer.primary_down() {
            Some(val.pointer.primary_pressed())
        } else {
            None
        };
        let pointer_right = if val.pointer.secondary_down() {
            Some(val.pointer.secondary_pressed())
        } else {
            None
        };
        let mut clipboard_override = None;
        let keys_pressed = val
            .events
            .iter()
            .filter_map(|event| match event {
                egui::Event::Copy => Some(Key::C),
                egui::Event::Cut => Some(Key::X),
                egui::Event::Paste(s) => {
                    clipboard_override = Some(s.clone());
                    Some(Key::V)
                }
                egui::Event::Key {
                    key, pressed: true, ..
                } => Some(key.into()),
                egui::Event::Text(s) => match s.as_str() {
                    "^" => Some(Key::Caret),
                    "#" => Some(Key::HashTag),
                    "(" => Some(Key::OpenParentheses),
                    ")" => Some(Key::CloseParentheses),
                    "&" => Some(Key::And),
                    "%" => Some(Key::Percent),
                    "_" => Some(Key::Underscore),
                    "<" => Some(Key::LessThen),
                    ">" => Some(Key::GreaterThen),
                    "±" => Some(Key::PlusMinus),
                    "\"" => Some(Key::DoubleQuote),
                    "$" => Some(Key::Dollar),
                    "¢" => Some(Key::Cent),
                    "~" => Some(Key::Tilde),
                    "*" => Some(Key::Mult),
                    _ => None,
                },
                _ => None,
            })
            .collect::<Vec<Key>>();
        InputState {
            keys_pressed,
            modifiers: val.modifiers.into(),
            raw_scroll_delta: Vec2 {
                x: val.raw_scroll_delta.x as f64,
                y: val.raw_scroll_delta.y as f64,
            },
            pointer_pos: val
                .pointer
                .latest_pos()
                .map(|a| Vec2::new(a.x as f64, a.y as f64)),
            pointer,
            pointer_right,
            multi: val.multi_touch().map(|i| Multi {
                translation_delta: Vec2::new(
                    i.translation_delta.x as f64,
                    i.translation_delta.y as f64,
                ),
                zoom_delta: i.zoom_delta as f64,
            }),
            clipboard_override,
        }
    }
}
impl InputState {
    pub(crate) fn keys_pressed(&self, keys: Option<Keys>) -> bool {
        if let Some(keys) = keys {
            keys.modifiers
                .map(|m| self.modifiers == m)
                .unwrap_or(self.modifiers.is_false())
                && self.keys_pressed.contains(&keys.key)
        } else {
            false
        }
    }
}
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[derive(Copy, Debug, Clone, PartialEq)]
pub struct Keys {
    ///None is equivalent to a set of false Modifiers
    modifiers: Option<Modifiers>,
    key: Key,
}
impl Keys {
    pub fn new(key: Key) -> Self {
        Self {
            key,
            modifiers: None,
        }
    }
    pub fn new_with_modifier(key: Key, modifiers: Modifiers) -> Self {
        Self {
            key,
            modifiers: Some(modifiers),
        }
    }
}
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[derive(Copy, Debug, Clone, PartialEq, Default)]
pub struct Modifiers {
    pub alt: bool,
    pub ctrl: bool,
    pub shift: bool,
    pub mac_cmd: bool,
    pub command: bool,
}
#[cfg(feature = "egui")]
impl From<Modifiers> for egui::Modifiers {
    fn from(val: Modifiers) -> Self {
        egui::Modifiers {
            alt: val.alt,
            ctrl: val.ctrl,
            shift: val.shift,
            mac_cmd: val.mac_cmd,
            command: val.command,
        }
    }
}
#[cfg(feature = "egui")]
impl From<egui::Modifiers> for Modifiers {
    fn from(val: egui::Modifiers) -> Self {
        Modifiers {
            alt: val.alt,
            ctrl: val.ctrl,
            shift: val.shift,
            mac_cmd: val.mac_cmd,
            command: val.command,
        }
    }
}
impl Modifiers {
    pub(crate) fn is_false(&self) -> bool {
        !self.mac_cmd && !self.alt && !self.command && !self.ctrl && !self.shift
    }
    pub fn alt(mut self) -> Self {
        self.alt = true;
        self
    }
    pub fn ctrl(mut self) -> Self {
        self.ctrl = true;
        self
    }
    pub fn shift(mut self) -> Self {
        self.shift = true;
        self
    }
    pub fn mac_cmd(mut self) -> Self {
        self.mac_cmd = true;
        self
    }
    pub fn command(mut self) -> Self {
        self.command = true;
        self
    }
}
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[derive(Copy, Debug, Clone, PartialEq, Eq, Hash, Default)]
pub struct Color {
    pub r: u8,
    pub g: u8,
    pub b: u8,
}
impl Color {
    pub(crate) fn new(r: u8, g: u8, b: u8) -> Self {
        Self { r, g, b }
    }
    pub(crate) fn splat(c: u8) -> Self {
        Self { r: c, g: c, b: c }
    }
    #[cfg(feature = "egui")]
    pub(crate) fn to_col(self) -> egui::Color32 {
        egui::Color32::from_rgb(self.r, self.g, self.b)
    }
    #[cfg(feature = "skia")]
    pub(crate) fn to_col(self) -> skia_safe::Color4f {
        skia_safe::Color4f::new(
            self.r as f32 / 255.0,
            self.g as f32 / 255.0,
            self.b as f32 / 255.0,
            1.0,
        )
    }
    #[cfg(feature = "tiny-skia")]
    pub(crate) fn to_col(self) -> tiny_skia::Color {
        tiny_skia::Color::from_rgba8(self.r, self.g, self.b, 255)
    }
}
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[derive(Copy, Debug, Clone, PartialEq, Default)]
pub struct Pos {
    pub x: f32,
    pub y: f32,
}
impl Pos {
    pub(crate) fn close(&self, rhs: Self) -> bool {
        self.x.floor() == rhs.x.floor() && self.y.floor() == rhs.y.floor()
    }
    pub fn new(x: f32, y: f32) -> Self {
        Self { x, y }
    }
    pub fn to_vec(&self) -> Vec2 {
        Vec2 {
            x: self.x as f64,
            y: self.y as f64,
        }
    }
    #[cfg(feature = "egui")]
    pub(crate) fn to_pos2(self) -> egui::Pos2 {
        egui::Pos2 {
            x: self.x,
            y: self.y,
        }
    }
    #[cfg(feature = "skia")]
    pub(crate) fn to_pos2(self) -> skia_safe::Point {
        skia_safe::Point::new(self.x, self.y)
    }
}
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[derive(Copy, Debug, Clone)]
pub enum Complex {
    Real(f64),
    Imag(f64),
    Complex(f64, f64),
}
impl Complex {
    pub fn to_options(self) -> (Option<f64>, Option<f64>) {
        match self {
            Complex::Real(y) => (Some(y), None),
            Complex::Imag(z) => (None, Some(z)),
            Complex::Complex(y, z) => (Some(y), Some(z)),
        }
    }
}
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[derive(Copy, Debug, Clone, PartialEq, Default)]
pub struct Vec2 {
    pub x: f64,
    pub y: f64,
}
impl Vec2 {
    pub fn norm(&self) -> f64 {
        self.y.hypot(self.x)
    }
    pub fn splat(v: f64) -> Self {
        Self { x: v, y: v }
    }
    pub fn new(x: f64, y: f64) -> Self {
        Self { x, y }
    }
    pub(crate) fn to_pos(self) -> Pos {
        Pos {
            x: self.x as f32,
            y: self.y as f32,
        }
    }
    pub fn to_tuple(self) -> (f32, f32) {
        (self.x as f32, self.y as f32)
    }
}
impl From<(f32, f32)> for Vec2 {
    fn from(value: (f32, f32)) -> Self {
        Self {
            x: value.0 as f64,
            y: value.1 as f64,
        }
    }
}
impl From<(f64, f64)> for Vec2 {
    fn from(value: (f64, f64)) -> Self {
        Self {
            x: value.0,
            y: value.1,
        }
    }
}
impl From<(f32, f32, f32)> for Vec3 {
    fn from(value: (f32, f32, f32)) -> Self {
        Self {
            x: value.0 as f64,
            y: value.1 as f64,
            z: value.2 as f64,
        }
    }
}
impl Sub for Vec2 {
    type Output = Vec2;
    fn sub(self, rhs: Self) -> Self::Output {
        Vec2::new(self.x - rhs.x, self.y - rhs.y)
    }
}
impl Sub for &Vec2 {
    type Output = Vec2;
    fn sub(self, rhs: Self) -> Self::Output {
        Vec2::new(self.x - rhs.x, self.y - rhs.y)
    }
}
impl Add for &Vec2 {
    type Output = Vec2;
    fn add(self, rhs: Self) -> Self::Output {
        Vec2::new(self.x + rhs.x, self.y + rhs.y)
    }
}
impl Add for Vec2 {
    type Output = Vec2;
    fn add(self, rhs: Self) -> Self::Output {
        Vec2::new(self.x + rhs.x, self.y + rhs.y)
    }
}
impl DivAssign<f64> for Vec2 {
    fn div_assign(&mut self, rhs: f64) {
        self.x /= rhs;
        self.y /= rhs;
    }
}
impl Sum for Vec2 {
    fn sum<I: Iterator<Item = Self>>(iter: I) -> Self {
        iter.fold(Vec2::splat(0.0), |a, b| a + b)
    }
}
impl MulAssign<f64> for Vec2 {
    fn mul_assign(&mut self, rhs: f64) {
        self.x *= rhs;
        self.y *= rhs;
    }
}
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[derive(Copy, Debug, Clone, Default)]
pub struct Vec3 {
    pub x: f64,
    pub y: f64,
    pub z: f64,
}
impl Vec3 {
    pub fn splat(v: f64) -> Self {
        Self { x: v, y: v, z: v }
    }
    pub fn new(x: f64, y: f64, z: f64) -> Self {
        Self { x, y, z }
    }
    pub fn to_tuple(self) -> (f32, f32, f32) {
        (self.x as f32, self.y as f32, self.z as f32)
    }
}
impl AddAssign<Vec2> for Vec2 {
    fn add_assign(&mut self, rhs: Vec2) {
        self.x += rhs.x;
        self.y += rhs.y;
    }
}
impl SubAssign<Vec2> for Vec2 {
    fn sub_assign(&mut self, rhs: Vec2) {
        self.x -= rhs.x;
        self.y -= rhs.y;
    }
}
impl MulAssign<f64> for Vec3 {
    fn mul_assign(&mut self, rhs: f64) {
        self.x *= rhs;
        self.y *= rhs;
        self.z *= rhs;
    }
}
impl DivAssign<f64> for Vec3 {
    fn div_assign(&mut self, rhs: f64) {
        self.x /= rhs;
        self.y /= rhs;
        self.z /= rhs;
    }
}
impl Div<Vec3> for Vec3 {
    type Output = Vec3;
    fn div(mut self, rhs: Vec3) -> Self::Output {
        self.x /= rhs.x;
        self.y /= rhs.y;
        self.z /= rhs.z;
        self
    }
}
impl DivAssign<Vec3> for Vec3 {
    fn div_assign(&mut self, rhs: Vec3) {
        self.x /= rhs.x;
        self.y /= rhs.y;
        self.z /= rhs.z;
    }
}
impl MulAssign<Vec3> for Vec3 {
    fn mul_assign(&mut self, rhs: Vec3) {
        self.x *= rhs.x;
        self.y *= rhs.y;
        self.z *= rhs.z;
    }
}
impl Mul<f64> for Vec3 {
    type Output = Vec3;
    fn mul(self, rhs: f64) -> Self::Output {
        Vec3::new(self.x * rhs, self.y * rhs, self.z * rhs)
    }
}
impl Sub for Vec3 {
    type Output = Vec3;
    fn sub(self, rhs: Self) -> Self::Output {
        Vec3::new(self.x - rhs.x, self.y - rhs.y, self.z - rhs.z)
    }
}
impl Add for Vec3 {
    type Output = Vec3;
    fn add(self, rhs: Self) -> Self::Output {
        Vec3::new(self.x + rhs.x, self.y + rhs.y, self.z + rhs.z)
    }
}
impl Add for Pos {
    type Output = Pos;
    fn add(self, rhs: Self) -> Self::Output {
        Pos::new(self.x + rhs.x, self.y + rhs.y)
    }
}
impl Sub for Pos {
    type Output = Pos;
    fn sub(self, rhs: Self) -> Self::Output {
        Pos::new(self.x - rhs.x, self.y - rhs.y)
    }
}
impl Mul<f32> for Pos {
    type Output = Pos;
    fn mul(self, rhs: f32) -> Self::Output {
        Pos::new(self.x * rhs, self.y * rhs)
    }
}
impl Div<f32> for Pos {
    type Output = Pos;
    fn div(self, rhs: f32) -> Self::Output {
        Pos::new(self.x / rhs, self.y / rhs)
    }
}
impl Div<f64> for Vec2 {
    type Output = Vec2;
    fn div(self, rhs: f64) -> Self::Output {
        Vec2::new(self.x / rhs, self.y / rhs)
    }
}
#[allow(dead_code)]
#[derive(Copy, Clone)]
pub(crate) enum Align {
    LeftBottom,
    LeftCenter,
    LeftTop,
    CenterBottom,
    CenterCenter,
    CenterTop,
    RightBottom,
    RightCenter,
    RightTop,
}
#[cfg(feature = "egui")]
impl From<Align> for egui::Align2 {
    fn from(val: Align) -> Self {
        match val {
            Align::LeftBottom => egui::Align2::LEFT_BOTTOM,
            Align::LeftCenter => egui::Align2::LEFT_CENTER,
            Align::LeftTop => egui::Align2::LEFT_TOP,
            Align::CenterBottom => egui::Align2::CENTER_BOTTOM,
            Align::CenterCenter => egui::Align2::CENTER_CENTER,
            Align::CenterTop => egui::Align2::CENTER_TOP,
            Align::RightBottom => egui::Align2::RIGHT_BOTTOM,
            Align::RightCenter => egui::Align2::RIGHT_CENTER,
            Align::RightTop => egui::Align2::RIGHT_TOP,
        }
    }
}
#[cfg(feature = "skia")]
impl From<Align> for skia_safe::utils::text_utils::Align {
    fn from(val: Align) -> Self {
        match val {
            Align::LeftBottom => skia_safe::utils::text_utils::Align::Left,
            Align::LeftCenter => skia_safe::utils::text_utils::Align::Left,
            Align::LeftTop => skia_safe::utils::text_utils::Align::Left,
            Align::CenterBottom => skia_safe::utils::text_utils::Align::Center,
            Align::CenterCenter => skia_safe::utils::text_utils::Align::Center,
            Align::CenterTop => skia_safe::utils::text_utils::Align::Center,
            Align::RightBottom => skia_safe::utils::text_utils::Align::Right,
            Align::RightCenter => skia_safe::utils::text_utils::Align::Right,
            Align::RightTop => skia_safe::utils::text_utils::Align::Right,
        }
    }
}
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[derive(Copy, Debug, Clone, PartialEq)]
pub enum Key {
    ArrowDown,
    ArrowLeft,
    ArrowRight,
    ArrowUp,
    Escape,
    Tab,
    Backspace,
    Enter,
    Space,
    Insert,
    Delete,
    Home,
    End,
    PageUp,
    PageDown,
    Copy,
    Cut,
    Paste,
    Colon,
    Comma,
    Backslash,
    Slash,
    Pipe,
    Questionmark,
    Exclamationmark,
    OpenBracket,
    CloseBracket,
    OpenCurlyBracket,
    CloseCurlyBracket,
    Backtick,
    Minus,
    Period,
    Plus,
    Equals,
    Semicolon,
    Quote,
    Num0,
    Num1,
    Num2,
    Num3,
    Num4,
    Num5,
    Num6,
    Num7,
    Num8,
    Num9,
    Caret,
    HashTag,
    A,
    B,
    C,
    D,
    E,
    F,
    G,
    H,
    I,
    J,
    K,
    L,
    M,
    N,
    O,
    P,
    Q,
    R,
    S,
    T,
    U,
    V,
    W,
    X,
    Y,
    Z,
    F1,
    F2,
    F3,
    F4,
    F5,
    F6,
    F7,
    F8,
    F9,
    F10,
    F11,
    F12,
    F13,
    F14,
    F15,
    F16,
    F17,
    F18,
    F19,
    F20,
    F21,
    F22,
    F23,
    F24,
    F25,
    F26,
    F27,
    F28,
    F29,
    F30,
    F31,
    F32,
    F33,
    F34,
    F35,
    OpenParentheses,
    CloseParentheses,
    And,
    Percent,
    Underscore,
    LessThen,
    GreaterThen,
    PlusMinus,
    DoubleQuote,
    Dollar,
    Cent,
    Tilde,
    Mult,
    Undefined,
}
#[cfg(feature = "egui")]
impl From<Key> for egui::Key {
    fn from(val: Key) -> Self {
        match val {
            Key::ArrowDown => egui::Key::ArrowDown,
            Key::ArrowLeft => egui::Key::ArrowLeft,
            Key::ArrowRight => egui::Key::ArrowRight,
            Key::ArrowUp => egui::Key::ArrowUp,
            Key::Escape => egui::Key::Escape,
            Key::Tab => egui::Key::Tab,
            Key::Backspace => egui::Key::Backspace,
            Key::Enter => egui::Key::Enter,
            Key::Space => egui::Key::Space,
            Key::Insert => egui::Key::Insert,
            Key::Delete => egui::Key::Delete,
            Key::Home => egui::Key::Home,
            Key::End => egui::Key::End,
            Key::PageUp => egui::Key::PageUp,
            Key::PageDown => egui::Key::PageDown,
            Key::Copy => egui::Key::Copy,
            Key::Cut => egui::Key::Cut,
            Key::Paste => egui::Key::Paste,
            Key::Colon => egui::Key::Colon,
            Key::Comma => egui::Key::Comma,
            Key::Backslash => egui::Key::Backslash,
            Key::Slash => egui::Key::Slash,
            Key::Pipe => egui::Key::Pipe,
            Key::Questionmark => egui::Key::Questionmark,
            Key::Exclamationmark => egui::Key::Exclamationmark,
            Key::OpenBracket => egui::Key::OpenBracket,
            Key::CloseBracket => egui::Key::CloseBracket,
            Key::OpenCurlyBracket => egui::Key::OpenCurlyBracket,
            Key::CloseCurlyBracket => egui::Key::CloseCurlyBracket,
            Key::Backtick => egui::Key::Backtick,
            Key::Minus => egui::Key::Minus,
            Key::Period => egui::Key::Period,
            Key::Plus => egui::Key::Plus,
            Key::Equals => egui::Key::Equals,
            Key::Semicolon => egui::Key::Semicolon,
            Key::Quote => egui::Key::Quote,
            Key::Num0 => egui::Key::Num0,
            Key::Num1 => egui::Key::Num1,
            Key::Num2 => egui::Key::Num2,
            Key::Num3 => egui::Key::Num3,
            Key::Num4 => egui::Key::Num4,
            Key::Num5 => egui::Key::Num5,
            Key::Num6 => egui::Key::Num6,
            Key::Num7 => egui::Key::Num7,
            Key::Num8 => egui::Key::Num8,
            Key::Num9 => egui::Key::Num9,
            Key::A => egui::Key::A,
            Key::B => egui::Key::B,
            Key::C => egui::Key::C,
            Key::D => egui::Key::D,
            Key::E => egui::Key::E,
            Key::F => egui::Key::F,
            Key::G => egui::Key::G,
            Key::H => egui::Key::H,
            Key::I => egui::Key::I,
            Key::J => egui::Key::J,
            Key::K => egui::Key::K,
            Key::L => egui::Key::L,
            Key::M => egui::Key::M,
            Key::N => egui::Key::N,
            Key::O => egui::Key::O,
            Key::P => egui::Key::P,
            Key::Q => egui::Key::Q,
            Key::R => egui::Key::R,
            Key::S => egui::Key::S,
            Key::T => egui::Key::T,
            Key::U => egui::Key::U,
            Key::V => egui::Key::V,
            Key::W => egui::Key::W,
            Key::X => egui::Key::X,
            Key::Y => egui::Key::Y,
            Key::Z => egui::Key::Z,
            Key::F1 => egui::Key::F1,
            Key::F2 => egui::Key::F2,
            Key::F3 => egui::Key::F3,
            Key::F4 => egui::Key::F4,
            Key::F5 => egui::Key::F5,
            Key::F6 => egui::Key::F6,
            Key::F7 => egui::Key::F7,
            Key::F8 => egui::Key::F8,
            Key::F9 => egui::Key::F9,
            Key::F10 => egui::Key::F10,
            Key::F11 => egui::Key::F11,
            Key::F12 => egui::Key::F12,
            Key::F13 => egui::Key::F13,
            Key::F14 => egui::Key::F14,
            Key::F15 => egui::Key::F15,
            Key::F16 => egui::Key::F16,
            Key::F17 => egui::Key::F17,
            Key::F18 => egui::Key::F18,
            Key::F19 => egui::Key::F19,
            Key::F20 => egui::Key::F20,
            Key::F21 => egui::Key::F21,
            Key::F22 => egui::Key::F22,
            Key::F23 => egui::Key::F23,
            Key::F24 => egui::Key::F24,
            Key::F25 => egui::Key::F25,
            Key::F26 => egui::Key::F26,
            Key::F27 => egui::Key::F27,
            Key::F28 => egui::Key::F28,
            Key::F29 => egui::Key::F29,
            Key::F30 => egui::Key::F30,
            Key::F31 => egui::Key::F31,
            Key::F32 => egui::Key::F32,
            Key::F33 => egui::Key::F33,
            Key::F34 => egui::Key::F34,
            Key::F35 => egui::Key::F35,
            _ => egui::Key::F35,
        }
    }
}
#[cfg(feature = "egui")]
impl From<&egui::Key> for Key {
    fn from(val: &egui::Key) -> Self {
        match val {
            egui::Key::ArrowDown => Key::ArrowDown,
            egui::Key::ArrowLeft => Key::ArrowLeft,
            egui::Key::ArrowRight => Key::ArrowRight,
            egui::Key::ArrowUp => Key::ArrowUp,
            egui::Key::Escape => Key::Escape,
            egui::Key::Tab => Key::Tab,
            egui::Key::Backspace => Key::Backspace,
            egui::Key::Enter => Key::Enter,
            egui::Key::Space => Key::Space,
            egui::Key::Insert => Key::Insert,
            egui::Key::Delete => Key::Delete,
            egui::Key::Home => Key::Home,
            egui::Key::End => Key::End,
            egui::Key::PageUp => Key::PageUp,
            egui::Key::PageDown => Key::PageDown,
            egui::Key::Copy => Key::Copy,
            egui::Key::Cut => Key::Cut,
            egui::Key::Paste => Key::Paste,
            egui::Key::Colon => Key::Colon,
            egui::Key::Comma => Key::Comma,
            egui::Key::Backslash => Key::Backslash,
            egui::Key::Slash => Key::Slash,
            egui::Key::Pipe => Key::Pipe,
            egui::Key::Questionmark => Key::Questionmark,
            egui::Key::Exclamationmark => Key::Exclamationmark,
            egui::Key::OpenBracket => Key::OpenBracket,
            egui::Key::CloseBracket => Key::CloseBracket,
            egui::Key::OpenCurlyBracket => Key::OpenCurlyBracket,
            egui::Key::CloseCurlyBracket => Key::CloseCurlyBracket,
            egui::Key::Backtick => Key::Backtick,
            egui::Key::Minus => Key::Minus,
            egui::Key::Period => Key::Period,
            egui::Key::Plus => Key::Plus,
            egui::Key::Equals => Key::Equals,
            egui::Key::Semicolon => Key::Semicolon,
            egui::Key::Quote => Key::Quote,
            egui::Key::Num0 => Key::Num0,
            egui::Key::Num1 => Key::Num1,
            egui::Key::Num2 => Key::Num2,
            egui::Key::Num3 => Key::Num3,
            egui::Key::Num4 => Key::Num4,
            egui::Key::Num5 => Key::Num5,
            egui::Key::Num6 => Key::Num6,
            egui::Key::Num7 => Key::Num7,
            egui::Key::Num8 => Key::Num8,
            egui::Key::Num9 => Key::Num9,
            egui::Key::A => Key::A,
            egui::Key::B => Key::B,
            egui::Key::C => Key::C,
            egui::Key::D => Key::D,
            egui::Key::E => Key::E,
            egui::Key::F => Key::F,
            egui::Key::G => Key::G,
            egui::Key::H => Key::H,
            egui::Key::I => Key::I,
            egui::Key::J => Key::J,
            egui::Key::K => Key::K,
            egui::Key::L => Key::L,
            egui::Key::M => Key::M,
            egui::Key::N => Key::N,
            egui::Key::O => Key::O,
            egui::Key::P => Key::P,
            egui::Key::Q => Key::Q,
            egui::Key::R => Key::R,
            egui::Key::S => Key::S,
            egui::Key::T => Key::T,
            egui::Key::U => Key::U,
            egui::Key::V => Key::V,
            egui::Key::W => Key::W,
            egui::Key::X => Key::X,
            egui::Key::Y => Key::Y,
            egui::Key::Z => Key::Z,
            egui::Key::F1 => Key::F1,
            egui::Key::F2 => Key::F2,
            egui::Key::F3 => Key::F3,
            egui::Key::F4 => Key::F4,
            egui::Key::F5 => Key::F5,
            egui::Key::F6 => Key::F6,
            egui::Key::F7 => Key::F7,
            egui::Key::F8 => Key::F8,
            egui::Key::F9 => Key::F9,
            egui::Key::F10 => Key::F10,
            egui::Key::F11 => Key::F11,
            egui::Key::F12 => Key::F12,
            egui::Key::F13 => Key::F13,
            egui::Key::F14 => Key::F14,
            egui::Key::F15 => Key::F15,
            egui::Key::F16 => Key::F16,
            egui::Key::F17 => Key::F17,
            egui::Key::F18 => Key::F18,
            egui::Key::F19 => Key::F19,
            egui::Key::F20 => Key::F20,
            egui::Key::F21 => Key::F21,
            egui::Key::F22 => Key::F22,
            egui::Key::F23 => Key::F23,
            egui::Key::F24 => Key::F24,
            egui::Key::F25 => Key::F25,
            egui::Key::F26 => Key::F26,
            egui::Key::F27 => Key::F27,
            egui::Key::F28 => Key::F28,
            egui::Key::F29 => Key::F29,
            egui::Key::F30 => Key::F30,
            egui::Key::F31 => Key::F31,
            egui::Key::F32 => Key::F32,
            egui::Key::F33 => Key::F33,
            egui::Key::F34 => Key::F34,
            egui::Key::F35 => Key::F35,
        }
    }
}
#[cfg(feature = "winit")]
impl From<Key> for winit::keyboard::Key {
    fn from(val: Key) -> Self {
        match val {
            Key::ArrowDown => winit::keyboard::Key::Named(winit::keyboard::NamedKey::ArrowDown),
            Key::ArrowLeft => winit::keyboard::Key::Named(winit::keyboard::NamedKey::ArrowLeft),
            Key::ArrowRight => winit::keyboard::Key::Named(winit::keyboard::NamedKey::ArrowRight),
            Key::ArrowUp => winit::keyboard::Key::Named(winit::keyboard::NamedKey::ArrowUp),
            Key::Escape => winit::keyboard::Key::Named(winit::keyboard::NamedKey::Escape),
            Key::Tab => winit::keyboard::Key::Named(winit::keyboard::NamedKey::Tab),
            Key::Backspace => winit::keyboard::Key::Named(winit::keyboard::NamedKey::Backspace),
            Key::Enter => winit::keyboard::Key::Named(winit::keyboard::NamedKey::Enter),
            Key::Space => winit::keyboard::Key::Named(winit::keyboard::NamedKey::Space),
            Key::Insert => winit::keyboard::Key::Named(winit::keyboard::NamedKey::Insert),
            Key::Delete => winit::keyboard::Key::Named(winit::keyboard::NamedKey::Delete),
            Key::Home => winit::keyboard::Key::Named(winit::keyboard::NamedKey::Home),
            Key::End => winit::keyboard::Key::Named(winit::keyboard::NamedKey::End),
            Key::PageUp => winit::keyboard::Key::Named(winit::keyboard::NamedKey::PageUp),
            Key::PageDown => winit::keyboard::Key::Named(winit::keyboard::NamedKey::PageDown),
            Key::Copy => winit::keyboard::Key::Named(winit::keyboard::NamedKey::Copy),
            Key::Cut => winit::keyboard::Key::Named(winit::keyboard::NamedKey::Cut),
            Key::Paste => winit::keyboard::Key::Named(winit::keyboard::NamedKey::Paste),
            Key::Colon => winit::keyboard::Key::Character(":".into()),
            Key::Comma => winit::keyboard::Key::Character(",".into()),
            Key::Backslash => winit::keyboard::Key::Character("\\".into()),
            Key::Slash => winit::keyboard::Key::Character("/".into()),
            Key::Pipe => winit::keyboard::Key::Character("|".into()),
            Key::Questionmark => winit::keyboard::Key::Character("?".into()),
            Key::Exclamationmark => winit::keyboard::Key::Character("!".into()),
            Key::OpenBracket => winit::keyboard::Key::Character("[".into()),
            Key::CloseBracket => winit::keyboard::Key::Character("]".into()),
            Key::OpenCurlyBracket => winit::keyboard::Key::Character("{".into()),
            Key::CloseCurlyBracket => winit::keyboard::Key::Character("}".into()),
            Key::Backtick => winit::keyboard::Key::Character("`".into()),
            Key::Minus => winit::keyboard::Key::Character("-".into()),
            Key::Period => winit::keyboard::Key::Character(".".into()),
            Key::Plus => winit::keyboard::Key::Character("+".into()),
            Key::Equals => winit::keyboard::Key::Character("=".into()),
            Key::Semicolon => winit::keyboard::Key::Character(";".into()),
            Key::Quote => winit::keyboard::Key::Character("\'".into()),
            Key::Num0 => winit::keyboard::Key::Character("0".into()),
            Key::Num1 => winit::keyboard::Key::Character("1".into()),
            Key::Num2 => winit::keyboard::Key::Character("2".into()),
            Key::Num3 => winit::keyboard::Key::Character("3".into()),
            Key::Num4 => winit::keyboard::Key::Character("4".into()),
            Key::Num5 => winit::keyboard::Key::Character("5".into()),
            Key::Num6 => winit::keyboard::Key::Character("6".into()),
            Key::Num7 => winit::keyboard::Key::Character("7".into()),
            Key::Num8 => winit::keyboard::Key::Character("8".into()),
            Key::Num9 => winit::keyboard::Key::Character("9".into()),
            Key::A => winit::keyboard::Key::Character("a".into()),
            Key::B => winit::keyboard::Key::Character("b".into()),
            Key::C => winit::keyboard::Key::Character("c".into()),
            Key::D => winit::keyboard::Key::Character("d".into()),
            Key::E => winit::keyboard::Key::Character("e".into()),
            Key::F => winit::keyboard::Key::Character("f".into()),
            Key::G => winit::keyboard::Key::Character("g".into()),
            Key::H => winit::keyboard::Key::Character("h".into()),
            Key::I => winit::keyboard::Key::Character("i".into()),
            Key::J => winit::keyboard::Key::Character("j".into()),
            Key::K => winit::keyboard::Key::Character("k".into()),
            Key::L => winit::keyboard::Key::Character("l".into()),
            Key::M => winit::keyboard::Key::Character("m".into()),
            Key::N => winit::keyboard::Key::Character("n".into()),
            Key::O => winit::keyboard::Key::Character("o".into()),
            Key::P => winit::keyboard::Key::Character("p".into()),
            Key::Q => winit::keyboard::Key::Character("q".into()),
            Key::R => winit::keyboard::Key::Character("r".into()),
            Key::S => winit::keyboard::Key::Character("s".into()),
            Key::T => winit::keyboard::Key::Character("t".into()),
            Key::U => winit::keyboard::Key::Character("u".into()),
            Key::V => winit::keyboard::Key::Character("v".into()),
            Key::W => winit::keyboard::Key::Character("w".into()),
            Key::X => winit::keyboard::Key::Character("x".into()),
            Key::Y => winit::keyboard::Key::Character("y".into()),
            Key::Z => winit::keyboard::Key::Character("z".into()),
            Key::Mult => winit::keyboard::Key::Character("*".into()),
            Key::Caret => winit::keyboard::Key::Character("^".into()),
            Key::HashTag => winit::keyboard::Key::Character("#".into()),
            Key::OpenParentheses => winit::keyboard::Key::Character("(".into()),
            Key::CloseParentheses => winit::keyboard::Key::Character(")".into()),
            Key::And => winit::keyboard::Key::Character("&".into()),
            Key::Percent => winit::keyboard::Key::Character("%".into()),
            Key::Underscore => winit::keyboard::Key::Character("_".into()),
            Key::LessThen => winit::keyboard::Key::Character("<".into()),
            Key::GreaterThen => winit::keyboard::Key::Character(">".into()),
            Key::PlusMinus => winit::keyboard::Key::Character("±".into()),
            Key::DoubleQuote => winit::keyboard::Key::Character("\"".into()),
            Key::Dollar => winit::keyboard::Key::Character("$".into()),
            Key::Cent => winit::keyboard::Key::Character("¢".into()),
            Key::Tilde => winit::keyboard::Key::Character("~".into()),
            Key::F1 => winit::keyboard::Key::Named(winit::keyboard::NamedKey::F1),
            Key::F2 => winit::keyboard::Key::Named(winit::keyboard::NamedKey::F2),
            Key::F3 => winit::keyboard::Key::Named(winit::keyboard::NamedKey::F3),
            Key::F4 => winit::keyboard::Key::Named(winit::keyboard::NamedKey::F4),
            Key::F5 => winit::keyboard::Key::Named(winit::keyboard::NamedKey::F5),
            Key::F6 => winit::keyboard::Key::Named(winit::keyboard::NamedKey::F6),
            Key::F7 => winit::keyboard::Key::Named(winit::keyboard::NamedKey::F7),
            Key::F8 => winit::keyboard::Key::Named(winit::keyboard::NamedKey::F8),
            Key::F9 => winit::keyboard::Key::Named(winit::keyboard::NamedKey::F9),
            Key::F10 => winit::keyboard::Key::Named(winit::keyboard::NamedKey::F10),
            Key::F11 => winit::keyboard::Key::Named(winit::keyboard::NamedKey::F11),
            Key::F12 => winit::keyboard::Key::Named(winit::keyboard::NamedKey::F12),
            Key::F13 => winit::keyboard::Key::Named(winit::keyboard::NamedKey::F13),
            Key::F14 => winit::keyboard::Key::Named(winit::keyboard::NamedKey::F14),
            Key::F15 => winit::keyboard::Key::Named(winit::keyboard::NamedKey::F15),
            Key::F16 => winit::keyboard::Key::Named(winit::keyboard::NamedKey::F16),
            Key::F17 => winit::keyboard::Key::Named(winit::keyboard::NamedKey::F17),
            Key::F18 => winit::keyboard::Key::Named(winit::keyboard::NamedKey::F18),
            Key::F19 => winit::keyboard::Key::Named(winit::keyboard::NamedKey::F19),
            Key::F20 => winit::keyboard::Key::Named(winit::keyboard::NamedKey::F20),
            Key::F21 => winit::keyboard::Key::Named(winit::keyboard::NamedKey::F21),
            Key::F22 => winit::keyboard::Key::Named(winit::keyboard::NamedKey::F22),
            Key::F23 => winit::keyboard::Key::Named(winit::keyboard::NamedKey::F23),
            Key::F24 => winit::keyboard::Key::Named(winit::keyboard::NamedKey::F24),
            Key::F25 => winit::keyboard::Key::Named(winit::keyboard::NamedKey::F25),
            Key::F26 => winit::keyboard::Key::Named(winit::keyboard::NamedKey::F26),
            Key::F27 => winit::keyboard::Key::Named(winit::keyboard::NamedKey::F27),
            Key::F28 => winit::keyboard::Key::Named(winit::keyboard::NamedKey::F28),
            Key::F29 => winit::keyboard::Key::Named(winit::keyboard::NamedKey::F29),
            Key::F30 => winit::keyboard::Key::Named(winit::keyboard::NamedKey::F30),
            Key::F31 => winit::keyboard::Key::Named(winit::keyboard::NamedKey::F31),
            Key::F32 => winit::keyboard::Key::Named(winit::keyboard::NamedKey::F32),
            Key::F33 => winit::keyboard::Key::Named(winit::keyboard::NamedKey::F33),
            Key::F34 => winit::keyboard::Key::Named(winit::keyboard::NamedKey::F34),
            Key::F35 => winit::keyboard::Key::Named(winit::keyboard::NamedKey::F35),
            Key::Undefined => winit::keyboard::Key::Named(winit::keyboard::NamedKey::F35),
        }
    }
}
#[cfg(feature = "winit")]
impl From<winit::keyboard::Key> for Key {
    fn from(val: winit::keyboard::Key) -> Self {
        match val {
            winit::keyboard::Key::Named(winit::keyboard::NamedKey::ArrowDown) => Key::ArrowDown,
            winit::keyboard::Key::Named(winit::keyboard::NamedKey::ArrowLeft) => Key::ArrowLeft,
            winit::keyboard::Key::Named(winit::keyboard::NamedKey::ArrowRight) => Key::ArrowRight,
            winit::keyboard::Key::Named(winit::keyboard::NamedKey::ArrowUp) => Key::ArrowUp,
            winit::keyboard::Key::Named(winit::keyboard::NamedKey::Escape) => Key::Escape,
            winit::keyboard::Key::Named(winit::keyboard::NamedKey::Tab) => Key::Tab,
            winit::keyboard::Key::Named(winit::keyboard::NamedKey::Backspace) => Key::Backspace,
            winit::keyboard::Key::Named(winit::keyboard::NamedKey::Enter) => Key::Enter,
            winit::keyboard::Key::Named(winit::keyboard::NamedKey::Space) => Key::Space,
            winit::keyboard::Key::Named(winit::keyboard::NamedKey::Insert) => Key::Insert,
            winit::keyboard::Key::Named(winit::keyboard::NamedKey::Delete) => Key::Delete,
            winit::keyboard::Key::Named(winit::keyboard::NamedKey::Home) => Key::Home,
            winit::keyboard::Key::Named(winit::keyboard::NamedKey::End) => Key::End,
            winit::keyboard::Key::Named(winit::keyboard::NamedKey::PageUp) => Key::PageUp,
            winit::keyboard::Key::Named(winit::keyboard::NamedKey::PageDown) => Key::PageDown,
            winit::keyboard::Key::Named(winit::keyboard::NamedKey::Copy) => Key::Copy,
            winit::keyboard::Key::Named(winit::keyboard::NamedKey::Cut) => Key::Cut,
            winit::keyboard::Key::Named(winit::keyboard::NamedKey::Paste) => Key::Paste,
            winit::keyboard::Key::Character(val) => {
                match val.to_string().to_ascii_lowercase().as_str() {
                    ":" => Key::Colon,
                    "," => Key::Comma,
                    "\\" => Key::Backslash,
                    "/" => Key::Slash,
                    "|" => Key::Pipe,
                    "?" => Key::Questionmark,
                    "!" => Key::Exclamationmark,
                    "[" => Key::OpenBracket,
                    "]" => Key::CloseBracket,
                    "{" => Key::OpenCurlyBracket,
                    "}" => Key::CloseCurlyBracket,
                    "`" => Key::Backtick,
                    "-" => Key::Minus,
                    "." => Key::Period,
                    "+" => Key::Plus,
                    "=" => Key::Equals,
                    ";" => Key::Semicolon,
                    "\'" => Key::Quote,
                    "0" => Key::Num0,
                    "1" => Key::Num1,
                    "2" => Key::Num2,
                    "3" => Key::Num3,
                    "4" => Key::Num4,
                    "5" => Key::Num5,
                    "6" => Key::Num6,
                    "7" => Key::Num7,
                    "8" => Key::Num8,
                    "9" => Key::Num9,
                    "a" => Key::A,
                    "b" => Key::B,
                    "c" => Key::C,
                    "d" => Key::D,
                    "e" => Key::E,
                    "f" => Key::F,
                    "g" => Key::G,
                    "h" => Key::H,
                    "i" => Key::I,
                    "j" => Key::J,
                    "k" => Key::K,
                    "l" => Key::L,
                    "m" => Key::M,
                    "n" => Key::N,
                    "o" => Key::O,
                    "p" => Key::P,
                    "q" => Key::Q,
                    "r" => Key::R,
                    "s" => Key::S,
                    "t" => Key::T,
                    "u" => Key::U,
                    "v" => Key::V,
                    "w" => Key::W,
                    "x" => Key::X,
                    "y" => Key::Y,
                    "z" => Key::Z,
                    "^" => Key::Caret,
                    "#" => Key::HashTag,
                    "(" => Key::OpenParentheses,
                    ")" => Key::CloseParentheses,
                    "&" => Key::And,
                    "%" => Key::Percent,
                    "_" => Key::Underscore,
                    "<" => Key::LessThen,
                    ">" => Key::GreaterThen,
                    "±" => Key::PlusMinus,
                    "\"" => Key::DoubleQuote,
                    "$" => Key::Dollar,
                    "¢" => Key::Cent,
                    "~" => Key::Tilde,
                    "*" => Key::Mult,
                    _ => Key::Undefined,
                }
            }
            winit::keyboard::Key::Named(winit::keyboard::NamedKey::F1) => Key::F1,
            winit::keyboard::Key::Named(winit::keyboard::NamedKey::F2) => Key::F2,
            winit::keyboard::Key::Named(winit::keyboard::NamedKey::F3) => Key::F3,
            winit::keyboard::Key::Named(winit::keyboard::NamedKey::F4) => Key::F4,
            winit::keyboard::Key::Named(winit::keyboard::NamedKey::F5) => Key::F5,
            winit::keyboard::Key::Named(winit::keyboard::NamedKey::F6) => Key::F6,
            winit::keyboard::Key::Named(winit::keyboard::NamedKey::F7) => Key::F7,
            winit::keyboard::Key::Named(winit::keyboard::NamedKey::F8) => Key::F8,
            winit::keyboard::Key::Named(winit::keyboard::NamedKey::F9) => Key::F9,
            winit::keyboard::Key::Named(winit::keyboard::NamedKey::F10) => Key::F10,
            winit::keyboard::Key::Named(winit::keyboard::NamedKey::F11) => Key::F11,
            winit::keyboard::Key::Named(winit::keyboard::NamedKey::F12) => Key::F12,
            winit::keyboard::Key::Named(winit::keyboard::NamedKey::F13) => Key::F13,
            winit::keyboard::Key::Named(winit::keyboard::NamedKey::F14) => Key::F14,
            winit::keyboard::Key::Named(winit::keyboard::NamedKey::F15) => Key::F15,
            winit::keyboard::Key::Named(winit::keyboard::NamedKey::F16) => Key::F16,
            winit::keyboard::Key::Named(winit::keyboard::NamedKey::F17) => Key::F17,
            winit::keyboard::Key::Named(winit::keyboard::NamedKey::F18) => Key::F18,
            winit::keyboard::Key::Named(winit::keyboard::NamedKey::F19) => Key::F19,
            winit::keyboard::Key::Named(winit::keyboard::NamedKey::F20) => Key::F20,
            winit::keyboard::Key::Named(winit::keyboard::NamedKey::F21) => Key::F21,
            winit::keyboard::Key::Named(winit::keyboard::NamedKey::F22) => Key::F22,
            winit::keyboard::Key::Named(winit::keyboard::NamedKey::F23) => Key::F23,
            winit::keyboard::Key::Named(winit::keyboard::NamedKey::F24) => Key::F24,
            winit::keyboard::Key::Named(winit::keyboard::NamedKey::F25) => Key::F25,
            winit::keyboard::Key::Named(winit::keyboard::NamedKey::F26) => Key::F26,
            winit::keyboard::Key::Named(winit::keyboard::NamedKey::F27) => Key::F27,
            winit::keyboard::Key::Named(winit::keyboard::NamedKey::F28) => Key::F28,
            winit::keyboard::Key::Named(winit::keyboard::NamedKey::F29) => Key::F29,
            winit::keyboard::Key::Named(winit::keyboard::NamedKey::F30) => Key::F30,
            winit::keyboard::Key::Named(winit::keyboard::NamedKey::F31) => Key::F31,
            winit::keyboard::Key::Named(winit::keyboard::NamedKey::F32) => Key::F32,
            winit::keyboard::Key::Named(winit::keyboard::NamedKey::F33) => Key::F33,
            winit::keyboard::Key::Named(winit::keyboard::NamedKey::F34) => Key::F34,
            winit::keyboard::Key::Named(winit::keyboard::NamedKey::F35) => Key::F35,
            _ => Key::Undefined,
        }
    }
}
pub enum NamedKey {
    ArrowDown,
    ArrowLeft,
    ArrowRight,
    ArrowUp,
    Escape,
    Tab,
    Backspace,
    Enter,
    Space,
    Insert,
    Delete,
    Home,
    End,
    PageUp,
    PageDown,
    Copy,
    Cut,
    Paste,
    F1,
    F2,
    F3,
    F4,
    F5,
    F6,
    F7,
    F8,
    F9,
    F10,
    F11,
    F12,
    F13,
    F14,
    F15,
    F16,
    F17,
    F18,
    F19,
    F20,
    F21,
    F22,
    F23,
    F24,
    F25,
    F26,
    F27,
    F28,
    F29,
    F30,
    F31,
    F32,
    F33,
    F34,
    F35,
}
pub enum KeyStr {
    Named(NamedKey),
    Character(char),
}
impl From<&Key> for KeyStr {
    fn from(key: &Key) -> Self {
        match key {
            Key::ArrowDown => KeyStr::Named(NamedKey::ArrowDown),
            Key::ArrowLeft => KeyStr::Named(NamedKey::ArrowLeft),
            Key::ArrowRight => KeyStr::Named(NamedKey::ArrowRight),
            Key::ArrowUp => KeyStr::Named(NamedKey::ArrowUp),
            Key::Escape => KeyStr::Named(NamedKey::Escape),
            Key::Tab => KeyStr::Named(NamedKey::Tab),
            Key::Backspace => KeyStr::Named(NamedKey::Backspace),
            Key::Enter => KeyStr::Named(NamedKey::Enter),
            Key::Space => KeyStr::Named(NamedKey::Space),
            Key::Insert => KeyStr::Named(NamedKey::Insert),
            Key::Delete => KeyStr::Named(NamedKey::Delete),
            Key::Home => KeyStr::Named(NamedKey::Home),
            Key::End => KeyStr::Named(NamedKey::End),
            Key::PageUp => KeyStr::Named(NamedKey::PageUp),
            Key::PageDown => KeyStr::Named(NamedKey::PageDown),
            Key::Copy => KeyStr::Named(NamedKey::Copy),
            Key::Cut => KeyStr::Named(NamedKey::Cut),
            Key::Paste => KeyStr::Named(NamedKey::Paste),
            Key::F1 => KeyStr::Named(NamedKey::F1),
            Key::F2 => KeyStr::Named(NamedKey::F2),
            Key::F3 => KeyStr::Named(NamedKey::F3),
            Key::F4 => KeyStr::Named(NamedKey::F4),
            Key::F5 => KeyStr::Named(NamedKey::F5),
            Key::F6 => KeyStr::Named(NamedKey::F6),
            Key::F7 => KeyStr::Named(NamedKey::F7),
            Key::F8 => KeyStr::Named(NamedKey::F8),
            Key::F9 => KeyStr::Named(NamedKey::F9),
            Key::F10 => KeyStr::Named(NamedKey::F10),
            Key::F11 => KeyStr::Named(NamedKey::F11),
            Key::F12 => KeyStr::Named(NamedKey::F12),
            Key::F13 => KeyStr::Named(NamedKey::F13),
            Key::F14 => KeyStr::Named(NamedKey::F14),
            Key::F15 => KeyStr::Named(NamedKey::F15),
            Key::F16 => KeyStr::Named(NamedKey::F16),
            Key::F17 => KeyStr::Named(NamedKey::F17),
            Key::F18 => KeyStr::Named(NamedKey::F18),
            Key::F19 => KeyStr::Named(NamedKey::F19),
            Key::F20 => KeyStr::Named(NamedKey::F20),
            Key::F21 => KeyStr::Named(NamedKey::F21),
            Key::F22 => KeyStr::Named(NamedKey::F22),
            Key::F23 => KeyStr::Named(NamedKey::F23),
            Key::F24 => KeyStr::Named(NamedKey::F24),
            Key::F25 => KeyStr::Named(NamedKey::F25),
            Key::F26 => KeyStr::Named(NamedKey::F26),
            Key::F27 => KeyStr::Named(NamedKey::F27),
            Key::F28 => KeyStr::Named(NamedKey::F28),
            Key::F29 => KeyStr::Named(NamedKey::F29),
            Key::F30 => KeyStr::Named(NamedKey::F30),
            Key::F31 => KeyStr::Named(NamedKey::F31),
            Key::F32 => KeyStr::Named(NamedKey::F32),
            Key::F33 => KeyStr::Named(NamedKey::F33),
            Key::F34 => KeyStr::Named(NamedKey::F34),
            Key::F35 => KeyStr::Named(NamedKey::F35),
            Key::Colon => KeyStr::Character(':'),
            Key::Comma => KeyStr::Character(','),
            Key::Backslash => KeyStr::Character('\\'),
            Key::Slash => KeyStr::Character('/'),
            Key::Pipe => KeyStr::Character('|'),
            Key::Questionmark => KeyStr::Character('?'),
            Key::Exclamationmark => KeyStr::Character('!'),
            Key::OpenBracket => KeyStr::Character('['),
            Key::CloseBracket => KeyStr::Character(']'),
            Key::OpenCurlyBracket => KeyStr::Character('{'),
            Key::CloseCurlyBracket => KeyStr::Character('}'),
            Key::Backtick => KeyStr::Character('`'),
            Key::Minus => KeyStr::Character('-'),
            Key::Period => KeyStr::Character('.'),
            Key::Plus => KeyStr::Character('+'),
            Key::Equals => KeyStr::Character('='),
            Key::Semicolon => KeyStr::Character(';'),
            Key::Quote => KeyStr::Character('\''),
            Key::Num0 => KeyStr::Character('0'),
            Key::Num1 => KeyStr::Character('1'),
            Key::Num2 => KeyStr::Character('2'),
            Key::Num3 => KeyStr::Character('3'),
            Key::Num4 => KeyStr::Character('4'),
            Key::Num5 => KeyStr::Character('5'),
            Key::Num6 => KeyStr::Character('6'),
            Key::Num7 => KeyStr::Character('7'),
            Key::Num8 => KeyStr::Character('8'),
            Key::Num9 => KeyStr::Character('9'),
            Key::A => KeyStr::Character('a'),
            Key::B => KeyStr::Character('b'),
            Key::C => KeyStr::Character('c'),
            Key::D => KeyStr::Character('d'),
            Key::E => KeyStr::Character('e'),
            Key::F => KeyStr::Character('f'),
            Key::G => KeyStr::Character('g'),
            Key::H => KeyStr::Character('h'),
            Key::I => KeyStr::Character('i'),
            Key::J => KeyStr::Character('j'),
            Key::K => KeyStr::Character('k'),
            Key::L => KeyStr::Character('l'),
            Key::M => KeyStr::Character('m'),
            Key::N => KeyStr::Character('n'),
            Key::O => KeyStr::Character('o'),
            Key::P => KeyStr::Character('p'),
            Key::Q => KeyStr::Character('q'),
            Key::R => KeyStr::Character('r'),
            Key::S => KeyStr::Character('s'),
            Key::T => KeyStr::Character('t'),
            Key::U => KeyStr::Character('u'),
            Key::V => KeyStr::Character('v'),
            Key::W => KeyStr::Character('w'),
            Key::X => KeyStr::Character('x'),
            Key::Y => KeyStr::Character('y'),
            Key::Z => KeyStr::Character('z'),
            Key::Mult => KeyStr::Character('*'),
            Key::Caret => KeyStr::Character('^'),
            Key::HashTag => KeyStr::Character('#'),
            Key::OpenParentheses => KeyStr::Character('('),
            Key::CloseParentheses => KeyStr::Character(')'),
            Key::And => KeyStr::Character('&'),
            Key::Percent => KeyStr::Character('%'),
            Key::Underscore => KeyStr::Character('_'),
            Key::LessThen => KeyStr::Character('<'),
            Key::GreaterThen => KeyStr::Character('>'),
            Key::PlusMinus => KeyStr::Character('±'),
            Key::DoubleQuote => KeyStr::Character('\''),
            Key::Dollar => KeyStr::Character('$'),
            Key::Cent => KeyStr::Character('¢'),
            Key::Tilde => KeyStr::Character('~'),
            Key::Undefined => KeyStr::Named(NamedKey::F35),
        }
    }
}