Skip to content

Commit

Permalink
Printer demo: the ink data now comes from the native code
Browse files Browse the repository at this point in the history
  • Loading branch information
ogoffart committed Sep 4, 2020
1 parent f5aeb9b commit 0751552
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 10 deletions.
16 changes: 14 additions & 2 deletions examples/printerdemo/cpp/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,23 @@
Please contact [email protected] for more information.
LICENSE END */
#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()
{
static MainWindow printer_demo;

printer_demo.set_ink_levels(std::make_shared<InkLevelModel>());
printer_demo.run();
}
11 changes: 10 additions & 1 deletion examples/printerdemo/rust/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,14 @@ pub fn main() {
#[cfg(all(debug_assertions, target_arch = "wasm32"))]
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();
}
18 changes: 11 additions & 7 deletions examples/printerdemo/ui/printerdemo.60
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,15 @@ MainWindow := Window {
width: 800lx;
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;

panel := TopPanel {
Expand Down Expand Up @@ -327,7 +336,7 @@ MainWindow := Window {
text.y: root.height / 5 + 5lx;
}
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
img.y: 1000000000lx;
text.color: #0000;
Expand Down Expand Up @@ -360,12 +369,7 @@ MainWindow := Window {

//GridLayout {
// spacing: 20lx;
for color_info[idx] in [
{color: #0ff, level: 60%},
{color: #ff0, level: 80%},
{color: #f0f, level: 70%},
{color: #000, level: 30%},
] : Rectangle {
for color_info[idx] in ink_levels : Rectangle {

color: white;

Expand Down

0 comments on commit 0751552

Please sign in to comment.