/* LICENSE BEGIN This file is part of the SixtyFPS Project -- https://sixtyfps.io Copyright (c) 2020 Olivier Goffart Copyright (c) 2020 Simon Hausmann SPDX-License-Identifier: GPL-3.0-only This file is also available under commercial licensing terms. Please contact info@sixtyfps.io for more information. LICENSE END */ #include using sixtyfps::interpreter::Value; struct InkLevelModel : sixtyfps::Model { int row_count() const override { return m_data.size(); } Value row_data(int i) const override { return m_data[i]; } private: static Value make_inklevel_value(sixtyfps::Color color, float level) { sixtyfps::interpreter::Struct s; s.set_field("color", Value(color)); s.set_field("level", level); return s; } std::vector m_data = { make_inklevel_value(sixtyfps::Color::from_rgb_uint8(255, 255, 0), 0.9), make_inklevel_value(sixtyfps::Color::from_rgb_uint8(255, 0, 255), 0.8), make_inklevel_value(sixtyfps::Color::from_rgb_uint8(0, 255, 255), 0.5), make_inklevel_value(sixtyfps::Color::from_rgb_uint8(0, 0, 0), 0.1), }; }; int main() { if (auto error = sixtyfps::register_font_from_path(FONTS_DIR "/NotoSans-Regular.ttf")) { fprintf(stderr, "Error registering Noto Sans Regular font: %s\n", error->data()); } if (auto error = sixtyfps::register_font_from_path(FONTS_DIR "/NotoSans-Bold.ttf")) { fprintf(stderr, "Error registering Noto Sans Bold font: %s\n", error->data()); } sixtyfps::interpreter::ComponentCompiler compiler; auto definition = compiler.build_from_path(SOURCE_DIR "/../ui/printerdemo.60"); for (auto diagnostic : compiler.diagnostics()) { std::cerr << (diagnostic.level == sixtyfps::interpreter::DiagnosticLevel::Warning ? "warning: " : "error: ") << diagnostic.message << std::endl; std::cerr << "location: " << diagnostic.source_file; if (diagnostic.line > 0) std::cerr << ":" << diagnostic.line; if (diagnostic.column > 0) std::cerr << ":" << diagnostic.column; std::cerr << std::endl; } if (!definition) { std::cerr << "compilation failure!" << std::endl; return EXIT_FAILURE; } auto instance = definition->create(); std::shared_ptr> ink_levels = std::make_shared(); if (!instance->set_property("ink_levels", ink_levels)) { std::cerr << "Could not set property ink_levels" << std::endl; return EXIT_FAILURE; } instance->set_callback("quit", [](auto) { std::exit(0); return Value(); }); instance->run(); }