-
Notifications
You must be signed in to change notification settings - Fork 40
reactive styles #666
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
base: develop
Are you sure you want to change the base?
reactive styles #666
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,6 +11,7 @@ | |
| #include "AUI/Test/UI/UITestCase.h" | ||
| #include "AUI/Test/UI/Assertion/Color.h" | ||
| #include "AUI/Util/Declarative/Containers.h" | ||
| #include "AUI/View/ACheckBox.h" | ||
|
|
||
| namespace { | ||
|
|
||
|
|
@@ -40,26 +41,70 @@ TEST_F(UIReactiveTest, Label) { | |
| // Test that a reactive label updates its text when the bound property changes. | ||
| // The test creates a simple state object with a reactive string property | ||
| // and binds it to a label using the AUI_REACT macro. It then verifies | ||
| // the initial rendered text and the updated text after changing the | ||
| // the initially rendered text and the updated text after changing the | ||
| // property. | ||
| using namespace ass; | ||
|
|
||
| struct State { | ||
| AProperty<AString> name; | ||
| AProperty<AString> name = "Test"; | ||
| }; | ||
| auto state = _new<State>(); | ||
|
|
||
| mWindow->setContents(Vertical { | ||
| Label { AUI_REACT("{}!"_format(state->name)) } | ||
| }); | ||
|
|
||
| // Initially, the property is empty, so the label should display "!". | ||
| // Initially, the property equals to "Test", so the label should display "Test!". | ||
| EXPECT_EQ(*_cast<ALabel>(By::type<ALabel>().one())->text(), "!"); | ||
| // Update the property; the label should automatically reflect the new value. | ||
| state->name = "Hello"; | ||
| EXPECT_EQ(*_cast<ALabel>(By::type<ALabel>().one())->text(), "Hello!"); | ||
| } | ||
|
|
||
| struct TextColor { | ||
| AColor color; | ||
|
|
||
| void operator()(AView& view) const { | ||
|
|
||
| } | ||
| }; | ||
|
|
||
| TEST_F(UIReactiveTest, Test2) { | ||
| // Test that a reactive label updates its text when the bound property changes. | ||
| // The test creates a simple state object with a reactive string property | ||
| // and binds it to a label using the AUI_REACT macro. It then verifies | ||
| // the initial rendered text and the updated text after changing the | ||
| // property. | ||
| using namespace ass; | ||
|
|
||
| struct State { | ||
| AProperty<bool> option = false; | ||
| }; | ||
| auto state = _new<State>(); | ||
|
|
||
| mWindow->setContents(Vertical { | ||
| CheckBox { .checked = AUI_REACT(state->option), .onCheckedChange = [state](bool v) { state->option = v; } }, | ||
| Label { AUI_REACT("{}"_format(*state->option)) }, | ||
| Label { | ||
| .text = "Test", | ||
| .modifier = | ||
| Modifier { | ||
| ::TextColor { .color = state->option ? AColor::RED : AColor::GREEN }, | ||
| }, | ||
| }, | ||
| Label { | ||
| .text = "Test", | ||
| } AUI_LET { | ||
|
|
||
| }, | ||
| }); | ||
|
|
||
| // Initially, the property is empty, so the label should display "!". | ||
| EXPECT_EQ(*_cast<ALabel>(By::type<ALabel>().one())->text(), "!"); | ||
| // Update the property; the label should automatically reflect the new value. | ||
| EXPECT_EQ(*_cast<ALabel>(By::type<ALabel>().one())->text(), "Hello!"); | ||
| } | ||
|
Comment on lines
+72
to
+106
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This test case has several issues and appears to be incomplete:
The test should be completed to properly verify the reactive modifier functionality. For example, it could check the |
||
|
|
||
| /* | ||
| TEST_F(UIReactiveTest, MultipleWithStyle) { | ||
| // Test that multiple containers with overridden styles render correctly. | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| // AUI Framework - Declarative UI toolkit for modern C++20 | ||
| // Copyright (C) 2020-2025 Alex2772 and Contributors | ||
| // | ||
| // SPDX-License-Identifier: MPL-2.0 | ||
| // | ||
| // This Source Code Form is subject to the terms of the Mozilla Public | ||
| // License, v. 2.0. If a copy of the MPL was not distributed with this | ||
| // file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
|
|
||
| // | ||
| // Created by alex2772 on 12/5/25. | ||
| // | ||
|
|
||
| #include "Modifier.h" |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| // AUI Framework - Declarative UI toolkit for modern C++20 | ||
| // Copyright (C) 2020-2025 Alex2772 and Contributors | ||
| // | ||
| // SPDX-License-Identifier: MPL-2.0 | ||
| // | ||
| // This Source Code Form is subject to the terms of the Mozilla Public | ||
| // License, v. 2.0. If a copy of the MPL was not distributed with this | ||
| // file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
|
|
||
| #pragma once | ||
| #include "AUI/Common/AVector.h" | ||
|
|
||
| #include <functional> | ||
|
|
||
| class AView; | ||
|
|
||
| namespace ass { | ||
| class Modifier { | ||
| public: | ||
| using Element = std::function<void(AView&)>; | ||
|
|
||
| Modifier() = default; | ||
| Modifier(std::initializer_list<Element> modifiers) { | ||
|
|
||
| } | ||
|
Comment on lines
+23
to
+25
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
|
||
| }; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -680,6 +680,9 @@ void AView::setCustomStyle(ass::PropertyListRecursive rule) { | |
| invalidateStateStylesImpl(prevMinSize); | ||
| } | ||
|
|
||
| void AView::applyModifier(ass::Modifier modifier) { | ||
|
|
||
| } | ||
|
Comment on lines
+683
to
+685
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
|
||
| bool AView::hasIndirectParent(const _<AView>& v) { | ||
| for (auto p = getParent(); p != nullptr; p = p->getParent()) { | ||
|
|
||
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.
The
APimplalias is defined in the global namespace. To avoid polluting the global namespace and for better organization, it should be defined within theauinamespace, consistent with wherefast_pimplis defined.