Make Key an enum

main
Elnu 1 year ago
parent 20e0b8dd08
commit f5e043c981

@ -3,26 +3,20 @@ pub use oyayubi::OYAYUBI;
use std::fmt::{Display, self};
pub struct Key {
pub latin: char,
pub normal: char,
pub shift: char,
pub alt_shift: Option<char>,
pub enum Key {
Oyayubi {
latin: char,
normal: char,
shift: char,
alt_shift: Option<char>,
}
}
impl Display for Key {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", self.latin)
}
}
impl Key {
const fn new(latin: char, normal: char, shift: char, alt_shift: Option<char>) -> Self {
Self {
latin,
normal,
shift,
alt_shift,
}
use Key::*;
write!(f, "{}", match self {
Oyayubi { latin, .. } => latin,
})
}
}

@ -1,34 +1,43 @@
use super::Key;
const fn k(latin: char, normal: char, shift: char, alt_shift: Option<char>) -> Key {
Key::Oyayubi {
latin,
normal,
shift,
alt_shift,
}
}
pub const OYAYUBI: [Key; 30] = [
Key::new('Q', '。', 'ぁ', None),
Key::new('W', 'か', 'え', None),
Key::new('E', 'た', 'り', None),
Key::new('R', 'こ', 'ゃ', None),
Key::new('T', 'さ', 'れ', None),
Key::new('Y', 'ら', 'よ', Some('ぱ')),
Key::new('U', 'ち', 'に', None),
Key::new('I', 'く', 'る', None),
Key::new('O', 'つ', 'ま', None),
Key::new('P', '', 'ぇ', Some('ぴ')),
Key::new('A', 'う', 'を', None),
Key::new('S', 'し', 'あ', None),
Key::new('D', 'て', 'な', None),
Key::new('F', 'け', 'ゅ', None),
Key::new('G', 'せ', 'も', None),
Key::new('H', 'は', 'み', None),
Key::new('J', 'と', 'お', None),
Key::new('K', 'き', 'の', None),
Key::new('L', 'い', 'ょ', Some('ぽ')),
Key::new(';', 'ん', 'っ', None), // Missing +
Key::new('Z', '', 'ぅ', None),
Key::new('X', 'ひ', 'ー', None),
Key::new('C', 'す', 'ろ', None),
Key::new('V', 'ふ', 'や', None),
Key::new('B', 'へ', 'ぃ', None),
Key::new('N', 'め', 'ぬ', Some('ぷ')),
Key::new('M', 'そ', 'ゆ', None),
Key::new(',', 'ね', 'む', Some('ぺ')), // Missing <
Key::new('.', 'ほ', 'わ', None), // Missing >
Key::new('?', '・', 'ぉ', Some('ゎ')) // Missing /
k('Q', '。', 'ぁ', None),
k('W', 'か', 'え', None),
k('E', 'た', 'り', None),
k('R', 'こ', 'ゃ', None),
k('T', 'さ', 'れ', None),
k('Y', 'ら', 'よ', Some('ぱ')),
k('U', 'ち', 'に', None),
k('I', 'く', 'る', None),
k('O', 'つ', 'ま', None),
k('P', '', 'ぇ', Some('ぴ')),
k('A', 'う', 'を', None),
k('S', 'し', 'あ', None),
k('D', 'て', 'な', None),
k('F', 'け', 'ゅ', None),
k('G', 'せ', 'も', None),
k('H', 'は', 'み', None),
k('J', 'と', 'お', None),
k('K', 'き', 'の', None),
k('L', 'い', 'ょ', Some('ぽ')),
k(';', 'ん', 'っ', None), // Missing +
k('Z', '', 'ぅ', None),
k('X', 'ひ', 'ー', None),
k('C', 'す', 'ろ', None),
k('V', 'ふ', 'や', None),
k('B', 'へ', 'ぃ', None),
k('N', 'め', 'ぬ', Some('ぷ')),
k('M', 'そ', 'ゆ', None),
k(',', 'ね', 'む', Some('ぺ')), // Missing <
k('.', 'ほ', 'わ', None), // Missing >
k('?', '・', 'ぉ', Some('ゎ')) // Missing /
];

