slint/demos/energy-monitor/ui/widgets/bar_chart.slint
Simon Hausmann a98d4709be Move printer demo and energy-monitor into new top-level demos/ folder
These are showing off use-cases for Slint, but they're not examples showing individual Slint features.

Also removed the old printerdemo while at it.
2024-10-25 12:09:32 +02:00

66 lines
No EOL
1.5 KiB
Text

// Copyright © SixtyFPS GmbH <info@slint.dev>
// SPDX-License-Identifier: MIT
import { Theme } from "../theme.slint";
import { ChartPattern } from "chart_pattern.slint";
component Bar {
in property <length> bar-height;
horizontal-stretch: 1;
Rectangle {
border-radius: 2px;
y: parent.height - self.height;
height: bar-height;
clip: true;
Rectangle {
height: root.height;
y: parent.height - self.height;
background: Theme.palette.bar-gradient;
}
}
}
export component BarBackground inherits Rectangle {
border-radius: 2px;
background: Theme.palette.bar-background-gradient;
opacity: 0.25;
}
export component BarChart {
in property <[float]> model;
in property <float> min;
in property <float> max;
in property <bool> active;
cache-rendering-hint: true;
ChartPattern {
count: model.length / 2;
}
layout := HorizontalLayout {
spacing: 1px;
for value in model : Bar {
private property <float> display-value;
min-height: 120px;
preferred-height: 100%;
bar-height: parent.height * (display-value - root.min) / (root.max - root.min);
states [
active when active : {
display-value: value;
in {
animate display-value { duration: Theme.durations.slow; easing: ease-in-out; }
}
}
]
}
}
}