Skip to content

Allow passing parameters to form constructors #54

@ProgramMax

Description

@ProgramMax

Is your feature request related to a problem? Please describe.
A few times now, I have wanted to pass parameters into a form's constructor.
An example of this might be a settings form which should by default display the current settings.
Another example might be a file/buffer to display.

Describe the solution you'd like
I would like a method of passing parameters to the form's constructor.
This isn't as simple as just that because it gets routed through several components.
The construction happens in the allocator, which happens inside the platform's form creation callback, which is triggered by the form factory.

We could use a template parameter pack. It will get a tad hairy because each parameter needs to be stored so it can survive through the callbacks. It might be better to just have a void* or type erased *.

Describe alternatives you've considered
Rather than constructor parameters, these could also be parameters to OnCreated().
It isn't clear to me which option is better.
A constructor likely stores the values for later use, such as creating the child controls. In this case, maybe it would be better to pass them during OnCreated() so they don't need to be stored after they are needed.
Alternatively, maybe the values are indeed stored and used beyond OnCreated(), in which case they'll hold garbage values prior to OnCreated() which could lead to bugs.

Given the OnCreate() acts sort of like Init() anyway, I think the constructor idea is already circumvented.
Maybe that is the thing that should change? Or maybe there should be a factory function rather than a constructor/OnCreated().

The problem is inherently a multi-staged construction since the platform decides when the actual form is created.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions