* [PATCH yew-widget-toolkit] widget: svg: allow auto conversion from f64 for `SvgLength`
@ 2026-04-02 13:53 Dominik Csapak
0 siblings, 0 replies; only message in thread
From: Dominik Csapak @ 2026-04-02 13:53 UTC (permalink / raw)
To: yew-devel
while the minimum required precision (and actual implementation) for svg
length in browsers is single precision (f32) accepting f64 for auto
conversion is more convenient that using 'as f32' everywhere we want
to convert.
Add a warning to the enum itself so it's clear that this loses
precision and possibly cuts of larger values.
Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
---
src/widget/canvas/mod.rs | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/src/widget/canvas/mod.rs b/src/widget/canvas/mod.rs
index 54d9bf3..ff0a1be 100644
--- a/src/widget/canvas/mod.rs
+++ b/src/widget/canvas/mod.rs
@@ -104,6 +104,8 @@ use crate::props::{IntoVTag, WidgetBuilder};
use pwt_macros::widget;
/// SVG length in pixel, em or percentage.
+///
+/// NOTE: implements `From<f64>` but internally only converts to `f32` with 'as f32`
#[derive(Copy, Clone, PartialEq)]
pub enum SvgLength {
Px(f32),
@@ -133,6 +135,12 @@ impl From<f32> for SvgLength {
}
}
+impl From<f64> for SvgLength {
+ fn from(v: f64) -> SvgLength {
+ SvgLength::Px(v as f32)
+ }
+}
+
impl From<usize> for SvgLength {
fn from(v: usize) -> SvgLength {
SvgLength::Px(v as f32)
--
2.47.3
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2026-04-02 13:53 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-04-02 13:53 [PATCH yew-widget-toolkit] widget: svg: allow auto conversion from f64 for `SvgLength` Dominik Csapak
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.