Build your own AI office with Univer Office SDK. Bring editing, calculation, collaboration, and file processing into your product for people and AI agents. Built on an extensible open-source core.
TypeScript boardcollaborationdocdocxexceloffce365officepdfpptpptxpresentationsdksheetslidesspreadsheetuniverwordwordprocessorworkspacexlsx
fix(sheets-table-ui): draw insert row icon as vector (#6939)
wpxp123456fb50a7cf83a5
diff --git a/packages/sheets-table-ui/src/views/widgets/__tests__/table-controls-util.spec.ts b/packages/sheets-table-ui/src/views/widgets/__tests__/table-controls-util.spec.tsindex 783471adfc..39fc9e1bca 100644--- a/packages/sheets-table-ui/src/views/widgets/__tests__/table-controls-util.spec.ts+++ b/packages/sheets-table-ui/src/views/widgets/__tests__/table-controls-util.spec.ts@@ -15,7 +15,7 @@*/import { describe, expect, it } from 'vitest';-import { buildTableMenuRegions, hitTestTableControl, TABLE_CONTROL_INSERT_BUTTON_SIZE } from '../table-controls-util';+import { buildCenteredPlusSegments, buildTableMenuRegions, hitTestTableControl, TABLE_CONTROL_INSERT_BUTTON_SIZE } from '../table-controls-util';describe('table controls geometry', () => {it('hit-tests the topmost region first', () => {@@ -39,4 +39,13 @@ describe('table controls geometry', () => {expect(regions.map((item) => item.action)).toEqual(['rename', 'update-range', 'set-theme', 'delete']);expect(regions[0]).toMatchObject({ left: 20, top: 30 });});++ it('builds centered plus segments around the insert button center', () => {+ const segments = buildCenteredPlusSegments(20, 30, 8);++ expect(segments).toEqual([+ { fromX: 16, fromY: 30, toX: 24, toY: 30 },+ { fromX: 20, fromY: 26, toX: 20, toY: 34 },+ ]);+ });});diff --git a/packages/sheets-table-ui/src/views/widgets/table-controls-util.ts b/packages/sheets-table-ui/src/views/widgets/table-controls-util.tsindex 1d8302cc79..4f19ad2cfa 100644--- a/packages/sheets-table-ui/src/views/widgets/table-controls-util.ts+++ b/packages/sheets-table-ui/src/views/widgets/table-controls-util.ts@@ -41,6 +41,13 @@ export interface ITableControlHitRegion {index?: number;}+export interface ITableControlLineSegment {+ fromX: number;+ fromY: number;+ toX: number;+ toY: number;+}+export const TABLE_CONTROL_MENU_ACTIONS: TableControlMenuAction[] = ['rename', 'update-range', 'set-theme', 'delete'];export function isPointInTableControlRegion(region: ITableControlHitRegion, x: number, y: number): boolean {@@ -68,3 +75,12 @@ export function buildTableMenuRegions(tableId: string, left: number, top: numberheight: TABLE_CONTROL_MENU_ITEM_HEIGHT,}));}++export function buildCenteredPlusSegments(centerX: number, centerY: number, size: number): [ITableControlLineSegment, ITableControlLineSegment] {+ const halfSize = size / 2;++ return [+ { fromX: centerX - halfSize, fromY: centerY, toX: centerX + halfSize, toY: centerY },+ { fromX: centerX, fromY: centerY - halfSize, toX: centerX, toY: centerY + halfSize },+ ];+}diff --git a/packages/sheets-table-ui/src/views/widgets/table-controls.shape.ts b/packages/sheets-table-ui/src/views/widgets/table-controls.shape.tsindex 1f839fbe89..382657d15c 100644--- a/packages/sheets-table-ui/src/views/widgets/table-controls.shape.ts+++ b/packages/sheets-table-ui/src/views/widgets/table-controls.shape.ts@@ -18,6 +18,7 @@ import type { IShapeProps, SpreadsheetSkeleton, UniverRenderingContext, Vector2import type { ITableControlHitRegion, TableControlMenuAction } from './table-controls-util';import { DEFAULT_FONTFACE_PLANE, Rect, Shape } from '@univerjs/engine-render';import {+ buildCenteredPlusSegments,buildTableMenuRegions,hitTestTableControl,TABLE_CONTROL_ANCHOR_HEIGHT,@@ -38,7 +39,7 @@ const MENU_RADIUS = 8;const MENU_BORDER = '#d9dee7';const MENU_HOVER_BG = '#f1f3f4';const INSERT_BUTTON_VISUAL_SIZE = 18;-const INSERT_BUTTON_TEXT_OFFSET_Y = -1;+const INSERT_BUTTON_PLUS_SIZE = 8;export interface ITableControlRenderItem {tableId: string;@@ -322,10 +323,15 @@ export class SheetTableControlsShape extends Shape<IShapeProps> {ctx.fill();ctx.strokeStyle = fill;ctx.stroke();- ctx.font = `12px ${DEFAULT_FONTFACE_PLANE}`;- ctx.fillStyle = fill;- ctx.textAlign = 'center';- ctx.fillText('+', centerX, centerY + INSERT_BUTTON_TEXT_OFFSET_Y);+ ctx.beginPath();+ ctx.strokeStyle = fill;+ ctx.lineWidth = 1;+ ctx.lineCap = 'round';+ for (const segment of buildCenteredPlusSegments(centerX, centerY, INSERT_BUTTON_PLUS_SIZE)) {+ ctx.moveTo(segment.fromX, segment.fromY);+ ctx.lineTo(segment.toX, segment.toY);+ }+ ctx.stroke();ctx.restore();}