[drag-and-drop] Add ability to translate layers and PaintCmd:s
This commit is contained in:
parent
ed8a69ab2f
commit
9833ca57a6
3 changed files with 47 additions and 2 deletions
|
@ -1,6 +1,6 @@
|
||||||
use ahash::AHashMap;
|
use ahash::AHashMap;
|
||||||
|
|
||||||
use crate::{math::Rect, paint::PaintCmd, Id};
|
use crate::{math::Rect, paint::PaintCmd, Id, *};
|
||||||
|
|
||||||
/// Different layer categories
|
/// Different layer categories
|
||||||
#[derive(Clone, Copy, Debug, Hash, Eq, PartialEq, Ord, PartialOrd)]
|
#[derive(Clone, Copy, Debug, Hash, Eq, PartialEq, Ord, PartialOrd)]
|
||||||
|
@ -105,6 +105,14 @@ impl PaintList {
|
||||||
assert!(idx.0 < self.0.len());
|
assert!(idx.0 < self.0.len());
|
||||||
self.0[idx.0] = (clip_rect, cmd);
|
self.0[idx.0] = (clip_rect, cmd);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Translate each paint-command and clip rectangle by this much, in-place
|
||||||
|
pub fn translate(&mut self, delta: Vec2) {
|
||||||
|
for (clip_rect, cmd) in &mut self.0 {
|
||||||
|
*clip_rect = clip_rect.translate(delta);
|
||||||
|
cmd.translate(delta);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Default)]
|
#[derive(Clone, Default)]
|
||||||
|
|
|
@ -3,6 +3,7 @@ use {
|
||||||
crate::{
|
crate::{
|
||||||
align::{anchor_rect, Align},
|
align::{anchor_rect, Align},
|
||||||
math::{Pos2, Rect},
|
math::{Pos2, Rect},
|
||||||
|
*,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -152,6 +153,35 @@ impl PaintCmd {
|
||||||
super::TextureId::Egui
|
super::TextureId::Egui
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Translate location by this much, in-place
|
||||||
|
pub fn translate(&mut self, delta: Vec2) {
|
||||||
|
match self {
|
||||||
|
PaintCmd::Noop => {}
|
||||||
|
PaintCmd::Circle { center, .. } => {
|
||||||
|
*center += delta;
|
||||||
|
}
|
||||||
|
PaintCmd::LineSegment { points, .. } => {
|
||||||
|
for p in points {
|
||||||
|
*p += delta;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
PaintCmd::Path { points, .. } => {
|
||||||
|
for p in points {
|
||||||
|
*p += delta;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
PaintCmd::Rect { rect, .. } => {
|
||||||
|
*rect = rect.translate(delta);
|
||||||
|
}
|
||||||
|
PaintCmd::Text { pos, .. } => {
|
||||||
|
*pos += delta;
|
||||||
|
}
|
||||||
|
PaintCmd::Triangles(triangles) => {
|
||||||
|
triangles.translate(delta);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug, Default, PartialEq)]
|
#[derive(Clone, Copy, Debug, Default, PartialEq)]
|
||||||
|
|
|
@ -243,6 +243,13 @@ impl Triangles {
|
||||||
}
|
}
|
||||||
output
|
output
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Translate location by this much, in-place
|
||||||
|
pub fn translate(&mut self, delta: Vec2) {
|
||||||
|
for v in &mut self.vertices {
|
||||||
|
v.pos += delta;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
@ -697,7 +704,7 @@ fn tessellate_paint_command(
|
||||||
if triangles.is_valid() {
|
if triangles.is_valid() {
|
||||||
out.append(triangles);
|
out.append(triangles);
|
||||||
} else {
|
} else {
|
||||||
debug_assert!(false, "Ivalid Triangles in PaintCmd::Traingles");
|
debug_assert!(false, "Invalid Triangles in PaintCmd::Triangles");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
PaintCmd::LineSegment { points, stroke } => {
|
PaintCmd::LineSegment { points, stroke } => {
|
||||||
|
|
Loading…
Reference in a new issue