Skip to content

Commit

Permalink
make horizontalScrolling changeable at runtime
Browse files Browse the repository at this point in the history
  • Loading branch information
joaomoreno committed Jun 11, 2020
1 parent 0a813c5 commit 08bf15f
Showing 1 changed file with 28 additions and 8 deletions.
36 changes: 28 additions & 8 deletions src/vs/base/browser/ui/list/listView.ts
Expand Up @@ -51,6 +51,7 @@ export interface IListViewAccessibilityProvider<T> {
export interface IListViewOptionsUpdate {
readonly additionalScrollHeight?: number;
readonly smoothScrolling?: boolean;
readonly horizontalScrolling?: boolean;
}

export interface IListViewOptions<T> extends IListViewOptionsUpdate {
Expand All @@ -61,7 +62,6 @@ export interface IListViewOptions<T> extends IListViewOptionsUpdate {
readonly setRowHeight?: boolean;
readonly supportDynamicHeights?: boolean;
readonly mouseSupport?: boolean;
readonly horizontalScrolling?: boolean;
readonly accessibilityProvider?: IListViewAccessibilityProvider<T>;
readonly transformOptimization?: boolean;
}
Expand Down Expand Up @@ -300,7 +300,7 @@ export class ListView<T> implements ISpliceable<T>, IDisposable {
this.scrollable = new Scrollable(getOrDefault(options, o => o.smoothScrolling, false) ? 125 : 0, cb => DOM.scheduleAtNextAnimationFrame(cb));
this.scrollableElement = this.disposables.add(new SmoothScrollableElement(this.rowsContainer, {
alwaysConsumeMouseWheel: true,
horizontal: this.horizontalScrolling ? ScrollbarVisibility.Auto : ScrollbarVisibility.Hidden,
horizontal: ScrollbarVisibility.Auto,
vertical: getOrDefault(options, o => o.verticalScrollMode, DefaultOptions.verticalScrollMode),
useShadows: getOrDefault(options, o => o.useShadows, DefaultOptions.useShadows),
}, this.scrollable));
Expand Down Expand Up @@ -329,14 +329,37 @@ export class ListView<T> implements ISpliceable<T>, IDisposable {
this.layout();
}

updateOptions(options: IListViewOptions<T>) {
updateOptions(options: IListViewOptionsUpdate) {
if (options.additionalScrollHeight !== undefined) {
this.additionalScrollHeight = options.additionalScrollHeight;
}

if (options.smoothScrolling !== undefined) {
this.scrollable.setSmoothScrollDuration(options.smoothScrolling ? 125 : 0);
}

if (options.horizontalScrolling !== undefined && options.horizontalScrolling !== this.horizontalScrolling) {
if (options.horizontalScrolling && this.supportDynamicHeights) {
throw new Error('Horizontal scrolling and dynamic heights not supported simultaneously');
}

this.horizontalScrolling = options.horizontalScrolling;
DOM.toggleClass(this.domNode, 'horizontal-scrolling', this.horizontalScrolling);

if (this.horizontalScrolling) {
for (const item of this.items) {
this.measureItemWidth(item);
}

this.updateScrollWidth();
this.scrollableElement.setScrollDimensions({ width: DOM.getContentWidth(this.domNode) });
this.rowsContainer.style.width = `${Math.max(this.scrollWidth || 0, this.renderWidth)}px`;
} else {
this.scrollableElementWidthDelayer.cancel();
this.scrollableElement.setScrollDimensions({ width: this.renderWidth, scrollWidth: this.renderWidth });
this.rowsContainer.style.width = '';
}
}
}

triggerScrollFromMouseWheelEvent(browserEvent: IMouseWheelEvent) {
Expand Down Expand Up @@ -485,6 +508,7 @@ export class ListView<T> implements ISpliceable<T>, IDisposable {

private eventuallyUpdateScrollWidth(): void {
if (!this.horizontalScrolling) {
this.scrollableElementWidthDelayer.cancel();
return;
}

Expand All @@ -496,10 +520,6 @@ export class ListView<T> implements ISpliceable<T>, IDisposable {
return;
}

if (this.items.length === 0) {
this.scrollableElement.setScrollDimensions({ scrollWidth: 0 });
}

let scrollWidth = 0;

for (const item of this.items) {
Expand All @@ -509,7 +529,7 @@ export class ListView<T> implements ISpliceable<T>, IDisposable {
}

this.scrollWidth = scrollWidth;
this.scrollableElement.setScrollDimensions({ scrollWidth: scrollWidth + 10 });
this.scrollableElement.setScrollDimensions({ scrollWidth: scrollWidth === 0 ? 0 : (scrollWidth + 10) });
}

updateWidth(index: number): void {
Expand Down

0 comments on commit 08bf15f

Please sign in to comment.