01-09-2013 06:11 AM
I m using a class which extends from BasicEditfield and overrided layout(), getPreferredWidth() and getPreferredHeight() methods.
Im adding this customized editfield to a scrollable HorizontalFeildManager.
For "left" alignment:
I able to display text properly,
In customized manager of setPositionChild(field,0,0) I given--------------------->A
For "right" alignment
I able to display text properly only when the entered text width is within the Screen width
In customized manager of setPositionChild(field,(screen_width-text_width)>0
so my problem is with "right" alignment,
with "right alignment" when im keep on trying text in editfield its returning(by getPreferredWidth()) some value and using line B i able to get result even if the text width is more. when textwidth is more the X-coordinate of line B is 0 and cursor is showing at right end only.
but I move from that field to another then I came back to the field which is right aligned the cursor is placed at 0th position , Im thinking its due to line B. so how to overcome this even if i go out of that field and came to that field the cursor focus should be at right end how to achieve this.
Thanks in advance
01-09-2013 08:51 AM
Can you explain what you are trying to achieve? It's not clear enough from your explanation.
There is one remark I can give right now, though: you should not use getPreferredWidth as the basis for your width calculations. You should check the overall text length (using getFont().getAdvance(getText()), for example) and see if it's more than the screen width (in which case the field will word wrap and take multiple lines).
In general, explain what you want to see and give both your Field's relevant code (layout() is extremely relevant here; if you are trying to utilize getPreferredWidth, show its code as well) and your Manager's (sublayout() of your Manager is the key part and there are many possibilities for small and huge mistakes there).
01-11-2013 12:41 PM
Hi arkadyz, For left & right content alignments im doing and achieving like below
In case of left:
So for left initially cursor position is at left end and keep on typing cursor is placed at right end (like above image) and characters are entering properly.
In case of right:
cursor placed at right end intially
keep on typing the characters are entered like above image
while entering more characters its like above here the problem comes,
actually for right alignment im doing setPositionChild(field, (screen_width-text_width),height) , when text_width is more the X-coordinate of this method becomes -ve value.at this case what I have to take.
how to get the right alignment properly, I hope now I explained properly about my requirement.
Coming to coding part:
I have taken customized editfield and added to Scrollable(style) HorizontalFieldManager.
In my customized editfield I overrided getPreferredWidth() and In sublayout of my manager Im using layoutchild(fld,screen_width,height), setPositionChild(fld, (screen_width-fld.getPreferredWidth),height).
here when fld.getPreferredWidth is more than screen_width due to -ve , X-value im not able to get the RIGHT alignment properly.
Thanks in advance
01-14-2013 08:38 AM
So you re-layout the manager on each key press in the field? OK.
First of all, please show your code of getPreferredWidth. I guess you might have some small mistake there.
Second, if you add your field to a scrolling manager, the manager will scroll properly with the cursor going right because edit field reports the cursor position as its focus rectangle (as you've discovered with your left-aligned field). Therefore, you don't have to give negative x position to the field. Why don't you calculate x as Math.max(0, <your calculated position>)? It will become zero once your field is too wide and will behave exactly like the left-aligned field which is fine at this point.
01-14-2013 09:33 AM
01-14-2013 10:46 AM
OK, I guessed something like that. I would suggest using font.getAdvance("W") (or another wide character) instead of the hard-coded 10 pixels.
Have you tried my suggestion of setting position to no less than zero?
01-14-2013 12:48 PM
Ok, arkadyz im trying with your inputs,
and as you said to use Math.max(0, <your calculated position>) like that I used 0 already when the difference is become -ve in setPositionChild() method, here when keep on typing it is behaving correctly but at this moment if I go from that field to another and came back to that field(move focus out and when that field retain focus) then my problem is
A) for RIGHT alignment initially when the field getting focus its behaving like below, its correct (the cursor position)
B) for RIGHT alignment while keep on typing ,then also cursor position is there itself which is correct.
C)If I move focus out its behaving like this, its normal
D) when my required getting focus(RIGHT alignmanted field) its getting like this , its correct (here the entered text_width is less thatn screen_width ), this what we expected
E) whenever the entered text_width is more than screen_width, its behaving like below, which we dont want.
I think it is because of we are giving X- coordinate is 0 when entered text_width is more than screen_width, i.e.,Math.max(0,"my calculated width") for X-coordinate.
So at this case how to set thecursor position (for right alignment), I have tried setCursorposition() but of no use.
Thanks in advance
01-14-2013 02:45 PM
Looks weird indeed.
Can you also show the code of layout() of your BasicEditField?
01-16-2013 10:15 AM
In layout I'm doing this
I have checked that width I'm getting 350( I.e, width=350)
In sub layout of my extended manager
Layoutchild(fld,text_width,hgt), // here text_width is giving entered text width
I'm not using setExtent() in sublayout,
Thanks in advance