summaryrefslogtreecommitdiff
path: root/src/sheet/map.rs
diff options
context:
space:
mode:
authorNathan Reiner <nathan@nathanreiner.xyz>2024-08-02 14:05:30 +0200
committerNathan Reiner <nathan@nathanreiner.xyz>2024-08-02 14:05:30 +0200
commit555a45a9f2b68a48b098099804ce795e3d5a350b (patch)
treec13dbfc5e380f9c2b21fa87ce889a6379fef44b2 /src/sheet/map.rs
parent04a5a938994ddb95cfaa9a74b180e457d3a2b5d0 (diff)
sheetview add background theme parameter
Diffstat (limited to 'src/sheet/map.rs')
-rw-r--r--src/sheet/map.rs37
1 files changed, 37 insertions, 0 deletions
diff --git a/src/sheet/map.rs b/src/sheet/map.rs
new file mode 100644
index 0000000..09209a3
--- /dev/null
+++ b/src/sheet/map.rs
@@ -0,0 +1,37 @@
+use std::sync::{Arc, RwLock};
+
+use mlua::prelude::*;
+
+use super::{cell::Cell, Sheet};
+
+pub trait LuaMap {
+ fn lua_map<'lua>(
+ &self,
+ func: LuaFunction<'lua>,
+ range: Vec<(usize, usize)>,
+ ) -> Result<(), LuaError>;
+}
+
+impl LuaMap for Arc<RwLock<Sheet>> {
+ fn lua_map<'lua>(
+ &self,
+ func: LuaFunction<'lua>,
+ range: Vec<(usize, usize)>,
+ ) -> Result<(), LuaError> {
+ let mut this = self.write().unwrap();
+ let mut sheet = this.clone();
+
+ for (row, column) in range.iter() {
+ let cellref = this.get_ref(*row, *column);
+
+ match func.call::<_, Cell>(cellref) {
+ Ok(cell) => sheet.set_cell(*row, *column, cell),
+ Err(error) => return Err(error),
+ }
+ }
+
+ this.apply(sheet);
+
+ Ok(())
+ }
+}