adjust the canvas if spaces are far positioned

This commit is contained in:
hannathkadher
2024-11-19 12:37:57 +04:00
parent 20f94e290d
commit 3147fc154f
2 changed files with 18 additions and 19 deletions

View File

@ -38,6 +38,7 @@ class _CommunityStructureAreaState extends State<CommunityStructureArea> {
super.initState();
spaces = widget.spaces.isNotEmpty ? flattenSpaces(widget.spaces) : [];
connections = widget.spaces.isNotEmpty ? createConnections(widget.spaces) : [];
_adjustCanvasSizeForSpaces();
}
@override
@ -48,10 +49,8 @@ class _CommunityStructureAreaState extends State<CommunityStructureArea> {
setState(() {
spaces = widget.spaces.isNotEmpty ? flattenSpaces(widget.spaces) : [];
connections = widget.spaces.isNotEmpty ? createConnections(widget.spaces) : [];
_adjustCanvasSizeForSpaces();
});
for (var space in spaces) {
print('InitState - Space Position ${space.name}: ${space.incomingConnection?.direction}');
}
}
}
@ -213,6 +212,18 @@ class _CommunityStructureAreaState extends State<CommunityStructureArea> {
});
}
void _adjustCanvasSizeForSpaces() {
for (var space in spaces) {
if (space.position.dx >= canvasWidth - 200) {
canvasWidth = space.position.dx + 200;
}
if (space.position.dy >= canvasHeight - 200) {
canvasHeight = space.position.dy + 200;
}
}
}
void _showCreateSpaceDialog(Size screenSize,
{Offset? position, int? parentIndex, String? direction}) {
showDialog(
@ -323,14 +334,6 @@ class _CommunityStructureAreaState extends State<CommunityStructureArea> {
List<SpaceModel> spaceList = spaces;
String communityUuid = widget.selectedCommunity!.uuid;
for (var space in spaceList) {
print("Processing space: ${space.name}, UUID: ${space.uuid}");
// Example: Log connections
print("Parent UUID: ${space.parent?.uuid}");
print("Incoming connection: ${space.incomingConnection?.direction}");
print("Outgoing connections: ${space.outgoingConnections.map((c) => c.direction).toList()}");
}
// Dispatch the save event
context.read<SpaceManagementBloc>().add(SaveSpacesEvent(
spaces: spaceList,