-
Notifications
You must be signed in to change notification settings - Fork 835
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow WindowSizeMsg to be sent on sub-model Init #987
Comments
Hi! So technically speaking you shouldn't use To pass the window width and height when switching to a new model you can simply set properties on the new model before returning it like you say: func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
switch msg := msg.(type) {
case tea.WindowSizeMsg:
m.width = msg.Width
m.height = msg.Height
return m, nil
case switchModelsMsg:
newModel := NewModel()
newModel.width = m.width
newModel.height = m.height
return newModel, newModel.Init() // switch models
}
} |
In bubbleo's navstack when pushing a new model on the stack I call Init and send the new model and Update with the window size msg for exactly the reason you mention. We need the model now in charge of the application to know what its size is. |
Reading this again, perhaps a |
@meowgorithm the main issue with that is I find having My initial thought was to just run |
I ran into the same exact issue. My solution was to give my new "sub" model structs a optional field with a pointer to a wrapper around the window state. Maybe not the best solution but it worked for me. 🤷🏼 |
When attempting to format content that is reliant on the width/height you must listen for
WindowSizeMsg
and store those values in the model:This presents a challenge when switching to a different model, as the
WindowSizeMsg
msg is never sent again.This means that you must either use global variables to keep track of the width/height, or pass around width/height variables to all of your sub models:
Describe the solution you'd like
Either allow a way to manually request the current WindowSize at say, Init(), or maybe provide a way to update the current model without using a mainmodel-submodels type architecture.
Maybe this is a non-issue for most, just something I found :)
The text was updated successfully, but these errors were encountered: