hboard/tmp.scm

93 lines
3.7 KiB
Scheme
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

(kbd/load-font "/home/user/.nix-profile/share/fonts/noto/NotoSans[wdth,wght].ttf")
(define state #f)
(kbd/defclass en (latin)
((init) (set! state 'lower))
((state) (or 'state 'lower))
((show-upper) (or (symbol=? (self state) 'upper) (symbol=? (self state) 'capslock)))
((show-lower) (symbol=? (self state) 'lower))
((show-symbols) (symbol=? (self state) 'symbols))
((show-numbers) (symbol=? (self state) 'numbers))
((show-preferences) (symbol=? (self state) 'preferences))
((rows)
(cond
((self show-upper) '((Q W E R T Y U I O P)
(A S D F G H J K L)
(Shift_L Z X C V B N M BackSpace)
(show_numbers preferences space "." Return)))
((self show-symbols) '((~ "`" "|" "·" π τ "÷" "×" "¶")
("©" "®" "£" "¥" ^ "°" * "{" "}")
(show_numbers_from_symbols \ / < > = "[" "]" BackSpace)
(show_letters preferences space "." Return)))
((self show-numbers) '((1 2 3 4 5 6 7 8 9 0)
("@" "#" $ % & - _ + "(" ")")
(show_symbols "," "\"" "'" : ";" ! ? BackSpace)
(show_letters preferences space "." Return)))
(else '((q w e r t y u i o p)
(a s d f g h j k l)
(Shift_L z x c v b n m BackSpace)
(show_numbers preferences space "." Return)))))
; 1 unit = keyboard width / total units in this row
((button-width sym)
(cond
((equal? sym 'Shift_L) 13.0)
((equal? sym 'BackSpace) 13.0)
((equal? sym 'show_numbers) 13.0)
((equal? sym 'show_letters) 13.0)
((equal? sym 'space) 54.0)
((equal? sym 'Return) 13.0)
(else 10.0)))
((button-padding sym)
(cond
((equal? sym 'a) (cons 5.0 0.0))
((equal? sym 'l) (cons 0.0 5.0))
(else (cons 0.0 0.0))))
((make-button sym x y w h)
(let ((sym (if (symbol? sym) (symbol->string sym) sym)))
(list sym (kbd/make-text (cons x y) (cons w h) sym "Noto Sans" 74))))
((make-row syms y width height)
(let ((total-x (apply + (map (lambda (sym)
(let ((pad (self button-padding sym))
(width (self button-width sym)))
(+ width (car pad) (cdr pad))))
syms))))
(define (scale u) (/ (* u width) total-x))
(define (calc x syms)
(if (null? syms)
'()
(let* ((sym (car syms))
(pad1 (self button-padding sym))
(pad (cons (scale (car pad1)) (scale (cdr pad1))))
(w (scale (self button-width sym))))
(cons (self make-button sym (+ x (car pad)) y w height)
(calc (+ x (car pad) w (cdr pad)) (cdr syms))))))
(calc 0 syms)))
((height) 500.0)
((make-layout rows kbd-width)
(define (height-list start end offset)
(if (> start end) '() (cons start (height-list (+ start offset) end offset))))
(define (append-all lists) (apply append lists))
(let*
((height (self height))
(row-height (/ height (length rows)))
(button-rows (map (lambda (row y) (self make-row row y kbd-width row-height))
(reverse rows)
(height-list 0 height row-height))))
(kbd/make-layout (cons (list "!bg" (kbd/make-rect (cons 0 0) (cons kbd-width height))) (append-all button-rows)))))
((kbd-layout)
(self make-layout (self rows) (kbd/width)))
; signals
((kbd/width-changed)
(kbd/set-layout (self kbd-layout))))