presses: Move press handling to Rust

This fixes some rendering things which would happen with multiple state-sharing buttons. It also removes some interfaces exposing rows, views, layouts, and buttons, bringing the code closer to removing them from the FFI entirely.
This commit is contained in:
Dorota Czaplejewicz
2019-10-17 13:33:23 +00:00
parent 3b6c19401c
commit c99efc430c
15 changed files with 626 additions and 611 deletions

View File

@ -2,6 +2,7 @@
use std::collections::HashMap;
use std::rc::Rc;
use std::borrow::Borrow;
use std::hash::{ Hash, Hasher };
use std::iter::FromIterator;
@ -111,7 +112,7 @@ pub mod c {
fn clone_owned(&self) -> T {
let rc = self.clone_ref();
let r = rc.borrow();
let r = RefCell::borrow(&rc);
r.to_owned()
}
}
@ -133,7 +134,13 @@ pub fn hash_map_map<K, V, F, K1, V1>(map: HashMap<K, V>, mut f: F)
}
/// Compares pointers but not internal values of Rc
pub struct Pointer<T>(Rc<T>);
pub struct Pointer<T>(pub Rc<T>);
impl<T> Pointer<T> {
pub fn new(value: T) -> Self {
Pointer(Rc::new(value))
}
}
impl<T> Hash for Pointer<T> {
fn hash<H: Hasher>(&self, state: &mut H) {
@ -149,6 +156,18 @@ impl<T> PartialEq for Pointer<T> {
impl<T> Eq for Pointer<T> {}
impl<T> Clone for Pointer<T> {
fn clone(&self) -> Self {
Pointer(self.0.clone())
}
}
impl<T> Borrow<Rc<T>> for Pointer<T> {
fn borrow(&self) -> &Rc<T> {
&self.0
}
}
#[cfg(test)]
mod tests {
use super::*;