From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gate001.proxmox.com (gate001.proxmox.com [45.144.208.40]) by lore.proxmox.com (Postfix) with ESMTPS id BCA951FF129 for ; Fri, 17 Jul 2026 14:55:59 +0200 (CEST) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id 7F04321419; Fri, 17 Jul 2026 14:55:59 +0200 (CEST) From: Dominik Csapak To: yew-devel@lists.proxmox.com Subject: [PATCH yew-widget-toolkit 4/4] dom: align: fix fallback check for placements Date: Fri, 17 Jul 2026 14:55:31 +0200 Message-ID: <20260717125555.2898147-5-d.csapak@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260717125555.2898147-1-d.csapak@proxmox.com> References: <20260717125555.2898147-1-d.csapak@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.282 Adjusted score from AWL reputation of From: address DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment (newer systems) RCVD_IN_DNSWL_LOW -0.7 Sender listed at https://www.dnswl.org/, low trust 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: LKHWMLFJEUAQRF44DYWC4QI73XD2GNBV X-Message-ID-Hash: LKHWMLFJEUAQRF44DYWC4QI73XD2GNBV 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: 'try_fit_rect' takes a 'has_fallback' parameter, and it was intended that this is false only for the last placement in the list. Since `skip(1)` was done before `enumerate()`, the index was off by one. Also the index is always smaller than `len()` so we have to compensate by 1 for that. Fix this by changing the order of `enumerate` and `skip` so the index is the 'correct' one, and add +1 before checking against the length. While at it, reuse `num_placements` instead of calculating the length again. Signed-off-by: Dominik Csapak --- src/dom/align.rs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/dom/align.rs b/src/dom/align.rs index a20cc6e..7d7fea8 100644 --- a/src/dom/align.rs +++ b/src/dom/align.rs @@ -480,16 +480,15 @@ where ); // try fallback placements if the first one does not fit - if options.placements.len() > 1 && !fits(&rect, &window_rect, &options.placements[0].direction) - { - for (idx, placement) in options.placements.iter().skip(1).enumerate() { + if num_placements > 1 && !fits(&rect, &window_rect, &options.placements[0].direction) { + for (idx, placement) in options.placements.iter().enumerate().skip(1) { let new_rect = try_fit_rect( &base, &element, &window_rect, placement, options.offset, - idx < num_placements, + idx + 1 < num_placements, ); if fits(&new_rect, &window_rect, &placement.direction) { -- 2.47.3