Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Player visual indicator of button pressed #1353

Merged
merged 1 commit into from
May 19, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions panel/models/player.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,24 @@ import * as p from "@bokehjs/core/properties"
import {div} from "@bokehjs/core/dom"
import {Widget, WidgetView} from "@bokehjs/models/widgets/widget"


function press(btn_list: HTMLButtonElement[]): void {
btn_list.forEach((btn) => btn.style.borderStyle = 'inset')
}

function unpress(btn_list: HTMLButtonElement[]): void {
btn_list.forEach((btn) => btn.style.borderStyle = 'outset')
}

export class PlayerView extends WidgetView {
model: Player

protected sliderEl: HTMLInputElement
protected loop_state: HTMLFormElement
protected timer: any
protected _toggle_reverse: CallableFunction
protected _toogle_pause: CallableFunction
protected _toggle_play: CallableFunction

connect_signals(): void {
super.connect_signals()
Expand Down Expand Up @@ -99,6 +111,20 @@ export class PlayerView extends WidgetView {
faster.onclick = () => this.faster()
button_div.appendChild(faster)

// toggle
this._toggle_reverse = () => {
unpress([pause, play])
press([reverse])
}
this._toogle_pause = () => {
unpress([reverse, play])
press([pause])
}
this._toggle_play = () => {
unpress([reverse, pause])
press([play])
}

// Loop control
this.loop_state = document.createElement('form')
this.loop_state.style.cssText = "margin: 0 auto; display: table"
Expand Down Expand Up @@ -240,6 +266,7 @@ export class PlayerView extends WidgetView {
}

pause_animation(): void {
this._toogle_pause()
this.model.direction = 0;
if (this.timer) {
clearInterval(this.timer);
Expand All @@ -249,13 +276,15 @@ export class PlayerView extends WidgetView {

play_animation(): void {
this.pause_animation();
this._toggle_play()
this.model.direction = 1;
if (!this.timer)
this.timer = setInterval(() => this.anim_step_forward(), this.model.interval);
}

reverse_animation(): void {
this.pause_animation();
this._toggle_reverse()
this.model.direction = -1;
if (!this.timer)
this.timer = setInterval(() => this.anim_step_reverse(), this.model.interval);
Expand Down