-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Index is cut off when names are too long for PersonCard #323 #338
Index is cut off when names are too long for PersonCard #323 #338
Conversation
@MightyCupcakes, thanks for your PR! By analyzing the history of the files in this pull request, we identified @damithc, @pyokagan and @edmundmok to be potential reviewers. |
v1@MightyCupcakes submitted v1 for review. Checkout this PR version locallygit fetch https://github.com/se-edu/addressbook-level4.git refs/pr/338/1/head:BRANCHNAME where |
* Ensures that the index is shown on the UI regardless of the length of the {@code Person} | ||
* name. | ||
*/ | ||
private void setMinWidthForIdLabel() { |
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.
Feels like this method can be inlined? The name of the method and the header comment doesn't seem to match up anyway (the intent is not obvious in the name :P).
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.
Well there are several reasons this is a method. The original solution involves the calculation of the length of text in the ID label and adjusting accordingly. Then I found this elegant solution that does it in one line.
However, setting minimum width for the label is not that obvious. So the method name can be renamed to better fit the intentions if you want.
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.
More importantly, I seem to recall the minWidth
property can be set via the FXML file? We should try not to encode too much style-related information in the code.
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.
FXML file, or via the stylesheet.
1a2814d
to
7603875
Compare
v2@MightyCupcakes submitted v2 for review. (📚 Archive) (📈 Interdiff between v1 and v2) Checkout this PR version locallygit fetch https://github.com/se-edu/addressbook-level4.git refs/pr/338/2/head:BRANCHNAME where |
@@ -30,7 +30,7 @@ | |||
<HBox spacing="5" alignment="CENTER_LEFT"> | |||
<children> | |||
<HBox> | |||
<Label fx:id="id" styleClass="cell_big_label"></Label> | |||
<Label fx:id="id" styleClass="cell_big_label" minWidth="-Infinity"/> |
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.
Might want to put a comment in the .fxml file for CS2103 students, to explain to them the purpose of doing minWidth="-Infinity"
.
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.
No, I don't agree.
I don't think it is a good idea to have to comment on every attribute we add to fxml files.
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.
What's the meaning of that attribute? 'Never truncate'? Is it a well documented JavaFx behavior students can find with a quick web search?
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 class Region
defines a constant USE_PREF_WIDTH
as Double.NEGATIVE_INFINITY
This is also one reason why I want to set this in the code instead in the FXML files because there are already meaningful constants names (along with javadocs!) already defined.
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.
I don't think it is a good idea to have to comment on every attribute we add to fxml files.
Agree. This case is a bit special though, because that attribute is not self explanatory nor common knowledge. Does this and this help to make the code more self-explanatory? i.e. somehow make the fxml code refer to the actual constant. Not sure if it is possible though.
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.
That might be the solution. Will explore this 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.
No additional comment.
fd24267
to
913991d
Compare
v3@MightyCupcakes submitted v3 for review. (📚 Archive) (📈 Interdiff between v2 and v3) Checkout this PR version locallygit fetch https://github.com/se-edu/addressbook-level4.git refs/pr/338/3/head:BRANCHNAME where |
<Label fx:id="id" styleClass="cell_big_label"></Label> | ||
<Label fx:id="id" styleClass="cell_big_label"> | ||
<minWidth> | ||
<Region fx:constant="USE_PREF_SIZE" /> |
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.
Kudos for figuring out the syntax for referring a constant from fxml. I guess we cannot say Region.USE_PREF_SIZE
?
On a related note, I still feel this can benefit from an explanatory comment though. A reader, especially someone new to fxml, may not be able to understand what's going on here.
Also, any chance of adding a test case that fails if this attribute is removed? I guess we have to do that in PersonCard unit test which is WIP.
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 test case that fails?
I guess it will be possible if the tests can detect the presence of an ellipsis character shown on the screen? I am not sure if this is possible with FxRobot. Or maybe we can check the width allocated to the label on a card and make some educated guess about the value being truncated or not?
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 JavaFx API's Label does not expose a public method to indicate that it has been truncated. Any checked to the actual displayed text requires the use of reflection because that is not accessible publicly (Source).
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.
I see. May be using label width as @MightyCupcakes has suggested?
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.
That can be explored. In fact, we might not need to guess the width if we create a separate label control, that automatically resizes, to determine the minimum required for a particular text.
913991d
to
a10a947
Compare
v4@MightyCupcakes submitted v4 for review. (📚 Archive) (📈 Interdiff between v3 and v4) Checkout this PR version locallygit fetch https://github.com/se-edu/addressbook-level4.git refs/pr/338/4/head:BRANCHNAME where |
V4Added comments. Although I am not so sure what is our stand on multi-line XML comments. |
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.
Just a minor suggestion.
We don't have a convention for multi-line comments on fxml yet. We should probably set indentation of markup files to 2 spaces instead, given their tendency for deep nesting, but that's not related to this PR.
<minWidth> | ||
<!-- | ||
Ensures that the index is shown on the UI regardless of the length of the | ||
Person's name |
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.
Ensures the label text is never truncated
?
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.
I am looking into simplifying the FXML files.
The FXML files can be simplified and some parent elements are unneeded. Removing those will reduce the amount of nesting needed.
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.
No other comments.
a10a947
to
0cce888
Compare
v5@MightyCupcakes submitted v5 for review. (📚 Archive) (📈 Interdiff between v4 and v5) Checkout this PR version locallygit fetch https://github.com/se-edu/addressbook-level4.git refs/pr/338/5/head:BRANCHNAME where |
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.
Commit message:
This is not desirable
as the PersonCard id is important for the user as they need it to use
and execute some commands (like the edit command)
Tried to shorten and to get rid of one of the two as
in the sentence:
This is not desirable as users need to know the index of a person
to perform some commands (e.g. edit command)
Let's modify the id label's minimum width to use its preferred width.
This sets it so that it tracks its preferred width as its minimum width
and therefore it will always be wide enough to display the containing
PersonCard id.
It's not exactly correct to say 'modify the id label's minimum width', right?
Also, try to shorten the sentence (feels a bit verbose).
0cce888
to
b54671b
Compare
Minor nit: Also add a full stop to the second paragraph. :) |
b54671b
to
5857bf3
Compare
v6@MightyCupcakes submitted v6 for review. (📚 Archive) (📈 Interdiff between v5 and v6) Checkout this PR version locallygit fetch https://github.com/se-edu/addressbook-level4.git refs/pr/338/6/head:BRANCHNAME where |
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.
[v6 1/1]
As a consequence, a very long name would possibly cause the id label to
overflow, replacing the number with an ellipsis. This is not desirable as
users need to know the index of a person to perform some commands
(e.g. edit command).
As a consequence, a very long person name could cause the number in id
label to be replaced with an ellipsis. This is not desirable as users need to
know the id number of a person to use some commands. (e.g. edit).
Let's set the id label's minimum width to its preferred width.
This is so that the id label will always be wide enough to display the
containing PersonCard id.
Let's set the id label's minimum width to its preferred width so that the
id label will always be wide enough to display the id number, regardless
of the length of person names.
Or can say |
02c244c
to
defe7e8
Compare
The id text label does not define its minimum width on the PersonCard cell. As a consequence, a very long person name could cause the number in the label to be truncated. This is not desirable as users need to know the id number of a person to use some commands (e.g. edit). Let's set the id label's minimum width to its preferred width so that the id label will always be wide enough to display the id number, regardless of the length of the person's name.
defe7e8
to
b5662d8
Compare
v7@MightyCupcakes submitted v7 for review. (📚 Archive) (📈 Interdiff between v6 and v7) Checkout this PR version locallygit fetch https://github.com/se-edu/addressbook-level4.git refs/pr/338/7/head:BRANCHNAME where |
Going to merge soon. |
Resolves #323
Before:
After: (Index modified)