From 87ecc0f250129d3b4c33fd3e4ba322185c67755b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sch=C3=BCtt?= Date: Fri, 12 Jan 2024 20:37:28 +0100 Subject: [PATCH] Add SvgRect::expand --- api.json | 11 +++++++++++ api/c/azul.h | 1 + api/cpp/azul.hpp | 1 + api/rust/src/lib.rs | 4 ++++ azul-css/src/css_properties.rs | 11 +++++++++++ azul-dll/src/lib.rs | 2 ++ azul-dll/src/python.rs | 9 +++++++++ 7 files changed, 39 insertions(+) diff --git a/api.json b/api.json index 8a28c838..14727beb 100644 --- a/api.json +++ b/api.json @@ -12643,6 +12643,17 @@ "returns": {"type": "bool"}, "fn_body": "svgrect.contains_point(point.x, point.y)" }, + "expand": { + "fn_args": [ + {"self": "ref"}, + {"padding_top": "f32"}, + {"padding_bottom": "f32"}, + {"padding_left": "f32"}, + {"padding_right": "f32"} + ], + "returns": {"type": "SvgRect"}, + "fn_body": "svgrect.expand(padding_top, padding_bottom, padding_left, padding_right)" + }, "tessellate_fill": { "fn_args": [ {"self": "ref"}, diff --git a/api/c/azul.h b/api/c/azul.h index afad82f9..1dd031ee 100644 --- a/api/c/azul.h +++ b/api/c/azul.h @@ -13185,6 +13185,7 @@ extern DLLIMPORT AzSvgVector AzSvgCubicCurve_getTangentVectorAtT(const AzSvgCubi extern DLLIMPORT AzTessellatedSvgNode AzSvgCubicCurve_tessellateStroke(const AzSvgCubicCurve* svgcubiccurve, AzSvgStrokeStyle stroke_style); extern DLLIMPORT AzSvgPoint AzSvgRect_getCenter(const AzSvgRect* svgrect); extern DLLIMPORT bool AzSvgRect_containsPoint(const AzSvgRect* svgrect, AzSvgPoint point); +extern DLLIMPORT AzSvgRect AzSvgRect_expand(const AzSvgRect* svgrect, float padding_top, float padding_bottom, float padding_left, float padding_right); extern DLLIMPORT AzTessellatedSvgNode AzSvgRect_tessellateFill(const AzSvgRect* svgrect, AzSvgFillStyle fill_style); extern DLLIMPORT AzTessellatedSvgNode AzSvgRect_tessellateStroke(const AzSvgRect* svgrect, AzSvgStrokeStyle stroke_style); extern DLLIMPORT AzTessellatedSvgNode AzTessellatedSvgNode_empty(); diff --git a/api/cpp/azul.hpp b/api/cpp/azul.hpp index 9b8c2cae..97b88644 100644 --- a/api/cpp/azul.hpp +++ b/api/cpp/azul.hpp @@ -11046,6 +11046,7 @@ namespace dll { TessellatedSvgNode SvgCubicCurve_tessellateStroke(const SvgCubicCurve* svgcubiccurve, AzSvgStrokeStyle stroke_style); SvgPoint SvgRect_getCenter(const SvgRect* svgrect); bool SvgRect_containsPoint(const SvgRect* svgrect, AzSvgPoint point); + SvgRect SvgRect_expand(const SvgRect* svgrect, float padding_top, float padding_bottom, float padding_left, float padding_right); TessellatedSvgNode SvgRect_tessellateFill(const SvgRect* svgrect, AzSvgFillStyle fill_style); TessellatedSvgNode SvgRect_tessellateStroke(const SvgRect* svgrect, AzSvgStrokeStyle stroke_style); TessellatedSvgNode TessellatedSvgNode_empty(); diff --git a/api/rust/src/lib.rs b/api/rust/src/lib.rs index 138774e6..4581be08 100644 --- a/api/rust/src/lib.rs +++ b/api/rust/src/lib.rs @@ -11157,6 +11157,7 @@ mod dll { pub(crate) fn AzSvgCubicCurve_tessellateStroke(svgcubiccurve: &AzSvgCubicCurve, stroke_style: AzSvgStrokeStyle) -> AzTessellatedSvgNode { unsafe { transmute(azul::AzSvgCubicCurve_tessellateStroke(transmute(svgcubiccurve), transmute(stroke_style))) } } pub(crate) fn AzSvgRect_getCenter(svgrect: &AzSvgRect) -> AzSvgPoint { unsafe { transmute(azul::AzSvgRect_getCenter(transmute(svgrect))) } } pub(crate) fn AzSvgRect_containsPoint(svgrect: &AzSvgRect, point: AzSvgPoint) -> bool { unsafe { transmute(azul::AzSvgRect_containsPoint(transmute(svgrect), transmute(point))) } } + pub(crate) fn AzSvgRect_expand(svgrect: &AzSvgRect, padding_top: f32, padding_bottom: f32, padding_left: f32, padding_right: f32) -> AzSvgRect { unsafe { transmute(azul::AzSvgRect_expand(transmute(svgrect), transmute(padding_top), transmute(padding_bottom), transmute(padding_left), transmute(padding_right))) } } pub(crate) fn AzSvgRect_tessellateFill(svgrect: &AzSvgRect, fill_style: AzSvgFillStyle) -> AzTessellatedSvgNode { unsafe { transmute(azul::AzSvgRect_tessellateFill(transmute(svgrect), transmute(fill_style))) } } pub(crate) fn AzSvgRect_tessellateStroke(svgrect: &AzSvgRect, stroke_style: AzSvgStrokeStyle) -> AzTessellatedSvgNode { unsafe { transmute(azul::AzSvgRect_tessellateStroke(transmute(svgrect), transmute(stroke_style))) } } pub(crate) fn AzTessellatedSvgNode_empty() -> AzTessellatedSvgNode { unsafe { transmute(azul::AzTessellatedSvgNode_empty()) } } @@ -11994,6 +11995,7 @@ mod dll { pub(crate) fn AzSvgCubicCurve_tessellateStroke(_: &AzSvgCubicCurve, _: AzSvgStrokeStyle) -> AzTessellatedSvgNode; pub(crate) fn AzSvgRect_getCenter(_: &AzSvgRect) -> AzSvgPoint; pub(crate) fn AzSvgRect_containsPoint(_: &AzSvgRect, _: AzSvgPoint) -> bool; + pub(crate) fn AzSvgRect_expand(_: &AzSvgRect, _: f32, _: f32, _: f32, _: f32) -> AzSvgRect; pub(crate) fn AzSvgRect_tessellateFill(_: &AzSvgRect, _: AzSvgFillStyle) -> AzTessellatedSvgNode; pub(crate) fn AzSvgRect_tessellateStroke(_: &AzSvgRect, _: AzSvgStrokeStyle) -> AzTessellatedSvgNode; pub(crate) fn AzTessellatedSvgNode_empty() -> AzTessellatedSvgNode; @@ -18139,6 +18141,8 @@ pub mod svg { pub fn get_center(&self) -> crate::svg::SvgPoint { unsafe { crate::dll::AzSvgRect_getCenter(self) } } /// Calls the `SvgRect::contains_point` function. pub fn contains_point<_1: Into>(&self, point: _1) -> bool { unsafe { crate::dll::AzSvgRect_containsPoint(self, point.into()) } } + /// Calls the `SvgRect::expand` function. + pub fn expand(&self, padding_top: f32, padding_bottom: f32, padding_left: f32, padding_right: f32) -> crate::svg::SvgRect { unsafe { crate::dll::AzSvgRect_expand(self, padding_top, padding_bottom, padding_left, padding_right) } } /// Calls the `SvgRect::tessellate_fill` function. pub fn tessellate_fill<_1: Into>(&self, fill_style: _1) -> crate::svg::TessellatedSvgNode { unsafe { crate::dll::AzSvgRect_tessellateFill(self, fill_style.into()) } } /// Calls the `SvgRect::tessellate_stroke` function. diff --git a/azul-css/src/css_properties.rs b/azul-css/src/css_properties.rs index 0684ddcb..47b74cd8 100644 --- a/azul-css/src/css_properties.rs +++ b/azul-css/src/css_properties.rs @@ -1904,6 +1904,17 @@ impl SvgRect { x > self.x && x < self.x + self.width && y > self.y && y < self.y + self.height } + /// Expands the rect with a certain amount of padding + pub fn expand(&self, padding_top: f32, padding_bottom: f32, padding_left: f32, padding_right: f32) -> SvgRect { + SvgRect { + width: self.width + padding_left + padding_right, + height: self.height + padding_top + padding_bottom, + x: self.x - padding_left, + y: self.y - padding_top, + .. *self + } + } + pub fn get_center(&self) -> SvgPoint { SvgPoint { x: self.x + (self.width / 2.0), diff --git a/azul-dll/src/lib.rs b/azul-dll/src/lib.rs index f960fe76..413188db 100644 --- a/azul-dll/src/lib.rs +++ b/azul-dll/src/lib.rs @@ -3678,6 +3678,8 @@ pub use AzSvgRectTT as AzSvgRect; #[no_mangle] pub extern "C" fn AzSvgRect_getCenter(svgrect: &AzSvgRect) -> AzSvgPoint { svgrect.get_center() } /// Equivalent to the Rust `SvgRect::contains_point()` function. #[no_mangle] pub extern "C" fn AzSvgRect_containsPoint(svgrect: &AzSvgRect, point: AzSvgPoint) -> bool { svgrect.contains_point(point.x, point.y) } +/// Equivalent to the Rust `SvgRect::expand()` function. +#[no_mangle] pub extern "C" fn AzSvgRect_expand(svgrect: &AzSvgRect, padding_top: f32, padding_bottom: f32, padding_left: f32, padding_right: f32) -> AzSvgRect { svgrect.expand(padding_top, padding_bottom, padding_left, padding_right) } /// Equivalent to the Rust `SvgRect::tessellate_fill()` function. #[no_mangle] pub extern "C" fn AzSvgRect_tessellateFill(svgrect: &AzSvgRect, fill_style: AzSvgFillStyle) -> AzTessellatedSvgNode { azul_impl::svg::tessellate_rect_fill(svgrect, fill_style) } /// Equivalent to the Rust `SvgRect::tessellate_stroke()` function. diff --git a/azul-dll/src/python.rs b/azul-dll/src/python.rs index ab6349b4..302480e6 100644 --- a/azul-dll/src/python.rs +++ b/azul-dll/src/python.rs @@ -31868,6 +31868,15 @@ impl AzSvgRect { mem::transmute(point), )) } } + fn expand(&self, padding_top: f32, padding_bottom: f32, padding_left: f32, padding_right: f32) -> AzSvgRect { + unsafe { mem::transmute(crate::AzSvgRect_expand( + mem::transmute(self), + mem::transmute(padding_top), + mem::transmute(padding_bottom), + mem::transmute(padding_left), + mem::transmute(padding_right), + )) } + } fn tessellate_fill(&self, fill_style: AzSvgFillStyle) -> AzTessellatedSvgNode { unsafe { mem::transmute(crate::AzSvgRect_tessellateFill( mem::transmute(self),