Skip to content

Commit e9e098d

Browse files
authored
Merge pull request #67 from devaryakjha/main
chore(release): stable release
2 parents ab39858 + 905df81 commit e9e098d

File tree

7 files changed

+116
-33
lines changed

7 files changed

+116
-33
lines changed

CHANGELOG.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,27 @@
33
All notable changes to this project will be documented in this file.
44
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
55

6+
## 2025-01-30
7+
8+
### Changes
9+
10+
---
11+
12+
Packages with breaking changes:
13+
14+
- There are no breaking changes in this release.
15+
16+
Packages with other changes:
17+
18+
- [`tagflow_table` - `v0.0.3-dev.0`](#tagflow_table---v003-dev0)
19+
20+
---
21+
22+
#### `tagflow_table` - `v0.0.3-dev.0`
23+
24+
- **FEAT**(tagflow_table): add column and row spacing properties to TagflowTable. ([66989cf5](https://github.com/devaryakjha/tagflow/commit/66989cf5e67805c2b472dcfccd9bed84158fdf8d))
25+
26+
627
## 2025-01-30
728

829
### Changes

examples/tagflow/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ dependencies:
1313
go_router: ^14.6.2
1414
google_fonts: ^6.2.1
1515
tagflow: ^0.0.1-dev.0+1
16-
tagflow_table: ^0.0.2-dev.0+1
16+
tagflow_table: ^0.0.3-dev.0
1717
url_launcher: ^6.3.1
1818

1919
dev_dependencies:

packages/tagflow_table/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 0.0.3-dev.0
2+
3+
- **FEAT**(tagflow_table): add column and row spacing properties to TagflowTable. ([66989cf5](https://github.com/devaryakjha/tagflow/commit/66989cf5e67805c2b472dcfccd9bed84158fdf8d))
4+
15
## 0.0.2+1
26

37
- Graduate package to a stable release. See pre-releases prior to this version for changelog entries.

packages/tagflow_table/lib/src/rendering/tagflow_table.dart

Lines changed: 67 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,10 @@ class RenderTagflowTable extends RenderBox
336336
Color? _headerBackgroundColor;
337337
EdgeInsets _padding = EdgeInsets.zero;
338338
IndexedWidgetBuilder? _separatorBuilder;
339+
double _columnSpacing = 0;
340+
double _rowSpacing = 0;
341+
342+
static const double _minimumColumnWidth = 40; // Adjust as needed
339343

340344
void setSeparatorBuilder(IndexedWidgetBuilder? value) {
341345
if (_separatorBuilder == value) return;
@@ -378,6 +382,18 @@ class RenderTagflowTable extends RenderBox
378382
markNeedsPaint();
379383
}
380384

385+
void setColumnSpacing(double value) {
386+
if (_columnSpacing == value) return;
387+
_columnSpacing = value;
388+
markNeedsLayout();
389+
}
390+
391+
void setRowSpacing(double value) {
392+
if (_rowSpacing == value) return;
393+
_rowSpacing = value;
394+
markNeedsLayout();
395+
}
396+
381397
@override
382398
void setupParentData(RenderBox child) {
383399
if (child.parentData is! TableCellData) {
@@ -392,6 +408,12 @@ class RenderTagflowTable extends RenderBox
392408
return;
393409
}
394410

411+
// Calculate total spacing needed between columns
412+
final totalColumnSpacing = (_columnCount - 1) * _columnSpacing;
413+
414+
// Calculate available width for columns after accounting for spacing and padding
415+
final availableWidth = constraints.maxWidth - totalColumnSpacing - _padding.horizontal;
416+
395417
// First pass: Calculate minimum and preferred column widths
396418
_columnWidths = List<double>.filled(_columnCount, 0);
397419
final columnFlexibility = List<double>.filled(_columnCount, 0);
@@ -407,39 +429,47 @@ class RenderTagflowTable extends RenderBox
407429
// Update minimum widths
408430
for (var i = 0; i < childParentData.colSpan; i++) {
409431
final colIndex = childParentData.column + i;
410-
_columnWidths[colIndex] =
411-
_columnWidths[colIndex].clamp(widthPerColumn, double.infinity);
412-
432+
_columnWidths[colIndex] = math.max(_columnWidths[colIndex], widthPerColumn);
433+
413434
// Track how flexible each column is based on content
414435
final flexibility = (maxWidth - minWidth) / childParentData.colSpan;
415-
columnFlexibility[colIndex] =
416-
math.max(columnFlexibility[colIndex], flexibility);
436+
columnFlexibility[colIndex] = math.max(columnFlexibility[colIndex], flexibility);
417437
}
418438
}
419439
child = childParentData.nextSibling;
420440
}
421441

422-
// Calculate total minimum width and distribute extra space
423-
final totalMinWidth =
424-
_columnWidths.reduce((a, b) => a + b) + _padding.horizontal;
425-
final extraWidth =
426-
(constraints.maxWidth - totalMinWidth).clamp(0.0, double.infinity);
427-
428-
if (extraWidth > 0) {
429-
// Calculate total flexibility
442+
// Calculate total current width and adjust if needed
443+
final totalColumnWidth = _columnWidths.reduce((a, b) => a + b);
444+
445+
if (totalColumnWidth > availableWidth) {
446+
// Need to shrink columns - distribute reduction proportionally
447+
final reduction = totalColumnWidth - availableWidth;
448+
449+
// Calculate shrink factors based on current widths
450+
final totalWidth = _columnWidths.reduce((a, b) => a + b);
451+
for (var i = 0; i < _columnCount; i++) {
452+
final proportion = _columnWidths[i] / totalWidth;
453+
_columnWidths[i] = math.max(
454+
_minimumColumnWidth,
455+
_columnWidths[i] - (reduction * proportion),
456+
);
457+
}
458+
} else if (totalColumnWidth < availableWidth) {
459+
// Extra space available - distribute using flexibility
460+
final extraWidth = availableWidth - totalColumnWidth;
430461
final totalFlexibility = columnFlexibility.reduce((a, b) => a + b);
431462

432463
if (totalFlexibility > 0) {
433-
// Distribute extra space proportionally to column flexibility
434464
for (var i = 0; i < _columnCount; i++) {
435465
final proportion = columnFlexibility[i] / totalFlexibility;
436466
_columnWidths[i] += extraWidth * proportion;
437467
}
438468
} else {
439-
// If no flexible columns found, distribute evenly
440-
final widthPerColumn = extraWidth / _columnCount;
469+
// If no flexible columns, distribute evenly
470+
final extraPerColumn = extraWidth / _columnCount;
441471
for (var i = 0; i < _columnCount; i++) {
442-
_columnWidths[i] += widthPerColumn;
472+
_columnWidths[i] += extraPerColumn;
443473
}
444474
}
445475
}
@@ -489,26 +519,32 @@ class RenderTagflowTable extends RenderBox
489519
}
490520
childParentData.offset = Offset(0, y);
491521
} else {
492-
// Calculate cell width and height
522+
// Calculate cell width and height including spacing
493523
var width = 0.0;
494524
for (var i = 0; i < childParentData.colSpan; i++) {
495525
width += _columnWidths[childParentData.column + i];
526+
if (i < childParentData.colSpan - 1) {
527+
width += _columnSpacing;
528+
}
496529
}
497530

498531
var height = 0.0;
499532
for (var i = 0; i < childParentData.rowSpan; i++) {
500533
height += _rowHeights[childParentData.row + i];
534+
if (i < childParentData.rowSpan - 1) {
535+
height += _rowSpacing;
536+
}
501537
}
502538

503-
// Calculate cell position
539+
// Calculate cell position with spacing
504540
var x = _padding.left;
505541
for (var i = 0; i < childParentData.column; i++) {
506-
x += _columnWidths[i];
542+
x += _columnWidths[i] + _columnSpacing;
507543
}
508544

509545
var y = _padding.top;
510546
for (var i = 0; i < childParentData.row; i++) {
511-
y += _rowHeights[i];
547+
y += _rowHeights[i] + _rowSpacing;
512548
}
513549

514550
// Layout child with tight constraints to prevent overflow
@@ -519,13 +555,15 @@ class RenderTagflowTable extends RenderBox
519555
child = childParentData.nextSibling;
520556
}
521557

522-
// Set table size
523-
size = constraints.constrain(
524-
Size(
525-
_columnWidths.reduce((a, b) => a + b) + _padding.horizontal,
526-
_rowHeights.reduce((a, b) => a + b) + _padding.vertical,
527-
),
528-
);
558+
// Update final table size to include spacing
559+
final tableWidth = _columnWidths.reduce((a, b) => a + b) +
560+
(_columnCount - 1) * _columnSpacing +
561+
_padding.horizontal;
562+
final tableHeight = _rowHeights.reduce((a, b) => a + b) +
563+
(_rowCount - 1) * _rowSpacing +
564+
_padding.vertical;
565+
566+
size = constraints.constrain(Size(tableWidth, tableHeight));
529567
}
530568

531569
@override
@@ -753,6 +791,7 @@ class RenderTagflowTable extends RenderBox
753791
rowHeights[childParentData.row + i]
754792
.clamp(childHeight, double.infinity);
755793
}
794+
child = childParentData.nextSibling;
756795
}
757796
child = childParentData.nextSibling;
758797
}

