mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-07-10 07:07:19 +00:00
Selects all children of a space when selecting a parent.
This commit is contained in:
@ -7,21 +7,21 @@ class SpacesConnectionsArrowPainter extends CustomPainter {
|
||||
final Map<String, Offset> positions;
|
||||
final double cardWidth = 150.0;
|
||||
final double cardHeight = 90.0;
|
||||
final String? selectedSpaceUuid;
|
||||
final Set<String> highlightedUuids;
|
||||
|
||||
SpacesConnectionsArrowPainter({
|
||||
required this.connections,
|
||||
required this.positions,
|
||||
this.selectedSpaceUuid,
|
||||
required this.highlightedUuids,
|
||||
});
|
||||
|
||||
@override
|
||||
void paint(Canvas canvas, Size size) {
|
||||
for (final connection in connections) {
|
||||
final isSelected = connection.to == selectedSpaceUuid;
|
||||
final isSelected = highlightedUuids.contains(connection.from);
|
||||
final paint = Paint()
|
||||
..color = isSelected
|
||||
? ColorsManager.primaryColor
|
||||
? ColorsManager.blackColor
|
||||
: ColorsManager.blackColor.withValues(alpha: 0.5)
|
||||
..strokeWidth = 2.0
|
||||
..style = PaintingStyle.stroke;
|
||||
@ -46,7 +46,7 @@ class SpacesConnectionsArrowPainter extends CustomPainter {
|
||||
|
||||
final circlePaint = Paint()
|
||||
..color = isSelected
|
||||
? ColorsManager.primaryColor
|
||||
? ColorsManager.blackColor
|
||||
: ColorsManager.blackColor.withValues(alpha: 0.5)
|
||||
..style = PaintingStyle.fill
|
||||
..blendMode = BlendMode.srcIn;
|
||||
|
@ -62,6 +62,15 @@ class _CommunityStructureCanvasState extends State<CommunityStructureCanvas>
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
Set<String> _getAllDescendantUuids(SpaceModel space) {
|
||||
final uuids = <String>{};
|
||||
for (final child in space.children) {
|
||||
uuids.add(child.uuid);
|
||||
uuids.addAll(_getAllDescendantUuids(child));
|
||||
}
|
||||
return uuids;
|
||||
}
|
||||
|
||||
void _runAnimation(Matrix4 target) {
|
||||
final animation = Matrix4Tween(
|
||||
begin: _transformationController.value,
|
||||
@ -174,16 +183,23 @@ class _CommunityStructureCanvasState extends State<CommunityStructureCanvas>
|
||||
|
||||
_calculateLayout(community.spaces, 0, {});
|
||||
|
||||
final selectedSpace = widget.selectedSpace;
|
||||
final highlightedUuids = <String>{};
|
||||
if (selectedSpace != null) {
|
||||
highlightedUuids.add(selectedSpace.uuid);
|
||||
highlightedUuids.addAll(_getAllDescendantUuids(selectedSpace));
|
||||
}
|
||||
|
||||
final widgets = <Widget>[];
|
||||
final connections = <SpaceConnectionModel>[];
|
||||
_generateWidgets(community.spaces, widgets, connections);
|
||||
_generateWidgets(community.spaces, widgets, connections, highlightedUuids);
|
||||
|
||||
return [
|
||||
CustomPaint(
|
||||
painter: SpacesConnectionsArrowPainter(
|
||||
connections: connections,
|
||||
positions: _positions,
|
||||
selectedSpaceUuid: widget.selectedSpace?.uuid,
|
||||
highlightedUuids: highlightedUuids,
|
||||
),
|
||||
child: Stack(alignment: AlignmentDirectional.center, children: widgets),
|
||||
),
|
||||
@ -194,11 +210,15 @@ class _CommunityStructureCanvasState extends State<CommunityStructureCanvas>
|
||||
List<SpaceModel> spaces,
|
||||
List<Widget> widgets,
|
||||
List<SpaceConnectionModel> connections,
|
||||
Set<String> highlightedUuids,
|
||||
) {
|
||||
for (final space in spaces) {
|
||||
final position = _positions[space.uuid];
|
||||
if (position == null) continue;
|
||||
|
||||
final isHighlighted = highlightedUuids.contains(space.uuid);
|
||||
final hasNoSelectedSpace = widget.selectedSpace == null;
|
||||
|
||||
widgets.add(
|
||||
Positioned(
|
||||
left: position.dx,
|
||||
@ -208,11 +228,7 @@ class _CommunityStructureCanvasState extends State<CommunityStructureCanvas>
|
||||
child: SpaceCardWidget(
|
||||
buildSpaceContainer: () {
|
||||
return Opacity(
|
||||
opacity: widget.selectedSpace == null
|
||||
? 1.0
|
||||
: widget.selectedSpace?.uuid != space.uuid
|
||||
? 0.5
|
||||
: 1.0,
|
||||
opacity: hasNoSelectedSpace || isHighlighted ? 1.0 : 0.5,
|
||||
child: SpaceCell(
|
||||
onTap: () => _onSpaceTapped(space),
|
||||
icon: space.icon,
|
||||
@ -229,9 +245,11 @@ class _CommunityStructureCanvasState extends State<CommunityStructureCanvas>
|
||||
);
|
||||
|
||||
for (final child in space.children) {
|
||||
connections.add(SpaceConnectionModel(from: space.uuid, to: child.uuid));
|
||||
connections.add(
|
||||
SpaceConnectionModel(from: space.uuid, to: child.uuid),
|
||||
);
|
||||
}
|
||||
_generateWidgets(space.children, widgets, connections);
|
||||
_generateWidgets(space.children, widgets, connections, highlightedUuids);
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user