@ -6,17 +6,20 @@
</defs>
{% for (key, (x, y)) in positions %}
<g x="{{ x }}" y="{{ y }}" transform="translate({{ x.to_user_units() }},{{ y.to_user_units() }})" width="{{ box_size }}" height="{{ box_size }}">
<rect width="{{ box_size }}" height="{{ box_size }}" fill="none" stroke="#cccccc" stroke-width="1pt" rx="2mm" />
{% let dy = "0.125em" %}
{% let font_size = "0.45cm" %}
{% let latin_font_size = "0.4cm" %}
{% let alt_shift_font_size = "0.325cm" %}
<text x="{{ box_size * 0.25 }}" y="{{ box_size * 0.25 }}" dominant-baseline="middle" text-anchor="middle" style="font-family: 'M PLUS Rounded 1c'" font-size="{{ latin_font_size }}" dy="{{ dy }}">{{ key.latin }}</text>
<text x="{{ box_size * 0.75 }}" y="{{ box_size * 0.25 }}" dominant-baseline="middle" text-anchor="middle" style="font-family: 'M PLUS Rounded 1c'" font-size="{{ font_size }}" dy="{{ dy }}">{{ key.shift }}</text>
<text x="{{ box_size * 0.75 }}" y="{{ box_size * 0.75 }}" dominant-baseline="middle" text-anchor="middle" style="font-family: 'M PLUS Rounded 1c'" font-size="{{ font_size }}" dy="{{ dy }}">{{ key.normal }}</text>
{% if let Some(alt_shift) = key.alt_shift %}
<text x="{{ box_size / 2.0 }}" y="{{ box_size / 2.0 }}" dominant-baseline="middle" text-anchor="middle" style="font-family: 'M PLUS Rounded 1c'" font-size="{{ alt_shift_font_size }}" dy="{{ dy }}">{{ alt_shift }}</text>
{% endif %}
{% match key %}
{% when crate::key::Key::Oyayubi with { latin, normal, shift, alt_shift } %}
<rect width="{{ box_size }}" height="{{ box_size }}" fill="none" stroke="#cccccc" stroke-width="1pt" rx="2mm" />
{% let dy = "0.125em" %}
{% let font_size = "0.45cm" %}
{% let latin_font_size = "0.4cm" %}
{% let alt_shift_font_size = "0.325cm" %}
<text x="{{ box_size * 0.25 }}" y="{{ box_size * 0.25 }}" dominant-baseline="middle" text-anchor="middle" style="font-family: 'M PLUS Rounded 1c'" font-size="{{ latin_font_size }}" dy="{{ dy }}">{{ latin }}</text>
<text x="{{ box_size * 0.75 }}" y="{{ box_size * 0.25 }}" dominant-baseline="middle" text-anchor="middle" style="font-family: 'M PLUS Rounded 1c'" font-size="{{ font_size }}" dy="{{ dy }}">{{ shift }}</text>
<text x="{{ box_size * 0.75 }}" y="{{ box_size * 0.75 }}" dominant-baseline="middle" text-anchor="middle" style="font-family: 'M PLUS Rounded 1c'" font-size="{{ font_size }}" dy="{{ dy }}">{{ normal }}</text>
{% if let Some(alt_shift) = alt_shift %}
<text x="{{ box_size / 2.0 }}" y="{{ box_size / 2.0 }}" dominant-baseline="middle" text-anchor="middle" style="font-family: 'M PLUS Rounded 1c'" font-size="{{ alt_shift_font_size }}" dy="{{ dy }}">{{ alt_shift }}</text>
{% endif %}
{% endmatch %}
</g>
{% endfor %}
</svg>

Before

Width:  |  Height:  |  Size: 1.7 KiB

After

Width:  |  Height:  |  Size: 1.9 KiB

Loading…
Cancel
Save