Skip to content

Commit

Permalink
Merge pull request #1433 from VisActor/1224-bug-dx-maxlinewidth
Browse files Browse the repository at this point in the history
1224 bug dx maxlinewidth
  • Loading branch information
fangsmile authored Apr 3, 2024
2 parents 8751379 + f5907e7 commit 2ad4dff
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"changes": [
{
"comment": "fix: maxLineWidth value should consider hierarchyOffset #1224\n\n",
"type": "none",
"packageName": "@visactor/vtable"
}
],
"packageName": "@visactor/vtable",
"email": "[email protected]"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"changes": [
{
"comment": "fix: tree leaf node textAlign right render error #1393\n\n",
"type": "none",
"packageName": "@visactor/vtable"
}
],
"packageName": "@visactor/vtable",
"email": "[email protected]"
}
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ export function updateCell(col: number, row: number, table: BaseTableAPI, addNew
// widthLimit: autoColWidth ? -1 : colWidth - (padding[1] + padding[3]),
heightLimit: cellHeight - (padding[0] + padding[2]),
pickable: false,
dx: hierarchyOffset,
dx: textAlign === 'left' ? hierarchyOffset : 0,
x
};
// const oldText = textMark.attribute.text;
Expand Down
4 changes: 3 additions & 1 deletion packages/vtable/src/scenegraph/layout/compute-row-height.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { CheckBox } from '@visactor/vrender-components';
import { decodeReactDom, dealPercentCalc } from '../component/custom';
import { getCellMergeRange } from '../../tools/merge-range';
import { getCellMergeInfo } from '../utils/get-cell-merge';
import { getHierarchyOffset } from '../utils/get-hierarchy-offset';

const utilTextMark = new Text({
ignoreBuf: true
Expand Down Expand Up @@ -723,7 +724,8 @@ function computeTextHeight(col: number, row: number, cellType: ColumnTypeOption,
});
}
} else if (autoWrapText) {
const maxLineWidth = cellWidth - (padding[1] + padding[3]) - iconWidth;
const hierarchyOffset = getHierarchyOffset(col, row, table);
const maxLineWidth = cellWidth - (padding[1] + padding[3]) - iconWidth - hierarchyOffset;
utilTextMark.setAttributes({
maxLineWidth,
text: lines,
Expand Down
12 changes: 8 additions & 4 deletions packages/vtable/src/scenegraph/utils/text-icon-layout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ export function createCellContent(
_contentOffset = -table.theme._contentOffset;
}
}

const attribute = {
text: text.length === 1 ? text[0] : text,
maxLineWidth: autoColWidth ? Infinity : cellWidth - (padding[1] + padding[3] + hierarchyOffset),
Expand All @@ -101,7 +100,7 @@ export function createCellContent(
// widthLimit: autoColWidth ? -1 : colWidth - (padding[1] + padding[3]),
heightLimit: autoRowHeight ? -1 : cellHeight - (padding[0] + padding[2]),
pickable: false,
dx: hierarchyOffset + _contentOffset,
dx: (textAlign === 'left' ? hierarchyOffset : 0) + _contentOffset,
whiteSpace: text.length === 1 && !autoWrapText ? 'no-wrap' : 'normal'
};
const wrapText = new Text(cellTheme.text ? (Object.assign({}, cellTheme.text, attribute) as any) : attribute);
Expand Down Expand Up @@ -218,7 +217,9 @@ export function createCellContent(
lineClamp,
wordBreak: 'break-word',
whiteSpace: text.length === 1 && !autoWrapText ? 'no-wrap' : 'normal',
dx: _contentOffset + (!contentLeftIcons.length && !contentRightIcons.length ? hierarchyOffset : 0)
dx:
(textAlign === 'left' ? (!contentLeftIcons.length && !contentRightIcons.length ? hierarchyOffset : 0) : 0) +
_contentOffset
};
const wrapText = new Text(cellTheme.text ? (Object.assign({}, cellTheme.text, attribute) as any) : attribute);
wrapText.name = 'text';
Expand Down Expand Up @@ -530,7 +531,10 @@ export function updateCellContentWidth(
let contentHeight: number;
if (textMark instanceof Text) {
oldTextHeight = textMark.AABBBounds.height();
textMark.setAttribute('maxLineWidth', distWidth - leftIconWidth - rightIconHeight - (padding[1] + padding[3]));
textMark.setAttribute(
'maxLineWidth',
distWidth - leftIconWidth - rightIconHeight - (padding[1] + padding[3]) - (textMark.attribute.dx ?? 0)
);
// contentWidth = textMark.AABBBounds.width();
contentHeight = textMark.AABBBounds.height();
} else if (textMark instanceof RichText) {
Expand Down

0 comments on commit 2ad4dff

Please sign in to comment.