all lists on lists.proxmox.com
 help / color / mirror / Atom feed
From: Dominik Csapak <d.csapak@proxmox.com>
To: yew-devel@lists.proxmox.com
Subject: [PATCH yew-widget-toolkit] widget: svg: allow auto conversion from f64 for `SvgLength`
Date: Thu,  2 Apr 2026 15:53:27 +0200	[thread overview]
Message-ID: <20260402135348.3516052-1-d.csapak@proxmox.com> (raw)

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





                 reply	other threads:[~2026-04-02 13:53 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260402135348.3516052-1-d.csapak@proxmox.com \
    --to=d.csapak@proxmox.com \
    --cc=yew-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal