I'm writing a GUI, and need to be able to replace a border-pane's :center section with another pane. The problem is, the call to config! in the handler doesn't have the effect of changing the pane. All other nearly identical calls elsewhere work.
The problem can be summed up as:
(ns live-math-pet.gui.mcve
(:require [seesaw.core :as sc]))
(defn -main []
(let [; The starting contents
child1 (sc/label :text "Hello!")
; What I want to change to at the click of a button
child2 (sc/label :text "World!")
base-pane (sc/border-panel :center child1)
change-btn (sc/button :listen [:action
(fn [_]
; This doesn't change the :center area
(sc/config! base-pane :center child2))])
frame (sc/frame :content base-pane)]
(sc/config! base-pane :south change-btn)
; These work, but the call to config! in the handler doesn't
(sc/config! base-pane :center (sc/label "Test1"))
(sc/config! base-pane :center child1)
(-> frame
(sc/pack!)
(sc/show!))))
The problem is, this doesn't do anything when I click the button. I expect config! to replace the :center section, but it doesn't. The click handler is firing, the config! just doesn't seem to do anything.
The calls to config! at the bottom work, even though the last call is identical.
After searching around, I found a solution, but it kind of rubs me wrong. If I change the handler to
(fn [_]
(sc/replace! base-pane child1 child2)
it works. I don't like this for a couple reasons though:
I need to know what the current contents are. If I don't know, I need to do a lookup, which seems wasteful.
If I'm giving it the child to replace, presumably it needs to search the parent to find the child. Again, this seems needlessly wasteful.
If base-pane was a frame, and I wanted to replace its :contents using config!, it would work as I'd expect.
Why doesn't config! work here? Is it necessary to use replace!?
Updates:
It turns out the button is having an effect, but it only makes the change after resizing the window for some reason.
When it adds the new panel, it overlays it over the previous one instead of replacing it. It looked like it needed to be repainted, so I tried running
(sc/repaint! (sc/select base-pane [:*])), but it didn't make a difference.At this point I realized I might just have to use
sc/replace!, but then ran into the problem of how to get the previous child.(config base-pane :center)doesn't work. I think I'm going to have to give each child a class, then usesc/select.