mirror of
https://github.com/unclebob/more-speech.git
synced 2024-09-30 02:21:02 +00:00
Holding down scroll buttons works.
This commit is contained in:
parent
98a428432c
commit
57f46040e2
@ -12,6 +12,12 @@
|
|||||||
(defn- left-up [button state]
|
(defn- left-up [button state]
|
||||||
(assoc-in state (conj (:path button) :left-came-up) true))
|
(assoc-in state (conj (:path button) :left-came-up) true))
|
||||||
|
|
||||||
|
(defn- left-down [button state]
|
||||||
|
(assoc-in state (conj (:path button) :left-went-down) true))
|
||||||
|
|
||||||
|
(defn- left-held [button state]
|
||||||
|
(assoc-in state (conj (:path button) :left-held-down) true))
|
||||||
|
|
||||||
(def NOW 1234) ; mock time of day
|
(def NOW 1234) ; mock time of day
|
||||||
(def mouse-out (map->mock-graphic {:x 0 :y 0}))
|
(def mouse-out (map->mock-graphic {:x 0 :y 0}))
|
||||||
(def mouse-in (map->mock-graphic {:x 10 :y 10}))
|
(def mouse-in (map->mock-graphic {:x 10 :y 10}))
|
||||||
@ -23,6 +29,8 @@
|
|||||||
(def b (map->button {:x 10 :y 10 :w 10 :h 10
|
(def b (map->button {:x 10 :y 10 :w 10 :h 10
|
||||||
:button-state :whatever
|
:button-state :whatever
|
||||||
:left-up left-up
|
:left-up left-up
|
||||||
|
:left-down left-down
|
||||||
|
:left-held left-held
|
||||||
:path [:application :button]}))
|
:path [:application :button]}))
|
||||||
|
|
||||||
(defn- make-state [graphics]
|
(defn- make-state [graphics]
|
||||||
@ -77,4 +85,25 @@
|
|||||||
b (get-in state [:application :button])]
|
b (get-in state [:application :button])]
|
||||||
(should= nil (:left-time b))))
|
(should= nil (:left-time b))))
|
||||||
|
|
||||||
|
(it "calls :left-down when left button goes down while in"
|
||||||
|
(let [state (make-state mouse-in-left-down)
|
||||||
|
state (assoc-in state [:application :button :button-state] :in)
|
||||||
|
state (w/update-widget b state)
|
||||||
|
b (get-in state [:application :button])]
|
||||||
|
(should (:left-went-down b))))
|
||||||
|
|
||||||
|
(it "does not call :left-down if left already down."
|
||||||
|
(let [state (make-state mouse-in-left-down)
|
||||||
|
state (assoc-in state [:application :button :button-state] :left)
|
||||||
|
state (w/update-widget b state)
|
||||||
|
b (get-in state [:application :button])]
|
||||||
|
(should-not (:left-went-down b))))
|
||||||
|
|
||||||
|
(it "calls :left-held if left already down."
|
||||||
|
(let [state (make-state mouse-in-left-down)
|
||||||
|
state (assoc-in state [:application :button :button-state] :left)
|
||||||
|
state (w/update-widget b state)
|
||||||
|
b (get-in state [:application :button])]
|
||||||
|
(should (:left-held-down b))))
|
||||||
|
|
||||||
)
|
)
|
@ -18,10 +18,12 @@
|
|||||||
(setup-widget [widget state]
|
(setup-widget [widget state]
|
||||||
(assoc widget :display-position 0
|
(assoc widget :display-position 0
|
||||||
:page-up (map->button {:x (+ x 20) :y (+ y h -30) :h 20 :w 20
|
:page-up (map->button {:x (+ x 20) :y (+ y h -30) :h 20 :w 20
|
||||||
:left-up scroll-up
|
:left-down scroll-up
|
||||||
|
:left-held scroll-up
|
||||||
:draw up-arrow})
|
:draw up-arrow})
|
||||||
:page-down (map->button {:x (+ x w -20) :y (+ y h -30) :h 20 :w 20
|
:page-down (map->button {:x (+ x w -20) :y (+ y h -30) :h 20 :w 20
|
||||||
:left-up scroll-down
|
:left-down scroll-down
|
||||||
|
:left-held scroll-down
|
||||||
:draw down-arrow})
|
:draw down-arrow})
|
||||||
))
|
))
|
||||||
(update-widget [widget state]
|
(update-widget [widget state]
|
||||||
@ -34,8 +36,9 @@
|
|||||||
(let [button-path (:path button)
|
(let [button-path (:path button)
|
||||||
parent-path (drop-last button-path)
|
parent-path (drop-last button-path)
|
||||||
article-window (get-in state parent-path)
|
article-window (get-in state parent-path)
|
||||||
|
articles (get-in state [:application :chronological-text-events])
|
||||||
display-position (:display-position article-window)
|
display-position (:display-position article-window)
|
||||||
display-position (+ display-position 19)
|
display-position (min (count articles) (inc display-position))
|
||||||
article-window (assoc article-window :display-position display-position)
|
article-window (assoc article-window :display-position display-position)
|
||||||
state (assoc-in state parent-path article-window)]
|
state (assoc-in state parent-path article-window)]
|
||||||
state))
|
state))
|
||||||
@ -45,7 +48,7 @@
|
|||||||
parent-path (drop-last button-path)
|
parent-path (drop-last button-path)
|
||||||
article-window (get-in state parent-path)
|
article-window (get-in state parent-path)
|
||||||
display-position (:display-position article-window)
|
display-position (:display-position article-window)
|
||||||
display-position (max 0 (- display-position 19))
|
display-position (max 0 (dec display-position))
|
||||||
article-window (assoc article-window :display-position display-position)
|
article-window (assoc article-window :display-position display-position)
|
||||||
state (assoc-in state parent-path article-window)]
|
state (assoc-in state parent-path article-window)]
|
||||||
state))
|
state))
|
||||||
|
@ -23,12 +23,33 @@
|
|||||||
which))
|
which))
|
||||||
|
|
||||||
(defn- check-call-left-up [state button which]
|
(defn- check-call-left-up [state button which]
|
||||||
(let [previous-state (:button-state button)]
|
(let [previous-state (:button-state button)
|
||||||
(if (and (nil? which) (= :left previous-state))
|
left-up (:left-up button)]
|
||||||
((:left-up button) button state)
|
(if (and left-up
|
||||||
|
(nil? which)
|
||||||
|
(= :left previous-state))
|
||||||
|
(left-up button state)
|
||||||
state)))
|
state)))
|
||||||
|
|
||||||
(defn- check-left-down [state button which]
|
(defn- check-call-left-down [state button which]
|
||||||
|
(let [button (get-in state (:path button))
|
||||||
|
previous-state (:button-state button)
|
||||||
|
left-down (:left-down button)]
|
||||||
|
(if (and left-down
|
||||||
|
(= :in previous-state)
|
||||||
|
(= :left which))
|
||||||
|
(left-down button state)
|
||||||
|
state)))
|
||||||
|
|
||||||
|
(defn- check-call-left-held [state button which]
|
||||||
|
(let [button (get-in state (:path button))
|
||||||
|
left-held (:left-held button)]
|
||||||
|
(if (and left-held
|
||||||
|
(= :left which))
|
||||||
|
(left-held button state)
|
||||||
|
state)))
|
||||||
|
|
||||||
|
(defn- check-set-left-time [state button which]
|
||||||
(let [previous-state (:button-state button)
|
(let [previous-state (:button-state button)
|
||||||
g (get-in state [:application :graphics])]
|
g (get-in state [:application :graphics])]
|
||||||
(if (and (= :in previous-state) (= :left which))
|
(if (and (= :in previous-state) (= :left which))
|
||||||
@ -51,7 +72,9 @@
|
|||||||
:out)
|
:out)
|
||||||
state (if in?
|
state (if in?
|
||||||
(-> state
|
(-> state
|
||||||
(check-left-down button which)
|
(check-set-left-time button which)
|
||||||
|
(check-call-left-down button which)
|
||||||
|
(check-call-left-held button which)
|
||||||
(check-call-left-up button which))
|
(check-call-left-up button which))
|
||||||
state)
|
state)
|
||||||
state (check-erase-left-time state button which)
|
state (check-erase-left-time state button which)
|
||||||
|
Loading…
Reference in New Issue
Block a user