You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm working on an app that connects to and manages several bluetooth devices at once. I would like to have a list of rich widgets which has one entry per device, and these need to react both to user input and to events from the bluetooth stack. The former is straightforward, but I'm stumped on how to make members of a model react to application-generated events. The following illustrates the problem (slintpad link)
The core problem is that I don't see any way to invoke any sort of behavior on widgets created as part of a for construct because I can't give the list of elements a name. I don't see anything I can index into even if I knew which row in the model I wanted to reference. I can change the model contents using [index] but I can't invoke behavior on the corresponding slint elements. I also don't see a way to create elements from my rust code and maintain references to them (to call invoke_blink on). Is it possible to create an app that has outside-driven interactivity in a modeled collection at all? How?
I've looked through quite a few examples, and I haven't found any that have outside-in interactivity on a collection. I'm open to other architectures/structures if I'm thinking about this unidiomatically, or workarounds if possible, but so far every avenue I've tried has been a dead end.
import { ListView, Button, VerticalBox, Slider, HorizontalBox } from "std-widgets.slint";
component BlinkyLight {
in property <string> label;
property <duration> last-count-tick: 0;
public function blink() {
last-count-tick = animation-tick();
}
VerticalBox {
Rectangle {
background: (Colors.black).mix(Colors.red, (animation-tick() - last-count-tick) / 250ms);
Text {
text: label;
}
}
}
}
export component AppWindow inherits Window {
width: 100px;
height: 400px;
public function blink_one() {
singleton.blink() // works, callable from rust code
}
public function blink(which: string) {
// How do I blink `c1` or `c2` etc from here?
}
VerticalBox {
singleton := BlinkyLight { label: "Singleton"; }
list_view := ListView {
for label in ["c1", "c2", "c3"]: BlinkyLight {
label: label;
}
}
Button {
clicked => blink_one();
text: "Blink 1";
}
ti := TextInput {
text: "c1";
}
Button {
clicked => blink(ti.text);
text: "Blink " + ti.text;
}
}
}
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
I'm working on an app that connects to and manages several bluetooth devices at once. I would like to have a list of rich widgets which has one entry per device, and these need to react both to user input and to events from the bluetooth stack. The former is straightforward, but I'm stumped on how to make members of a model react to application-generated events. The following illustrates the problem (slintpad link)
The core problem is that I don't see any way to invoke any sort of behavior on widgets created as part of a
forconstruct because I can't give the list of elements a name. I don't see anything I can index into even if I knew which row in the model I wanted to reference. I can change the model contents using[index]but I can't invoke behavior on the corresponding slint elements. I also don't see a way to create elements from my rust code and maintain references to them (to call invoke_blink on). Is it possible to create an app that has outside-driven interactivity in a modeled collection at all? How?I've looked through quite a few examples, and I haven't found any that have outside-in interactivity on a collection. I'm open to other architectures/structures if I'm thinking about this unidiomatically, or workarounds if possible, but so far every avenue I've tried has been a dead end.
Beta Was this translation helpful? Give feedback.
All reactions