Dynamic composition of application parts #959
Replies: 2 comments 3 replies
-
Currently this is a bit awkward and we're open to find out what kind of syntax this could have. Several options are available.
property <[ImageInfo]> images;
property <[SvgInfo]> svgs;
property <[TextInfo]> texts;
//...
for it in images : Image { ... }
for it in svgs : Svg { ... }
for it in texts : Text { ... }
for it in items : Rectangle {
// this could clearly benefit to have some C-style `enum` in the language
if (it.type == 0) : Image { ... }
if (it.type == 1) : Svg { ... }
if (it.type == 2) : Text { ... }
} the I was thinking maybe there should be some kind of a But what would be the ideal solution that would work for you? What kind of syntax would you use for it. |
Beta Was this translation helpful? Give feedback.
-
I was more thinking of a solution via code, e.g. by providing some way to create a "child control" via code and then add it to the main control. I am not sure if the current approach to generate the item_tree could be adapted to make item nodes dynamically. The second place where this would be really helpful is for composing whole applications. In my case, I am having 10-30 different screens, where the user can navigate to. Now I would need to add all those screens to the main window and use the "if approach". But additionally this would also require to bind all the properties via the main window (see example code below). export MainWindowViewModel := {
property <int> activeScreen;
property <Screen1ViewModel> screen1Model;
property <Screen2ViewModel> screen2Model;
property <Screen3ViewModel> screen3Model;
...
}
MyWindow := MainWindow {
property <MainWindowViewModel> model;
if (model.activeScreen == 0): Screen1 {
model: model.screen1Model
}
if (model.activeScreen == 1): Screen2 {
model: model.screen2Model
}
if (model.activeScreen == 2): Screen3 {
model: model.screen3Model
}
} Or is there a different way to do that? |
Beta Was this translation helpful? Give feedback.
-
In all the examples I have so far only seen that the UI for the whole application is defined upfront statically. The only dynamic aspects are conditionals and repetition like documented at https://slint-ui.com/releases/0.2.0/docs/cpp/markdown/langref.html#repetition
Is there a way to achieve some truly dynamic composition (other than including all possible widget types and binding the visibility of those).
One of my use cases for this is a kind of "report representation" consisting of multiple elements that are put one after the other. But there are 5-10 different element types (e.g. image, SVG, text, table, chart, etc.). Ideally I can create the widget via code and then attach it in some way in the "main page".
Beta Was this translation helpful? Give feedback.
All reactions