| 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 | import { Palette } from "std-widgets.slint" ; |
| 5 | |
| 6 | SubElement := Rectangle { |
| 7 | property sub_color <=> sub.color; |
| 8 | sub := Text { text: "sub" ; } |
| 9 | } |
| 10 | |
| 11 | TestCase := Rectangle { |
| 12 | // This binding allow the test to set the style's default color so that we can compare it |
| 13 | property<color> binding_to_default_text_color: Palette.foreground; |
| 14 | |
| 15 | default_text := Text { text: "default" ; } |
| 16 | text_with_color := Text { |
| 17 | text: "yellow" ; |
| 18 | color: #ffff00ff; |
| 19 | } |
| 20 | text_in_sub_element := SubElement { sub_color: #ff0000; } |
| 21 | text_in_state := Text { } |
| 22 | states [ xx when false: { text_in_state.color: #abc; } ] |
| 23 | |
| 24 | property <color> default_text_color: default_text.color; |
| 25 | property <color> color_of_initialized_text: text_with_color.color; |
| 26 | property <color> color_of_sub_element_text: text_in_sub_element.sub_color; |
| 27 | property <color> color_in_state: text-in-state.color; |
| 28 | |
| 29 | property <bool> test: default_text_color == Palette.foreground && color-of-initialized-text == #ffff00ff |
| 30 | && color_of_sub_element_text == #ff0000 && color-in-state == Palette.foreground; |
| 31 | } |
| 32 | |
| 33 | |
| 34 | /* |
| 35 | |
| 36 | ```cpp |
| 37 | auto handle = TestCase::create(); |
| 38 | const TestCase &instance = *handle; |
| 39 | assert_eq(instance.get_default_text_color(), instance.get_binding_to_default_text_color()); |
| 40 | assert_eq(instance.get_color_of_initialized_text(), slint::Color::from_rgb_uint8(255, 255, 0)); |
| 41 | assert_eq(instance.get_color_of_sub_element_text(), slint::Color::from_rgb_uint8(255, 0, 0)); |
| 42 | assert_eq(instance.get_color_in_state(), instance.get_binding_to_default_text_color()); |
| 43 | ``` |
| 44 | |
| 45 | ```rust |
| 46 | let instance = TestCase::new().unwrap(); |
| 47 | assert_eq!(instance.get_default_text_color(), instance.get_binding_to_default_text_color()); |
| 48 | assert_eq!(instance.get_color_of_initialized_text(), slint::Color::from_rgb_u8(255, 255, 0)); |
| 49 | assert_eq!(instance.get_color_of_sub_element_text(), slint::Color::from_rgb_u8(255, 0, 0)); |
| 50 | assert_eq!(instance.get_color_in_state(), instance.get_binding_to_default_text_color()); |
| 51 | ``` |
| 52 | |
| 53 | */ |
| 54 | |