dunlin/frame.fnl
Daniel Barlow 5069e6aff1 move command state into per-frame table
lots of dependent changes here, unfortunately

- get rid of Buffer.current (it's per-frame now)
- in define-command, functions providing default parameter values
   now accept frame as parameter
- in keymaps, parameter values are functions that accept frame as
   parameter
2022-12-27 12:25:50 +00:00

69 lines
2.3 KiB
Fennel

(local { : Gtk : Gdk : WebKit2 : cairo } (require :lgi))
(local { : view } (require :fennel))
(local lume (require :lume))
(local Command (require :command))
(local keymap (require :keymap))
(var frames [])
(fn new-frame [global-keymap]
(let [hpad 2
vpad 2
self {}
recogniser (keymap.recogniser global-keymap)
commander (Command.commander self)
window (Gtk.Window {
:title "Dunlin"
:default_width 800
:default_height 720
:on_destroy Gtk.main_quit
})
container (Gtk.Box {
:orientation Gtk.Orientation.VERTICAL
})
progress-bar (Gtk.ProgressBar {
:orientation Gtk.Orientation.HORIZONTAL
:fraction 1.0
:margin 0
})
contentwidget (Gtk.Box {
:orientation Gtk.Orientation.VERTICAL
})
]
(tset window :on_key_release_event
(fn [window event]
(when (not (commander:active?))
(match (recogniser:accept-event event)
[name params] (commander:invoke-interactively name params)
(nil prompt) (print "prompted" prompt)))
(when (and event.state.MOD1_MASK
(= event.keyval (string.byte "x")))
(commander:activate))))
(doto container
(: :pack_start commander.widget false false vpad)
(: :pack_start progress-bar false false vpad)
(: :pack_start contentwidget true true vpad))
(window:add container)
(window:show_all)
(let [f
{
:window window
:buffer nil
:content contentwidget
:show-buffer (fn [self b]
(each [_ w (pairs (contentwidget:get_children))]
(w:hide))
(tset self :buffer b)
(contentwidget:pack_start b.webview true true 0)
(b.webview:show))
}]
(lume.extend self f)
(table.insert frames self)
self)))
{ :new new-frame :frames frames }