Printer demo: the ink data now comes from the native code

This commit is contained in:
Olivier Goffart 2020-09-04 15:49:33 +02:00
parent f5aeb9ba60
commit 0751552068
3 changed files with 35 additions and 10 deletions

View file

@ -8,11 +8,23 @@
Please contact info@sixtyfps.io for more information. Please contact info@sixtyfps.io for more information.
LICENSE END */ LICENSE END */
#include "printerdemo.h" #include "printerdemo.h"
#include <iostream>
struct InkLevelModel : sixtyfps::Model {
int count() const override { return m_data.size(); }
const void *get(int i) const override { return &m_data[i]; }
/// FIXME: Ideally it should be a better type in the generated code
using InkData = std::tuple<sixtyfps::Color, float>;
std::vector<InkData> m_data = {
{ sixtyfps::Color(0xffffff00), 0.9 },
{ sixtyfps::Color(0xff00ffff), 0.5 },
{ sixtyfps::Color(0xffff00ff), 0.8 },
{ sixtyfps::Color(0xff000000), 0.1 }};
};
int main() int main()
{ {
static MainWindow printer_demo; static MainWindow printer_demo;
printer_demo.set_ink_levels(std::make_shared<InkLevelModel>());
printer_demo.run(); printer_demo.run();
} }

View file

@ -19,5 +19,14 @@ 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();
MainWindow::new().run(); let main_window = MainWindow::new();
// FIXME: better represtation of the models
main_window.set_ink_levels(sixtyfps::re_exports::SharedArray::from(&[
(sixtyfps::Color::from_rgb(0, 255, 255), 0.40),
(sixtyfps::Color::from_rgb(255, 0, 255), 0.20),
(sixtyfps::Color::from_rgb(255, 255, 0), 0.50),
(sixtyfps::Color::from_rgb(0, 0, 0), 0.80),
]));
main_window.run();
} }

View file

@ -236,6 +236,15 @@ MainWindow := Window {
width: 800lx; width: 800lx;
height: 600lx; height: 600lx;
/// 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
property <[{color: color, level: float}]> ink_levels: [
{color: #0ff, level: 60%},
{color: #ff0, level: 80%},
{color: #f0f, level: 70%},
{color: #000, level: 30%},
];
property<int> active_page: 0; property<int> active_page: 0;
panel := TopPanel { panel := TopPanel {
@ -327,7 +336,7 @@ MainWindow := Window {
text.y: root.height / 5 + 5lx; text.y: root.height / 5 + 5lx;
} }
invisible when root.active_page > 0 && root.active_page != idx + 1 : { invisible when root.active_page > 0 && root.active_page != idx + 1 : {
color: white; color: transparent;
// FIXME: should probaby hide the entire item under with z-ordering // FIXME: should probaby hide the entire item under with z-ordering
img.y: 1000000000lx; img.y: 1000000000lx;
text.color: #0000; text.color: #0000;
@ -360,12 +369,7 @@ MainWindow := Window {
//GridLayout { //GridLayout {
// spacing: 20lx; // spacing: 20lx;
for color_info[idx] in [ for color_info[idx] in ink_levels : Rectangle {
{color: #0ff, level: 60%},
{color: #ff0, level: 80%},
{color: #f0f, level: 70%},
{color: #000, level: 30%},
] : Rectangle {
color: white; color: white;