mirror of
https://github.com/slint-ui/slint.git
synced 2025-11-02 21:03:00 +00:00
Some more comments to iot-dashboard
This commit is contained in:
parent
73ddea74a8
commit
24bafdb2f9
3 changed files with 26 additions and 14 deletions
|
|
@ -1,5 +1,17 @@
|
||||||
|
This example is a clone of https://github.com/peter-ha/qskinny/tree/iot-dashboard/examples/iot-dashboard
|
||||||
|
|
||||||
|
The images are originating from that repository
|
||||||
|
|
||||||
|
The main.60 and iot-dashboard.60 files are basically a pure translation from
|
||||||
|
the C++ QSkinny code to self-contained .60.
|
||||||
|
|
||||||
|
Online preview:
|
||||||
|
https://sixtyfps.io/editor/preview.html?load_url=https://raw.githubusercontent.com/sixtyfpsui/sixtyfps/master/examples/iot-dashboard/main.60
|
||||||
|
|
||||||
|
The Example was also extended with .cpp code to show how to use the C++
|
||||||
|
interpreter to dynamically generate .60 files on the fly and to show different
|
||||||
|
widgets and their backend, forwarding all the properties from widgets to the
|
||||||
|
root so they can be changed by the backends.
|
||||||
|
|
||||||
Clone of https://github.com/peter-ha/qskinny/tree/iot-dashboard/examples/iot-dashboard
|
|
||||||
|
|
||||||
The images are from that repository
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -44,19 +44,16 @@ std::string WidgetLocation::location_bindings() const
|
||||||
{
|
{
|
||||||
auto maybe_binding = [](std::string_view name, const auto &opt_value) -> std::string {
|
auto maybe_binding = [](std::string_view name, const auto &opt_value) -> std::string {
|
||||||
if (opt_value.has_value()) {
|
if (opt_value.has_value()) {
|
||||||
return fmt::format("{}: {};", name, opt_value.value());
|
return fmt::format(" {}: {};\n", name, opt_value.value());
|
||||||
} else {
|
} else {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
return fmt::format(
|
return fmt::format(
|
||||||
R"60(
|
R"60(row: {};
|
||||||
row: {};
|
col: {};
|
||||||
col: {};
|
{}{})60",
|
||||||
{}
|
|
||||||
{}
|
|
||||||
)60",
|
|
||||||
row, column, maybe_binding("rowspan", row_span), maybe_binding("colspan", col_span));
|
row, column, maybe_binding("rowspan", row_span), maybe_binding("colspan", col_span));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -123,11 +120,11 @@ DashboardBuilder::build(sixtyfps::interpreter::ComponentCompiler &compiler) cons
|
||||||
std::string forwarded_property_name = properties_prefix;
|
std::string forwarded_property_name = properties_prefix;
|
||||||
forwarded_property_name.append(property.name);
|
forwarded_property_name.append(property.name);
|
||||||
|
|
||||||
main_content_properties.append(fmt::format("property <{0}> {1} <=> {2}.{3};\n",
|
main_content_properties.append(fmt::format(" property <{0}> {1} <=> {2}.{3};\n",
|
||||||
property.type_name, forwarded_property_name,
|
property.type_name, forwarded_property_name,
|
||||||
widget_name, property.name));
|
widget_name, property.name));
|
||||||
|
|
||||||
exposed_properties.append(fmt::format("property <{0}> {1} <=> main_content.{1};\n",
|
exposed_properties.append(fmt::format(" property <{0}> {1} <=> main_content.{1};\n",
|
||||||
property.type_name, forwarded_property_name));
|
property.type_name, forwarded_property_name));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -149,7 +146,7 @@ DashboardBuilder::build(sixtyfps::interpreter::ComponentCompiler &compiler) cons
|
||||||
std::string forwarded_property_name = properties_prefix;
|
std::string forwarded_property_name = properties_prefix;
|
||||||
forwarded_property_name.append(property.name);
|
forwarded_property_name.append(property.name);
|
||||||
|
|
||||||
exposed_properties.append(fmt::format("property <{0}> {1} <=> {2}.{3};\n",
|
exposed_properties.append(fmt::format(" property <{0}> {1} <=> {2}.{3};\n",
|
||||||
property.type_name, forwarded_property_name,
|
property.type_name, forwarded_property_name,
|
||||||
widget_name, property.name));
|
widget_name, property.name));
|
||||||
}
|
}
|
||||||
|
|
@ -161,7 +158,7 @@ DashboardBuilder::build(sixtyfps::interpreter::ComponentCompiler &compiler) cons
|
||||||
{0}
|
{0}
|
||||||
|
|
||||||
MainContent := VerticalLayout {{
|
MainContent := VerticalLayout {{
|
||||||
{4}
|
{4}
|
||||||
|
|
||||||
spacing: 24px;
|
spacing: 24px;
|
||||||
TopBar {{
|
TopBar {{
|
||||||
|
|
@ -181,7 +178,7 @@ MainContent := VerticalLayout {{
|
||||||
MainWindow := Window {{
|
MainWindow := Window {{
|
||||||
title: "IOT dashboard";
|
title: "IOT dashboard";
|
||||||
|
|
||||||
{3}
|
{3}
|
||||||
|
|
||||||
HorizontalLayout {{
|
HorizontalLayout {{
|
||||||
padding: 0; spacing: 0;
|
padding: 0; spacing: 0;
|
||||||
|
|
|
||||||
|
|
@ -87,6 +87,9 @@ void HumidityWidget::update_fake_humidity()
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
DashboardBuilder builder;
|
DashboardBuilder builder;
|
||||||
|
|
||||||
|
// The widgets and their position is hardcoded for now, but one could imagine getting this
|
||||||
|
// from a config file, and istentiating the widgets with a factory function
|
||||||
builder.add_top_bar_widget(std::make_shared<ClockWidget>());
|
builder.add_top_bar_widget(std::make_shared<ClockWidget>());
|
||||||
builder.add_grid_widget(std::make_shared<PlaceholderWidget>("Usage"), { 0, 0, 2 });
|
builder.add_grid_widget(std::make_shared<PlaceholderWidget>("Usage"), { 0, 0, 2 });
|
||||||
builder.add_grid_widget(std::make_shared<PlaceholderWidget>("IndoorTemperature"), { 0, 1 });
|
builder.add_grid_widget(std::make_shared<PlaceholderWidget>("IndoorTemperature"), { 0, 1 });
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue