add get set fill macro
This commit is contained in:
parent
3c27917afa
commit
8d5e408653
6 changed files with 86 additions and 83 deletions
|
@ -1,9 +1,12 @@
|
|||
use crate::macros::{
|
||||
wrap_get_set_fill_2d, wrap_uniffi_object, wrap_width_height,
|
||||
};
|
||||
use servicepoint::{Brightness, DataRef, Grid};
|
||||
use std::sync::{Arc};
|
||||
use crate::macros::{wrap_width_height, wrap_uniffi_object};
|
||||
use std::sync::Arc;
|
||||
|
||||
wrap_uniffi_object!(BrightnessGrid);
|
||||
wrap_width_height!(BrightnessGrid);
|
||||
wrap_get_set_fill_2d!(BrightnessGrid, Brightness);
|
||||
|
||||
#[uniffi::export]
|
||||
impl BrightnessGrid {
|
||||
|
@ -17,36 +20,16 @@ impl BrightnessGrid {
|
|||
|
||||
#[uniffi::constructor]
|
||||
pub fn load(width: u64, height: u64, data: Vec<u8>) -> Arc<Self> {
|
||||
Self::internal_new(servicepoint::BrightnessGrid::saturating_load(
|
||||
width as usize,
|
||||
height as usize,
|
||||
&data,
|
||||
).unwrap())
|
||||
}
|
||||
|
||||
pub fn set(&self, x: u64, y: u64, value: u8) {
|
||||
self.actual.write().unwrap().set(
|
||||
x as usize,
|
||||
y as usize,
|
||||
Brightness::saturating_from(value),
|
||||
Self::internal_new(
|
||||
servicepoint::BrightnessGrid::saturating_load(
|
||||
width as usize,
|
||||
height as usize,
|
||||
&data,
|
||||
)
|
||||
.unwrap(),
|
||||
)
|
||||
}
|
||||
|
||||
pub fn get(&self, x: u64, y: u64) -> u8 {
|
||||
self.actual
|
||||
.read()
|
||||
.unwrap()
|
||||
.get(x as usize, y as usize)
|
||||
.into()
|
||||
}
|
||||
|
||||
pub fn fill(&self, value: u8) {
|
||||
self.actual
|
||||
.write()
|
||||
.unwrap()
|
||||
.fill(Brightness::saturating_from(value))
|
||||
}
|
||||
|
||||
pub fn equals(&self, other: &BrightnessGrid) -> bool {
|
||||
let a = self.actual.read().unwrap();
|
||||
let b = other.actual.read().unwrap();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue