treilik / bubbleboxer

MIT License
64 stars 4 forks source link

SizeFunc: How to get the size for the models? #4

Closed Robert-M-Muench closed 2 years ago

Robert-M-Muench commented 2 years ago

I have the suspicion that I need to provide the size of the different models on my own. Is there a way, where boxer will derive the necessary sizes itself? If not, what's the best practice to find out the size of my models?

treilik commented 2 years ago

I hope this will answer your question: bubbletea sends at the beginning of the program a message to the contained Model (here likely bubbleboxer) with the information of the size of the terminal. This message is then by the nodes of the layout-tree passed down to the leafes - your models.

So your models receive a message of type bubbletea.WindowSizeMsg and they should save the contained size in them. Then you have the size information stored in your models and so you can render there View accordingly.

If you want to change the size of one of your Models you have to set the SizeFunc's in the ancestral-layout-tree-nodes accordingly. see example

Robert-M-Muench commented 2 years ago

Before I get bubbletea.WindowSizeMsg the first time in the Update() function, the View() function gets called. Which triggers the model has to wide lines error. (BTW: it should read too not to, and I added the boxwidth & linelength to the error message)

So, I somehow have to pick some reasonable sizing defaults?

Robert-M-Muench commented 2 years ago

Answer: The WindowSizeMsg from BubbleTea comes in asynchronously. And, I made an error to call bubbleboxer.UpdateSize during model creation before the whole BubbleTea program was running.