packages/tagflow_table/lib/src/widgets/converter.dart

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ final class TagflowTableConverter
3030
this.headerBackgroundColor,
3131
this.treatFirstRowAsHeader = false,
3232
this.separatorBuilder,
33+
this.columnSpacing,
34+
this.rowSpacing,
3335
});
3436

3537
/// The background color of the header row.
@@ -47,6 +49,11 @@ final class TagflowTableConverter
4749
/// The separator is placed between each row.
4850
final material.IndexedWidgetBuilder? separatorBuilder;
4951

52+
final double? columnSpacing;
53+
54+
///
55+
final double? rowSpacing;
56+
5057
@override
5158
Set<String> get supportedTags => {'table'};
5259

@@ -171,6 +178,8 @@ final class TagflowTableConverter
171178
headerBackgroundColor: headerBackgroundColor,
172179
padding: style.padding ?? material.EdgeInsets.zero,
173180
separatorBuilder: separatorBuilder,
181+
columnSpacing: columnSpacing ?? 0,
182+
rowSpacing: rowSpacing ?? 0,
174183
children: cells,
175184
),
176185
);

packages/tagflow_table/lib/src/widgets/tagflow_table.dart

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ final class TagflowTable extends MultiChildRenderObjectWidget {
7272
this.headerBackgroundColor,
7373
this.padding = EdgeInsets.zero,
7474
this.separatorBuilder,
75+
this.columnSpacing = 0.0, // Add this
76+
this.rowSpacing = 0.0, // Add this
7577
}) : border = border ?? TagflowTableBorder.none,
7678
super(children: children);
7779

