dunlin/frame.fnl

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 }