feat: show my cursor (#12745)

Signed-off-by: fufesou <linlong1266@gmail.com>
This commit is contained in:
fufesou
2025-08-28 15:20:01 +08:00
committed by GitHub
parent ac70f380a6
commit d0e9c6dc57
62 changed files with 1276 additions and 27 deletions

View File

@@ -2040,6 +2040,22 @@ pub async fn get_ipv6_socket() -> Option<(Arc<UdpSocket>, bytes::Bytes)> {
None
}
// The color is the same to `str2color()` in flutter.
pub fn str2color(s: &str, alpha: u8) -> u32 {
let bytes = s.as_bytes();
// dart code `160 << 16 + 114 << 8 + 91` results `0`.
let mut hash: u32 = 0;
for &byte in bytes {
let code = byte as u32;
hash = code.wrapping_add((hash << 5).wrapping_sub(hash));
}
hash = hash % 16777216;
let rgb = hash & 0xFF7FFF;
(alpha as u32) << 24 | rgb
}
#[cfg(test)]
mod tests {
use super::*;