Skip to content

Commit f191672

Browse files
committed
Refactor positioning calculation and relocate node sizing methods
This commit modifies positioning logic, specifically the calculation of offsets and pin locations. Methods for retrieving the widest and tallest children from a list of nodes were moved from `passive_stack_transformer.dart` to `utils.dart` for better organization and easier code reuse. New checks were introduced in `freeform_decorators.dart` to prevent illegal positions outside parent bounds in wrapped nodes. Other minor changes were made in several files to accommodate these primary changes.
1 parent baae745 commit f191672

File tree

2 files changed

+46
-45
lines changed

2 files changed

+46
-45
lines changed

lib/src/transformers/node_transformers/passive_stack_transformer.dart

Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -6,50 +6,6 @@ import '../../../codelessly_sdk.dart';
66
class PassiveStackTransformer extends NodeWidgetTransformer<BaseNode> {
77
PassiveStackTransformer(super.getNode, super.manager);
88

9-
/// Retrieves the widest child from given [siblings].
10-
static BaseNode? getWidestNode(List<BaseNode> siblings) {
11-
if (siblings.isEmpty) return null;
12-
13-
return siblings.reduce((a, b) {
14-
// If one of the siblings has alignment, while the other does not,
15-
// return the one with alignment.
16-
if (a.alignment != AlignmentModel.none &&
17-
b.alignment == AlignmentModel.none) {
18-
return a;
19-
}
20-
if (b.alignment != AlignmentModel.none &&
21-
a.alignment == AlignmentModel.none) {
22-
return b;
23-
}
24-
25-
// If both siblings have alignment or both do not have alignment, compare
26-
// their widths.
27-
return a.basicBoxLocal.width > b.basicBoxLocal.width ? a : b;
28-
});
29-
}
30-
31-
/// Retrieves the tallest child from given [siblings].
32-
static BaseNode? getTallestNode(List<BaseNode> siblings) {
33-
if (siblings.isEmpty) return null;
34-
35-
return siblings.reduce((a, b) {
36-
// If one of the siblings has alignment, while the other does not,
37-
// return the one with alignment.
38-
if (a.alignment != AlignmentModel.none &&
39-
b.alignment == AlignmentModel.none) {
40-
return a;
41-
}
42-
if (b.alignment != AlignmentModel.none &&
43-
a.alignment == AlignmentModel.none) {
44-
return b;
45-
}
46-
47-
// If both siblings have alignment or both do not have alignment, compare
48-
// their heights.
49-
return a.basicBoxLocal.height > b.basicBoxLocal.height ? a : b;
50-
});
51-
}
52-
539
static Widget buildStackChild(
5410
BaseNode node,
5511
BaseNode parent,

lib/src/utils/utils.dart

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,9 +316,54 @@ T? mostCommon<T>(List<T> list) {
316316
final sortedEntries = counts.entries.toList()
317317
..sort((a, b) => b.value.compareTo(a.value));
318318

319-
if (sortedEntries.length > 1 && sortedEntries[0].value == sortedEntries[1].value) {
319+
if (sortedEntries.length > 1 &&
320+
sortedEntries[0].value == sortedEntries[1].value) {
320321
return null;
321322
}
322323

323324
return sortedEntries.first.key;
324325
}
326+
327+
/// Retrieves the widest child from given [siblings].
328+
BaseNode? getWidestNode(List<BaseNode> siblings) {
329+
if (siblings.isEmpty) return null;
330+
331+
return siblings.reduce((a, b) {
332+
// If one of the siblings has alignment, while the other does not,
333+
// return the one with alignment.
334+
if (a.alignment != AlignmentModel.none &&
335+
b.alignment == AlignmentModel.none) {
336+
return a;
337+
}
338+
if (b.alignment != AlignmentModel.none &&
339+
a.alignment == AlignmentModel.none) {
340+
return b;
341+
}
342+
343+
// If both siblings have alignment or both do not have alignment, compare
344+
// their widths.
345+
return a.basicBoxLocal.width > b.basicBoxLocal.width ? a : b;
346+
});
347+
}
348+
349+
/// Retrieves the tallest child from given [siblings].
350+
BaseNode? getTallestNode(List<BaseNode> siblings) {
351+
if (siblings.isEmpty) return null;
352+
353+
return siblings.reduce((a, b) {
354+
// If one of the siblings has alignment, while the other does not,
355+
// return the one with alignment.
356+
if (a.alignment != AlignmentModel.none &&
357+
b.alignment == AlignmentModel.none) {
358+
return a;
359+
}
360+
if (b.alignment != AlignmentModel.none &&
361+
a.alignment == AlignmentModel.none) {
362+
return b;
363+
}
364+
365+
// If both siblings have alignment or both do not have alignment, compare
366+
// their heights.
367+
return a.basicBoxLocal.height > b.basicBoxLocal.height ? a : b;
368+
});
369+
}

0 commit comments

Comments
 (0)