| 1 | // Copyright © SixtyFPS GmbH <info@slint.dev> |
| 2 | // SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-2.0 OR LicenseRef-Slint-Software-3.0 |
| 3 | |
| 4 | export component TabBarBase inherits TouchArea { |
| 5 | // injected properties: |
| 6 | // The currently selected tab |
| 7 | in-out property <int> current; |
| 8 | // The total number of tabs |
| 9 | in-out property <int> num-tabs; |
| 10 | |
| 11 | // Returns the index of the previous tab |
| 12 | protected pure function previous-tab() -> int { |
| 13 | return Math.max(root.current - 1, 0); |
| 14 | } |
| 15 | |
| 16 | // Returns the index of the next tab |
| 17 | protected pure function next-tab() -> int { |
| 18 | return Math.min(root.current + 1, root.num-tabs - 1); |
| 19 | } |
| 20 | |
| 21 | private property <length> scroll-delta: 2px; |
| 22 | |
| 23 | // Allows scrolling through the tabs |
| 24 | scroll-event(event) => { |
| 25 | if (event.delta-y < -root.scroll-delta) { |
| 26 | root.current = next-tab(); |
| 27 | return accept; |
| 28 | } |
| 29 | if (event.delta-y > -root.scroll-delta) { |
| 30 | root.current = previous-tab(); |
| 31 | return accept; |
| 32 | } |
| 33 | reject |
| 34 | } |
| 35 | } |
| 36 | |