aboutsummaryrefslogtreecommitdiff
path: root/src/layout.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/layout.rs')
-rw-r--r--src/layout.rs29
1 files changed, 9 insertions, 20 deletions
diff --git a/src/layout.rs b/src/layout.rs
index 2650a51..bc476c8 100644
--- a/src/layout.rs
+++ b/src/layout.rs
@@ -22,7 +22,7 @@ impl Prelayout {
let mut standard_columns = pl.standard_columns.clone();
let mut index_columns = pl.index_columns.clone();
- let mut count = rng.gen_range(1..=NUM_KEYS - 1);
+ let mut count = rng.gen_range(1..NUM_KEYS);
while count > 0 {
let source_index: bool = rng.gen();
let target_index: bool = rng.gen();
@@ -120,8 +120,6 @@ impl Prelayout {
#[derive(Copy, Clone)]
pub struct Layout {
keys: [char; NUM_KEYS],
- // index in KEY_CHAR -> index in layout
- translate_index: [usize; NUM_KEYS],
}
impl Layout {
@@ -134,31 +132,22 @@ impl Layout {
Layout::char_array_to_layout(pl.to_char_array())
}
- fn char_array_to_layout(layout: [char; NUM_KEYS]) -> Layout {
- let mut translate_index: [usize; NUM_KEYS] = [0; NUM_KEYS];
-
- for (i, seek) in KEY_CHARS.iter().enumerate() {
- for (j, found) in layout.iter().enumerate() {
- if seek == found {
- translate_index[i] = j;
- }
- }
+ pub fn get_index(&self, c: char) -> usize {
+ let mut found_key = 0;
+ while self.keys[found_key] != c {
+ found_key += 1
}
+ found_key
+ }
- return Layout {
- keys: layout,
- translate_index,
- };
+ fn char_array_to_layout(keys: [char; NUM_KEYS]) -> Layout {
+ return Layout { keys };
}
pub fn get_key(&self, index: usize) -> char {
self.keys[index]
}
- pub fn translate_index(&self, i: usize) -> usize {
- self.translate_index[i]
- }
-
pub fn from_verbose(inp: &str) -> Option<Layout> {
let mut layout: [char; NUM_KEYS] = ['x'; NUM_KEYS];