;;; ll-box --- luki boxes -*- lexical-binding: t -*- ;; ;;; Commentary: ;; ;;; Code: (require 'cl-lib) (cl-pushnew "." load-path :test #'string=) (require 'll) (-> 'll-button) (cl-defstruct ll-box (x 0 :type integer) (y 0 :type integer) (w 8 :type integer) (h 8 :type integer) (data [97 98 99 100 101 102 103 104] :type array)) (cl-defmethod ll-box-size ((b ll-box)) (* (ll-box-w b) (ll-box-h b))) (cl-defmethod ll-box-draw-at ((b ll-box) x y di &optional border) (when-let* ((chr (cl-case border (-1 (or 9623 9581)) ( 0 (or 9604 9472)) (-2 (or 9622 9582)) ( 1 (or 9612 9474)) (-3 (or 9624 9583)) ( 2 (or 9600 9472)) (-4 (or 9629 9584)) ( 3 (or 9616 9474)) (t (aref (ll-box-data b) (m di (--- (ll-box-data b))))))) (chr-str (char-to-string chr)) (col (cond (border `(:foreground "#199696")) ((= chr 32) `(:background "#6464ff")) (`(:foreground "#32afaf" :background "#3264ff"))))) (goto-char (+ (pos-bol (+ (line-number-at-pos (point-min)) (- y (line-number-at-pos)))) x)) (@i (propertize chr-str 'face col)) (delete-char 1))) (cl-defmethod ll-box-draw ((b ll-box)) (cl-loop for i from 0 below (ll-box-size b) for x-idx = (m i (ll-box-w b)) for y-idx = (/ i (ll-box-w b)) for top = (z y-idx) for left = (z x-idx) for right = (= 1 (- (ll-box-w b) x-idx)) for down = (= 1 (- (ll-box-h b) y-idx)) for border = (cond ((& top left) -1) ((& top right) -2) ((& down right) -3) ((& down left) -4) (top 0) (right 1) (down 2) (left 3)) for x = (+ (ll-box-x b) x-idx) for y = (+ (line-number-at-pos (point-min)) (ll-box-y b) y-idx) do (ll-box-draw-at b x y i border) finally (goto-char (+ (pos-bol 2) (ll-box-x b))) (delete-char 23) (ll-insert-button "<" (L (_) (-- (ll-box-x b))) nil) (@i 32) (ll-insert-button "^" (L (_) (-- (ll-box-y b))) nil) (@i 32) (ll-insert-button "v" (L (_) (++ (ll-box-y b))) nil) (@i 32) (ll-insert-button ">" (L (_) (++ (ll-box-x b))) nil))) (defvar ll-box-lb nil) (defun ll-box-draw-init () (cl-loop initially (new-buf "*ll-box-draw*") (or (ll-box-p ll-box-lb) (setf ll-box-lb (make-ll-box :x 8 :y 5 :w 23 :h 12 :data [108 108 45 98 111 120 32 32]))) repeat 28 do (@i (propertize (make-string 98 183) 'face `(:foreground "#643296")) 10) finally (ll-box-draw ll-box-lb))) ;; test: (ll-box-draw-init) (<- 'll-box) ;;; ll-box.el ends here