From 351b95e556febeaa4de288cfb9a77d46beded585 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Arne=20Schl=C3=BCter?= Date: Wed, 23 Jan 2019 14:00:55 +0100 Subject: [PATCH] Implement progress bar with svg --- .../components/audio_player/views.cljs | 21 +++++--- src/sass/app.sass | 48 +++++++------------ 2 files changed, 30 insertions(+), 39 deletions(-) diff --git a/src/cljs/airsonic_ui/components/audio_player/views.cljs b/src/cljs/airsonic_ui/components/audio_player/views.cljs index 3602ba7..4959634 100644 --- a/src/cljs/airsonic_ui/components/audio_player/views.cljs +++ b/src/cljs/airsonic_ui/components/audio_player/views.cljs @@ -17,6 +17,18 @@ (defn- ratio->width [ratio] (str (.toFixed (min 100 (* 100 ratio)) 2) "%")) +(defn progress-bars [buffered-width played-width] + [:svg.progress-bars {:aria-hidden "true"} + [:svg.complete-song-bar + [:rect {:x 0, :y "50%", :width "100%", :height 1}]] + [:svg.buffered-part-bar + [:rect.click-dummy {:on-click seek + :x 0, :y 0, :width buffered-width, :height "100%"}] + [:rect {:x 0, :y "50%", :width buffered-width, :height 1}]] + [:svg.played-back-bar + [:rect {:x 0, :y "50%", :width played-width, :height 1}] + [:circle {:cx played-width, :cy "50%", :r 2.5}]]]) + (defn progress-indicators [song status] (let [current-time (:current-time status) buffered (:buffered status) @@ -26,13 +38,8 @@ (h/format-duration duration :brief? true)) buffered-width (ratio->width (/ buffered duration)) played-width (ratio->width (/ current-time duration))] - [:article.progress-indicators {:aria-hidden "true"} - [:div.progress-bars - [:div.complete-song-bar] - [:div.buffered-part-bar {:style {:width buffered-width} - :on-click seek}] - [:div.played-back-bar {:style {:width played-width}} - [:div.played-back-knob]]] + [:article.progress-indicators + [progress-bars buffered-width played-width] [:div.progress-info-text.duration-text progress-text]])) (defn playback-info [song status] diff --git a/src/sass/app.sass b/src/sass/app.sass index dcc8613..059a292 100644 --- a/src/sass/app.sass +++ b/src/sass/app.sass @@ -48,6 +48,7 @@ // shows cover and current track align-items: center flex-grow: 1 + flex-basis: 25% color: inherit .media-left @@ -71,15 +72,18 @@ +tablet display: flex - flex-grow: 3 + flex-basis: 75% height: 1rem .progress-info-text - color: whitesmoke + color: $dark-invert font-size: $size-7 flex-shrink: 0 flex-grow: 0 + svg + overflow: visible + .progress-bars margin-left: .6rem margin-right: .6rem @@ -90,47 +94,27 @@ .buffered-part-bar, .played-back-bar height: 1rem - position: absolute - top: 0 - left: 0 - - // these are the actual bars - &:after - content: '' - display: block - height: 1px - position: relative - top: 50% - .complete-song-bar width: 100% - &:after - background: rgb(93,93,93) + rect + fill: rgb(93,93,93) .buffered-part-bar - cursor: pointer + rect + fill: rgb(143,143,143) - &:after - background: rgb(143,143,143) + .click-dummy + cursor: pointer + fill: transparent .played-back-bar pointer-events: none - &:after - background: whitesmoke - - .played-back-knob - position: absolute - width: 5px - height: 5px - left: 100% - top: 50% - margin-left: -2.5px - margin-top: -2.5px - background: whitesmoke - border-radius: 100% + circle, + rect + fill: $dark-invert // buttons to control current playback and playlist behavior .playback-controls,