Add an icon inside a Codename One TextModeLayout - codenameone

My problem is that I didn't find any way to properly add an icon near a TextComponent, inside a TextModeLayout, to mask/unmask a password.
It's a layout problem only, because the code of the ActionListener to mask/unmask the password works correctly at least in the Simulator (it's taken from Codename One - Mask and Unmask Password Field on iOS).
On iPhone skin, the InputComponents labels and text fields are not aligned correctly:
On Android skin, the text is not aligned correctly if it doesn't valide:
About my code, instead of adding the InputComponent (of the password) directly to the TextModeLayout container, I enclosed the InputComponent and the Button inside a BorderLayout, and then I added the BorderLayout container to the TextModeLayout container.

When you do that the text mode layout stops working for that component as it's unaware of the layout in the hierarchy. The hierarchy in the border layout is the responsibility of that layout.
The solution is to extend the TextComponent and add that functionality to Codename One. As a workaround we might be able to rely on the behavior of the current component since the field is already in a border layout component. So something like this might work:
TextField tf = myTextComponent.getField();
Container b = tf.getParent();
b.add(EAST, unmask);

Related

Grid vs Box: when to use which ? - MUI

So I have the following question which I believe is quite valid.
So Box and Grid are Layout components which you are suppose to add other components inside those as far as I'm aware. However sometimes Box does the job for me and sometimes is Grid and SOMETIMES I use both at same time.
This question came to mind to me after I was trying to CENTER a component, so in this example when I use GRID I can center the component in the middle of the screen without any issues:
Grid Example:
ExampleA-Sandbox
Box Example:
ExampleB-Sandbox
I know I can just simply add pl={number} to the box component and then I can move the box to a desire location but that's not the point.

AppBar / Dialog within child container boundaries

My issue stems from wishing to have a mobile phone rendered in the page, which mimics that of an actual phone. I would like to use components from Material UI such as AppBar and Dialog, however they do not stay confined to the container of the phone, and instead still show in the entire browser window.
When I use a Dialog Component however, it's still relative to the actual browser viewport, and not that of the "phone", such as the following:
I would like it to do what is seen in the picture below, without using an IFrame.
Is there a way I can set an anchor for the components - or at least force them to treat a specific element as their boundary? Thanks.
For those wondering if this is resolved, the solution was to roll my own Dialog and Backdrop Components with Paper, and Box components.
A ref was passed into a Box component which surrounds the entire "Phone App", and it's current Element is passed into a Mui Portal's container property.
This allows for the container of the Custom "Dialog" to be the container I wished to have things bounded by.

Touch-to-zoom animation in Codename One

I have an image inside a Codename One Label. I would like to open it to fullscreen after a tap and with an animation zoom, like in this video:
https://stuff.mit.edu/afs/sipb/project/android/docs/training/animation/anim_zoom.mp4
How can I get something similar using Codename One? Thank you for any hint.
You can do two things:
Place the image in a layered layout on the entire form and just animateLayout() the UI. This will produce this effect without moving to a new form. Assuming the image is a ScaleImageLabel.
You can move to a separate Form with a transition that mutates the content of the current form in that way specifically MorphTransition which was designed just for this effect. Make sure to use setName for the component in the source and destination forms so the transition will know which component to morph into which. You can morph multiple components:
MorphTransition m = MorphTransition.create(1200).morph(componentName);

Codename One square buttons

In Codename One, I need a class MyButton that extends Button. I want that every myButton instance is a Button which width and height are always equal (to the maximum of their values).
I know that every Component has setWidth and setHeight methods, but they are for the use of the layouts, I suppose that I should not use them directly.
I also know that I can create a Container with a custom layout and place a Button inside it... but in that case I’m not extending the Button class.
My question is if I can extend Button to create square buttons, or if the use of a Container with a custom layout is the only option.
You can use GridLayout which gives everything the exact same width/height but I'm guessing that what you are looking for is:
Container.setSameSize(Component...);
Container.setSameWidth(Component...);
Container.setSameHeight(Component...);
It's static and the components don't need to be in the same container. They'll get the same width/height by returning the preferred width/height of the largest among the set.

How can I rebuild Form Component in Codename One

I'm trying to create Custom Form configuration with scrollable TitleArea. The Form (black) has a BoxLayout.Y_AXIS Layout in BorderLayout.CENTER (blue). StatusBar (green) stays in BorderLayout.NORTH (green), when rest of the TitleArea (cyan) is in the first position in BoxLayout.
removeComponentFromForm function is unavailable for using in extended class. How can I remove components from Form to removing titleArea from BorderLayout.NORTH?
Why use the title area at all? Why not just add a component to the top of the box layout Y and style it as a Title that way you can scroll it out?
You can also use the new Toolbar API that includes many abilities to fade out the title as you scroll etc. See:
http://www.codenameone.com/blog/toolbar.html
http://www.codenameone.com/blog/cats-in-toolbars.html

Resources