diff --git a/CHANGELOG.md b/CHANGELOG.md index c85f0d26..b22a0f66 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,7 +15,9 @@ - file: honor server's `remote-root` option (remove root path from displayed path and returned value) - matrix: if `scroll` is `true`, children's values no longer feed the matrix' value and onValue script, it will be used for scrolling state, like with panels - menu: changed default `layout` to `vertical` - - root/panel/modal/tab: add `onScroll` script; value is no longer used for scrolling + - root/panel/modal/tab: support setting `scroll` to `hidden` (hides scrollbars and allows scrolling) + - add new `scrollbar` widget that connects to a scrolling container widget and acts as it scrollbar + - scripting - user scripts are longer protected against infinite loop and the main window object may be reached (it's not supported to break out of scripting context, but resources are no longer wasted to prevent it) @@ -25,9 +27,10 @@ - breaking change - dropped support for iOS 10.3 - - scrollbars are no longer emulated iOS; in general now only the scrollbar color and width are set (using the standard css scrollbar-* properties) to be more in line with system scrollbars in general - macOS Catalina or abov is now required (the node package will work on older system) - - panels no longer use their value to set/get their scrolling state, not do they sync scrolling automatically. There's now a dedicated onScroll script that must be used instead, along with the setScroll and getScroll functions. + - scrollbars are no longer emulated iOS + - scrollbar styling is now done using only the standard css scrollbar-* properties) to be more in line with system scrollbars in general + - panels no longer use their value to set/get their scrolling state, not do they sync scrolling automatically. Instead there's now a dedicated scrollbar widget that can be used for this. ## 1.29.8 diff --git a/src/client/widgets/containers/panel.mjs b/src/client/widgets/containers/panel.mjs index 04f02e93..73cd23c6 100644 --- a/src/client/widgets/containers/panel.mjs +++ b/src/client/widgets/containers/panel.mjs @@ -47,7 +47,7 @@ class Panel extends Container() { }, scripting: { onTouch: {type: 'script', value: '', editor:'javascript', help: ['Script executed when the panel is touched and released, and when the pointer moves when the widget is touched. See documentation.',]}, - onScroll: {type: 'script', value: '', editor:'javascript', help: ['Script executed when the panel is scrolled. See documentation.',]}, + // onScroll: {type: 'script', value: '', editor:'javascript', help: ['Script executed when the panel is scrolled. See documentation.',]}, } }) @@ -102,46 +102,22 @@ class Panel extends Container() { this.container.classList.add('contains-widgets') if (this.getProp('scroll')) { - - if (this.getProp('onScroll')) { - this.scripts.onScroll = new Script({ - widget: this, - property: 'onScroll', - code: this.getProp('onScroll'), - context: {event: {}, value: 0} - }) - } - this.scroll = [0, 0] this.scrollThumb = [1, 1] this.scrollWidth = 1 this.scrollHeight = 1 - this.settingScroll = false - this.settingScrollEnd = null fastdom.measure(()=>{ this.scrollWidth = this.widget.scrollWidth - this.widget.clientWidth this.scrollHeight = this.widget.scrollHeight - this.widget.clientHeight this.scrollThumb = [this.widget.clientWidth / this.widget.scrollWidth || 1, this.widget.clientHeight / this.widget.scrollHeight || 1] }) this.on('scroll', ()=>{ - this.scrollWidth = this.widget.scrollWidth - this.widget.clientWidth - this.scrollHeight = this.widget.scrollHeight - this.widget.clientHeight - this.scroll = [this.widget.scrollLeft / this.scrollWidth || 0, this.widget.scrollTop / this.scrollHeight || 0] - this.scrollThumb = [this.widget.clientWidth / this.widget.scrollWidth || 1, this.widget.clientHeight / this.widget.scrollHeight || 1] - if (this.settingScroll) { - clearTimeout(this.settingScrollEnd) - this.settingScrollEnd = setTimeout(()=>{ - this.settingScroll = false - }) - } else if (this.scripts.onScroll) { - this.scripts.onScroll.run({ - value: this.value, - event: { - x: this.scroll[0], - y: this.scroll[1] - } - }, {sync: true, send: true}) - } + fastdom.measure(()=>{ + this.scrollWidth = this.widget.scrollWidth - this.widget.clientWidth + this.scrollHeight = this.widget.scrollHeight - this.widget.clientHeight + this.scroll = [this.widget.scrollLeft / this.scrollWidth || 0, this.widget.scrollTop / this.scrollHeight || 0] + this.scrollThumb = [this.widget.clientWidth / this.widget.scrollWidth || 1, this.widget.clientHeight / this.widget.scrollHeight || 1] + }) }, {element: this.widget}) } @@ -296,7 +272,7 @@ class Panel extends Container() { } setScroll(x, y, updateDom) { - this.settingScroll = true + if (x !== undefined) { this.scroll[0] = x if (updateDom) this.widget.scrollLeft = x * this.scrollWidth diff --git a/src/client/widgets/sliders/scrollbar.mjs b/src/client/widgets/sliders/scrollbar.mjs index 8b6d7759..344aabe9 100644 --- a/src/client/widgets/sliders/scrollbar.mjs +++ b/src/client/widgets/sliders/scrollbar.mjs @@ -2,6 +2,7 @@ import Fader from './fader.mjs' import StaticProperties from '../mixins/static_properties.mjs' import {clip} from '../utils.mjs' import widgetManager from '../../managers/widgets.mjs' +import fastdom from 'fastdom' export default class Scrollbar extends StaticProperties(Fader, { range: {min: 0, max: 1}, @@ -153,15 +154,18 @@ export default class Scrollbar extends StaticProperties(Fader, { var index = this.getProp('horizontal') ? 0 : 1, size = this.getProp('horizontal') ? this.width : this.height - this.thumbSize = this.scrollTarget.scrollThumb[index] - this.cssVars.knobSize = Math.max(this.thumbSize * size, 30) - this.setValue(this.scrollTarget.scroll[index], {fromPanel:true, send:true, sync:true}) + fastdom.measure(()=>{ + fastdom.mutate(()=>{ + this.thumbSize = this.scrollTarget.scrollThumb[index] + this.cssVars.knobSize = Math.max(this.thumbSize * size, 30) + this.setValue(this.scrollTarget.scroll[index], {fromPanel:true, send:true, sync:true}) + }) + }) + } this.scrollTarget.on('scroll', onScroll) - setTimeout(()=>{ - onScroll() - }) + onScroll() }