more cleanup

This commit is contained in:
Simon Gardling 2022-06-01 02:26:21 -04:00
parent 5c5c4d09fb
commit 4cdd764956
3 changed files with 57 additions and 11 deletions

View File

@ -20,7 +20,9 @@ include!(concat!(
"/src/unicode_helper.rs"
));
fn font_stripper(from: &str, out: &str, unicodes: Vec<String>) -> Result<Vec<u8>, String> {
fn font_stripper(from: &str, out: &str, unicodes: Vec<char>) -> Result<Vec<u8>, String> {
let unicodes: Vec<String> = unicodes.iter().map(|c| to_unicode_hash(*c)).collect();
let new_path = [&env::var("OUT_DIR").unwrap(), out].concat();
let unicodes_formatted = unicodes
.iter()
@ -70,15 +72,54 @@ fn main() {
main_chars.append(&mut vec!['π', '"']);
let processed_normal: Vec<String> = main_chars.iter().map(|a| to_unicode_hash(*a)).collect();
{
let filtered_chars: Vec<char> = main_chars
.iter()
.filter(|c| !c.is_alphanumeric())
.cloned()
.collect();
let chars_array = format!(
"const VALID_EXTRA_CHARS: [char; {}] = {};",
filtered_chars.len(),
[
"[",
&filtered_chars
.iter()
.map(|c| format!("'{}'", c.escape_unicode()))
.enumerate()
.map(|(i, x)| {
// Add comma and space if needed
match filtered_chars.len() > i + 1 {
true => x + ", ",
false => x,
}
})
.collect::<Vec<String>>()
.concat(),
"]",
]
.concat()
);
let path = Path::new(&env::var("OUT_DIR").unwrap()).join("valid_chars.rs");
let mut file = BufWriter::new(File::create(&path).expect("Could not save compressed_data"));
write!(&mut file, "{}", chars_array).expect("unable to write chars_array");
// file.write_all(data_compressed.as_slice())
// .expect("Failed to save compressed data");
}
let fonts = FontDefinitions {
font_data: BTreeMap::from([
(
"Ubuntu-Light".to_owned(),
FontData::from_owned(
font_stripper("Ubuntu-Light.ttf", "ubuntu-light.ttf", processed_normal)
.unwrap(),
font_stripper(
"Ubuntu-Light.ttf",
"ubuntu-light.ttf",
[main_chars, vec!['∫']].concat(),
)
.unwrap(),
),
),
(
@ -87,7 +128,7 @@ fn main() {
font_stripper(
"NotoEmoji-Regular.ttf",
"noto-emoji.ttf",
vec!["1F31E".to_owned(), "1F319".to_owned(), "2716".to_owned()],
vec!['🌞', '🌙', '✖'],
)
.unwrap(),
),
@ -95,12 +136,7 @@ fn main() {
(
"emoji-icon-font".to_owned(),
FontData::from_owned(
font_stripper(
"emoji-icon-font.ttf",
"emoji-icon.ttf",
vec!["2699".to_owned()],
)
.unwrap(),
font_stripper("emoji-icon-font.ttf", "emoji-icon.ttf", vec!['⚙']).unwrap(),
)
.tweak(FontTweak {
scale: 0.8,

View File

@ -115,6 +115,12 @@ impl FunctionManager {
}),
);
// Only keep valid chars
new_string = new_string
.chars()
.filter(|c| crate::misc::is_valid_char(c))
.collect::<String>();
// If not fully open, return here as buttons cannot yet be displayed, therefore the user is inable to mark it for deletion
if ui.ctx().animate_bool(*te_id, re.has_focus()) == 1.0 {
function.autocomplete.update_string(&new_string);

View File

@ -182,3 +182,7 @@ pub fn random_u64() -> Result<u64, getrandom::Error> {
// Merge buffer into u64
Ok(u64::from_be_bytes(buf))
}
include!(concat!(env!("OUT_DIR"), "/valid_chars.rs"));
pub fn is_valid_char(c: &char) -> bool { c.is_alphanumeric() | VALID_EXTRA_CHARS.contains(c) }