如何为简单的扫雷游戏创建 MigLayout?

How to create a MigLayout for a simple minesweeper game?

我在做一个简单的clojure扫雷游戏,主要是锻炼一下语言。 "core game engine" 已准备就绪,现在我想添加一个简单的 UI。我查看了 seesaw,到目前为止效果很好。

我唯一纠结的是我想使用的 mig layout。我的想法是采用以下布局:

 _______________________
[_________NORTH_________]
[   ][             ][   ]
[ W ][    FIXED    ][ E ]
[ E ][    SIZE     ][ A ]
[ S ][    BOARD    ][ S ]
[ T ][             ][ T ]
[___][_____________][___]
[_________SOUTH_________]

如果 window 调整大小,北、西、东和南应该增长。主面板应具有固定大小,其中包含代表游戏板的所有按钮。

在阅读 mig 布局之前,我考虑过使用包含网格面板的边框面板,但正如 seesaw github 页面中所述:

Seesaw has rudimentary support for GridBagLayout in the seesaw.core/form-panel function. I don't recommend using this because it's half-baked and not as powerful as using MigLayout (seesaw.mig) or JGoodies (seesaw.forms).

我想试试 MigLayout。我的第一次尝试:

(defn make-border-panel 
[]
(mig-panel 
 :constraints ["fill" "[grow][][grow]" "[grow][][grow]"]
 :items [ 
       ["X"                  "shrink 0"  ]
       ["X"                  "shrink 0"  ]
       ["X"                  "shrink 0"  ]
       ["X"                  "shrink 0"  ]
       ["X"                  "shrink 0"  ]
       ["X"                  "shrink 0"  ]
       ["X"                  "shrink 0"  ]
       ["X"                  "shrink 0"  ]
       ["X"                  "shrink 0"  ]
       ["Minesweeper North"  "dock north"]
       ["W"                  "dock west" ]
       ["E"                  "dock east" ]
       ["Minesweeper South"  "dock south"]
      ]))

更新 1

我暂时忽略北、南、西、东,并执行以下操作以至少获得中心板:

(defn make-button [x y]
   (button :id (format "cell_%d_%d" x y)
           :icon (clojure.java.io/resource "minesweeper/icons/button.png")))


(defn make-board
  [w h]
  (mig-panel 
      :constraints [(str "wrap" w) "[]" "[]" ]
      :items (for [x (range w) y (range h)]  
          (vector (make-button x y) "w 24px!, h 24px!"))))

我意识到我的扫雷游戏并不需要 WEST 和 EAST 面板。我的最终布局如下所示:

 _____________
[____NORTH____]
[             ]
[             ]
[   CENTER    ]
[             ]
[_____________]
[____SOUTH____]

中心本身是另一个 mig 面板,其中包含代表地雷的按钮。 Clojure 中的代码如下所示:

(defn make-layout
  [rows cols level]
  (mig-panel
   :constraints ["wrap1" "[center]" "[][]" ]
   :items       [[(make-info-panel)]
                [(make-board-panel rows cols level)]]))


(defn make-board-panel
  [rows cols level]
  (let [bg (button-group)]
    (mig-panel
     :constraints [(str "gap 0, wrap" rows) "[]" "[]" ]
     :items       (for [row (range rows) col (range cols)]
                    (vector (make-button row col level bg) "w 24px!, h 24px!")))))