Skip to content

Commit

Permalink
Fix nodegraph disconnect function
Browse files Browse the repository at this point in the history
  • Loading branch information
fschutt committed Sep 5, 2021
1 parent dda7fdb commit 1983540
Show file tree
Hide file tree
Showing 12 changed files with 818 additions and 622 deletions.
35 changes: 35 additions & 0 deletions api.json
Original file line number Diff line number Diff line change
Expand Up @@ -11611,6 +11611,13 @@
{"items": {"type": "SvgPathElementVec"}}
],
"functions": {
"reverse": {
"doc": "Reverses the order of points in the path so that the path runs in the opposite direction afterwards",
"fn_args": [
{"self": "refmut"}
],
"fn_body": "svgpath.reverse()"
},
"tessellate_fill": {
"fn_args": [
{"self": "ref"},
Expand Down Expand Up @@ -11638,6 +11645,13 @@
{"CubicCurve": {"type": "SvgCubicCurve"}}
],
"functions": {
"reverse": {
"doc": "Reverses the order of points in the path so that the path runs in the opposite direction afterwards",
"fn_args": [
{"self": "refmut"}
],
"fn_body": "svgpathelement.reverse()"
},
"get_start": {
"doc": "Returns the starting point of this item",
"fn_args": [
Expand Down Expand Up @@ -11766,6 +11780,13 @@
{"end": {"type": "SvgPoint"}}
],
"functions": {
"reverse": {
"doc": "Reverses the order of points in the path so that the path runs in the opposite direction afterwards",
"fn_args": [
{"self": "refmut"}
],
"fn_body": "svgline.reverse()"
},
"get_start": {
"doc": "Returns the starting point of this item",
"fn_args": [
Expand Down Expand Up @@ -11853,6 +11874,13 @@
{"end": {"type": "SvgPoint"}}
],
"functions": {
"reverse": {
"doc": "Reverses the order of points in the curve so that the curve runs in the opposite direction afterwards",
"fn_args": [
{"self": "refmut"}
],
"fn_body": "svgquadraticcurve.reverse()"
},
"get_start": {
"doc": "Returns the starting point of this item",
"fn_args": [
Expand Down Expand Up @@ -11941,6 +11969,13 @@
{"end": {"type": "SvgPoint"}}
],
"functions": {
"reverse": {
"doc": "Reverses the order of points in the curve so that the curve runs in the opposite direction afterwards",
"fn_args": [
{"self": "refmut"}
],
"fn_body": "svgcubiccurve.reverse()"
},
"get_start": {
"doc": "Returns the starting point of this item",
"fn_args": [
Expand Down
5 changes: 5 additions & 0 deletions api/c/azul.h
Original file line number Diff line number Diff line change
Expand Up @@ -12531,9 +12531,11 @@ extern DLLIMPORT AzTessellatedSvgNode AzSvgStyledNode_tessellate(const AzSvgStyl
extern DLLIMPORT void AzSvgStyledNode_delete(AzSvgStyledNode* restrict instance);
extern DLLIMPORT AzTessellatedSvgNode AzSvgCircle_tessellateFill(const AzSvgCircle* svgcircle, AzSvgFillStyle fill_style);
extern DLLIMPORT AzTessellatedSvgNode AzSvgCircle_tessellateStroke(const AzSvgCircle* svgcircle, AzSvgStrokeStyle stroke_style);
extern DLLIMPORT void AzSvgPath_reverse(AzSvgPath* restrict svgpath);
extern DLLIMPORT AzTessellatedSvgNode AzSvgPath_tessellateFill(const AzSvgPath* svgpath, AzSvgFillStyle fill_style);
extern DLLIMPORT AzTessellatedSvgNode AzSvgPath_tessellateStroke(const AzSvgPath* svgpath, AzSvgStrokeStyle stroke_style);
extern DLLIMPORT void AzSvgPath_delete(AzSvgPath* restrict instance);
extern DLLIMPORT void AzSvgPathElement_reverse(AzSvgPathElement* restrict svgpathelement);
extern DLLIMPORT AzSvgPoint AzSvgPathElement_getStart(const AzSvgPathElement* svgpathelement);
extern DLLIMPORT AzSvgPoint AzSvgPathElement_getEnd(const AzSvgPathElement* svgpathelement);
extern DLLIMPORT AzSvgRect AzSvgPathElement_getBounds(const AzSvgPathElement* svgpathelement);
Expand All @@ -12546,6 +12548,7 @@ extern DLLIMPORT AzTessellatedSvgNode AzSvgPathElement_tessellateStroke(const Az
extern DLLIMPORT float AzSvgVector_angleDegrees(const AzSvgVector* svgvector);
extern DLLIMPORT AzSvgVector AzSvgVector_normalize(const AzSvgVector* svgvector);
extern DLLIMPORT AzSvgVector AzSvgVector_rotate90DegCcw(const AzSvgVector* svgvector);
extern DLLIMPORT void AzSvgLine_reverse(AzSvgLine* restrict svgline);
extern DLLIMPORT AzSvgPoint AzSvgLine_getStart(const AzSvgLine* svgline);
extern DLLIMPORT AzSvgPoint AzSvgLine_getEnd(const AzSvgLine* svgline);
extern DLLIMPORT AzSvgRect AzSvgLine_getBounds(const AzSvgLine* svgline);
Expand All @@ -12555,6 +12558,7 @@ extern DLLIMPORT float AzSvgLine_getXAtT(const AzSvgLine* svgline, float t);
extern DLLIMPORT float AzSvgLine_getYAtT(const AzSvgLine* svgline, float t);
extern DLLIMPORT AzSvgVector AzSvgLine_getTangentVectorAtT(const AzSvgLine* svgline, float t);
extern DLLIMPORT AzTessellatedSvgNode AzSvgLine_tessellateStroke(const AzSvgLine* svgline, AzSvgStrokeStyle stroke_style);
extern DLLIMPORT void AzSvgQuadraticCurve_reverse(AzSvgQuadraticCurve* restrict svgquadraticcurve);
extern DLLIMPORT AzSvgPoint AzSvgQuadraticCurve_getStart(const AzSvgQuadraticCurve* svgquadraticcurve);
extern DLLIMPORT AzSvgPoint AzSvgQuadraticCurve_getEnd(const AzSvgQuadraticCurve* svgquadraticcurve);
extern DLLIMPORT AzSvgRect AzSvgQuadraticCurve_getBounds(const AzSvgQuadraticCurve* svgquadraticcurve);
Expand All @@ -12564,6 +12568,7 @@ extern DLLIMPORT float AzSvgQuadraticCurve_getXAtT(const AzSvgQuadraticCurve* sv
extern DLLIMPORT float AzSvgQuadraticCurve_getYAtT(const AzSvgQuadraticCurve* svgquadraticcurve, float t);
extern DLLIMPORT AzSvgVector AzSvgQuadraticCurve_getTangentVectorAtT(const AzSvgQuadraticCurve* svgquadraticcurve, float t);
extern DLLIMPORT AzTessellatedSvgNode AzSvgQuadraticCurve_tessellateStroke(const AzSvgQuadraticCurve* svgquadraticcurve, AzSvgStrokeStyle stroke_style);
extern DLLIMPORT void AzSvgCubicCurve_reverse(AzSvgCubicCurve* restrict svgcubiccurve);
extern DLLIMPORT AzSvgPoint AzSvgCubicCurve_getStart(const AzSvgCubicCurve* svgcubiccurve);
extern DLLIMPORT AzSvgPoint AzSvgCubicCurve_getEnd(const AzSvgCubicCurve* svgcubiccurve);
extern DLLIMPORT AzSvgRect AzSvgCubicCurve_getBounds(const AzSvgCubicCurve* svgcubiccurve);
Expand Down
5 changes: 5 additions & 0 deletions api/cpp/azul.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10495,9 +10495,11 @@ namespace dll {
void SvgStyledNode_delete(SvgStyledNode* restrict instance);
TessellatedSvgNode SvgCircle_tessellateFill(const SvgCircle* svgcircle, AzSvgFillStyle fill_style);
TessellatedSvgNode SvgCircle_tessellateStroke(const SvgCircle* svgcircle, AzSvgStrokeStyle stroke_style);
void SvgPath_reverse(SvgPath* restrict svgpath);
TessellatedSvgNode SvgPath_tessellateFill(const SvgPath* svgpath, AzSvgFillStyle fill_style);
TessellatedSvgNode SvgPath_tessellateStroke(const SvgPath* svgpath, AzSvgStrokeStyle stroke_style);
void SvgPath_delete(SvgPath* restrict instance);
void SvgPathElement_reverse(SvgPathElement* restrict svgpathelement);
SvgPoint SvgPathElement_getStart(const SvgPathElement* svgpathelement);
SvgPoint SvgPathElement_getEnd(const SvgPathElement* svgpathelement);
SvgRect SvgPathElement_getBounds(const SvgPathElement* svgpathelement);
Expand All @@ -10510,6 +10512,7 @@ namespace dll {
float SvgVector_angleDegrees(const SvgVector* svgvector);
SvgVector SvgVector_normalize(const SvgVector* svgvector);
SvgVector SvgVector_rotate90DegCcw(const SvgVector* svgvector);
void SvgLine_reverse(SvgLine* restrict svgline);
SvgPoint SvgLine_getStart(const SvgLine* svgline);
SvgPoint SvgLine_getEnd(const SvgLine* svgline);
SvgRect SvgLine_getBounds(const SvgLine* svgline);
Expand All @@ -10519,6 +10522,7 @@ namespace dll {
float SvgLine_getYAtT(const SvgLine* svgline, float t);
SvgVector SvgLine_getTangentVectorAtT(const SvgLine* svgline, float t);
TessellatedSvgNode SvgLine_tessellateStroke(const SvgLine* svgline, AzSvgStrokeStyle stroke_style);
void SvgQuadraticCurve_reverse(SvgQuadraticCurve* restrict svgquadraticcurve);
SvgPoint SvgQuadraticCurve_getStart(const SvgQuadraticCurve* svgquadraticcurve);
SvgPoint SvgQuadraticCurve_getEnd(const SvgQuadraticCurve* svgquadraticcurve);
SvgRect SvgQuadraticCurve_getBounds(const SvgQuadraticCurve* svgquadraticcurve);
Expand All @@ -10528,6 +10532,7 @@ namespace dll {
float SvgQuadraticCurve_getYAtT(const SvgQuadraticCurve* svgquadraticcurve, float t);
SvgVector SvgQuadraticCurve_getTangentVectorAtT(const SvgQuadraticCurve* svgquadraticcurve, float t);
TessellatedSvgNode SvgQuadraticCurve_tessellateStroke(const SvgQuadraticCurve* svgquadraticcurve, AzSvgStrokeStyle stroke_style);
void SvgCubicCurve_reverse(SvgCubicCurve* restrict svgcubiccurve);
SvgPoint SvgCubicCurve_getStart(const SvgCubicCurve* svgcubiccurve);
SvgPoint SvgCubicCurve_getEnd(const SvgCubicCurve* svgcubiccurve);
SvgRect SvgCubicCurve_getBounds(const SvgCubicCurve* svgcubiccurve);
Expand Down
15 changes: 15 additions & 0 deletions api/rust/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10351,8 +10351,10 @@ mod dll {
pub(crate) fn AzSvgStyledNode_tessellate(_: &AzSvgStyledNode) -> AzTessellatedSvgNode;
pub(crate) fn AzSvgCircle_tessellateFill(_: &AzSvgCircle, _: AzSvgFillStyle) -> AzTessellatedSvgNode;
pub(crate) fn AzSvgCircle_tessellateStroke(_: &AzSvgCircle, _: AzSvgStrokeStyle) -> AzTessellatedSvgNode;
pub(crate) fn AzSvgPath_reverse(_: &mut AzSvgPath);
pub(crate) fn AzSvgPath_tessellateFill(_: &AzSvgPath, _: AzSvgFillStyle) -> AzTessellatedSvgNode;
pub(crate) fn AzSvgPath_tessellateStroke(_: &AzSvgPath, _: AzSvgStrokeStyle) -> AzTessellatedSvgNode;
pub(crate) fn AzSvgPathElement_reverse(_: &mut AzSvgPathElement);
pub(crate) fn AzSvgPathElement_getStart(_: &AzSvgPathElement) -> AzSvgPoint;
pub(crate) fn AzSvgPathElement_getEnd(_: &AzSvgPathElement) -> AzSvgPoint;
pub(crate) fn AzSvgPathElement_getBounds(_: &AzSvgPathElement) -> AzSvgRect;
Expand All @@ -10365,6 +10367,7 @@ mod dll {
pub(crate) fn AzSvgVector_angleDegrees(_: &AzSvgVector) -> f32;
pub(crate) fn AzSvgVector_normalize(_: &AzSvgVector) -> AzSvgVector;
pub(crate) fn AzSvgVector_rotate90DegCcw(_: &AzSvgVector) -> AzSvgVector;
pub(crate) fn AzSvgLine_reverse(_: &mut AzSvgLine);
pub(crate) fn AzSvgLine_getStart(_: &AzSvgLine) -> AzSvgPoint;
pub(crate) fn AzSvgLine_getEnd(_: &AzSvgLine) -> AzSvgPoint;
pub(crate) fn AzSvgLine_getBounds(_: &AzSvgLine) -> AzSvgRect;
Expand All @@ -10374,6 +10377,7 @@ mod dll {
pub(crate) fn AzSvgLine_getYAtT(_: &AzSvgLine, _: f32) -> f32;
pub(crate) fn AzSvgLine_getTangentVectorAtT(_: &AzSvgLine, _: f32) -> AzSvgVector;
pub(crate) fn AzSvgLine_tessellateStroke(_: &AzSvgLine, _: AzSvgStrokeStyle) -> AzTessellatedSvgNode;
pub(crate) fn AzSvgQuadraticCurve_reverse(_: &mut AzSvgQuadraticCurve);
pub(crate) fn AzSvgQuadraticCurve_getStart(_: &AzSvgQuadraticCurve) -> AzSvgPoint;
pub(crate) fn AzSvgQuadraticCurve_getEnd(_: &AzSvgQuadraticCurve) -> AzSvgPoint;
pub(crate) fn AzSvgQuadraticCurve_getBounds(_: &AzSvgQuadraticCurve) -> AzSvgRect;
Expand All @@ -10383,6 +10387,7 @@ mod dll {
pub(crate) fn AzSvgQuadraticCurve_getYAtT(_: &AzSvgQuadraticCurve, _: f32) -> f32;
pub(crate) fn AzSvgQuadraticCurve_getTangentVectorAtT(_: &AzSvgQuadraticCurve, _: f32) -> AzSvgVector;
pub(crate) fn AzSvgQuadraticCurve_tessellateStroke(_: &AzSvgQuadraticCurve, _: AzSvgStrokeStyle) -> AzTessellatedSvgNode;
pub(crate) fn AzSvgCubicCurve_reverse(_: &mut AzSvgCubicCurve);
pub(crate) fn AzSvgCubicCurve_getStart(_: &AzSvgCubicCurve) -> AzSvgPoint;
pub(crate) fn AzSvgCubicCurve_getEnd(_: &AzSvgCubicCurve) -> AzSvgPoint;
pub(crate) fn AzSvgCubicCurve_getBounds(_: &AzSvgCubicCurve) -> AzSvgRect;
Expand Down Expand Up @@ -16100,6 +16105,8 @@ pub mod svg {

#[doc(inline)] pub use crate::dll::AzSvgPath as SvgPath;
impl SvgPath {
/// Reverses the order of points in the path so that the path runs in the opposite direction afterwards
pub fn reverse(&mut self) { unsafe { crate::dll::AzSvgPath_reverse(self) } }
/// Calls the `SvgPath::tessellate_fill` function.
pub fn tessellate_fill(&self, fill_style: SvgFillStyle) -> crate::svg::TessellatedSvgNode { unsafe { crate::dll::AzSvgPath_tessellateFill(self, fill_style) } }
/// Calls the `SvgPath::tessellate_stroke` function.
Expand All @@ -16110,6 +16117,8 @@ pub mod svg {

#[doc(inline)] pub use crate::dll::AzSvgPathElement as SvgPathElement;
impl SvgPathElement {
/// Reverses the order of points in the path so that the path runs in the opposite direction afterwards
pub fn reverse(&mut self) { unsafe { crate::dll::AzSvgPathElement_reverse(self) } }
/// Returns the starting point of this item
pub fn get_start(&self) -> crate::svg::SvgPoint { unsafe { crate::dll::AzSvgPathElement_getStart(self) } }
/// Returns the ending point of this item
Expand Down Expand Up @@ -16149,6 +16158,8 @@ pub mod svg {

#[doc(inline)] pub use crate::dll::AzSvgLine as SvgLine;
impl SvgLine {
/// Reverses the order of points in the path so that the path runs in the opposite direction afterwards
pub fn reverse(&mut self) { unsafe { crate::dll::AzSvgLine_reverse(self) } }
/// Returns the starting point of this item
pub fn get_start(&self) -> crate::svg::SvgPoint { unsafe { crate::dll::AzSvgLine_getStart(self) } }
/// Returns the ending point of this item
Expand All @@ -16173,6 +16184,8 @@ pub mod svg {

#[doc(inline)] pub use crate::dll::AzSvgQuadraticCurve as SvgQuadraticCurve;
impl SvgQuadraticCurve {
/// Reverses the order of points in the curve so that the curve runs in the opposite direction afterwards
pub fn reverse(&mut self) { unsafe { crate::dll::AzSvgQuadraticCurve_reverse(self) } }
/// Returns the starting point of this item
pub fn get_start(&self) -> crate::svg::SvgPoint { unsafe { crate::dll::AzSvgQuadraticCurve_getStart(self) } }
/// Returns the ending point of this item
Expand All @@ -16197,6 +16210,8 @@ pub mod svg {

#[doc(inline)] pub use crate::dll::AzSvgCubicCurve as SvgCubicCurve;
impl SvgCubicCurve {
/// Reverses the order of points in the curve so that the curve runs in the opposite direction afterwards
pub fn reverse(&mut self) { unsafe { crate::dll::AzSvgCubicCurve_reverse(self) } }
/// Returns the starting point of this item
pub fn get_start(&self) -> crate::svg::SvgPoint { unsafe { crate::dll::AzSvgCubicCurve_getStart(self) } }
/// Returns the ending point of this item
Expand Down
55 changes: 44 additions & 11 deletions azul-core/src/svg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ pub struct SvgLine {
}

impl SvgLine {
pub fn reverse(&mut self) {
let temp = self.start;
self.start = self.end;
self.end = temp;
}
pub fn get_start(&self) -> SvgPoint { self.start }
pub fn get_end(&self) -> SvgPoint { self.end }

Expand Down Expand Up @@ -94,6 +99,13 @@ pub enum SvgPathElement {
}

impl SvgPathElement {
pub fn reverse(&mut self) {
match self {
SvgPathElement::Line(l) => l.reverse(),
SvgPathElement::QuadraticCurve(qc) => qc.reverse(),
SvgPathElement::CubicCurve(cc) => cc.reverse(),
}
}
pub fn get_start(&self) -> SvgPoint {
match self {
SvgPathElement::Line(l) => l.get_start(),
Expand Down Expand Up @@ -164,6 +176,38 @@ pub struct SvgPath {
pub items: SvgPathElementVec,
}

impl SvgPath {
pub fn is_closed(&self) -> bool {
let first = self.items.as_ref().first();
let last = self.items.as_ref().last();
match (first, last) {
(Some(f), Some(l)) => (f.get_start() == l.get_end()),
_ => false,
}
}

// reverses the order of elements in the path
pub fn reverse(&mut self) {
// swap self.items with a default vec
let mut vec = SvgPathElementVec::from_const_slice(&[]);
core::mem::swap(&mut vec, &mut self.items);
let mut vec = vec.into_library_owned_vec();

// reverse the order of items in the vec
vec.reverse();

// reverse the order inside the item itself
// i.e. swap line.start and line.end
for item in vec.iter_mut() {
item.reverse();
}

// swap back
let mut vec = SvgPathElementVec::from_vec(vec);
core::mem::swap(&mut vec, &mut self.items);
}
}

#[derive(Debug, Clone, PartialEq, PartialOrd)]
#[repr(C)]
pub struct SvgMultiPolygon {
Expand All @@ -183,17 +227,6 @@ impl_vec_clone!(SvgMultiPolygon, SvgMultiPolygonVec, SvgMultiPolygonVecDestructo
impl_vec_partialeq!(SvgMultiPolygon, SvgMultiPolygonVec);
impl_vec_partialord!(SvgMultiPolygon, SvgMultiPolygonVec);

impl SvgPath {
pub fn is_closed(&self) -> bool {
let first = self.items.as_ref().first();
let last = self.items.as_ref().last();
match (first, last) {
(Some(f), Some(l)) => (f.get_start() == l.get_end()),
_ => false,
}
}
}

/// One `SvgNode` corresponds to one SVG `<path></path>` element
#[derive(Debug, Clone, PartialOrd, PartialEq)]
#[repr(C, u8)]
Expand Down
14 changes: 14 additions & 0 deletions azul-css/src/css_properties.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1464,6 +1464,15 @@ const STEP_SIZE_F32: f32 = 0.05;

impl SvgCubicCurve {

pub fn reverse(&mut self) {
let mut temp = self.start;
self.start = self.end;
self.end = temp;
temp = self.ctrl_1;
self.ctrl_1 = self.ctrl_2;
self.ctrl_2 = temp;
}

pub fn get_start(&self) -> SvgPoint { self.start }
pub fn get_end(&self) -> SvgPoint { self.end }

Expand Down Expand Up @@ -1617,6 +1626,11 @@ pub struct SvgQuadraticCurve {
}

impl SvgQuadraticCurve {
pub fn reverse(&mut self) {
let mut temp = self.start;
self.start = self.end;
self.end = temp;
}
pub fn get_start(&self) -> SvgPoint { self.start }
pub fn get_end(&self) -> SvgPoint { self.end }
pub fn get_bounds(&self) -> SvgRect {
Expand Down
10 changes: 7 additions & 3 deletions azul-css/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,13 @@ macro_rules! impl_vec_as_hashmap {($struct_type:ident, $struct_name:ident) => (
}

pub fn remove_hm_item(&mut self, remove_key: &$struct_type) {
let mut vec = self.clone().into_library_owned_vec();
vec.retain(|v| v == remove_key);
*self = Self::from_vec(vec);
*self = Self::from_vec(
self
.as_ref()
.iter()
.filter_map(|r| if *r == *remove_key { None } else { Some(*r) })
.collect::<Vec<_>>()
);
}

pub fn contains_hm_item(&self, searched: &$struct_type) -> bool {
Expand Down
Loading

0 comments on commit 1983540

Please sign in to comment.