This repository has no description
0

Configure Feed

Select the types of activity you want to include in your feed.

✨ Object tagging

+51
+21
src/graphics/layer.rs
··· 144 144 } 145 145 } 146 146 147 + pub fn objects_with_tag( 148 + &mut self, 149 + tag: impl Display, 150 + ) -> impl Iterator<Item = (&String, &mut ColoredObject)> { 151 + let tag_str = format!("{}", tag); 152 + self.objects 153 + .iter_mut() 154 + .filter(move |(_, obj)| obj.has_tag(&tag_str)) 155 + } 156 + 157 + pub fn tag_objects( 158 + &mut self, 159 + tag: impl Display, 160 + objects: impl Fn(&String, &ColoredObject) -> bool, 161 + ) { 162 + let tag_str = format!("{}", tag); 163 + for (_, obj) in self.objects.iter_mut().filter(|(id, obj)| objects(id, obj)) { 164 + obj.tag(&tag_str); 165 + } 166 + } 167 + 147 168 /// Returns the effective region the layer occupies, by merging all its objects' regions. 148 169 pub fn region(&self) -> Region { 149 170 self.objects
+30
src/graphics/objects.rs
··· 1 1 use crate::{Fill, Filter, Point, Region, Transformation}; 2 + use std::fmt::Display; 3 + 4 + use itertools::Itertools; 2 5 #[cfg(feature = "web")] 3 6 use wasm_bindgen::prelude::*; 4 7 ··· 53 56 pub fill: Option<Fill>, 54 57 pub filters: Vec<Filter>, 55 58 pub transformations: Vec<Transformation>, 59 + pub tags: Vec<String>, 56 60 } 57 61 58 62 impl ColoredObject { ··· 102 106 pub fn region(&self) -> Region { 103 107 self.object.region() 104 108 } 109 + 110 + pub fn tag(&mut self, tag: impl Display) { 111 + self.tags.push(format!("{tag}")); 112 + } 113 + 114 + pub fn remove_tag(&mut self, tag: impl Display) { 115 + let tag_str = format!("{tag}"); 116 + self.tags.retain(|t| t != &tag_str); 117 + } 118 + 119 + pub fn tagged(mut self, tag: impl Display) -> Self { 120 + self.tags.push(format!("{tag}")); 121 + self 122 + } 123 + 124 + pub fn has_tag(&self, tag: impl Display) -> bool { 125 + let tag_str = format!("{tag}"); 126 + self.tags.iter().any(|t| t == &tag_str) 127 + } 105 128 } 106 129 107 130 impl std::fmt::Display for ColoredObject { ··· 111 134 fill, 112 135 filters, 113 136 transformations, 137 + tags, 114 138 } = self; 115 139 116 140 if fill.is_some() { ··· 127 151 write!(f, " with transformations {:?}", transformations)?; 128 152 } 129 153 154 + if !tags.is_empty() { 155 + write!(f, "{}", tags.iter().map(|t| format!("#{t}")).join(" "))?; 156 + } 157 + 130 158 Ok(()) 131 159 } 132 160 } ··· 138 166 fill: None, 139 167 filters: vec![], 140 168 transformations: vec![], 169 + tags: vec![], 141 170 } 142 171 } 143 172 } ··· 149 178 fill, 150 179 filters: vec![], 151 180 transformations: vec![], 181 + tags: vec![], 152 182 } 153 183 } 154 184 }