@@ -82,6 +84,8 @@ final class TagflowTable extends MultiChildRenderObjectWidget {
8284
final Color? headerBackgroundColor;
8385
final EdgeInsets padding;
8486
final IndexedWidgetBuilder? separatorBuilder;
87+
final double columnSpacing;
88+
final double rowSpacing;
8589

8690
@override
8791
RenderTagflowTable createRenderObject(BuildContext context) {
@@ -91,7 +95,9 @@ final class TagflowTable extends MultiChildRenderObjectWidget {
9195
..setTreatFirstRowAsHeader(value: treatFirstRowAsHeader)
9296
..setHeaderBackgroundColor(headerBackgroundColor)
9397
..setSeparatorBuilder(separatorBuilder)
94-
..setPadding(padding);
98+
..setPadding(padding)
99+
..setColumnSpacing(columnSpacing) // Add this
100+
..setRowSpacing(rowSpacing); // Add this
95101
}
96102

97103
@override
@@ -105,7 +111,9 @@ final class TagflowTable extends MultiChildRenderObjectWidget {
105111
..setTreatFirstRowAsHeader(value: treatFirstRowAsHeader)
106112
..setHeaderBackgroundColor(headerBackgroundColor)
107113
..setSeparatorBuilder(separatorBuilder)
108-
..setPadding(padding);
114+
..setPadding(padding)
115+
..setColumnSpacing(columnSpacing) // Add this
116+
..setRowSpacing(rowSpacing); // Add this
109117
}
110118

111119
@override
@@ -128,6 +136,8 @@ final class TagflowTable extends MultiChildRenderObjectWidget {
128136
headerBackgroundColor,
129137
),
130138
)
131-
..add(DiagnosticsProperty<EdgeInsets>('padding', padding));
139+
..add(DiagnosticsProperty<EdgeInsets>('padding', padding))
140+
..add(DoubleProperty('columnSpacing', columnSpacing))
141+
..add(DoubleProperty('rowSpacing', rowSpacing));
132142
}
133143
}

packages/tagflow_table/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: tagflow_table
22
description: A pluggable package for tagflow to add support for advanced HTML tables.
3-
version: 0.0.2+1
3+
version: 0.0.3-dev.0
44
repository: https://github.com/devaryakjha/tagflow
55
homepage: https://docs.arya.run/tagflow
66
issue_tracker: https://github.com/devaryakjha/tagflow/issues

0 commit comments

Comments
 (0)