Skip to content

Commit aa318a4

Browse files
committed
UI/XUI: Adjust design, add a silent set options to dropdown
1 parent 1efcc8a commit aa318a4

File tree

7 files changed

+35
-24
lines changed

7 files changed

+35
-24
lines changed

.vscode/settings.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,8 @@
125125
"memory_resource": "cpp",
126126
"ranges": "cpp",
127127
"__verbose_abort": "cpp",
128-
"numbers": "cpp"
128+
"numbers": "cpp",
129+
"execution": "cpp"
129130
},
130131
"editor.formatOnSave": false,
131132
"editor.trimAutoWhitespace": true,

shared/CP_SDK/UI/Components/CDropdown.hpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ namespace CP_SDK::UI::Components {
3030

3131
_v::Func<std::u16string_view> m_GetValue;
3232

33-
_v::Action<bool> m_SetInteractable;
34-
_v::Action<const std::vector<std::u16string>&> m_SetOptions;
35-
_v::Action<std::u16string_view, bool> m_SetValue;
33+
_v::Action<bool> m_SetInteractable;
34+
_v::Action<const std::vector<std::u16string>&, bool> m_SetOptions;
35+
_v::Action<std::u16string_view, bool> m_SetValue;
3636

3737
public:
3838
UIFieldRefDel<_u::RectTransform> RTransform;
@@ -53,8 +53,9 @@ namespace CP_SDK::UI::Components {
5353
/// @param p_Interactable New state
5454
CDropdown* SetInteractable(bool p_Interactable);
5555
/// @brief Set available options
56-
/// @param p_Options New options list
57-
CDropdown* SetOptions(const std::vector<std::u16string>& p_Options);
56+
/// @param options New options list
57+
/// @param notifyOnValueChanged Should notify on value changed?
58+
CDropdown* SetOptions(const std::vector<std::u16string>& options, bool notifyOnValueChanged = true);
5859
/// @brief Set value
5960
/// @param p_Value New value
6061
/// @param p_Notify Should notify?

shared/CP_SDK/UI/DefaultComponents/DefaultCDropdown.hpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,9 @@ namespace CP_SDK::UI::DefaultComponents {
6161
/// @param p_Interactable New state
6262
void SetInteractable_Impl(bool p_Interactable);
6363
/// @brief Set available options
64-
/// @param p_Options New options list
65-
void SetOptions_Impl(const std::vector<std::u16string>& p_Options);
64+
/// @param options New options list
65+
/// @param notifyOnValueChanged Should notify on value changed?
66+
void SetOptions_Impl(const std::vector<std::u16string>& options, bool notifyOnValueChanged = true);
6667
/// @brief Set value
6768
/// @param p_Value New value
6869
/// @param p_Notify Should notify?

shared/CP_SDK/XUI/XUIDropdown.hpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,9 @@ namespace CP_SDK::XUI {
112112
/// @param p_Interactable New state
113113
XUIDropdown* SetInteractable(bool p_Interactable) XUI_PROXY_IMPL(_v::CDropdown, { x->SetInteractable(p_Interactable); })
114114
/// @brief Set available options
115-
/// @param p_Options New options list
116-
XUIDropdown* SetOptions(std::vector<std::u16string> p_Options) XUI_PROXY_IMPL(_v::CDropdown, { x->SetOptions(p_Options); })
115+
/// @param options New options list
116+
/// @param notifyOnValueChanged Should notify on value changed?
117+
XUIDropdown* SetOptions(std::vector<std::u16string> options, bool notifyOnValueChanged = true) XUI_PROXY_IMPL(_v::CDropdown, { x->SetOptions(options, notifyOnValueChanged); })
117118
/// @brief Set value
118119
/// @param p_Value New value
119120
/// @param p_Notify Should notify?

src/CP_SDK/UI/Components/CDropDown.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,11 @@ namespace CP_SDK::UI::Components {
5454
return this;
5555
}
5656
/// @brief Set available options
57-
/// @param p_Options New options list
58-
CDropdown* CDropdown::SetOptions(const std::vector<std::u16string>& p_Options)
57+
/// @param options New options list
58+
/// @param notifyOnValueChanged Should notify on value changed?
59+
CDropdown* CDropdown::SetOptions(const std::vector<std::u16string>& options, bool notifyOnValueChanged)
5960
{
60-
m_SetOptions(p_Options);
61+
m_SetOptions(options, notifyOnValueChanged);
6162
return this;
6263
}
6364
/// @brief Set value

src/CP_SDK/UI/DefaultComponents/DefaultCDropdown.cpp

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,8 @@ namespace CP_SDK::UI::DefaultComponents {
7979
m_Icon->RTransform()->set_pivot (Vector2( 1.0f, 0.5f));
8080
m_Icon->RTransform()->set_anchorMin (Vector2( 1.0f, 0.5f));
8181
m_Icon->RTransform()->set_anchorMax (Vector2( 1.0f, 0.5f));
82-
m_Icon->RTransform()->set_anchoredPosition(Vector2(-0.5f, 0.0f));
83-
m_Icon->RTransform()->set_sizeDelta (Vector2( 4.0f, 4.0f));
82+
m_Icon->RTransform()->set_anchoredPosition(Vector2(-1.5f, 0.0f));
83+
m_Icon->RTransform()->set_sizeDelta (Vector2( 3.0f, 3.0f));
8484
m_Icon->SetSprite(UISystem::GetUIDownArrowSprite().Ptr());
8585
m_Icon->OnClick({this, &DefaultCDropdown::Button_OnClick});
8686

@@ -150,22 +150,28 @@ namespace CP_SDK::UI::DefaultComponents {
150150
m_Icon->SetInteractable(p_Interactable);
151151
}
152152
/// @brief Set available options
153-
/// @param p_Options New options list
154-
void DefaultCDropdown::SetOptions_Impl(const std::vector<std::u16string>& p_Options)
153+
/// @param options New options list
154+
/// @param notifyOnValueChanged Should notify on value changed?
155+
void DefaultCDropdown::SetOptions_Impl(const std::vector<std::u16string>& options, bool notifyOnValueChanged)
155156
{
157+
auto l_ValueStr = std::u16string(GetValue_Impl());
156158
m_Options.clear();
157159

158-
if (!p_Options.empty())
160+
if (!options.empty())
159161
{
160-
m_Options.reserve(p_Options.size());
161-
m_Options.insert(m_Options.begin(), p_Options.begin(), p_Options.end());
162+
m_Options.reserve(options.size());
163+
m_Options.insert(options.begin(), options.begin(), options.end());
162164
}
163165

164-
if (m_Value > m_Options.size())
166+
auto l_It = std::find(m_Options.begin(), m_Options.end(), l_ValueStr);
167+
auto l_NewValue = l_It != m_Options.end() ? l_It - m_Options.begin() : -1;
168+
if (m_Value != l_NewValue)
165169
{
166-
m_Value = -1;
170+
m_Value = l_NewValue;
167171
Refresh();
168-
Notify();
172+
173+
if (notifyOnValueChanged)
174+
Notify();
169175
}
170176
else
171177
Refresh();

src/CP_SDK/UI/DefaultComponents/DefaultCTextInput.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ namespace CP_SDK::UI::DefaultComponents {
8989
m_ValueText->SetAlign(TMPro::TextAlignmentOptions::MidlineLeft);
9090
m_ValueText->RTransform()->set_anchorMin (Vector2( 0.0f, 0.0f));
9191
m_ValueText->RTransform()->set_anchorMax (Vector2( 1.0f, 1.0f));
92-
m_ValueText->RTransform()->set_anchoredPosition (Vector2(-2.5f, 0.0f));
92+
m_ValueText->RTransform()->set_anchoredPosition (Vector2(-1.5f, 0.0f));
9393
m_ValueText->RTransform()->set_sizeDelta (Vector2(-5.0f, 0.0f));
9494

9595
m_Button = get_gameObject()->AddComponent<Button*>();

0 commit comments

Comments
 (0)