add width and height macro
This commit is contained in:
		
							parent
							
								
									9fa09fe33e
								
							
						
					
					
						commit
						3c27917afa
					
				
					 5 changed files with 28 additions and 36 deletions
				
			
		|  | @ -1,8 +1,9 @@ | |||
| use servicepoint::{DataRef, Grid}; | ||||
| use std::sync::{Arc}; | ||||
| use crate::macros::wrap_uniffi_object; | ||||
| use crate::macros::{wrap_width_height, wrap_uniffi_object}; | ||||
| 
 | ||||
| wrap_uniffi_object!(Bitmap); | ||||
| wrap_width_height!(Bitmap); | ||||
| 
 | ||||
| #[uniffi::export] | ||||
| impl Bitmap { | ||||
|  | @ -42,14 +43,7 @@ impl Bitmap { | |||
|     pub fn fill(&self, value: bool) { | ||||
|         self.actual.write().unwrap().fill(value) | ||||
|     } | ||||
|     pub fn width(&self) -> u64 { | ||||
|         self.actual.read().unwrap().width() as u64 | ||||
|     } | ||||
| 
 | ||||
|     pub fn height(&self) -> u64 { | ||||
|         self.actual.read().unwrap().height() as u64 | ||||
|     } | ||||
| 
 | ||||
|     
 | ||||
|     pub fn equals(&self, other: &Bitmap) -> bool { | ||||
|         let a = self.actual.read().unwrap(); | ||||
|         let b = other.actual.read().unwrap(); | ||||
|  |  | |||
|  | @ -1,8 +1,9 @@ | |||
| use servicepoint::{Brightness, DataRef, Grid}; | ||||
| use std::sync::{Arc}; | ||||
| use crate::macros::wrap_uniffi_object; | ||||
| use crate::macros::{wrap_width_height, wrap_uniffi_object}; | ||||
| 
 | ||||
| wrap_uniffi_object!(BrightnessGrid); | ||||
| wrap_width_height!(BrightnessGrid); | ||||
| 
 | ||||
| #[uniffi::export] | ||||
| impl BrightnessGrid { | ||||
|  | @ -45,13 +46,6 @@ impl BrightnessGrid { | |||
|             .unwrap() | ||||
|             .fill(Brightness::saturating_from(value)) | ||||
|     } | ||||
|     pub fn width(&self) -> u64 { | ||||
|         self.actual.read().unwrap().width() as u64 | ||||
|     } | ||||
| 
 | ||||
|     pub fn height(&self) -> u64 { | ||||
|         self.actual.read().unwrap().height() as u64 | ||||
|     } | ||||
| 
 | ||||
|     pub fn equals(&self, other: &BrightnessGrid) -> bool { | ||||
|         let a = self.actual.read().unwrap(); | ||||
|  |  | |||
|  | @ -2,9 +2,10 @@ use crate::cp437_grid::Cp437Grid; | |||
| use servicepoint::{Grid, SetValueSeriesError}; | ||||
| use std::convert::Into; | ||||
| use std::sync::{Arc}; | ||||
| use crate::macros::wrap_uniffi_object; | ||||
| use crate::macros::{wrap_width_height, wrap_uniffi_object}; | ||||
| 
 | ||||
| wrap_uniffi_object!(CharGrid); | ||||
| wrap_width_height!(CharGrid); | ||||
| 
 | ||||
| #[derive(uniffi::Error, thiserror::Error, Debug)] | ||||
| pub enum CharGridError { | ||||
|  | @ -59,14 +60,6 @@ impl CharGrid { | |||
|         Ok(()) | ||||
|     } | ||||
| 
 | ||||
|     pub fn width(&self) -> u64 { | ||||
|         self.actual.read().unwrap().width() as u64 | ||||
|     } | ||||
| 
 | ||||
|     pub fn height(&self) -> u64 { | ||||
|         self.actual.read().unwrap().height() as u64 | ||||
|     } | ||||
| 
 | ||||
|     pub fn equals(&self, other: &CharGrid) -> bool { | ||||
|         let a = self.actual.read().unwrap(); | ||||
|         let b = other.actual.read().unwrap(); | ||||
|  |  | |||
|  | @ -1,9 +1,10 @@ | |||
| use crate::char_grid::CharGrid; | ||||
| use servicepoint::{DataRef, Grid}; | ||||
| use std::sync::{Arc}; | ||||
| use crate::macros::wrap_uniffi_object; | ||||
| use crate::macros::{wrap_width_height, wrap_uniffi_object}; | ||||
| 
 | ||||
| wrap_uniffi_object!(Cp437Grid); | ||||
| wrap_width_height!(Cp437Grid); | ||||
| 
 | ||||
| #[uniffi::export] | ||||
| impl Cp437Grid { | ||||
|  | @ -38,13 +39,6 @@ impl Cp437Grid { | |||
|     pub fn fill(&self, value: u8) { | ||||
|         self.actual.write().unwrap().fill(value) | ||||
|     } | ||||
|     pub fn width(&self) -> u64 { | ||||
|         self.actual.read().unwrap().width() as u64 | ||||
|     } | ||||
| 
 | ||||
|     pub fn height(&self) -> u64 { | ||||
|         self.actual.read().unwrap().height() as u64 | ||||
|     } | ||||
| 
 | ||||
|     pub fn equals(&self, other: &Cp437Grid) -> bool { | ||||
|         let a = self.actual.read().unwrap(); | ||||
|  |  | |||
|  | @ -13,7 +13,7 @@ macro_rules! wrap_uniffi_object { | |||
|                 }) | ||||
|             } | ||||
|         } | ||||
|          
 | ||||
| 
 | ||||
|         #[uniffi::export] | ||||
|         impl $new_t { | ||||
|             #[uniffi::constructor] | ||||
|  | @ -27,4 +27,21 @@ macro_rules! wrap_uniffi_object { | |||
|     }; | ||||
| } | ||||
| 
 | ||||
| pub(crate) use wrap_uniffi_object; | ||||
| pub(crate) use wrap_uniffi_object; | ||||
| 
 | ||||
| macro_rules! wrap_width_height { | ||||
|     ($t:ident) => { | ||||
|         #[uniffi::export] | ||||
|         impl $t { | ||||
|             pub fn width(&self) -> u64 { | ||||
|                 self.actual.read().unwrap().width() as u64 | ||||
|             } | ||||
|         
 | ||||
|             pub fn height(&self) -> u64 { | ||||
|                 self.actual.read().unwrap().height() as u64 | ||||
|             } | ||||
|         } | ||||
|     }; | ||||
| } | ||||
| 
 | ||||
| pub(crate) use wrap_width_height; | ||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Vinzenz Schroeter
						Vinzenz Schroeter