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
feat: scroll bar hover style (#4708)
lumix04af678bc385
diff --git a/.vscode/settings.json b/.vscode/settings.jsonindex 6e45915aeb..37a69460d3 100644--- a/.vscode/settings.json+++ b/.vscode/settings.json@@ -30,6 +30,7 @@"COUNTA","CRDT","customd",+ "dashedrect","Datas","DATEFMTLISG","demi",@@ -106,6 +107,7 @@"rbush","redi","rowheader",+ "scrolltrack","shrinkability","Sider","strechability",diff --git a/e2e/visual-comparison/docs/docs-visual-comparison.spec.ts-snapshots/default-doc-ci-chromium-linux.png b/e2e/visual-comparison/docs/docs-visual-comparison.spec.ts-snapshots/default-doc-ci-chromium-linux.pngindex 380bf676ec..0fedcc2f68 100644Binary files a/e2e/visual-comparison/docs/docs-visual-comparison.spec.ts-snapshots/default-doc-ci-chromium-linux.png and b/e2e/visual-comparison/docs/docs-visual-comparison.spec.ts-snapshots/default-doc-ci-chromium-linux.png differdiff --git a/e2e/visual-comparison/sheets/sheets-visual-comparison.spec.ts-snapshots/defaultstyle-ci-chromium-linux.png b/e2e/visual-comparison/sheets/sheets-visual-comparison.spec.ts-snapshots/defaultstyle-ci-chromium-linux.pngindex 0d71f2abd4..1a7d212d63 100644Binary files a/e2e/visual-comparison/sheets/sheets-visual-comparison.spec.ts-snapshots/defaultstyle-ci-chromium-linux.png and b/e2e/visual-comparison/sheets/sheets-visual-comparison.spec.ts-snapshots/defaultstyle-ci-chromium-linux.png differdiff --git a/e2e/visual-comparison/sheets/sheets-visual-comparison.spec.ts-snapshots/demo-sheet-ci-chromium-linux.png b/e2e/visual-comparison/sheets/sheets-visual-comparison.spec.ts-snapshots/demo-sheet-ci-chromium-linux.pngindex 77ee4f123e..400130ef1b 100644Binary files a/e2e/visual-comparison/sheets/sheets-visual-comparison.spec.ts-snapshots/demo-sheet-ci-chromium-linux.png and b/e2e/visual-comparison/sheets/sheets-visual-comparison.spec.ts-snapshots/demo-sheet-ci-chromium-linux.png differdiff --git a/e2e/visual-comparison/sheets/sheets-visual-comparison.spec.ts-snapshots/facade-sheet-hooks-ci-chromium-linux.png b/e2e/visual-comparison/sheets/sheets-visual-comparison.spec.ts-snapshots/facade-sheet-hooks-ci-chromium-linux.pngindex ef0450f85d..5c919b5a64 100644Binary files a/e2e/visual-comparison/sheets/sheets-visual-comparison.spec.ts-snapshots/facade-sheet-hooks-ci-chromium-linux.png and b/e2e/visual-comparison/sheets/sheets-visual-comparison.spec.ts-snapshots/facade-sheet-hooks-ci-chromium-linux.png differdiff --git a/e2e/visual-comparison/sheets/sheets-visual-comparison.spec.ts-snapshots/set-force-string-cell-ci-chromium-linux.png b/e2e/visual-comparison/sheets/sheets-visual-comparison.spec.ts-snapshots/set-force-string-cell-ci-chromium-linux.pngindex 849483a5c0..9c1af83f84 100644Binary files a/e2e/visual-comparison/sheets/sheets-visual-comparison.spec.ts-snapshots/set-force-string-cell-ci-chromium-linux.png and b/e2e/visual-comparison/sheets/sheets-visual-comparison.spec.ts-snapshots/set-force-string-cell-ci-chromium-linux.png differdiff --git a/e2e/visual-comparison/sheets/sheets-visual-comparison.spec.ts-snapshots/set-text-format-number-cell-ci-chromium-linux.png b/e2e/visual-comparison/sheets/sheets-visual-comparison.spec.ts-snapshots/set-text-format-number-cell-ci-chromium-linux.pngindex 8a8e2d941f..21692c332a 100644Binary files a/e2e/visual-comparison/sheets/sheets-visual-comparison.spec.ts-snapshots/set-text-format-number-cell-ci-chromium-linux.png and b/e2e/visual-comparison/sheets/sheets-visual-comparison.spec.ts-snapshots/set-text-format-number-cell-ci-chromium-linux.png differdiff --git a/packages/engine-formula/src/basics/database.ts b/packages/engine-formula/src/basics/database.tsindex 26945fcf12..2d636f9073 100644--- a/packages/engine-formula/src/basics/database.ts+++ b/packages/engine-formula/src/basics/database.ts@@ -14,10 +14,12 @@* limitations under the License.*/+import type { ArrayValueObject } from '../engine/value-object/array-value-object';+import type { BaseValueObject } from '../engine/value-object/base-value-object';import { isRealNum } from '@univerjs/core';import { findCompareToken } from '../engine/utils/object-compare';-import { type ArrayValueObject, ValueObjectFactory } from '../engine/value-object/array-value-object';-import { type BaseValueObject, ErrorValueObject } from '../engine/value-object/base-value-object';+import { ValueObjectFactory } from '../engine/value-object/array-value-object';+import { ErrorValueObject } from '../engine/value-object/base-value-object';import { ErrorType } from './error-type';type DatabaseValueType = string | number | null;diff --git a/packages/engine-render/src/shape/base-scroll-bar.ts b/packages/engine-render/src/shape/base-scroll-bar.tsdeleted file mode 100644index a1cdc318f9..0000000000--- a/packages/engine-render/src/shape/base-scroll-bar.ts+++ /dev/null@@ -1,207 +0,0 @@-/**- * Copyright 2023-present DreamNum Co., Ltd.- *- * Licensed under the Apache License, Version 2.0 (the "License");- * you may not use this file except in compliance with the License.- * You may obtain a copy of the License at- *- * http://www.apache.org/licenses/LICENSE-2.0- *- * Unless required by applicable law or agreed to in writing, software- * distributed under the License is distributed on an "AS IS" BASIS,- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.- * See the License for the specific language governing permissions and- * limitations under the License.- */--import type { Nullable } from '@univerjs/core';--import type { Vector2 } from '../basics/vector2';-import type { UniverRenderingContext } from '../context';-import type { Scene } from '../scene';-import type { Rect } from './rect';-import { Disposable } from '@univerjs/core';--export interface IScrollBarProps {- thumbMargin?: number;- thumbLengthRatio?: number;- thumbBackgroundColor?: string;- thumbHoverBackgroundColor?: string;- thumbActiveBackgroundColor?: string;- /**- * The thickness of a scrolling bar.- */- barSize?: number;- barBackgroundColor?: string;- barBorder?: number;- barBorderColor?: string;-- enableHorizontal?: boolean;- enableVertical?: boolean;-- mainScene?: Scene;-- minThumbSizeH?: number;- minThumbSizeV?: number;-}--export abstract class BaseScrollBar extends Disposable {- enableHorizontal: boolean = true;-- enableVertical: boolean = true;-- horizontalThumbSize: number = 0;- horizontalMinusMiniThumb: number = 0;- horizontalBarWidth: number = 0;-- horizonScrollTrack: Nullable<Rect>;- horizonThumbRect: Nullable<Rect>;-- verticalThumbSize: number = 0;- verticalBarHeight: number = 0;- verticalMinusMiniThumb: number = 0;-- verticalScrollTrack: Nullable<Rect>;- verticalThumbRect: Nullable<Rect>;-- placeholderBarRect: Nullable<Rect>;-- get limitX() {- if (!this.horizonThumbRect?.visible) {- return 0;- }- return this.horizontalBarWidth - this.horizontalThumbSize;- }-- get limitY() {- if (!this.verticalThumbRect?.visible) {- return 0;- }- return this.verticalBarHeight - this.verticalThumbSize;- }-- get ratioScrollX(): number {- if (- this.enableHorizontal === false ||- this.horizontalThumbSize === undefined ||- this.horizontalBarWidth === undefined- ) {- return 1;- }-- const ratio = (- ((this.horizontalThumbSize - this.horizontalMinusMiniThumb) * this.miniThumbRatioX) /- this.horizontalBarWidth- );-- if (Number.isNaN(ratio)) {- return 1;- } else {- return ratio;- }- }-- get ratioScrollY(): number {- if (- this.enableVertical === false ||- this.verticalThumbSize === undefined ||- this.verticalBarHeight === undefined- ) {- return 1;- }- const ratio = (- ((this.verticalThumbSize - this.verticalMinusMiniThumb) * this.miniThumbRatioY) / this.verticalBarHeight- );-- if (Number.isNaN(ratio)) {- return 1;- } else {- return ratio;- }- }-- get miniThumbRatioX() {- const limit = this.horizontalBarWidth - this.horizontalThumbSize;-- if (limit === 0) {- return 0;- }-- const actual = this.horizontalBarWidth - (this.horizontalThumbSize - this.horizontalMinusMiniThumb);-- if (actual === 0) {- return 0;- }-- return limit / actual;- }-- get miniThumbRatioY() {- const limit = this.verticalBarHeight - this.verticalThumbSize;-- if (limit === 0) {- return 0;- }-- const actual = this.verticalBarHeight - (this.verticalThumbSize - this.verticalMinusMiniThumb);-- if (actual === 0) {- return 0;- }-- return limit / actual;- }-- pick(coord: Vector2) {- if (this.horizonThumbRect?.isHit(coord)) {- return this.horizonThumbRect;- }-- if (this.verticalThumbRect?.isHit(coord)) {- return this.verticalThumbRect;- }-- if (this.horizonScrollTrack?.isHit(coord)) {- return this.horizonScrollTrack;- }-- if (this.verticalScrollTrack?.isHit(coord)) {- return this.verticalScrollTrack;- }-- return null;- }-- override dispose() {- this.horizonScrollTrack?.dispose();- this.horizonThumbRect?.dispose();- this.verticalScrollTrack?.dispose();- this.verticalThumbRect?.dispose();- this.placeholderBarRect?.dispose();-- this.horizonScrollTrack = null;- this.horizonThumbRect = null;- this.verticalScrollTrack = null;- this.verticalThumbRect = null;- this.placeholderBarRect = null;- }-- hasHorizonThumb() {- return this.horizonThumbRect?.visible || false;- }-- hasVerticalThumb() {- return this.verticalThumbRect?.visible || false;- }-- abstract resize(- parentWidth: Nullable<number>,- parentHeight: Nullable<number>,- contentWidth: number,- contentHeight: number- ): void;-- abstract makeDirty(state: boolean): void;-- abstract render(ctx: UniverRenderingContext, left?: number, top?: number): void;-}diff --git a/packages/engine-render/src/shape/scroll-bar.ts b/packages/engine-render/src/shape/scroll-bar.tsindex dfe5dc1b4b..1e79d87456 100644--- a/packages/engine-render/src/shape/scroll-bar.ts+++ b/packages/engine-render/src/shape/scroll-bar.ts@@ -21,15 +21,68 @@ import type { Vector2 } from '../basics/vector2';import type { UniverRenderingContext } from '../context';import type { Scene } from '../scene';import type { Viewport } from '../viewport';-import type { IScrollBarProps } from './base-scroll-bar';+import { Disposable, Tools } from '@univerjs/core';import { Subscription } from 'rxjs';import { Transform } from '../basics/transform';-import { BaseScrollBar } from './base-scroll-bar';import { Rect } from './rect';+/**+ * Sadly, the props name here is not the same as the members in Scrollbar.+ */+export interface IScrollBarProps {+ mainScene?: Scene;+ thumbMargin?: number;+ thumbLengthRatio?: number;+ thumbBackgroundColor?: string;+ thumbHoverBackgroundColor?: string;+ thumbActiveBackgroundColor?: string;+ /**+ * The thickness of a scrolling track(not scrolling thumb).+ */+ barSize?: number;+ /**+ * The thickness of track border.+ */+ barBorder?: number;++ enableHorizontal?: boolean;+ enableVertical?: boolean;++ /**+ * The min width of horizon thumb+ */+ minThumbSizeH?: number;++ /**+ * The min height of vertical thumb+ */+ minThumbSizeV?: number;+}+const MIN_THUMB_SIZE = 17;+const DEFAULT_TRACK_SIZE = 10;+const HOVER_TRACK_SIZE = 10;+const DEFAULT_THUMB_MARGIN = 2;+const HOVER_THUMB_MARGIN = 1;++export class ScrollBar extends Disposable {+ enableHorizontal: boolean = true;+ enableVertical: boolean = true;++ horizontalThumbSize: number = 0;+ horizontalMinusMiniThumb: number = 0;+ horizontalTrackWidth: number = 0;+ horizonScrollTrack: Nullable<Rect>;+ horizonThumbRect: Nullable<Rect>;++ verticalThumbSize: number = 0;+ verticalTrackHeight: number = 0;+ verticalMinusMiniThumb: number = 0;+ verticalScrollTrack: Nullable<Rect>;+ verticalThumbRect: Nullable<Rect>;++ placeholderBarRect: Nullable<Rect>;-export class ScrollBar extends BaseScrollBar {protected _viewport!: Viewport;private _mainScene: Nullable<Scene>;@@ -43,53 +96,47 @@ export class ScrollBar extends BaseScrollBar {private _isVerticalMove = false;private _horizonPointerMoveSub: Nullable<Subscription>;-private _horizonPointerUpSub: Nullable<Subscription>;-private _verticalPointerMoveSub: Nullable<Subscription>;-private _verticalPointerUpSub: Nullable<Subscription>;+ private _thumbDefaultBackgroundColor = 'rgba(24, 28, 42, 0.20)';+ private _thumbHoverBackgroundColor = 'rgba(24, 28, 42, 0.30)';+ private _thumbActiveBackgroundColor = 'rgba(24, 28, 42, 0.40)';+ private _trackBackgroundColor = 'rgba(255,255,255,0.5)';+ private _trackBorderColor = 'rgba(255,255,255,0.7)';+/*** The thickness of a scrolling track- * ThumbSize = barSize - thumbMargin * 2+ * ThumbSize = trackSize - thumbMargin * 2*/- barSize = 14;-- barBorder = 1;+ private _trackThickness: number = DEFAULT_TRACK_SIZE;+ // private _hTrackThickness: number = DEFAULT_TRACK_SIZE;+ // private _vTrackThickness: number = DEFAULT_TRACK_SIZE;/*** The margin between thumb and bar.* ThumbSize = barSize - thumbMargin * 2*/- thumbMargin = 2;+ // private _thumbMargin = DEFAULT_THUMB_MARGIN;+ private _vThumbMargin = DEFAULT_THUMB_MARGIN;+ private _hThumbMargin = DEFAULT_THUMB_MARGIN;- thumbLengthRatio = 1;+ // origin: barBorder+ private _trackBorderThickness = 1;+ private _thumbLengthRatio = 1;/**- * todo: @DR-univer。 Mainly inject themeService in order to obtain colors.+ * The min width of horizon thumb, Corresponds to minThumbSizeH in props*/- thumbBackgroundColor = 'rgba(24, 28, 42, 0.20)';- thumbHoverBackgroundColor = 'rgba(24, 28, 42, 0.30)';- thumbActiveBackgroundColor = 'rgba(24, 28, 42, 0.40)';- barBackgroundColor = 'rgba(255,255,255,0.5)';- barBorderColor = 'rgba(255,255,255,0.7)';-+ private _minThumbSizeH = MIN_THUMB_SIZE;/**- * The min width of horizon thumb.+ * The min height of vertical thumb, Corresponds to minThumbSizeV in props*/- minThumbSizeH = MIN_THUMB_SIZE;- /**- * The min height of vertical thumb.- */- minThumbSizeV = MIN_THUMB_SIZE;+ private _minThumbSizeV = MIN_THUMB_SIZE;private _eventSub = new Subscription();- get scrollHandleThickness() {- return Math.max(0, this.barSize - this.thumbMargin * 2);- }-constructor(view: Viewport, props?: IScrollBarProps) {super();if (!view) {@@ -103,12 +150,172 @@ export class ScrollBar extends BaseScrollBar {this._viewport.setScrollBar(this);}+ setProps(props?: IScrollBarProps) {+ if (!props) {+ return;+ }++ const themeKeys = Object.keys(props);+ if (themeKeys.length === 0) {+ return;+ }++ themeKeys.forEach((key) => {+ if (props[key as keyof IScrollBarProps] !== undefined) {+ (this as IKeyValue)[`_${key}`] = props[key as keyof IScrollBarProps];+ }+ });++ if (Tools.isDefine(props.barSize)) {+ this._trackThickness = props.barSize;+ }++ if (Tools.isDefine(props.barBorder)) {+ this._trackBorderThickness = props.barBorder;+ }++ if (Tools.isDefine(props.thumbMargin)) {+ this._hThumbMargin = props.thumbMargin;+ this._vThumbMargin = props.thumbMargin;+ }+ }++ get limitX() {+ if (!this.horizonThumbRect?.visible) {+ return 0;+ }+ return this.horizontalTrackWidth - this.horizontalThumbSize;+ }++ get limitY() {+ if (!this.verticalThumbRect?.visible) {+ return 0;+ }+ return this.verticalTrackHeight - this.verticalThumbSize;+ }++ get ratioScrollX(): number {+ if (+ this.enableHorizontal === false ||+ this.horizontalThumbSize === undefined ||+ this.horizontalTrackWidth === undefined+ ) {+ return 1;+ }++ const ratio = (+ ((this.horizontalThumbSize - this.horizontalMinusMiniThumb) * this.miniThumbRatioX) /+ this.horizontalTrackWidth+ );++ if (Number.isNaN(ratio)) {+ return 1;+ } else {+ return ratio;+ }+ }++ get ratioScrollY(): number {+ if (+ this.enableVertical === false ||+ this.verticalThumbSize === undefined ||+ this.verticalTrackHeight === undefined+ ) {+ return 1;+ }+ const ratio = (+ ((this.verticalThumbSize - this.verticalMinusMiniThumb) * this.miniThumbRatioY) / this.verticalTrackHeight+ );++ if (Number.isNaN(ratio)) {+ return 1;+ } else {+ return ratio;+ }+ }++ get miniThumbRatioX() {+ const limit = this.horizontalTrackWidth - this.horizontalThumbSize;++ if (limit === 0) {+ return 0;+ }++ const actual = this.horizontalTrackWidth - (this.horizontalThumbSize - this.horizontalMinusMiniThumb);++ if (actual === 0) {+ return 0;+ }++ return limit / actual;+ }++ get miniThumbRatioY() {+ const limit = this.verticalTrackHeight - this.verticalThumbSize;++ if (limit === 0) {+ return 0;+ }++ const actual = this.verticalTrackHeight - (this.verticalThumbSize - this.verticalMinusMiniThumb);++ if (actual === 0) {+ return 0;+ }++ return limit / actual;+ }++ hasHorizonThumb() {+ return this.horizonThumbRect?.visible || false;+ }++ hasVerticalThumb() {+ return this.verticalThumbRect?.visible || false;+ }++ get scrollHorizonThumbThickness() {+ return Math.max(0, this._trackThickness - this._hThumbMargin * 2);+ }++ get scrollVerticalThumbThickness() {+ return Math.max(0, this._trackThickness - this._vThumbMargin * 2);+ }++ set barSize(v: number) {+ this._trackThickness = v;+ }++ get barSize() {+ return this._trackThickness;+ }++ set trackThickness(v: number) {+ this._trackThickness = v;+ }++ get trackThickness() {+ return this._trackThickness;+ }+static attachTo(view: Viewport, props?: IScrollBarProps) {return new ScrollBar(view, props);}override dispose() {super.dispose();+ this.horizonScrollTrack?.dispose();+ this.horizonThumbRect?.dispose();+ this.verticalScrollTrack?.dispose();+ this.verticalThumbRect?.dispose();+ this.placeholderBarRect?.dispose();++ this.horizonScrollTrack = null;+ this.horizonThumbRect = null;+ this.verticalScrollTrack = null;+ this.verticalThumbRect = null;+ this.placeholderBarRect = null;+this._horizonPointerMoveSub?.unsubscribe();this._horizonPointerUpSub?.unsubscribe();this._verticalPointerMoveSub?.unsubscribe();@@ -118,7 +325,7 @@ export class ScrollBar extends BaseScrollBar {this._viewport.removeScrollBar();}- override render(ctx: UniverRenderingContext, left: number = 0, top: number = 0) {+ render(ctx: UniverRenderingContext, left: number = 0, top: number = 0) {const { scrollX, scrollY } = this._viewport;ctx.save();const transform = new Transform([1, 0, 0, 1, left, top]);@@ -141,113 +348,41 @@ export class ScrollBar extends BaseScrollBar {ctx.restore();}- override resize(- parentWidth: number = 0,- parentHeight: number = 0,- contentWidth: number = 0,- contentHeight: number = 0- ) {- if (parentWidth === 0 && parentWidth === 0) {- return;- }-- this._resizeHorizontal(parentWidth, parentHeight, contentWidth);+ private _resizeHorizontal() {+ const viewportH = this._viewportH;+ const viewportW = this._viewportW;+ const contentWidth = this._contentW;- this._resizeVertical(parentWidth, parentHeight, contentHeight);-- if (this.enableHorizontal && this.enableVertical) {- this.placeholderBarRect?.transformByState({- left: parentWidth - this.barSize,- top: parentHeight - this.barSize,- width: Math.max(0, this.barSize - this.barBorder),- height: Math.max(0, this.barSize - this.barBorder),- });- }- }-- override makeDirty(state: boolean) {- this.horizonScrollTrack?.makeDirty(state);- this.horizonThumbRect?.makeDirty(state);- this.verticalScrollTrack?.makeDirty(state);- this.verticalThumbRect?.makeDirty(state);- this.placeholderBarRect?.makeDirty(state);-- this.makeViewDirty(state);- }-- makeViewDirty(state: boolean) {- const mainScene = this._mainScene || this._viewport.scene;- mainScene.makeDirty(state);- }-- override pick(coord: Vector2) {- if (this.horizonThumbRect?.isHit(coord)) {- return this.horizonThumbRect;- }-- if (this.verticalThumbRect?.isHit(coord)) {- return this.verticalThumbRect;- }-- if (this.horizonScrollTrack?.isHit(coord)) {- return this.horizonScrollTrack;- }-- if (this.verticalScrollTrack?.isHit(coord)) {- return this.verticalScrollTrack;- }-- return null;- }-- setProps(props?: IScrollBarProps) {- if (!props) {- return;- }-- const themeKeys = Object.keys(props);- if (themeKeys.length === 0) {- return;- }-- themeKeys.forEach((key) => {- if (props[key as keyof IScrollBarProps] !== undefined) {- (this as IKeyValue)[`${key}`] = props[key as keyof IScrollBarProps];- }- });- }-- private _resizeHorizontal(parentWidth: number, parentHeight: number, contentWidth: number) {// ratioScrollY = 内容可视区高度/内容实际区高度= 滑动条的高度/滑道高度=滚动条的顶部距离/实际内容区域顶部距离;if (!this.enableHorizontal) {return;}this.horizontalMinusMiniThumb = 0;- this.horizontalBarWidth = parentWidth - (this.enableVertical ? this.barSize : 0) - this.barBorder;+ this.horizontalTrackWidth = viewportW - (this.enableVertical ? this._trackThickness : 0) - this._trackBorderThickness;this.horizontalThumbSize =- ((this.horizontalBarWidth * (this.horizontalBarWidth - this.barBorder)) / contentWidth) *- this.thumbLengthRatio;+ ((this.horizontalTrackWidth * (this.horizontalTrackWidth - this._trackBorderThickness)) / contentWidth) *+ this._thumbLengthRatio;// this._horizontalThumbWidth = this._horizontalThumbWidth < MINI_THUMB_SIZE ? MINI_THUMB_SIZE : this._horizontalThumbWidth;- if (this.horizontalThumbSize < this.minThumbSizeH) {- this.horizontalMinusMiniThumb = this.minThumbSizeH - this.horizontalThumbSize;- this.horizontalThumbSize = this.minThumbSizeH;+ if (this.horizontalThumbSize < this._minThumbSizeH) {+ this.horizontalMinusMiniThumb = this._minThumbSizeH - this.horizontalThumbSize;+ this.horizontalThumbSize = this._minThumbSizeH;}this.horizonScrollTrack?.transformByState({left: 0,- top: parentHeight - this.barSize,- width: this.horizontalBarWidth,- height: Math.max(0, this.barSize - this.barBorder),+ top: viewportH - this._trackThickness,+ width: this.horizontalTrackWidth,+ height: Math.max(0, this._trackThickness - this._trackBorderThickness),});- if (this.horizontalThumbSize >= parentWidth - this.barSize) {- // why hide the thumb rect ?- // this.horizonThumbRect?.setProps({- // visible: false,- // });+ // content is smaller than viewport size+ if (this.horizontalThumbSize >= viewportW - this._trackThickness) {+ this.horizonThumbRect?.setProps({+ visible: false,+ });} else {if (!this.horizonThumbRect?.visible) {this.horizonThumbRect?.setProps({@@ -257,88 +392,170 @@ export class ScrollBar extends BaseScrollBar {this.horizonThumbRect?.transformByState({left: this._viewport.scrollX,- top: parentHeight - this.barSize + this.thumbMargin,+ top: viewportH - this._trackThickness + this._hThumbMargin,width: this.horizontalThumbSize,- height: this.scrollHandleThickness,+ height: this.scrollHorizonThumbThickness,});}}- private _resizeVertical(parentWidth: number, parentHeight: number, contentHeight: number) {+ private _resizeVertical() {+ const viewportH = this._viewportH;+ const viewportW = this._viewportW;+ const contentHeight = this._contentH;+if (!this.enableVertical) {return;}this.verticalMinusMiniThumb = 0;- this.verticalBarHeight = parentHeight - (this.enableHorizontal ? this.barSize : 0) - this.barBorder;+ this.verticalTrackHeight = viewportH - (this.enableHorizontal ? this._trackThickness : 0) - this._trackBorderThickness;this.verticalThumbSize =- ((this.verticalBarHeight * this.verticalBarHeight) / contentHeight) * this.thumbLengthRatio;+ ((this.verticalTrackHeight * this.verticalTrackHeight) / contentHeight) * this._thumbLengthRatio;// this._verticalThumbHeight = this._verticalThumbHeight < MINI_THUMB_SIZE ? MINI_THUMB_SIZE : this._verticalThumbHeight;- if (this.verticalThumbSize < this.minThumbSizeV) {- this.verticalMinusMiniThumb = this.minThumbSizeV - this.verticalThumbSize;- this.verticalThumbSize = this.minThumbSizeV;+ if (this.verticalThumbSize < this._minThumbSizeV) {+ this.verticalMinusMiniThumb = this._minThumbSizeV - this.verticalThumbSize;+ this.verticalThumbSize = this._minThumbSizeV;}this.verticalScrollTrack?.transformByState({- left: parentWidth - this.barSize,+ left: viewportW - this._trackThickness,top: 0,- width: Math.max(0, this.barSize - this.barBorder),- height: this.verticalBarHeight,+ width: Math.max(0, this._trackThickness - this._trackBorderThickness),+ height: this.verticalTrackHeight,});- if (this.verticalThumbSize >= parentHeight - this.barSize) {- // why hide the thumb rect ?- // this.verticalThumbRect?.setProps({- // visible: false,- // });+ // content is smaller than viewport size+ if (this.verticalThumbSize >= viewportH - this._trackThickness) {+ this.verticalThumbRect?.setProps({+ visible: false,+ });} else {if (!this.verticalThumbRect?.visible) {this.verticalThumbRect?.setProps({visible: true,});}-this.verticalThumbRect?.transformByState({- left: parentWidth - this.barSize + this.thumbMargin,+ left: viewportW - this._trackThickness + this._vThumbMargin,top: this._viewport.scrollY,- width: this.scrollHandleThickness,+ width: this.scrollVerticalThumbThickness,height: this.verticalThumbSize,});}}+ private _resizeRightBottomCorner() {+ const viewportH = this._viewportH;+ const viewportW = this._viewportW;+ if (this.enableHorizontal && this.enableVertical) {+ this.placeholderBarRect?.transformByState({+ left: viewportW - this._trackThickness,+ top: viewportH - this._trackThickness,+ width: Math.max(0, this._trackThickness - this._trackBorderThickness),+ height: Math.max(0, this._trackThickness - this._trackBorderThickness),+ });+ }+ }++ private _viewportH = 0;+ private _viewportW = 0;+ private _contentW = 0;+ private _contentH = 0;+ /**+ * Adjust scroll track & thumb size based on the viewport size.+ * @param viewportWidth+ * @param viewportHeight+ * @param contentWidth+ * @param contentHeight+ */+ resize(+ viewportWidth: number = 0,+ viewportHeight: number = 0,+ contentWidth: number = 0,+ contentHeight: number = 0+ ) {+ if (viewportWidth === 0 && viewportWidth === 0) {+ return;+ }++ this._viewportH = viewportHeight;+ this._viewportW = viewportWidth;+ this._contentW = contentWidth;+ this._contentH = contentHeight;++ this._resizeHorizontal();+ this._resizeVertical();+ this._resizeRightBottomCorner();+ }++ makeDirty(state: boolean) {+ this.horizonScrollTrack?.makeDirty(state);+ this.horizonThumbRect?.makeDirty(state);+ this.verticalScrollTrack?.makeDirty(state);+ this.verticalThumbRect?.makeDirty(state);+ this.placeholderBarRect?.makeDirty(state);++ this.makeViewDirty(state);+ }++ makeViewDirty(state: boolean) {+ const mainScene = this._mainScene || this._viewport.scene;+ mainScene.makeDirty(state);+ }++ pick(coord: Vector2) {+ if (this.horizonThumbRect?.isHit(coord)) {+ return this.horizonThumbRect;+ }++ if (this.verticalThumbRect?.isHit(coord)) {+ return this.verticalThumbRect;+ }++ if (this.horizonScrollTrack?.isHit(coord)) {+ return this.horizonScrollTrack;+ }++ if (this.verticalScrollTrack?.isHit(coord)) {+ return this.verticalScrollTrack;+ }++ return null;+ }+private _initialScrollRect() {if (this.enableHorizontal) {this.horizonScrollTrack = new Rect('__horizonBarRect__', {- fill: this.barBackgroundColor!,- strokeWidth: this.barBorder,- stroke: this.barBorderColor!,+ fill: this._trackBackgroundColor!,+ strokeWidth: this._trackBorderThickness,+ stroke: this._trackBorderColor!,});this.horizonThumbRect = new Rect('__horizonThumbRect__', {radius: 6,- fill: this.thumbBackgroundColor!,+ fill: this._thumbDefaultBackgroundColor!,});}if (this.enableVertical) {this.verticalScrollTrack = new Rect('__verticalBarRect__', {- fill: this.barBackgroundColor!,- strokeWidth: this.barBorder,- stroke: this.barBorderColor!,+ fill: this._trackBackgroundColor!,+ strokeWidth: this._trackBorderThickness,+ stroke: this._trackBorderColor!,});this.verticalThumbRect = new Rect('__verticalThumbRect__', {radius: 6,- fill: this.thumbBackgroundColor!,+ fill: this._thumbDefaultBackgroundColor!,});}if (this.enableHorizontal && this.enableVertical) {this.placeholderBarRect = new Rect('__placeholderBarRect__', {- fill: this.barBackgroundColor!,- strokeWidth: this.barBorder,- stroke: this.barBorderColor!,+ fill: this._trackBackgroundColor!,+ strokeWidth: this._trackBorderThickness,+ stroke: this._trackBorderColor!,});}}@@ -352,12 +569,12 @@ export class ScrollBar extends BaseScrollBar {if (this.verticalThumbRect) {this._eventSub.add(this.verticalThumbRect.onPointerEnter$.subscribeEvent((evt: unknown, state: EventState) => {- this._hoverFunc(this.thumbHoverBackgroundColor!, this.verticalThumbRect!)(evt, state);+ this._verticalHoverFunc(this._thumbHoverBackgroundColor!, evt, state);}));}if (this.verticalThumbRect) {this._eventSub.add(this.verticalThumbRect.onPointerLeave$.subscribeEvent((evt: unknown, state: EventState) => {- this._hoverFunc(this.thumbBackgroundColor!, this.verticalThumbRect!)(evt, state);+ this._verticalHoverLeaveFunc(this._thumbDefaultBackgroundColor!, evt, state);}));}@@ -384,7 +601,7 @@ export class ScrollBar extends BaseScrollBar {this._lastY = e.offsetY;// srcElement.fill = this._thumbHoverBackgroundColor!;srcElement?.setProps({- fill: this.thumbActiveBackgroundColor!,+ fill: this._thumbActiveBackgroundColor!,});mainScene.setCaptureObject(this.verticalThumbRect!);mainScene.disableObjectsEvent();@@ -413,18 +630,49 @@ export class ScrollBar extends BaseScrollBar {mainScene.releaseCapturedObject();mainScene.enableObjectsEvent();srcElement?.setProps({- fill: this.thumbHoverBackgroundColor!,+ fill: this._thumbHoverBackgroundColor!,});this.makeViewDirty(true);});}- private _hoverFunc(color: string, object: Rect): (evt: unknown, state: EventState) => void {+ private _horizonHoverFunc(color: string, evt: unknown, state: EventState) {+ // this._trackThickness = HOVER_TRACK_SIZE;+ this._hThumbMargin = HOVER_THUMB_MARGIN;+ this._resizeHorizontal();+ this._resizeRightBottomCorner();+ this._hoverFunc(color, this.horizonThumbRect!)(evt, state);+ }++ private _horizonHoverLeaveFunc(color: string, evt: unknown, state: EventState) {+ // this._trackThickness = DEFAULT_TRACK_SIZE;+ this._hThumbMargin = DEFAULT_THUMB_MARGIN;+ this._resizeHorizontal();+ this._resizeRightBottomCorner();+ this._hoverFunc(color, this.horizonThumbRect!)(evt, state);+ }++ private _verticalHoverFunc(color: string, evt: unknown, state: EventState) {+ this._vThumbMargin = HOVER_THUMB_MARGIN;+ this._resizeVertical();+ this._resizeRightBottomCorner();+ this._hoverFunc(color, this.verticalThumbRect!)(evt, state);+ }++ private _verticalHoverLeaveFunc(color: string, evt: unknown, state: EventState) {+ this._vThumbMargin = DEFAULT_THUMB_MARGIN;+ this._resizeVertical();+ this._resizeRightBottomCorner();+ this._hoverFunc(color, this.verticalThumbRect!)(evt, state);+ }++ private _hoverFunc(color: string, thumb: Rect): (evt: unknown, state: EventState) => void {return (_evt: unknown, _state: EventState) => {- const srcElement = object;- srcElement.setProps({+ thumb.setProps({fill: color,});+ this._trackThickness = HOVER_TRACK_SIZE;+ this._resizeHorizontal();this.makeViewDirty(true);};}@@ -438,12 +686,12 @@ export class ScrollBar extends BaseScrollBar {if (this.horizonThumbRect) {this._eventSub.add(this.horizonThumbRect.onPointerEnter$.subscribeEvent((evt: unknown, state: EventState) => {- this._hoverFunc(this.thumbHoverBackgroundColor, this.horizonThumbRect!)(evt, state);+ this._horizonHoverFunc(this._thumbHoverBackgroundColor, evt, state);}));}if (this.horizonThumbRect) {this._eventSub.add(this.horizonThumbRect.onPointerLeave$.subscribeEvent((evt: unknown, state: EventState) => {- this._hoverFunc(this.thumbBackgroundColor, this.horizonThumbRect!)(evt, state);+ this._horizonHoverLeaveFunc(this._thumbDefaultBackgroundColor, evt, state);}));}@@ -466,7 +714,7 @@ export class ScrollBar extends BaseScrollBar {this._lastX = e.offsetX;this._lastY = e.offsetY;this.horizonThumbRect?.setProps({- fill: this.thumbActiveBackgroundColor!,+ fill: this._thumbActiveBackgroundColor!,});this.makeViewDirty(true);mainScene.setCaptureObject(this.horizonThumbRect!);@@ -488,12 +736,12 @@ export class ScrollBar extends BaseScrollBar {mainScene.getEngine()?.setCapture();});this._horizonPointerUpSub = mainScene.onPointerUp$.subscribeEvent((evt: unknown, state: EventState) => {- const srcElement = this.horizonThumbRect;+ ;this._isHorizonMove = false;mainScene.releaseCapturedObject();mainScene.enableObjectsEvent();- srcElement?.setProps({- fill: this.thumbHoverBackgroundColor!,+ this.horizonThumbRect?.setProps({+ fill: this._thumbHoverBackgroundColor!,});this.makeViewDirty(true);});diff --git a/packages/engine-render/src/viewport.ts b/packages/engine-render/src/viewport.tsindex 8f86a63a04..eeed4f3657 100644--- a/packages/engine-render/src/viewport.ts+++ b/packages/engine-render/src/viewport.ts@@ -21,7 +21,7 @@ import type { IWheelEvent } from './basics/i-events';import type { IBoundRectNoAngle, IViewportInfo } from './basics/vector2';import type { UniverRenderingContext } from './context';import type { Scene } from './scene';-import type { BaseScrollBar } from './shape/base-scroll-bar';+import type { ScrollBar } from './shape/scroll-bar';import { EventSubject, Tools } from '@univerjs/core';import { Subject } from 'rxjs';import { RENDER_CLASS_TYPE } from './basics/const';@@ -178,7 +178,7 @@ export class Viewport {private _scene!: Scene;- private _scrollBar?: Nullable<BaseScrollBar>;+ private _scrollBar?: Nullable<ScrollBar>;private _isWheelPreventDefaultX: boolean = false;private _isWheelPreventDefaultY: boolean = false;@@ -461,7 +461,7 @@ export class Viewport {} as IViewportReSizeParam);}- setScrollBar(instance: BaseScrollBar) {+ setScrollBar(instance: ScrollBar) {this._scrollBar = instance;this._updateScrollByViewportScrollValue();}