From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) by lore.proxmox.com (Postfix) with ESMTPS id 3F9471FF142 for ; Tue, 05 May 2026 09:32:41 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 12F071816B; Tue, 5 May 2026 09:32:41 +0200 (CEST) From: Dominik Csapak To: pdm-devel@lists.proxmox.com Subject: [PATCH yew-widget-toolkit v2 1/3] js-helper: add client-to-svg-coordinate conversion helper Date: Tue, 5 May 2026 09:31:52 +0200 Message-ID: <20260505073203.398548-2-d.csapak@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260505073203.398548-1-d.csapak@proxmox.com> References: <20260505073203.398548-1-d.csapak@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.050 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 SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [lib.rs] Message-ID-Hash: Y2BDMC3M27CM77WQHT66FVIHQXOG5KEB X-Message-ID-Hash: Y2BDMC3M27CM77WQHT66FVIHQXOG5KEB 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: Proxmox Datacenter Manager development discussion List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: Doing this in rust would mean we have to expose additional web-sys features or doing the binding ourselves. Also since error handling for the necessary code would be longer than the actual two line javascript code, just have a short helper here. This will be used in the upcoming Map widget to convert from pointer position to svg coordinates. Signed-off-by: Dominik Csapak --- js-helper-module.js | 7 +++++++ src/lib.rs | 5 +++++ 2 files changed, 12 insertions(+) diff --git a/js-helper-module.js b/js-helper-module.js index 838c987..53291f3 100644 --- a/js-helper-module.js +++ b/js-helper-module.js @@ -31,6 +31,12 @@ function toggle_popover(popover) { popover.togglePopover(); } +function client_to_svg_coords(svg, x, y) { + const pt = new DOMPoint(x, y); + const svgPt = pt.matrixTransform(svg.getScreenCTM().inverse()); + return [svgPt.x, svgPt.y]; +} + export { test_alert, show_dialog, @@ -39,4 +45,5 @@ export { hide_popover, show_popover, toggle_popover, + client_to_svg_coords, }; diff --git a/src/lib.rs b/src/lib.rs index d3ac6ea..bd51b0d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -297,6 +297,7 @@ extern "C" { pub fn show_popover(popover: web_sys::Node); pub fn hide_popover(popover: web_sys::Node); pub fn toggle_popover(popover: web_sys::Node); + pub fn client_to_svg_coords(svg: &web_sys::Node, x: f64, y: f64) -> Vec; } // Create wrapper which panics if called from target_arch!=wasm32 @@ -329,6 +330,10 @@ mod panic_wrapper { pub fn toggle_popover(_popover: web_sys::Node) { unreachable!() } + /// Calculate the svg coordinates from viewport ones + pub fn client_to_svg_coords(_svg: &web_sys::Node, _x: f64, _y: f64) -> Vec { + unreachable!() + } } // some helpers -- 2.47.3