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}; use std::fmt::{Display, self};
pub struct Key { pub enum Key {
pub latin: char, Oyayubi {
pub normal: char, latin: char,
pub shift: char, normal: char,
pub alt_shift: Option<char>, shift: char,
alt_shift: Option<char>,
}
} }
impl Display for Key { impl Display for Key {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", self.latin) use Key::*;
} write!(f, "{}", match self {
} Oyayubi { latin, .. } => latin,
})
impl Key {
const fn new(latin: char, normal: char, shift: char, alt_shift: Option<char>) -> Self {
Self {
latin,
normal,
shift,
alt_shift,
}
} }
} }

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

@ -6,17 +6,20 @@
</defs> </defs>
{% for (key, (x, y)) in positions %} {% 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 }}"> <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" /> {% match key %}
{% let dy = "0.125em" %} {% when crate::key::Key::Oyayubi with { latin, normal, shift, alt_shift } %}
{% let font_size = "0.45cm" %} <rect width="{{ box_size }}" height="{{ box_size }}" fill="none" stroke="#cccccc" stroke-width="1pt" rx="2mm" />
{% let latin_font_size = "0.4cm" %} {% let dy = "0.125em" %}
{% let alt_shift_font_size = "0.325cm" %} {% let font_size = "0.45cm" %}
<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> {% let latin_font_size = "0.4cm" %}
<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> {% let alt_shift_font_size = "0.325cm" %}
<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> <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>
{% if let Some(alt_shift) = key.alt_shift %} <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 / 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> <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>
{% endif %} {% 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> </g>
{% endfor %} {% endfor %}
</svg> </svg>

Before

Width:  |  Height:  |  Size: 1.7 KiB

After

Width:  |  Height:  |  Size: 1.9 KiB

Loading…
Cancel
Save