From f2f771097b310e022252d96164fcbf444e82ac1f Mon Sep 17 00:00:00 2001 From: ruinivist Date: Fri, 15 Aug 2025 23:53:45 +0000 Subject: [PATCH] add option to update buildCacheExtent --- lib/core/controller/controller.dart | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/lib/core/controller/controller.dart b/lib/core/controller/controller.dart index 7286dc8..5b6c3d1 100644 --- a/lib/core/controller/controller.dart +++ b/lib/core/controller/controller.dart @@ -14,6 +14,8 @@ import 'package:uuid/uuid.dart'; part 'debug.dart'; part 'types.dart'; +final _kBuildCacheBuffer = Offset(50, 50); // buffer I always add to the input build cache extent + /// Controller for [LazyCanvas] class LazyCanvasController with ChangeNotifier { final Uuid _uuid = Uuid(); @@ -21,7 +23,7 @@ class LazyCanvasController with ChangeNotifier { double _baseScale = 1, _scale = 1; late Size _canvasSize; final HashMap _children = HashMap(); // CanvasChildId for IDs - final Offset? _buildCacheExtent; + Offset? _buildCacheExtent; late Offset _buildExtent; final Size _hashCellSize; bool _init = false; @@ -53,7 +55,7 @@ class LazyCanvasController with ChangeNotifier { this.onWidgetEnteredRender, this.onWidgetExitedRender, }) : _hashCellSize = hashCellSize, - _buildCacheExtent = buildCacheExtent != null ? buildCacheExtent + Offset(50, 50) : null + _buildCacheExtent = buildCacheExtent != null ? buildCacheExtent + _kBuildCacheBuffer : null // only top left is considered so if a widget has long width, it'll not be rendered // unless the cache extent is sufficient { @@ -99,6 +101,12 @@ class LazyCanvasController with ChangeNotifier { _context = context; } + /// Applied on the next build + void setBuildCacheExtent(Offset extent) { + _buildCacheExtent = extent + _kBuildCacheBuffer; + _buildExtent = Offset(_canvasSize.width, _canvasSize.height) + _buildCacheExtent!; + } + // ==================== Utils ==================== void markDirty() { @@ -229,6 +237,7 @@ class LazyCanvasController with ChangeNotifier { _focusChildOnBuild = null; } + // _renderCacheDirty depends on _markDirty + other stuff if (!_renderCacheDirty && !forceRebuild) { // if the render cache is not dirty, we can use the cached result return _lastRenderedWidgets;