| 1 | // Copyright © SixtyFPS GmbH <info@slint.dev> |
| 2 | // SPDX-License-Identifier: MIT |
| 3 | |
| 4 | import { DemoPalette, Page } from "common.slint" ; |
| 5 | |
| 6 | export struct InkLevel { |
| 7 | color: color, |
| 8 | level: float, |
| 9 | } |
| 10 | |
| 11 | export component InkPage inherits Page { |
| 12 | in property <[InkLevel]> ink-levels; |
| 13 | in property <bool> page-visible; |
| 14 | |
| 15 | header: @tr("Ink Level" ); |
| 16 | |
| 17 | |
| 18 | Rectangle { |
| 19 | height: 75%; |
| 20 | width: 50%; |
| 21 | |
| 22 | HorizontalLayout { |
| 23 | spacing: root.width * 5%; |
| 24 | |
| 25 | for color-info in root.ink-levels : Rectangle { |
| 26 | ink := Rectangle { |
| 27 | width: parent.width; |
| 28 | height: parent.height * color-info.level; |
| 29 | y: parent.height - self.height; |
| 30 | clip: true; |
| 31 | |
| 32 | states [ |
| 33 | inactive when !root.page-visible : { |
| 34 | height: 0; |
| 35 | out { |
| 36 | animate height { duration: 750ms; easing: ease-in-out; } |
| 37 | } |
| 38 | in { |
| 39 | animate height { duration: 200ms; easing: ease-in; } |
| 40 | } |
| 41 | } |
| 42 | ] |
| 43 | Rectangle { |
| 44 | background: color-info.color; |
| 45 | border-radius: self.width / 2; |
| 46 | border-width: 2px; |
| 47 | height: parent.height + parent.y; |
| 48 | y: -parent.y; |
| 49 | } |
| 50 | } |
| 51 | |
| 52 | Rectangle { |
| 53 | property <length> r: (parent.width - self.height) / 2; |
| 54 | property <length> y2: max(0phx, max(self.r - self.y, self.y - parent.height + self.r)); |
| 55 | |
| 56 | y: max(ink.y - self.height, 0phx); |
| 57 | height: 2px; |
| 58 | // w = 2*sqrt(r² - (max(0, min(r-y , y-h+r)))²) |
| 59 | width: 2*sqrt((self.r*self.r - self.y2*self.y2)/(1phx * 1phx))*1phx; // FIXME: it would be nice if sqrt could do proper unit handling |
| 60 | x: (parent.width - self.width) / 2; |
| 61 | background: DemoPalette.neutral-box; |
| 62 | } |
| 63 | |
| 64 | Rectangle { |
| 65 | border-radius: self.width / 2; |
| 66 | border-color: DemoPalette.neutral-box; |
| 67 | border-width: 2px; |
| 68 | } |
| 69 | } |
| 70 | } |
| 71 | } |
| 72 | } |
| 73 | |