我正在尝试为即将到来的项目在 Clojure 和 CL 之间做出决定。为了弄湿我的脚,我玩弄了一些简单的 GUI 东西。
这是我在 CL / Ltk 中的内容:
(ql:quickload "ltk")
(defpackage :myed
(:use :ltk :cl))
(in-package :myed)
(defun ed-label (fr)
(make-instance 'label :master fr :font "Sans-Serif" :text "Editor"))
(defparameter *text-field*
(make-instance 'text
:font "monospaced" :takefocus :t))
(defparameter *a-tale*
"It was the best of times, it was the worst of times, it was the age of wisdom, it was the age of foolishness, it was the epoch of belief, it was the epoch of incredulity, it was the season of Light")
(defun make-frame ()
(with-ltk ()
(let* ((f (make-instance 'frame))
(scroll (make-instance 'scrolled-text :master f))
(outtext (textbox scroll)))
(pack f)
(configure outtext :font "monospaced" :background "#aea79f" :wrap :word)
(pack (ed-label f) :anchor :nw :side :top)
(pack scroll :anchor :nw :expand t :fill :both)
(pack *text-field* :anchor :sw :fill :x :ipady 10)
(setf (text outtext) *a-tale*)
(bind *text-field* "<KeyPress-Return>"
(lambda (event) (format-output outtext)))
(configure f :borderwidth 2))))
(defun format-output (target)
"Print inputstring with newlines and > ."
(append-text target (format nil "~%~%> ~A~%~%" (text *text-field*)))
(clear-text *text-field*))
两个文本字段,当我在底部窗口中输入文本并按 Enter 键时,会添加换行符和“>”,并将文本附加到顶部文本字段中。
在 Clojure 我试过跷跷板和这个:
(ns myedclj.core
(:use [seesaw core keymap])
(:require [seesaw.bind :as bind]))
(def outtext
( text
:multi-line? true :wrap-lines? true :editable? false))
(def ed-label (label :text "Editor"))
(def intext
(text :multi-line? false :editable? true))
(def a-tale
"It was the best of times, it was the worst of times, it was the age of wisdom, it was the age of foolishness, it was the epoch of belief, it was the epoch of incredulity, it was the season of Light")
(defn format-output
[target]
(.append target (str "\n\n" "> " (text intext))))
(map-key intext "ENTER" (fn [_] (format-output outtext)))
(text! outtext a-tale)
(defn make-frame []
(frame :content (vertical-panel
:border 2
:items [ed-label
(scrollable outtext)
intext])))
(defn -main [& args]
(-> (make-frame)
pack!
show!))
不幸的是,这不起作用。windowcontents 的尺寸与我想要的相反,我看不到任何滚动条。顺便说一句,我的 Swing 知识不存在。
任何帮助将不胜感激。