我正在尝试为即将到来的项目在Clojure和CL之间做出选择。为了让我的脚湿透,我在玩一些简单的图形用户界面的东西。
这是我在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*))两个TextFields,当我在底部窗口中输入文本并按Enter时,换行符和一个">“将被添加,文本将被附加到顶部文本字段中。
在Clojure中,我尝试了Seesaw,并且是这样的:
(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!))不幸的是,这是不起作用的。窗口内容的大小与我想要的大小相反,并且我没有看到任何滚动条。顺便说一句,我的Swing知识根本不存在。
任何帮助都将不胜感激。
发布于 2013-06-16 20:03:00
(更新了CL版本的更接近工作的版本。查看带有可拖动分隔线的90/10拆分版本的修订历史记录。)
一旦文本不再适合输出文本区域,滚动条就会出现。
还可以使用(config! in-text :size [400 :by 20])配置大小,对于out-scrollable也是如此。
(ns myedclj.core
(:require [seesaw.core :refer :all]
[seesaw.keymap :refer :all]
[seesaw.bind :as bind]))
(def in-text
(text :editable? true :multi-line? false
:size [400 :by 20]))
(def out-text
(text :editable? false :multi-line? true :wrap-lines? true))
(def out-scrollable
(scrollable out-text
:size [400 :by 180]))
(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! [source target]
(value! target (str (value target) "\n\n> " (value source)))
(value! source ""))
(defn attach-listeners! []
(map-key in-text "ENTER"
(fn [_] (format-output! in-text out-text))
:scope :self))
(defn make-frame []
(frame
:title "Seesaw example"
:content (vertical-panel
:border 2
:items [out-scrollable
in-text])
:on-close :exit))
(defn -main [& args]
(native!)
(value! out-text a-tale)
(attach-listeners!)
(let [f (make-frame)]
(pack! f)
(show! f)))https://stackoverflow.com/questions/17132185
复制相似问题