From aa4aa9ac8a586837f3651bd0ee539883e9c9d723 Mon Sep 17 00:00:00 2001
From: griffi-gh <prasol258@gmail.com>
Date: Tue, 4 Mar 2025 16:46:32 +0100
Subject: [PATCH] implement list_bounds_partial

---
 hui-painter-wip/src/paint/command/list.rs | 17 +++++++++++------
 1 file changed, 11 insertions(+), 6 deletions(-)

diff --git a/hui-painter-wip/src/paint/command/list.rs b/hui-painter-wip/src/paint/command/list.rs
index 15e2c26..658638b 100644
--- a/hui-painter-wip/src/paint/command/list.rs
+++ b/hui-painter-wip/src/paint/command/list.rs
@@ -1,9 +1,6 @@
-use std::hash::Hasher;
-
+use std::{hash::Hasher, ops::RangeFull};
 use hui_shared::rect::Rect;
-
 use crate::PainterInstance;
-
 use super::PaintCommand;
 
 pub struct PaintList {
@@ -56,12 +53,20 @@ impl PaintCommand for PaintList {
   }
 
   fn bounds(&self, ctx: &PainterInstance) -> Rect {
-    if self.commands.is_empty() {
+    self.list_bounds_partial(ctx, ..)
+  }
+}
+
+impl PaintList {
+  /// Get the bounds of a range of commands stored in this list
+  pub fn list_bounds_partial(&self, ctx: &PainterInstance, range: RangeFull) -> Rect {
+    let selector = &self.commands[range];
+    if selector.is_empty() {
       return Rect::ZERO;
     }
     let mut position = glam::Vec2::splat(f32::MAX);
     let mut size = glam::Vec2::splat(f32::MIN);
-    for command in &self.commands {
+    for command in selector {
       let bounds = command.bounds(ctx);
       position = position.min(bounds.position);
       size = size.max(bounds.size);