From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [IPv6:2a01:7e0:0:424::9]) by lore.proxmox.com (Postfix) with ESMTPS id C25F51FF13C for ; Thu, 02 Apr 2026 15:53:55 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 5EC9B1BC48; Thu, 2 Apr 2026 15:54:25 +0200 (CEST) From: Dominik Csapak 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 Message-ID: <20260402135348.3516052-1-d.csapak@proxmox.com> X-Mailer: git-send-email 2.47.3 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL -1.451 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment RCVD_IN_VALIDITY_CERTIFIED_BLOCKED 1 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. RCVD_IN_VALIDITY_RPBL_BLOCKED 1 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. RCVD_IN_VALIDITY_SAFE_BLOCKED 1 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Message-ID-Hash: QDGEDY3Z64MNUP24TGQYE7DQV3MSKAX6 X-Message-ID-Hash: QDGEDY3Z64MNUP24TGQYE7DQV3MSKAX6 X-MailFrom: d.csapak@proxmox.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.10 Precedence: list List-Id: Yew framework devel list at Proxmox List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: 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 --- 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` but internally only converts to `f32` with 'as f32` #[derive(Copy, Clone, PartialEq)] pub enum SvgLength { Px(f32), @@ -133,6 +135,12 @@ impl From for SvgLength { } } +impl From for SvgLength { + fn from(v: f64) -> SvgLength { + SvgLength::Px(v as f32) + } +} + impl From for SvgLength { fn from(v: usize) -> SvgLength { SvgLength::Px(v as f32) -- 2.47.3