Skip to content
Browse files

(fixes #17) fixed "lines" macro to not to ignore padding top

  • Loading branch information...
1 parent 9303503 commit 8dd07f509a189e0325d4cc93f2dac14b1acc096e @fukamachi committed Nov 14, 2010
Showing with 9 additions and 7 deletions.
  1. +2 −1 src/L5/context.clj
  2. +2 −2 src/L5/layout.clj
  3. +5 −4 src/L5/slide.clj
View
3 src/L5/context.clj
@@ -31,7 +31,8 @@
:current (ref 0)
:width (:width params)
:height (:height params)
- :padding (:padding params)
+ :global-padding (or (:global-padding params) (:padding params))
+ :padding {:top 0, :right 0, :bottom 0, :left 0}
:font-size (:font-size params)
:font-family (:font-family params)
:actions (ref nil)}]
View
4 src/L5/layout.clj
@@ -31,9 +31,9 @@
:body [~@strs]})
(defmacro lines [& strs]
- ;; FIXME: ignores a top padding in the context
(let [line-height (/ (:font-size (context)) 3)]
- `{:attr {:padding {:top ~line-height :bottom ~line-height}}
+ `{:attr {:padding {:top (+ (-> (context) :padding :top) ~line-height)
+ :bottom ~line-height}}
:body [~@strs]}))
(defmacro item [& strs]
View
9 src/L5/slide.clj
@@ -103,7 +103,7 @@
(int (:top (:padding attr)))
nil)
(let [font (Font. (:font-family attr) 0 (or (:font-size attr) 300))
- padding (:padding attr)
+ padding (merge-with + (:padding attr) (select-keys (:global-padding attr) [:left :right :bottom]))
text-shape (build-str-shape g body font (:width attr) (:text-align attr))
bounds (.getBounds text-shape)
affine (cond
@@ -118,7 +118,7 @@
(let [next-y (draw-text-shape g text-shape affine padding)]
(.setColor g default-color)
(if (nil? (:font-size attr))
- (- next-y (-> attr :padding :bottom))
+ (- next-y (-> attr :global-padding :bottom))
next-y)))))
(defn- get-next-attr [attr y]
@@ -129,7 +129,8 @@
(merge (select-keys context
[:width :height
:font-family :font-size
- :position :text-align])
+ :position :text-align
+ :global-padding])
attr
{:padding (merge (:padding context)
(if (= :fixed (:position attr)) {:top 0 :bottom 0})
@@ -148,7 +149,7 @@
(defn draw-slide [context idx]
(let [slides @(:slides context)]
(when (and @(:g context) slides (get slides idx))
- (let [y (ref (-> context :padding :top))]
+ (let [y (ref (-> context :global-padding :top))]
(doseq [elem (get slides idx)]
(let [elem (normalize-element context elem)
elem-y (draw @(:g context)

0 comments on commit 8dd07f5

Please sign in to comment.
Something went wrong with that request. Please try again.