-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlayout.lisp
29 lines (21 loc) · 1.06 KB
/
layout.lisp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
;;; -*- Mode: LISP; Syntax: COMMON-LISP; Package: TRIVIAL-GUI; Base: 10; -*-
(in-package #:trivial-gui)
(defparameter *layouts* (make-hash-table :test 'eql))
(defun layout (name)
(layout-updater (gethash name *layouts* (make-layout))))
(defun vertical-layout-updater (parent)
(let* ((children (children-of parent))
(interval (/ 1f0 (length children))))
(iterate
(for child in-vector children with-index child-index)
(setf (slot-value child 'origin) (sb-cga:vec 0f0 (* interval child-index) 0f0))
(setf (slot-value child 'size) (sb-cga:vec 1f0 interval 0f0)))))
(setf (gethash :vertical *layouts*) #'vertical-layout-updater)
(defun horizontal-layout-updater (parent)
(let* ((children (children-of parent))
(interval (/ 1f0 (length children))))
(iterate
(for child in-vector children with-index child-index)
(setf (slot-value child 'origin) (sb-cga:vec (* interval child-index) 0f0 0f0))
(setf (slot-value child 'size) (sb-cga:vec interval 1f0 0f0)))))
(setf (gethash :horizontal *layouts*) #'horizontal-layout-updater)