Experiments with slint

main
Margret Riegert 2026-02-22 23:23:49 -05:00
parent e71ddcb726
commit f7af29eb75
No known key found for this signature in database
4 changed files with 72 additions and 18 deletions

View File

@ -8,13 +8,13 @@ slint::include_modules!();
fn main() -> Result<(), Box<dyn Error>> { fn main() -> Result<(), Box<dyn Error>> {
let ui = AppWindow::new()?; let ui = AppWindow::new()?;
ui.on_request_increase_value({ // ui.on_request_increase_value({
let ui_handle = ui.as_weak(); // let ui_handle = ui.as_weak();
move || { // move || {
let ui = ui_handle.unwrap(); // let ui = ui_handle.unwrap();
ui.set_counter(ui.get_counter() + 1); // ui.set_counter(ui.get_counter() + 1);
} // }
}); // });
ui.run()?; ui.run()?;

View File

@ -1,18 +1,32 @@
import { Button, VerticalBox } from "std-widgets.slint"; import { Button, VerticalBox, TextEdit } from "std-widgets.slint";
import { ChatView } from "chat-view.slint";
export component AppWindow inherits Window { export component AppWindow inherits Window {
in-out property <int> counter: 42;
callback request-increase-value(); VerticalLayout {
VerticalBox {
Text { ChatView {
text: "Counter: \{root.counter}"; messages: [
{ text: "hello", sender: "Bob", time: "10:00" },
{ text: "hey!", sender: "Joe", time: "10:01" },
{ text: "i like cats c:", sender: "Bob", time: "10:03" },
{ text: "me too c:", sender: "Joe", time: "10:08" },
{
text: "meow meow meow meow meow meow meow meow meow meow meow meow meow meow meow meow meow meow meow meow meow meow meow meow meow meow meow meow meow meow meow meow meow meow meow ",
sender: "Joe",
time: "10:08"
},
{
text: "meow meow meow meow meow meow meow meow meow meow meow meow meow meow meow meow meow meow meow meow meow meow meow meow meow meow meow meow meow meow meow meow meow meow meow ",
sender: "Bob",
time: "10:12"
},
];
} }
Button { TextEdit {
text: "Increase value"; height: 64px;
clicked => { font-size: 16px;
root.request-increase-value();
}
} }
} }
} }

16
ui/chat-view.slint Normal file
View File

@ -0,0 +1,16 @@
import { Button, VerticalBox, ScrollView } from "std-widgets.slint";
import { Message } from "message.slint";
export component ChatView inherits ScrollView {
in property <[{text: string, sender: string, time: string}]> messages;
VerticalLayout {
spacing: 5px;
for message in root.messages: Message {
text: message.text;
sender: message.sender;
time: message.time;
}
}
}

24
ui/message.slint Normal file
View File

@ -0,0 +1,24 @@
export component Message inherits Rectangle {
in property <string> sender;
in property <string> time;
in property <string> text;
VerticalLayout {
padding-top: 12px;
Text {
text: sender + " " + time;
x: 12px;
font-size: 12px;
}
Text {
text: text;
x: 24px;
font-size: 16px;
wrap: word-wrap;
}
}
}