autocommit 2022-04-05 18:28:42 CEST
This commit is contained in:
parent
1f05ea431e
commit
a3e9f21fc5
29 changed files with 568 additions and 225 deletions
|
|
@ -1,12 +1,21 @@
|
|||
use crate::rect::{Container, Rect, Region};
|
||||
use crate::utils::windows::WindowsExt;
|
||||
use once_cell::unsync::Lazy;
|
||||
use smallvec::SmallVec;
|
||||
use std::cmp::Ordering;
|
||||
use std::collections::{BinaryHeap};
|
||||
use std::collections::BinaryHeap;
|
||||
use std::mem;
|
||||
use std::ops::Deref;
|
||||
use std::rc::Rc;
|
||||
|
||||
#[thread_local]
|
||||
static EMPTY: Lazy<Rc<Region>> = Lazy::new(|| {
|
||||
Rc::new(Region {
|
||||
rects: Default::default(),
|
||||
extents: Default::default(),
|
||||
})
|
||||
});
|
||||
|
||||
impl Region {
|
||||
pub fn new(rect: Rect) -> Rc<Self> {
|
||||
let mut rects = SmallVec::new();
|
||||
|
|
@ -17,9 +26,13 @@ impl Region {
|
|||
})
|
||||
}
|
||||
|
||||
pub fn empty() -> Rc<Self> {
|
||||
EMPTY.clone()
|
||||
}
|
||||
|
||||
pub fn from_rects(rects: &[Rect]) -> Rc<Self> {
|
||||
if rects.is_empty() {
|
||||
return Rc::new(Self::default());
|
||||
return Self::empty();
|
||||
}
|
||||
if rects.len() == 1 {
|
||||
return Self::new(rects[0]);
|
||||
|
|
@ -531,13 +544,22 @@ impl Default for BuilderOp {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct RegionBuilder {
|
||||
base: Rc<Region>,
|
||||
op: BuilderOp,
|
||||
pending: Vec<Rect>,
|
||||
}
|
||||
|
||||
impl Default for RegionBuilder {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
base: Region::empty(),
|
||||
op: Default::default(),
|
||||
pending: Default::default(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl RegionBuilder {
|
||||
pub fn add(&mut self, rect: Rect) {
|
||||
self.set_op(BuilderOp::Add);
|
||||
|
|
@ -556,7 +578,7 @@ impl RegionBuilder {
|
|||
|
||||
pub fn clear(&mut self) {
|
||||
self.pending.clear();
|
||||
self.base = Rc::new(Region::default());
|
||||
self.base = Region::empty();
|
||||
}
|
||||
|
||||
fn set_op(&mut self, op: BuilderOp) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue