AIT/src/controller/view_utils/input_utils.rs

38 lines
896 B
Rust
Raw Normal View History

2024-03-10 11:54:32 +03:00
use gtk4 as gtk;
use bitvec::{order::Lsb0, view::AsBits};
use gtk::{prelude::*, *};
use std::ops::Deref;
2024-03-10 11:54:32 +03:00
const ASCII_ZERO_CHAR_POSITION: u8 = 48;
2024-08-09 23:39:11 +03:00
pub fn processing_input(input: impl Into<String>) -> String {
2024-03-10 11:54:32 +03:00
input
2024-08-09 23:39:11 +03:00
.into()
2024-03-10 11:54:32 +03:00
.split_ascii_whitespace()
.filter(|&x| !x.is_empty())
.fold(String::new(), |c: String, n: &str| c + n)
2024-03-10 11:54:32 +03:00
}
pub fn from_vec_bits_to_string(raw_data: &[u8]) -> String {
raw_data
.iter()
.map(|bit| -> char { (bit + ASCII_ZERO_CHAR_POSITION).into() })
.collect()
2024-03-10 11:54:32 +03:00
}
2024-08-09 23:39:11 +03:00
pub fn from_string_to_vec_bits(raw_data: impl Into<String>) -> Vec<u8> {
2024-03-10 11:54:32 +03:00
raw_data
2024-08-09 23:39:11 +03:00
.into()
2024-03-10 11:54:32 +03:00
.as_bits::<Lsb0>()
.iter()
.step_by(8)
.map(|x| *x.deref() as u8)
.collect()
}
pub fn clearing(output: &TextView, input: &TextView) {
input.buffer().set_text("");
output.buffer().set_text("");
}