Make menu-alist type real alist
This commit is contained in:
parent
7956aef3e5
commit
e6e4410a91
|
@ -35,8 +35,10 @@
|
||||||
(defun main ()
|
(defun main ()
|
||||||
"A pathetic fascimile of a main loop. Look, I'm still tinkering!"
|
"A pathetic fascimile of a main loop. Look, I'm still tinkering!"
|
||||||
(let ((matrix (make-screen-matrix))
|
(let ((matrix (make-screen-matrix))
|
||||||
(items '(("PLAY" (SELECTION . 100) (SELECTED . T)) ("QUIT" (SELECTION . 100)) ("ESCAPE")
|
(items `(((LABEL . "PLAY") (SELECTION . 100) (SELECTED . T))
|
||||||
("RUN AWAY" (SELECTION . -100)))))
|
((LABEL . "QUIT") (SELECTION . 100) (FUNCTION . ,(lambda () (print "AAAAAA"))))
|
||||||
|
((LABEL . "ESCAPE"))
|
||||||
|
((LABEL . "RUN AWAY") (SELECTION . -100)))))
|
||||||
(cl-charms:with-curses ()
|
(cl-charms:with-curses ()
|
||||||
(cl-charms:enable-raw-input :interpret-control-characters 't)
|
(cl-charms:enable-raw-input :interpret-control-characters 't)
|
||||||
(clear-screen)
|
(clear-screen)
|
||||||
|
|
30
ui.lisp
30
ui.lisp
|
@ -19,7 +19,7 @@
|
||||||
|
|
||||||
(defpackage :flora-search-aurora.ui
|
(defpackage :flora-search-aurora.ui
|
||||||
(:use :cl :flora-search-aurora.display :flora-search-aurora.input :assoc-utils)
|
(:use :cl :flora-search-aurora.display :flora-search-aurora.input :assoc-utils)
|
||||||
(:export #:ui-loop #:render-menu-strip :selection :selected))
|
(:export #:ui-loop #:render-menu-strip :label :selection :selected))
|
||||||
|
|
||||||
(in-package :flora-search-aurora.ui)
|
(in-package :flora-search-aurora.ui)
|
||||||
|
|
||||||
|
@ -107,12 +107,12 @@ left-to-right, unless negative — in which case, right-to-left."
|
||||||
"Render several menu items to the matrix, starting at the given x/y coordinates,
|
"Render several menu items to the matrix, starting at the given x/y coordinates,
|
||||||
maximum width for any given item, and the height of all items.
|
maximum width for any given item, and the height of all items.
|
||||||
The item list should be an alist of the following format:
|
The item list should be an alist of the following format:
|
||||||
((“LABEL” ((SELECTED . 'T)(SELECTION . 100))) (“LABEL-2” (SELECTION . -20)) ⋯)"
|
(((LABEL . “FOO”)(SELECTED . T)(SELECTION . 100)) ((LABEL . “BAR”)(SELECTION . -20)) ⋯)"
|
||||||
(let ((x x))
|
(let ((x x))
|
||||||
(mapcar
|
(mapcar
|
||||||
(lambda (item)
|
(lambda (item)
|
||||||
(let* ((label (car item))
|
(let* ((label (cdr (assoc 'label item)))
|
||||||
(selection (or (cdr (assoc 'selection (cdr item)))
|
(selection (or (cdr (assoc 'selection item))
|
||||||
0))
|
0))
|
||||||
(width (at-most max-item-width
|
(width (at-most max-item-width
|
||||||
(+ (length label) 2))))
|
(+ (length label) 2))))
|
||||||
|
@ -120,7 +120,7 @@ The item list should be an alist of the following format:
|
||||||
:width width
|
:width width
|
||||||
:height height
|
:height height
|
||||||
:selection selection
|
:selection selection
|
||||||
:selected (cdr (assoc 'selected (cdr item))))
|
:selected (cdr (assoc 'selected item)))
|
||||||
(setf x (+ x width 1))))
|
(setf x (+ x width 1))))
|
||||||
items))
|
items))
|
||||||
matrix)
|
matrix)
|
||||||
|
@ -154,9 +154,9 @@ item's “selected-percentage”, so that they converge at the right percent.
|
||||||
That is, 0 for non-selected items and 100 for selected items."
|
That is, 0 for non-selected items and 100 for selected items."
|
||||||
(mapcar
|
(mapcar
|
||||||
(lambda (item)
|
(lambda (item)
|
||||||
(let* ((selection (assoc 'selection (cdr item)))
|
(let* ((selection (assoc 'selection item))
|
||||||
(selection-num (or (cdr selection) 0))
|
(selection-num (or (cdr selection) 0))
|
||||||
(selectedp (cdr (assoc 'selected (cdr item)))))
|
(selectedp (cdr (assoc 'selected item))))
|
||||||
(if selection
|
(if selection
|
||||||
(setf (cdr selection)
|
(setf (cdr selection)
|
||||||
(gravitate-toward
|
(gravitate-toward
|
||||||
|
@ -179,8 +179,7 @@ That is, 0 for non-selected items and 100 for selected items."
|
||||||
(#\→ (select-right-menu-item menu-alist))
|
(#\→ (select-right-menu-item menu-alist))
|
||||||
(#\← (select-left-menu-item menu-alist)))
|
(#\← (select-left-menu-item menu-alist)))
|
||||||
(if (eq (getf input :char) #\return)
|
(if (eq (getf input :char) #\return)
|
||||||
(ignore-errors (apply (cdr (assoc 'function (cdr selected-item))) '()))))))
|
(ignore-errors (apply (cdr (assoc 'function selected-item)) '()))))))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
(defun select-menu-item (menu-alist position)
|
(defun select-menu-item (menu-alist position)
|
||||||
|
@ -188,13 +187,13 @@ That is, 0 for non-selected items and 100 for selected items."
|
||||||
(let ((old-position (selected-menu-item-position menu-alist)))
|
(let ((old-position (selected-menu-item-position menu-alist)))
|
||||||
;; The “polarity” (direction of selection) depends on the relative
|
;; The “polarity” (direction of selection) depends on the relative
|
||||||
;; direction of the previous selection.
|
;; direction of the previous selection.
|
||||||
(setf (aget (cdr (nth position menu-alist)) 'selection)
|
(setf (aget (nth position menu-alist) 'selection)
|
||||||
(if (< old-position position) 10 -10))
|
(if (< old-position position) 10 -10))
|
||||||
(setf (aget (cdr (nth position menu-alist)) 'selected) 't)
|
(setf (aget (nth position menu-alist) 'selected) 't)
|
||||||
;; Likewise for the previously-selected item.
|
;; Likewise for the previously-selected item.
|
||||||
(setf (aget (cdr (nth old-position menu-alist)) 'selection)
|
(setf (aget (nth old-position menu-alist) 'selection)
|
||||||
(if (< old-position position) -90 90))
|
(if (< old-position position) -90 90))
|
||||||
(setf (aget (cdr (nth old-position menu-alist)) 'selected) nil))
|
(setf (aget (nth old-position menu-alist) 'selected) nil))
|
||||||
menu-alist)
|
menu-alist)
|
||||||
|
|
||||||
|
|
||||||
|
@ -205,7 +204,7 @@ That is, 0 for non-selected items and 100 for selected items."
|
||||||
(select-menu-item menu-alist new-selection))))
|
(select-menu-item menu-alist new-selection))))
|
||||||
|
|
||||||
|
|
||||||
(defun select-left-menu-item (menu-alist)
|
(defun select-left-menu-item ( menu-alist)
|
||||||
"Select the item to the left of the currenty-selected item."
|
"Select the item to the left of the currenty-selected item."
|
||||||
(let ((new-selection (- (selected-menu-item-position menu-alist) 1)))
|
(let ((new-selection (- (selected-menu-item-position menu-alist) 1)))
|
||||||
(if (>= new-selection 0)
|
(if (>= new-selection 0)
|
||||||
|
@ -217,8 +216,7 @@ That is, 0 for non-selected items and 100 for selected items."
|
||||||
(position
|
(position
|
||||||
't menu-alist
|
't menu-alist
|
||||||
:test (lambda (ignore list-item)
|
:test (lambda (ignore list-item)
|
||||||
(cdr (assoc 'selected
|
(cdr (assoc 'selected list-item)))))
|
||||||
(cdr list-item))))))
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Ŝarĝante…
Reference in New Issue