Skip to content
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

Limit the number of character in Token (or add "...") #179

Closed
muhammad-naderi opened this issue Nov 9, 2015 · 14 comments
Closed

Limit the number of character in Token (or add "...") #179

muhammad-naderi opened this issue Nov 9, 2015 · 14 comments
Labels

Comments

@muhammad-naderi
Copy link

Hi,

great work on the library, Thanks !

here is a bug_report / request,

when the token's width is longer than the MultiAutoCompleteTextView's width, somehow the token gets cropped (Which is not a bad thing!) and then it gets duplicated in two lines.
so either let me know how I can prevent the duplication, or how we can replace the string in the token with string.substring(0,LIMIT) + "..." or any other enhancement

in the first screenshot you can see both TAC s showing the tokens OK!
screenshot_2015-11-09-15-30-10

here the right one increased in size, hence the left one gets smaller than the token (ONLY ONE TOKEN, IT HAS) and you can see how it gets duplicated
screenshot_2015-11-09-15-30-17

same goes with the left one here

screenshot_2015-11-09-15-30-25

@mgod
Copy link
Contributor

mgod commented Nov 9, 2015

The duplication is definitely a bug. To avoid the extra long token, you just need to return a view from getViewForObject that isn't wider than the available space. Maybe add a maxWidth an appropriate details in your layout?

@mgod mgod added the bug label Nov 9, 2015
@muhammad-naderi
Copy link
Author

Actually right now I am doing such a thing, but this results in the tokens gets small all the time, frankly it's not that beautiful,
screenshot_2015-11-10-11-30-47

what I think would be great is for the token to get re-sized on-demand (while it's bigger than the available space.

@mgod
Copy link
Contributor

mgod commented Nov 10, 2015

I don't think doing a lot of work on the layout is going to do a much better job than just picking a reasonable token size maximum. If we ware going to do fully justified tokens, we'd also need to be able to expand them as well. If we're not, I'm not sure the result would be much better than if you set you max width to about 1/3 of the available space of the field.

@mgod
Copy link
Contributor

mgod commented Nov 10, 2015

More helpful note is that you can probably do this yourself if you want. In your subclass of TokenCompleteTextView you can use Layout.getDesiredWidth on getText and mod that by maxTextWidth. This will give you the amount of space left in the current line. If you subtract that from maxTextWidth, that's how much space your token can take and fit on the last line. You may need to account for the space characters between tokens and the prefix if you have one.

@mgod
Copy link
Contributor

mgod commented Nov 10, 2015

I could see adding a call that would give the amount of space left for tokens on the current line, which would make custom token sizing relatively straightforward. I just don't think adding a bunch of custom layout finagling code to an already tricky library is going to give good results.

@mgod
Copy link
Contributor

mgod commented Nov 10, 2015

I take everything back, this might be very simple.

@mgod
Copy link
Contributor

mgod commented Nov 10, 2015

can you take a look at https://github.com/splitwise/TokenAutoComplete/tree/width-experiment and let me know if it works for you?

@muhammad-naderi
Copy link
Author

The only file that has been changed is link to File
right?
if yes, then No, the problem still exists and the tokens get duplicated

@mgod
Copy link
Contributor

mgod commented Nov 14, 2015

I'm terribly sorry, I failed to actually push the changes. You should see more changed now. This doesn't fix the duplicate issue, but does let you do custom handling for the width of tokens by overriding maxTokenWidth in your TokenCompleteTextView. Something like:

protected float maxTokenWidth() {
    float left = getTextLineWidthLeft();
    if (left < maxTextWidth() / 4) {
        return maxTextWidth();
    } else {
        return left;
    }
}

@muhammad-naderi
Copy link
Author

to be completely honest I do not get how this can help me !
my problem is that I generate the TAC in run time, and also change the width while user focuses on the TAC, (in pictures you may see that first, two TACs have weight of 0.5, each, then when user focuses on each one, it gains weight from the other one and the weight distribution becomes 0.8 and 0.2 , and vice versa.

so if you help me out a little more, I can check what ever you want :)

@mgod
Copy link
Contributor

mgod commented Nov 16, 2015

Ah, I see. Sorry to misunderstand. I think live resizing and auto layout of the tokens on field resize is possible, and the code I've added in that branch is the start of it. I don't think this is something I'll be able to get in a comfortable place to add to the main library.

@muhammad-naderi
Copy link
Author

No problem, and again thanks for your nice work.

back to the duplication bug, can I have an ETA on it, please?

@mgod
Copy link
Contributor

mgod commented Nov 17, 2015

Unfortunately, It's not something I can see a simple fix to, so I'm not sure when I'll get it done.

@mgod
Copy link
Contributor

mgod commented Mar 9, 2019

Version 3.0.0 cleaned up a lot of the token handling code. Can you try it and let me know if you're still seeing the duplication issue?

@mgod mgod closed this as completed Mar 9, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants