-
Notifications
You must be signed in to change notification settings - Fork 772
Add enabled property to animations to toggle them on/off
#9604
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
task-jp
wants to merge
1
commit into
slint-ui:master
Choose a base branch
from
task-jp:animate-enabled
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,209 @@ | ||
| // Copyright © SixtyFPS GmbH <[email protected]> | ||
| // SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-2.0 OR LicenseRef-Slint-Software-3.0 | ||
|
|
||
| TestCase := Rectangle { | ||
| // Test static enabled values | ||
| property <int> value-with-default: 100; | ||
| animate value-with-default { | ||
| duration: 1000ms; | ||
| // enabled defaults to true | ||
| } | ||
|
|
||
| property <int> value-disabled: 100; | ||
| animate value-disabled { | ||
| duration: 1000ms; | ||
| enabled: false; | ||
| } | ||
|
|
||
| property <int> value-enabled: 100; | ||
| animate value-enabled { | ||
| duration: 1000ms; | ||
| enabled: true; | ||
| } | ||
|
|
||
| // Test dynamic enabled value | ||
| in-out property <bool> animation-enabled: true; | ||
| in-out property <int> value-dynamic: 100; | ||
| animate value-dynamic { | ||
| duration: 1000ms; | ||
| enabled: animation-enabled; | ||
| } | ||
|
|
||
| init => { | ||
| // Change enabled to false in init | ||
| animation-enabled = false; | ||
| } | ||
| } | ||
|
|
||
| /* | ||
|
|
||
| ```rust | ||
| let instance = TestCase::new().unwrap(); | ||
|
|
||
| // Test static enabled values | ||
| assert_eq!(instance.get_value_with_default(), 100); | ||
| assert_eq!(instance.get_value_disabled(), 100); | ||
| assert_eq!(instance.get_value_enabled(), 100); | ||
|
|
||
| instance.set_value_with_default(200); | ||
| instance.set_value_disabled(200); | ||
| instance.set_value_enabled(200); | ||
|
|
||
| // No time has elapsed yet | ||
| assert_eq!(instance.get_value_with_default(), 100); | ||
| assert_eq!(instance.get_value_disabled(), 200); // disabled: no animation | ||
| assert_eq!(instance.get_value_enabled(), 100); | ||
|
|
||
| // Half the animation | ||
| slint_testing::mock_elapsed_time(500); | ||
| assert_eq!(instance.get_value_with_default(), 150); // default enabled: animated | ||
| assert_eq!(instance.get_value_disabled(), 200); // disabled: no animation | ||
| assert_eq!(instance.get_value_enabled(), 150); // enabled: animated | ||
|
|
||
| // Full animation | ||
| slint_testing::mock_elapsed_time(500); | ||
| assert_eq!(instance.get_value_with_default(), 200); | ||
| assert_eq!(instance.get_value_disabled(), 200); | ||
| assert_eq!(instance.get_value_enabled(), 200); | ||
|
|
||
| // Test dynamic enabled value | ||
| assert_eq!(instance.get_value_dynamic(), 100); | ||
| assert_eq!(instance.get_animation_enabled(), false); // Changed in init | ||
|
|
||
| // Set new value - should NOT animate because enabled was set to false in init | ||
| instance.set_value_dynamic(200); | ||
| assert_eq!(instance.get_value_dynamic(), 200); // Immediately changes, no animation | ||
|
|
||
| // Enable animation | ||
| instance.set_animation_enabled(true); | ||
| instance.set_value_dynamic(300); | ||
| assert_eq!(instance.get_value_dynamic(), 200); // Animation enabled, should animate | ||
|
|
||
| // Half the animation | ||
| slint_testing::mock_elapsed_time(500); | ||
| assert_eq!(instance.get_value_dynamic(), 250); // Animated to halfway | ||
|
|
||
| // Full animation | ||
| slint_testing::mock_elapsed_time(500); | ||
| assert_eq!(instance.get_value_dynamic(), 300); | ||
|
|
||
| // Disable animation again | ||
| instance.set_animation_enabled(false); | ||
| instance.set_value_dynamic(100); | ||
| assert_eq!(instance.get_value_dynamic(), 100); // Immediately changes, no animation | ||
| ``` | ||
|
|
||
|
|
||
| ```cpp | ||
| auto handle = TestCase::create(); | ||
| const TestCase &instance = *handle; | ||
|
|
||
| // Test static enabled values | ||
| assert_eq(instance.get_value_with_default(), 100); | ||
| assert_eq(instance.get_value_disabled(), 100); | ||
| assert_eq(instance.get_value_enabled(), 100); | ||
|
|
||
| instance.set_value_with_default(200); | ||
| instance.set_value_disabled(200); | ||
| instance.set_value_enabled(200); | ||
|
|
||
| // No time has elapsed yet | ||
| assert_eq(instance.get_value_with_default(), 100); | ||
| assert_eq(instance.get_value_disabled(), 200); // disabled: no animation | ||
| assert_eq(instance.get_value_enabled(), 100); | ||
|
|
||
| // Half the animation | ||
| slint_testing::mock_elapsed_time(500); | ||
| assert_eq(instance.get_value_with_default(), 150); // default enabled: animated | ||
| assert_eq(instance.get_value_disabled(), 200); // disabled: no animation | ||
| assert_eq(instance.get_value_enabled(), 150); // enabled: animated | ||
|
|
||
| // Full animation | ||
| slint_testing::mock_elapsed_time(500); | ||
| assert_eq(instance.get_value_with_default(), 200); | ||
| assert_eq(instance.get_value_disabled(), 200); | ||
| assert_eq(instance.get_value_enabled(), 200); | ||
|
|
||
| // Test dynamic enabled value | ||
| assert_eq(instance.get_value_dynamic(), 100); | ||
| assert_eq(instance.get_animation_enabled(), false); // Changed in init | ||
|
|
||
| // Set new value - should NOT animate because enabled was set to false in init | ||
| instance.set_value_dynamic(200); | ||
| assert_eq(instance.get_value_dynamic(), 200); // Immediately changes, no animation | ||
|
|
||
| // Enable animation | ||
| instance.set_animation_enabled(true); | ||
| instance.set_value_dynamic(300); | ||
| assert_eq(instance.get_value_dynamic(), 200); // Animation enabled, should animate | ||
|
|
||
| // Half the animation | ||
| slint_testing::mock_elapsed_time(500); | ||
| assert_eq(instance.get_value_dynamic(), 250); // Animated to halfway | ||
|
|
||
| // Full animation | ||
| slint_testing::mock_elapsed_time(500); | ||
| assert_eq(instance.get_value_dynamic(), 300); | ||
|
|
||
| // Disable animation again | ||
| instance.set_animation_enabled(false); | ||
| instance.set_value_dynamic(100); | ||
| assert_eq(instance.get_value_dynamic(), 100); // Immediately changes, no animation | ||
| ``` | ||
|
|
||
| ```js | ||
| var instance = new slint.TestCase({}); | ||
|
|
||
| // Test static enabled values | ||
| assert.equal(instance.value_with_default, 100); | ||
| assert.equal(instance.value_disabled, 100); | ||
| assert.equal(instance.value_enabled, 100); | ||
|
|
||
| instance.value_with_default = 200; | ||
| instance.value_disabled = 200; | ||
| instance.value_enabled = 200; | ||
|
|
||
| // No time has elapsed yet | ||
| assert.equal(instance.value_with_default, 100); | ||
| assert.equal(instance.value_disabled, 200); // disabled: no animation | ||
| assert.equal(instance.value_enabled, 100); | ||
|
|
||
| // Half the animation | ||
| slintlib.private_api.mock_elapsed_time(500); | ||
| assert.equal(instance.value_with_default, 150); // default enabled: animated | ||
| assert.equal(instance.value_disabled, 200); // disabled: no animation | ||
| assert.equal(instance.value_enabled, 150); // enabled: animated | ||
|
|
||
| // Full animation | ||
| slintlib.private_api.mock_elapsed_time(500); | ||
| assert.equal(instance.value_with_default, 200); | ||
| assert.equal(instance.value_disabled, 200); | ||
| assert.equal(instance.value_enabled, 200); | ||
|
|
||
| // Test dynamic enabled value | ||
| assert.equal(instance.value_dynamic, 100); | ||
| assert.equal(instance.animation_enabled, false); // Changed in init | ||
|
|
||
| // Set new value - should NOT animate because enabled was set to false in init | ||
| instance.value_dynamic = 200; | ||
| assert.equal(instance.value_dynamic, 200); // Immediately changes, no animation | ||
|
|
||
| // Enable animation | ||
| instance.animation_enabled = true; | ||
| instance.value_dynamic = 300; | ||
| assert.equal(instance.value_dynamic, 200); // Animation enabled, should animate | ||
|
|
||
| // Half the animation | ||
| slintlib.private_api.mock_elapsed_time(500); | ||
| assert.equal(instance.value_dynamic, 250); // Animated to halfway | ||
|
|
||
| // Full animation | ||
| slintlib.private_api.mock_elapsed_time(500); | ||
| assert.equal(instance.value_dynamic, 300); | ||
|
|
||
| // Disable animation again | ||
| instance.animation_enabled = false; | ||
| instance.value_dynamic = 100; | ||
| assert.equal(instance.value_dynamic, 100); // Immediately changes, no animation | ||
| ``` | ||
| */ | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for new test, please use the new syntax with
component TestCase {