rename + add docs

This commit is contained in:
2025-07-07 21:40:37 +00:00
parent 5d7152ee05
commit 44e1fd3abc
12 changed files with 36 additions and 29 deletions
+3 -3
View File
@@ -1,5 +1,5 @@
import 'package:flutter/material.dart';
import 'package:infinite_lazy_2d_grid/infinite_lazy_2d_grid.dart';
import 'package:infinite_lazy_grid/infinite_lazy_grid.dart';
import 'widgets/fps.dart';
@@ -11,7 +11,7 @@ class App extends StatefulWidget {
}
class _AppState extends State<App> {
final CanvasController controller = CanvasController(debug: true);
final LazyCanvasController controller = LazyCanvasController(debug: true);
@override
void initState() {
@@ -53,7 +53,7 @@ class _AppState extends State<App> {
),
body: Stack(
children: [
CanvasView(controller: controller, canvasBackground: SingleColorBackround(Colors.white)),
LazyCanvas(controller: controller, canvasBackground: SingleColorBackround(Colors.white)),
Positioned(bottom: 64, left: 16, child: Fps()),
],
),
+1 -1
View File
@@ -1,4 +1,4 @@
import 'package:example/app.dart';
import './app.dart';
import 'package:flutter/material.dart';
void main() {
+1 -1
View File
@@ -75,7 +75,7 @@ packages:
description: flutter
source: sdk
version: "0.0.0"
infinite_lazy_2d_grid:
infinite_lazy_grid:
dependency: "direct main"
description:
path: ".."
+1 -1
View File
@@ -11,7 +11,7 @@ dependencies:
flutter:
sdk: flutter
cupertino_icons: ^1.0.8
infinite_lazy_2d_grid:
infinite_lazy_grid:
path: ..
dev_dependencies:
+2
View File
@@ -1,5 +1,7 @@
import 'package:flutter/material.dart';
import './render.dart';
/// Abstract definition for a [LazyCanvas] background.
abstract class CanvasBackground {
/// the fill color of background
final Color bgColor;
+9 -5
View File
@@ -1,18 +1,19 @@
import 'dart:collection';
import 'package:flutter/material.dart';
import 'package:infinite_lazy_2d_grid/utils/measure_size.dart';
import '../../utils/measure_size.dart';
import '../spatial_hashing.dart';
import '../../utils/offset_extensions.dart';
import '../../utils/size_extensions.dart';
import '../../utils/conversions.dart';
import '../../utils/styles.dart';
import '../render.dart';
part 'debug.dart';
part 'types.dart';
/// Every canvas view needs one and this handles the positioning logic
class CanvasController with ChangeNotifier {
/// Controller for [LazyCanvas]
class LazyCanvasController with ChangeNotifier {
int _nextId = 0; // surely we won't run out of IDs, Clueless
Offset _gsTopLeftOffset = Offset.zero;
Offset? _lastProcessedOffset;
@@ -30,7 +31,7 @@ class CanvasController with ChangeNotifier {
bool debug;
CanvasController({this.debug = false, Offset? buildCacheExtent, Size hashCellSize = const Size(100, 100)})
LazyCanvasController({this.debug = false, Offset? buildCacheExtent, Size hashCellSize = const Size(100, 100)})
: _hashCellSize = hashCellSize,
_buildCacheExtent = buildCacheExtent != null ? buildCacheExtent + Offset(50, 50) : null
// only top left is considered so if a widget has long width, it'll not be rendered
@@ -64,10 +65,12 @@ class CanvasController with ChangeNotifier {
}
}
/// Called when a child widget's size changes.
void onChildSizeChange(int id, Size size) {
_children[id]!.lastRenderedSize = size;
}
/// Set the ticker provider for animations.
void setTickerProvider(TickerProvider ticker) {
_ticker = ticker;
}
@@ -139,7 +142,7 @@ class CanvasController with ChangeNotifier {
notifyListeners();
}
/// Increment or decrement the scale by a delta value.
/// Increment or decrement the scale by an additive delta value.
void updateScalebyDelta(double delta) {
final focalPoint = Offset(canvasSize.width / 2, canvasSize.height / 2);
final newScale = _scale + delta;
@@ -259,6 +262,7 @@ class CanvasController with ChangeNotifier {
// ==================== Animation ====================
/// Animate the canvas to a new offset and scale
Future<void> animateToOffsetAndScale({
required Offset offset,
required double scale,
+9 -8
View File
@@ -1,23 +1,24 @@
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:infinite_lazy_2d_grid/core/controller/controller.dart';
import 'package:infinite_lazy_2d_grid/utils/offset_extensions.dart';
import 'package:infinite_lazy_2d_grid/utils/styles.dart';
import '../utils/offset_extensions.dart';
import '../utils/styles.dart';
import 'background.dart';
import 'controller/controller.dart';
/// An infinite canvas that places all the children at the specified positions.
class CanvasView extends StatefulWidget {
/// Needs a [LazyCanvasController] to control the canvas and a [CanvasBackground] to draw the background.
class LazyCanvas extends StatefulWidget {
final CanvasBackground canvasBackground;
final CanvasController controller;
final LazyCanvasController controller;
const CanvasView({required this.controller, required this.canvasBackground, super.key});
const LazyCanvas({required this.controller, required this.canvasBackground, super.key});
@override
State<CanvasView> createState() => _CanvasViewState();
State<LazyCanvas> createState() => _LazyCanvasState();
}
class _CanvasViewState extends State<CanvasView> with TickerProviderStateMixin<CanvasView> {
class _LazyCanvasState extends State<LazyCanvas> with TickerProviderStateMixin<LazyCanvas> {
@override
void initState() {
super.initState();
+2
View File
@@ -12,6 +12,8 @@ class PointData<T> {
PointData(this.point, this.data);
}
/// Data structure for spatial hashing to get widgets to be built quickly
/// based on their position in a 2D grid.
class SpatialHashing<T> {
final Size cellSize;
final HashMap<Point, T> _pointData = HashMap<Point, T>();
+1 -1
View File
@@ -1,4 +1,4 @@
name: infinite_lazy_2d_grid
name: infinite_lazy_grid
description: "A new Flutter package project."
version: 0.0.1
homepage:
+6 -8
View File
@@ -1,8 +1,6 @@
import 'package:flutter_test/flutter_test.dart';
import 'package:flutter/material.dart';
import 'package:infinite_lazy_2d_grid/core/render.dart';
import 'package:infinite_lazy_2d_grid/core/controller/controller.dart';
import 'package:infinite_lazy_2d_grid/core/background.dart';
import 'package:infinite_lazy_grid/infinite_lazy_grid.dart';
class TestChild extends StatelessWidget {
final int index;
@@ -15,14 +13,14 @@ class TestChild extends StatelessWidget {
void main() {
testWidgets('CanvasView renders only visible children and reduces count on zoom out', (WidgetTester tester) async {
final controller = CanvasController(debug: true);
final controller = LazyCanvasController(debug: true);
for (int i = 0; i < 10000; i++) {
controller.addChild(Offset((i % 80) * 100.0, (i ~/ 80) * 100.0), (_) => TestChild(index: i));
}
await tester.pumpWidget(
MaterialApp(
home: Scaffold(
body: CanvasView(controller: controller, canvasBackground: SingleColorBackround(Colors.white)),
body: LazyCanvas(controller: controller, canvasBackground: SingleColorBackround(Colors.white)),
),
),
);
@@ -46,18 +44,18 @@ void main() {
});
testWidgets('CanvasView scales as expected', (WidgetTester tester) async {
final controller = CanvasController(debug: true);
final controller = LazyCanvasController(debug: true);
controller.addChild(const Offset(0, 0), (_) => TestChild(index: 0));
controller.addChild(const Offset(100, 100), (_) => TestChild(index: 1));
await tester.pumpWidget(
MaterialApp(
home: Scaffold(
body: CanvasView(controller: controller, canvasBackground: SingleColorBackround(Colors.white)),
body: LazyCanvas(controller: controller, canvasBackground: SingleColorBackround(Colors.white)),
),
),
);
await tester.pumpAndSettle();
final context = tester.element(find.byType(CanvasView));
final context = tester.element(find.byType(LazyCanvas));
// Initial size check
final finder = find.byType(TestChild);
+1 -1
View File
@@ -1,5 +1,5 @@
import 'package:flutter_test/flutter_test.dart';
import 'package:infinite_lazy_2d_grid/core/spatial_hashing.dart';
import 'package:infinite_lazy_grid/core/spatial_hashing.dart';
import 'dart:math';
import 'package:flutter/material.dart';