update tile selector to use horiz-wrapper layout

This commit is contained in:
Jeremy Penner 2021-12-21 09:36:38 -06:00
parent f81dd88a52
commit 8b646eac4b
2 changed files with 14 additions and 22 deletions

View file

@ -3,7 +3,7 @@
(local tiledraw (require :editor.tiledraw)) (local tiledraw (require :editor.tiledraw))
(local util (require :lib.util)) (local util (require :lib.util))
(local files (require :game.files)) (local files (require :game.files))
(local {: attach-imstate : button : vert} (util.require :editor.imgui)) (local {: attach-imstate : button : vert : horiz-wrapper} (util.require :editor.imgui))
(local GraphicsEditView (View:extend)) (local GraphicsEditView (View:extend))
@ -40,25 +40,17 @@
(love.graphics.draw sprite x y 0 self.sprite-scale self.sprite-scale) (love.graphics.draw sprite x y 0 self.sprite-scale self.sprite-scale)
(values (* (sprite:getWidth) self.sprite-scale) (* (sprite:getHeight) self.sprite-scale))))) (values (* (sprite:getWidth) self.sprite-scale) (* (sprite:getHeight) self.sprite-scale)))))
(fn tile-selector [{: view : x : y : w : scale &as form} chosen-itile ?key] (fn tile-selector [{: view &as form} selected-itile ?key]
(var tilex x) (var selected-itile selected-itile)
(var tiley y) (let [wrap (horiz-wrapper form)]
(var selected-itile nil) (for [itile 1 (length view.tilecache.tiles)]
(var (pixw pixh) (view:tilesize)) (let [{: x : y} form
(when (= files.game.platform :ii) (set pixw (* (/ pixw 8) 7))) (w h) (view:draw-sprite x y itile ?key)]
(local tilew (* scale pixw)) (when (and w h)
(local tileh (* scale pixh)) (when (= itile selected-itile)
(for [itile 1 (length view.tilecache.tiles)] (love.graphics.rectangle :line (- x 2) (- y 2) (+ w 4) (+ h 4)))
(view:draw-sprite tilex tiley itile ?key) (when (wrap button {:tag [:tile itile] : w : h})
(when (= itile chosen-itile) (set selected-itile itile))))))
(love.graphics.rectangle :line (- tilex 2) (- tiley 2) (+ tilew 4) (+ tileh 4)))
(when (button {: view :tag [:tile itile] :x tilex :y tiley :w tilew :h tileh})
(set selected-itile itile))
(set tilex (+ tilex tilew 4))
(when (>= (+ tilex tilew) (+ x w))
(set tilex x)
(set tiley (+ tiley tileh 4))))
(set form.h (+ tiley tileh (- y)))
selected-itile) selected-itile)
(fn GraphicsEditView.draw-tile-selector [self form ?key] (fn GraphicsEditView.draw-tile-selector [self form ?key]

View file

@ -308,7 +308,7 @@
(each [key (pairs form)] (each [key (pairs form)]
(when (= (. form-preserved-keys key) nil) (when (= (. form-preserved-keys key) nil)
(tset form key nil))) (tset form key nil)))
(lume.extend form overrides) (lume.extend form (or overrides {}))
form) form)
(fn vert [form viewfn overrides ...] (fn vert [form viewfn overrides ...]
@ -326,7 +326,7 @@
(fn [viewfn overrides ...] (fn [viewfn overrides ...]
(let [result [(viewfn (prepare-form form overrides) ...)]] (let [result [(viewfn (prepare-form form overrides) ...)]]
(set form.x (+ form.x (or form.w 0) (or form.xpad 0))) (set form.x (+ form.x (or form.w 0) (or form.xpad 0)))
(when (> form.x (+ x w)) (when (> (+ form.x (or form.w 0)) (+ x w))
(set form.x x) (set form.x x)
(set form.y (+ form.y form.h (or form.ypad 0)))) (set form.y (+ form.y form.h (or form.ypad 0))))
(table.unpack result)))) (table.unpack result))))