Skip to main content

KeyGeometry

Struct KeyGeometry 

Source
pub struct KeyGeometry { /* private fields */ }
Expand description

宿主注册的一份字母键几何,按键宽、键高的中位数归一。id 是宿主分配的非零代次,布局一变(旋转、分离、单手、键高、微软 ; 显隐)就换一个。

Implementations§

Source§

impl KeyGeometry

Source

pub fn new( id: u32, keys: &[KeyRect; 26], semicolon: Option<KeyRect>, duplicates: &[(u8, KeyRect)], ) -> Result<Self, KeyGeometryError>

keys 是 a 到 z,semicolon 是微软双拼显示的 ; 键,duplicates 是分离键盘里重复的字母键。数值都要有限、宽高为正,归一后的键心都在 COORDINATE_LIMIT 之内,否则整份拒绝。

Source

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 个字母键或数值不合格时整份拒绝。

Source

pub fn id(&self) -> u32

Source

pub fn fingerprint(&self) -> u64

几何内容(归一单位和每个键心)的指纹。宿主可能用同一个代次下发内容不同的几何,方案层把它当新几何处理;按触点计价的缓存键要带上它,才不会把旧布局算出的答案交给新布局。内容相同(==)的几何指纹相同。

Source

pub fn has_semicolon(&self) -> bool

有没有 ; 键(宿主只在微软双拼下显示它)。

Source

pub fn touch(&self, key: u8, x: f32, y: f32) -> Option<KeyTouch>

宿主坐标里的按下点 (x, y) 落在 key 上的触点:取 key 离它最近的那个实例,偏移量化到 1/20 键并钳到 ±1.5 键。key 不在几何里(没有 ; 键时的 ;、不是字母)、坐标不是有限数或归一后超出 COORDINATE_LIMIT 时为 None,这一键按没有触点处理。大写字母按小写算。

Source

pub fn penalty( &self, pressed: u8, touch: KeyTouch, candidate: u8, tuning: &TouchTuning, ) -> Option<f64>

按在 pressed 上、落点是 touch 时,把这一键换成 candidate 的罚分。候选键取离落点最近的实例,所以分离键盘上的重复键各自就近。pressed 或 candidate 不在几何里时为 None。

Source

pub fn adjacent(&self, pressed: u8, touch: KeyTouch, candidate: u8) -> bool

平面表的邻键 candidate 在这份几何上是否真的挨着被按的那个实例。分离键盘上 T 和 Y 分在两半,平面表的这条邻接就不成立。

Trait Implementations§

Source§

impl Clone for KeyGeometry

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for KeyGeometry

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl PartialEq for KeyGeometry

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for KeyGeometry

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.