mirror of
https://github.com/unclebob/more-speech.git
synced 2024-09-30 02:21:02 +00:00
Calculate the number of headers that fit in the article frame.
This commit is contained in:
parent
e84781d962
commit
9d54c856cf
@ -1,7 +1,8 @@
|
||||
(ns more-speech.ui.article-window-spec
|
||||
(:require [speclj.core :refer :all]
|
||||
[more-speech.ui.article-window :refer :all]
|
||||
[more-speech.ui.widget :refer [widget setup-widget]]))
|
||||
[more-speech.ui.widget :refer [widget setup-widget]]
|
||||
[more-speech.ui.graphics :as g]))
|
||||
|
||||
(describe "article window"
|
||||
(context "setup"
|
||||
@ -65,3 +66,25 @@
|
||||
(should= [1 2 3] (map :id threaded-events))
|
||||
(should= [0 1 2] (map :indent threaded-events))))
|
||||
)
|
||||
|
||||
(defrecord mock-graphics []
|
||||
g/graphics
|
||||
(line-height [graphics]
|
||||
20)
|
||||
)
|
||||
|
||||
(declare state frame)
|
||||
|
||||
(describe "article frame"
|
||||
(context "setup"
|
||||
(with state {:application
|
||||
{:graphics (->mock-graphics)
|
||||
}
|
||||
}
|
||||
)
|
||||
(with frame {:x 0 :y 0 :w 500 :h 500})
|
||||
(it "determines number of article headers fit in the frame"
|
||||
(let [frame (setup-article-frame @state @frame)]
|
||||
(should= 10 (:n-headers frame)))
|
||||
)
|
||||
))
|
||||
|
@ -1,5 +1,6 @@
|
||||
(ns more-speech.ui.article-window
|
||||
(:require
|
||||
[more-speech.ui.config :as config]
|
||||
[more-speech.ui.cursor :as cursor]
|
||||
[more-speech.content.article :as a]
|
||||
[more-speech.ui.widget :refer [widget]]
|
||||
@ -16,12 +17,13 @@
|
||||
scroll-up
|
||||
scroll-down
|
||||
update-article-frame
|
||||
setup-article-frame
|
||||
thread-events)
|
||||
|
||||
(defrecord article-frame [x y w h display-position]
|
||||
widget
|
||||
(setup-widget [widget state]
|
||||
widget)
|
||||
(setup-article-frame state widget))
|
||||
(update-widget [widget state]
|
||||
(update-article-frame state widget))
|
||||
(draw-widget [widget state]
|
||||
@ -29,15 +31,25 @@
|
||||
state)
|
||||
)
|
||||
|
||||
(defn setup-article-frame [state frame]
|
||||
(let [graphics (get-in state [:application :graphics])
|
||||
line-height (g/line-height graphics)
|
||||
header-height (+ config/header-bottom-margin
|
||||
config/header-top-margin
|
||||
(* config/header-lines line-height))
|
||||
headers (quot (:h frame) header-height)
|
||||
frame (assoc frame :n-headers headers)]
|
||||
frame))
|
||||
|
||||
(defn- update-article-frame [state frame]
|
||||
(if (get-in state [:application :update-articles] true)
|
||||
(let [application (:application state)
|
||||
article-map (:text-event-map application)
|
||||
event-map (:text-event-map application)
|
||||
events (:chronological-text-events application)
|
||||
articles (thread-events events article-map (:open-thread application))
|
||||
threaded-events (thread-events events event-map (:open-thread application))
|
||||
display-position (:display-position frame)
|
||||
articles (drop display-position articles)
|
||||
articles (take 19 articles)
|
||||
end-position (min (count threaded-events) (+ display-position (:n-headers frame)))
|
||||
articles (subvec threaded-events display-position end-position)
|
||||
frame-path (:path frame)
|
||||
state (assoc-in state (conj frame-path :displayed-articles) articles)
|
||||
state (assoc-in state (conj frame-path :last-display-position) display-position)
|
||||
|
5
src/more_speech/ui/config.clj
Normal file
5
src/more_speech/ui/config.clj
Normal file
@ -0,0 +1,5 @@
|
||||
(ns more-speech.ui.config)
|
||||
|
||||
(def header-lines 2)
|
||||
(def header-top-margin 5)
|
||||
(def header-bottom-margin 5)
|
Loading…
Reference in New Issue
Block a user