Optimizing conditionals

This commit is contained in:
Amy Grinn 2024-12-17 12:39:19 -05:00
parent 6aed092c24
commit 0e5fc5a73b
No known key found for this signature in database
GPG key ID: 6B558BED1DCF3192

View file

@ -748,14 +748,14 @@
(let row ((r r-start)
(y (- (vec2-y center) (* tile-height (floor (/ height 2))))))
;; Draw menu background
(if (= r r-start)
(let* ((x (- (vec2-x center) (* tile-width (floor (/ width 2)))))
(w (* tile-width width))
(h (* tile-height height)))
(set-fill-color! context "#000")
(fill-rect context x y w h)
(set-stroke-color! context "blue")
(stroke-rect context x y w h)))
(when (= r r-start)
(let* ((x (- (vec2-x center) (* tile-width (floor (/ width 2)))))
(w (* tile-width width))
(h (* tile-height height)))
(set-fill-color! context "#000")
(fill-rect context x y w h)
(set-stroke-color! context "blue")
(stroke-rect context x y w h)))
;; Draw menu text
(set-text-align! context "center")
(set-font! context "normal 16px monogram")
@ -764,13 +764,12 @@
(if (= r r-start)
(fill-text context (menu-name (current-menu)) (vec2-x center) (+ y text-offset-y))
(if (and (>= r -1) (< r-index num-items) (< r r-end))
(let* ((item (cond
((= r -1)
(if (= (current-menu-page) 0) "Back" "..."))
((and (= r (1- r-end)) (< r-index (1- num-items)))
"...")
(else
(menu-item-name (vector-ref (menu-items (current-menu)) r-index)))))
(let* ((item (if (= r -1)
(if (= (current-menu-page) 0)
"Back" "...")
(if (and (= r (1- r-end)) (< r-index (1- num-items)))
"..."
(menu-item-name (vector-ref (menu-items (current-menu)) r-index)))))
(text (string-append (if (= r-index (current-menu-index)) "▸ " " ") item)))
(fill-text context text (vec2-x center) (+ y text-offset-y))))))
;; Draw next row