Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Reply
New Contributor
meandnano
Posts: 8
Registered: ‎01-30-2014
My Device: Z10
My Carrier: BalalaykaTelecom
Accepted Solution

How to find absolute position of the last character in the label

[ Edited ]

Hello forum!

 

Today I have another unusual task. I need to place some Control ( e.g. button or any other one ) over the Label (or anything that can display text) right after the last symbol of the text. I guess I can use AbsloluteLayout  to set actual position of the control over the Label, but I'm not sure how to find this position. 

 

The label can have multiple lines and text can have totally different length.

 

Can anyone help me with this?

Please use plain text.
Developer
BBSJdev
Posts: 6,094
Registered: ‎07-05-2012
My Device: Playbook, Dev Alpha C, Z10 LE, Z30
My Carrier: Orange

Re: How to find absolute position of the last character in the label

Over the last text character or over the end of the label as the latter is easy the first not so much?


If you've been helped click on Like Button, if you've been saved buy the app. :smileyhappy:

Developer of stokLocker, Sympatico and Super Sentences.
Please use plain text.
New Contributor
meandnano
Posts: 8
Registered: ‎01-30-2014
My Device: Z10
My Carrier: BalalaykaTelecom

Re: How to find absolute position of the last character in the label

 

Over the end of the text, right after last character. So if last line is shorter than the whole label, my button should be placed on this last line after the final word.

Please use plain text.
Developer
BBSJdev
Posts: 6,094
Registered: ‎07-05-2012
My Device: Playbook, Dev Alpha C, Z10 LE, Z30
My Carrier: Orange

Re: How to find absolute position of the last character in the label

That's a tough one as even with a fixed width font if you are having a multiline label it's going to be hard to work out where the sentences will break.

 

Any chance you can change the design or is it fixed?

 

I say that because I think you will have to write your own custom control which although doable is a sizeable bit of work.


If you've been helped click on Like Button, if you've been saved buy the app. :smileyhappy:

Developer of stokLocker, Sympatico and Super Sentences.
Please use plain text.
New Contributor
meandnano
Posts: 8
Registered: ‎01-30-2014
My Device: Z10
My Carrier: BalalaykaTelecom

Re: How to find absolute position of the last character in the label

[ Edited ]

Well, I've tried (not so hard actually) to create my own Control, but with no success yet.

And there's no way to change the design - my client wants a complete copy of his iOS/Android app and this feature is implemented there (unfortunately I can't have those sources).

 

Right now I have temporary solution with WebView and a simple HTML/CSS code, but since it's a list item I've got some troubles with the speed.

 

So I need to solve this problem of getting width/height of a text and lines...

Please use plain text.
Developer
BBSJdev
Posts: 6,094
Registered: ‎07-05-2012
My Device: Playbook, Dev Alpha C, Z10 LE, Z30
My Carrier: Orange

Re: How to find absolute position of the last character in the label

Creating a custom control is not the hard part it's writing a custom control where you are responsible for placing the characters which would be fairly non-trivial.

 

Getting the width and height is not the problem, with a fixed width font you can work out where the last character is on a single line and calculate the x & y.

 

The problem starts when that text goes over one line at that point you can measure the height of the control but unless you know where the breaks appeared in the sentence I can't see how you would then know where the last word is you'd know the y but not the x.

 


If you've been helped click on Like Button, if you've been saved buy the app. :smileyhappy:

Developer of stokLocker, Sympatico and Super Sentences.
Please use plain text.
Developer
BBSJdev
Posts: 6,094
Registered: ‎07-05-2012
My Device: Playbook, Dev Alpha C, Z10 LE, Z30
My Carrier: Orange

Re: How to find absolute position of the last character in the label

It's always possible that I've missed something but I spent a lot of time reading up on everything to do with text for my app and I can't recall anything that would even remotely help you. I can't even think of a hacky way to do it.

 

You would also need to cope with the user changing the default font size. Something that can be easily locked out but not easily accommodated.

 

I think you are left with basically writing your own custom control Label.

 

Or cheating and accepting the button always on the bottom-right, after all how different will it look from iOS most of the time. :smileyhappy:


If you've been helped click on Like Button, if you've been saved buy the app. :smileyhappy:

Developer of stokLocker, Sympatico and Super Sentences.
Please use plain text.
New Contributor
meandnano
Posts: 8
Registered: ‎01-30-2014
My Device: Z10
My Carrier: BalalaykaTelecom

Re: How to find absolute position of the last character in the label

It will look pretty much different. That list is designed as for web page. At least problem easily solves with HTML and they have the same design in their website.

 

How do you think, is it possible to find a position of any predefined charachter? What if I'll put it after the text and will look for its position after the text is set. Would it help?

Please use plain text.
Developer
BBSJdev
Posts: 6,094
Registered: ‎07-05-2012
My Device: Playbook, Dev Alpha C, Z10 LE, Z30
My Carrier: Orange

Re: How to find absolute position of the last character in the label

Could you switch to using a WebView then rather than a Label if you have a solution in html?

As I said if the font is fixed width it's pretty simple it's just pos = Control offset + (num chars * font_width_in_pixels).

But as soon as you have a line break all bets are off.

If you've been helped click on Like Button, if you've been saved buy the app. :smileyhappy:

Developer of stokLocker, Sympatico and Super Sentences.
Please use plain text.
New Contributor
meandnano
Posts: 8
Registered: ‎01-30-2014
My Device: Z10
My Carrier: BalalaykaTelecom

Re: How to find absolute position of the last character in the label

I think I found a way of solving this, but still have one question - how to find font width in pixels?

Please use plain text.