pub struct KeyGeometry { /* private fields */ }Expand description
宿主注册的一份字母键几何,按键宽、键高的中位数归一。id 是宿主分配的非零代次,布局一变(旋转、分离、单手、键高、微软 ; 显隐)就换一个。
Implementations§
Source§impl KeyGeometry
impl KeyGeometry
Sourcepub fn new(
id: u32,
keys: &[KeyRect; 26],
semicolon: Option<KeyRect>,
duplicates: &[(u8, KeyRect)],
) -> Result<Self, KeyGeometryError>
pub fn new( id: u32, keys: &[KeyRect; 26], semicolon: Option<KeyRect>, duplicates: &[(u8, KeyRect)], ) -> Result<Self, KeyGeometryError>
keys 是 a 到 z,semicolon 是微软双拼显示的 ; 键,duplicates 是分离键盘里重复的字母键。数值都要有限、宽高为正,归一后的键心都在 COORDINATE_LIMIT 之内,否则整份拒绝。
Sourcepub fn from_json(bytes: &[u8]) -> Result<Option<Self>, String>
pub fn from_json(bytes: &[u8]) -> Result<Option<Self>, String>
宿主下发的 JSON:{"id":u32,"keys":[[cx,cy,w,h] × 26,按 a..z],"semicolon":[cx,cy,w,h]|null,"duplicates":[["g",cx,cy,w,h],…]},形状沿用滑行请求。空串或 id 为 0 表示清除,返回 Ok(None);多出的字段、不是 26 个字母键或数值不合格时整份拒绝。
pub fn id(&self) -> u32
Sourcepub fn fingerprint(&self) -> u64
pub fn fingerprint(&self) -> u64
几何内容(归一单位和每个键心)的指纹。宿主可能用同一个代次下发内容不同的几何,方案层把它当新几何处理;按触点计价的缓存键要带上它,才不会把旧布局算出的答案交给新布局。内容相同(==)的几何指纹相同。
Sourcepub fn has_semicolon(&self) -> bool
pub fn has_semicolon(&self) -> bool
有没有 ; 键(宿主只在微软双拼下显示它)。
Sourcepub fn touch(&self, key: u8, x: f32, y: f32) -> Option<KeyTouch>
pub fn touch(&self, key: u8, x: f32, y: f32) -> Option<KeyTouch>
宿主坐标里的按下点 (x, y) 落在 key 上的触点:取 key 离它最近的那个实例,偏移量化到 1/20 键并钳到 ±1.5 键。key 不在几何里(没有 ; 键时的 ;、不是字母)、坐标不是有限数或归一后超出 COORDINATE_LIMIT 时为 None,这一键按没有触点处理。大写字母按小写算。
Trait Implementations§
Source§impl Clone for KeyGeometry
impl Clone for KeyGeometry
Source§impl Debug for KeyGeometry
impl Debug for KeyGeometry
Source§impl PartialEq for KeyGeometry
impl PartialEq for KeyGeometry
impl StructuralPartialEq for KeyGeometry
Auto Trait Implementations§
impl Freeze for KeyGeometry
impl RefUnwindSafe for KeyGeometry
impl Send for KeyGeometry
impl Sync for KeyGeometry
impl Unpin for KeyGeometry
impl UnsafeUnpin for KeyGeometry
impl UnwindSafe for KeyGeometry
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more