add option to update buildCacheExtent

This commit is contained in:
2025-08-15 23:53:45 +00:00
parent 36ceef199b
commit f2f771097b
+11 -2
View File
@@ -14,6 +14,8 @@ import 'package:uuid/uuid.dart';
part 'debug.dart'; part 'debug.dart';
part 'types.dart'; part 'types.dart';
final _kBuildCacheBuffer = Offset(50, 50); // buffer I always add to the input build cache extent
/// Controller for [LazyCanvas] /// Controller for [LazyCanvas]
class LazyCanvasController with ChangeNotifier { class LazyCanvasController with ChangeNotifier {
final Uuid _uuid = Uuid(); final Uuid _uuid = Uuid();
@@ -21,7 +23,7 @@ class LazyCanvasController with ChangeNotifier {
double _baseScale = 1, _scale = 1; double _baseScale = 1, _scale = 1;
late Size _canvasSize; late Size _canvasSize;
final HashMap<CanvasChildId, _ChildInfo> _children = HashMap<CanvasChildId, _ChildInfo>(); // CanvasChildId for IDs final HashMap<CanvasChildId, _ChildInfo> _children = HashMap<CanvasChildId, _ChildInfo>(); // CanvasChildId for IDs
final Offset? _buildCacheExtent; Offset? _buildCacheExtent;
late Offset _buildExtent; late Offset _buildExtent;
final Size _hashCellSize; final Size _hashCellSize;
bool _init = false; bool _init = false;
@@ -53,7 +55,7 @@ class LazyCanvasController with ChangeNotifier {
this.onWidgetEnteredRender, this.onWidgetEnteredRender,
this.onWidgetExitedRender, this.onWidgetExitedRender,
}) : _hashCellSize = hashCellSize, }) : _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 // only top left is considered so if a widget has long width, it'll not be rendered
// unless the cache extent is sufficient // unless the cache extent is sufficient
{ {
@@ -99,6 +101,12 @@ class LazyCanvasController with ChangeNotifier {
_context = context; _context = context;
} }
/// Applied on the next build
void setBuildCacheExtent(Offset extent) {
_buildCacheExtent = extent + _kBuildCacheBuffer;
_buildExtent = Offset(_canvasSize.width, _canvasSize.height) + _buildCacheExtent!;
}
// ==================== Utils ==================== // ==================== Utils ====================
void markDirty() { void markDirty() {
@@ -229,6 +237,7 @@ class LazyCanvasController with ChangeNotifier {
_focusChildOnBuild = null; _focusChildOnBuild = null;
} }
// _renderCacheDirty depends on _markDirty + other stuff
if (!_renderCacheDirty && !forceRebuild) { if (!_renderCacheDirty && !forceRebuild) {
// if the render cache is not dirty, we can use the cached result // if the render cache is not dirty, we can use the cached result
return _lastRenderedWidgets; return _lastRenderedWidgets;