-
Notifications
You must be signed in to change notification settings - Fork 5.4k
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
UnitConverter: Automatically flip units when users set one to the same type than the other #375
Conversation
Locking the PR since the associated Issue isn't approved yet. That way conversation on the problem being addressed is discussed in the Issue, so that future PR discussion can be limited to the implementation of the fix. |
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.
Thanks Rudy! Code works great, sorry for not getting to this earlier. Merge conflicts were not too bad, I can help work them out if needed. Overall looks good, left a few nit comments.
rebase done |
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.
Minor comments after the merge.
This pull request has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for 7 days. Thank you for your contributions to Windows Calculator! |
This pull request has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for 7 days. Thank you for your contributions to Windows Calculator! |
if ((m_valueFromUnlocalized != m_lastAnnouncedFrom | ||
|| m_valueToUnlocalized != m_lastAnnouncedTo) | ||
&& m_Unit1 != nullptr | ||
&& m_Unit2 != nullptr) |
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 method header mentions a validation against zero as well, does zero need to be added as a conditional to the if?
{ | ||
m_lastAnnouncedFrom = m_valueFromUnlocalized; | ||
m_lastAnnouncedTo = m_valueToUnlocalized; | ||
|
||
Unit ^ unitFrom = Value1Active ? Unit1 : Unit2; | ||
Unit ^ unitTo = (unitFrom == Unit1) ? Unit2 : Unit1; | ||
Unit^ unitFrom = Value1Active ? m_Unit1 : m_Unit2; |
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.
nit: Could be out of scope but m_Unit1 and m_Unit2 don't feel like very descriptive variable names. New to the codebase so could be wrong though. Feel like something that better describes the unit may be better suited versus just numbering them.
{ | ||
auto formerValue = m_Unit1; | ||
m_Unit1 = value; | ||
//Be sure m_Unit1 is set before setting Unit2 |
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.
Why is this validation the case? Is there some sequential logic that fires with setting these in a certain order? An extra comment line giving more context might be helpful.
{ | ||
auto formerValue = m_Unit2; | ||
m_Unit2 = value; | ||
//Be sure m_Unit2 is set before setting Unit1 |
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.
similar thought here
{ | ||
m_lastAnnouncedFrom = m_valueFromUnlocalized; | ||
m_lastAnnouncedTo = m_valueToUnlocalized; | ||
|
||
Unit ^ unitFrom = Value1Active ? Unit1 : Unit2; | ||
Unit ^ unitTo = (unitFrom == Unit1) ? Unit2 : Unit1; | ||
Unit^ unitFrom = Value1Active ? m_Unit1 : m_Unit2; |
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.
Very cool that you can do null coalescing in cpp!!
@@ -284,6 +284,8 @@ for (unsigned int k = 0; k < categoryList->Size; k++) | |||
wstring unit1Name = vm->Unit1->Name->Data(); | |||
for (unsigned int j = 0; j < unitList->Size; j++) | |||
{ | |||
if (i == j) |
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.
a comment might help with understanding why i == j is a skip condition in this loop
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.
Good stuff! Added some comments.
We're converting Calculator to C# with a PR for the conversion coming in the next few days, so we're going to close this PR. If you want to revisit the issue, please open a new PR after the conversion has completed. |
Fixes #266
Description of the changes:
OBSERVABLE_PROPERTY_RW
for Unit1 and Unit2 by custom code.Unit1
is equals to the current value ofUnit2
, if it's the case, setUnit2
to the former value ofUnit1
.Unit1
andUnit2
bym_Unit1
andm_Unit2
when possibleHow changes were validated: