mirror of
https://github.com/slint-ui/slint.git
synced 2025-11-19 03:28:52 +00:00
Change the exaple to used named struct for models
This commit is contained in:
parent
bfe2bf2478
commit
221bb853d7
5 changed files with 26 additions and 19 deletions
|
|
@ -9,15 +9,13 @@
|
||||||
LICENSE END */
|
LICENSE END */
|
||||||
#include "printerdemo.h"
|
#include "printerdemo.h"
|
||||||
|
|
||||||
// FIXME: Ideally it should be a better type in the generated code
|
|
||||||
using InkData = std::tuple<sixtyfps::Color, float>;
|
|
||||||
|
|
||||||
struct InkLevelModel : sixtyfps::Model<InkData>
|
struct InkLevelModel : sixtyfps::Model<InkLevel>
|
||||||
{
|
{
|
||||||
int row_count() const override { return m_data.size(); }
|
int row_count() const override { return m_data.size(); }
|
||||||
InkData row_data(int i) const override { return m_data[i]; }
|
InkLevel row_data(int i) const override { return m_data[i]; }
|
||||||
|
|
||||||
std::vector<InkData> m_data = { { sixtyfps::Color::from_rgb_uint8(255, 255, 0), 0.9 },
|
std::vector<InkLevel> m_data = { { sixtyfps::Color::from_rgb_uint8(255, 255, 0), 0.9 },
|
||||||
{ sixtyfps::Color::from_rgb_uint8(0, 255, 255), 0.5 },
|
{ sixtyfps::Color::from_rgb_uint8(0, 255, 255), 0.5 },
|
||||||
{ sixtyfps::Color::from_rgb_uint8(255, 0, 255), 0.8 },
|
{ sixtyfps::Color::from_rgb_uint8(255, 0, 255), 0.8 },
|
||||||
{ sixtyfps::Color::from_rgb_uint8(0, 0, 0), 0.1 } };
|
{ sixtyfps::Color::from_rgb_uint8(0, 0, 0), 0.1 } };
|
||||||
|
|
|
||||||
|
|
@ -22,10 +22,10 @@ pub fn main() {
|
||||||
let main_window = MainWindow::new();
|
let main_window = MainWindow::new();
|
||||||
// FIXME: better represtation of the models
|
// FIXME: better represtation of the models
|
||||||
main_window.set_ink_levels(sixtyfps::VecModel::from_slice(&[
|
main_window.set_ink_levels(sixtyfps::VecModel::from_slice(&[
|
||||||
(sixtyfps::Color::from_rgb_u8(0, 255, 255), 0.40),
|
InkLevel { color: sixtyfps::Color::from_rgb_u8(0, 255, 255), level: 0.40 },
|
||||||
(sixtyfps::Color::from_rgb_u8(255, 0, 255), 0.20),
|
InkLevel { color: sixtyfps::Color::from_rgb_u8(255, 0, 255), level: 0.20 },
|
||||||
(sixtyfps::Color::from_rgb_u8(255, 255, 0), 0.50),
|
InkLevel { color: sixtyfps::Color::from_rgb_u8(255, 255, 0), level: 0.50 },
|
||||||
(sixtyfps::Color::from_rgb_u8(0, 0, 0), 0.80),
|
InkLevel { color: sixtyfps::Color::from_rgb_u8(0, 0, 0), level: 0.80 },
|
||||||
]));
|
]));
|
||||||
|
|
||||||
main_window.run();
|
main_window.run();
|
||||||
|
|
|
||||||
|
|
@ -258,6 +258,11 @@ TopPanel := Rectangle {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export InkLevel := {
|
||||||
|
property<color> color;
|
||||||
|
property<float> level;
|
||||||
|
}
|
||||||
|
|
||||||
MainWindow := Window {
|
MainWindow := Window {
|
||||||
|
|
||||||
width: 800lx;
|
width: 800lx;
|
||||||
|
|
@ -265,7 +270,7 @@ MainWindow := Window {
|
||||||
|
|
||||||
/// Note that this property is overwriten in the .cpp and .rs code.
|
/// Note that this property is overwriten in the .cpp and .rs code.
|
||||||
// The data is only in this file so it looks good in the viewer
|
// The data is only in this file so it looks good in the viewer
|
||||||
property <[{color: color, level: float}]> ink_levels: [
|
property <[InkLevel]> ink_levels: [
|
||||||
{color: #0ff, level: 60%},
|
{color: #0ff, level: 60%},
|
||||||
{color: #ff0, level: 80%},
|
{color: #ff0, level: 80%},
|
||||||
{color: #f0f, level: 70%},
|
{color: #f0f, level: 70%},
|
||||||
|
|
|
||||||
|
|
@ -22,19 +22,18 @@ pub fn main() {
|
||||||
#[cfg(all(debug_assertions, target_arch = "wasm32"))]
|
#[cfg(all(debug_assertions, target_arch = "wasm32"))]
|
||||||
console_error_panic_hook::set_once();
|
console_error_panic_hook::set_once();
|
||||||
|
|
||||||
type TodoModelData = (bool, sixtyfps::SharedString);
|
let todo_model = Rc::new(sixtyfps::VecModel::<TodoItem>::from(vec![
|
||||||
let todo_model = Rc::new(sixtyfps::VecModel::<TodoModelData>::from(vec![
|
TodoItem { checked: true, title: "Implement the .60 file".into() },
|
||||||
(true, "Implement the .60 file".into()),
|
TodoItem { checked: true, title: "Do the rust part".into() },
|
||||||
(true, "Do the rust part".into()),
|
TodoItem { checked: false, title: "Make the C++ code".into() },
|
||||||
(false, "Make the C++ code".into()),
|
TodoItem { checked: false, title: "???".into() },
|
||||||
(false, "???".into()),
|
TodoItem { checked: false, title: "Profit".into() },
|
||||||
(false, "Profit".into()),
|
|
||||||
]));
|
]));
|
||||||
|
|
||||||
let main_window = MainWindow::new();
|
let main_window = MainWindow::new();
|
||||||
main_window.as_ref().on_todo_added({
|
main_window.as_ref().on_todo_added({
|
||||||
let todo_model = todo_model.clone();
|
let todo_model = todo_model.clone();
|
||||||
move |text| todo_model.push((true, text))
|
move |text| todo_model.push(TodoItem { checked: true, title: text })
|
||||||
});
|
});
|
||||||
|
|
||||||
main_window.set_todo_model(Some(todo_model));
|
main_window.set_todo_model(Some(todo_model));
|
||||||
|
|
|
||||||
|
|
@ -10,12 +10,17 @@ LICENSE END */
|
||||||
|
|
||||||
import { SpinBox, Button, CheckBox, Slider } from "sixtyfps_widgets.60";
|
import { SpinBox, Button, CheckBox, Slider } from "sixtyfps_widgets.60";
|
||||||
|
|
||||||
|
export TodoItem := {
|
||||||
|
property <string> title;
|
||||||
|
property <bool> checked;
|
||||||
|
}
|
||||||
|
|
||||||
MainWindow := Window {
|
MainWindow := Window {
|
||||||
width: 400lx;
|
width: 400lx;
|
||||||
height: 600lx;
|
height: 600lx;
|
||||||
signal todo_added(string);
|
signal todo_added(string);
|
||||||
|
|
||||||
property <[{title: string, checked: bool}]> todo_model: [
|
property <[TodoItem]> todo_model: [
|
||||||
{ title: "Implement the .60 file", checked: true },
|
{ title: "Implement the .60 file", checked: true },
|
||||||
{ title: "Do the rust part", checked: false },
|
{ title: "Do the rust part", checked: false },
|
||||||
{ title: "Make the C++ code", checked: false },
|
{ title: "Make the C++ code", checked: false },
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue