My app features a floating action button which size I would like to increase. I want it much bigger. Please note that I've already achieved to change its color by changing the background color of the style applied to the FAB. Unfortunatelly it does not yield the expected change with the following code :
Font fabFont = UIManager.getInstance().getComponentStyle("Score").getFont();
fabFont.derive(Display.getInstance().convertToPixels(ParametresGeneraux.getFabSizeInMilli()), Font.STYLE_PLAIN);
fabStyle.setFont(fabFont);
The FAB size remains constant. What is the proper way to increase the FAB ?
Any help appreciated,
This seems to be hardcoded in the class, notice that what you see in the FAB is the icon not the text so increasing the text size will do nothing. I have two potential solutions.
First I'll add a method to set the default FAB icon size in millimeters:
FloatingActionButton.setIconDefaultSize(4);
The current default is 3.8f which we found consistent with native.
The second method is on a per instance basis and will work before the library update today:
FontImage image = FontImage.createMaterial(icon, "FloatingActionButton", 4);
fabInstance.setIcon(image);
You can obviously increase the padding as well in the UIID to make the whole thing even bigger...
Related
Today I spent two hours trying to align vertically the text of a toogle button at the bottom of the button icon.
The button icon height is a three or four times longer than the text height: the text must be vertically aligned at the bottom of the icon.
The method setVerticalAlignment(int valign) works as expect if the parameter is Component.TOP or Component.CENTER, but Component.BOTTOM acts exactly as Component.CENTER.
I tried a lot of workarounds, without success. It’s odd that a so easy task is hard to do: am I missing something? Thank you.
I don’t know if it’s relevant, however I’m also using setTextPosition(Component.RIGHT).
Edited answer...
That code is a bit difficult to work with and has so many nuances and misbehavior's. I usually end up just splitting the text and icon to separate labels and using something like a flow layout:
Form hi = new Form("Big and Small", BoxLayout.y());
CheckBox toggle = CheckBox.createToggle("My Text");
toggle.setUIID("Label");
Label bigIcon = new Label("");
FontImage.setMaterialIcon(bigIcon, FontImage.MATERIAL_INFO, 10);
Container lead = FlowLayout.encloseBottomInRow(toggle, bigIcon);
lead.setUIID("ToggleButton");
lead.setLeadComponent(toggle);
hi.add(lead);
hi.show();
Note that at this time this code requires a change that was added yesterday to the code (the ByRow method). Initially I thought this was a bug in FlowLayout but it seems it was just two different ways of calculating vertical alignment for the container.
To get a sense of why aligning and placing labels is so hard check out this code responsible for that: https://github.com/codenameone/CodenameOne/blob/fd2acfc10eb22f4b7a3089aeac4e967280f92b4e/CodenameOne/src/com/codename1/ui/plaf/DefaultLookAndFeel.java#L1314-L1623
This is just the generic code. There are copies of it in native iOS and Android code (for performance).
Is there a way to detect the background color at one certain point of the page dynamically? I have a website with a fixed header, and the default logo on it is white (default background is black). However, as I scroll down there are sections that have white background, so the logo would have to change colour to black.
Setting it based on scrolling position is not possible, because all sections have different heights and the height is often dependent on the content.
I have found mix-blend-color, but unfortunately its support is pretty bad across browsers. Also tried numerous npm packages, but none of them seem to pick up the background colour.
Is there another way to dynamically change the logo color without getting the background color?
Answer 1
I never tried this, but I think this might lead to the answer.
You can use document.elementFromPoint.
This will retrieve the top element at some (x, y) point.
So you can set the x and y to 1px down the border of your modal ( or some place where you know that will only have element with the background color you want) and get the element.
And check, on a scroll event listener, what is the element at that position and get it's background color.
Is this a good thing to do? Maybe not, but it works and it have good support across browsers.
Answer 2
Setting it based on scrolling position is not possible
Of course it's possible!
If your modal is with position absolute, what you can do is get the modal's ref and use element.getBoundingClientRect() to get it's position.
Then on each section, you also get the ref (you will have an array of section's ref) in the parent component, which knows the modal's refs and section's ref.
Then, on a scroll event, you use getBoundingClientRect on each section element and check if it's inside the modal logo.
To check if it's inside, you can simply use the top and bottom ( if the scroll is vertical).
This is harder to implement, but I think it's the way to go.
I'm using the SpanLabel Component, but on the screen the text content does not occupying the full width when text size is lower
Someone can help please?
This can happen if the width isn't deterministic. The SpanLabel won't be able to reflow and at best will cause only its own Container to resize. There are two solutions:
Deterministic hierarchy - this is generally best but not always possible
Use TextArea - sometimes this works around the issue by reducing the hierarchy depth.
Deterministic layout means that the size of the elements is determined in a clear way by the hierarchy. E.g. BoxLayout.Y is deterministic on the X axis as it gives the components on the X axis all available space. FlowLayout isn't deterministic as it gives components their preferred size.
Some layouts can go back and forth and vary in determinism based on their axis.
This is important because when we layout the components we go from top down. So we go through the Form to its children asking each for their preferred size. If at this point the SpanLabel doesn't know its size it can give the wrong value and we can't really fix that later as we don't reflow the UI. Reflow would create a potential infinite loop and a performance problem at best.
We try to workaround some of this behavior by making a revalidate() call within TextArea but that has its limits. If the hierarchy is too deep the preferred size is already set and won't adapt. SpanLabel is just a Container with a TextArea and a Label (for the icon). So by only using a TextArea you'd slightly simplify the hierarchy and it sometimes might be enough. E.g.
TextArea t = new TextArea(myText);
t.setEditable(false);
t.setFocusable(false);
t.setUIID("Label");
I am using quill js and making a fully responsive editor that will scale font-size with the container, using the view width property.
I have it fully built except for one problem:
Even though I am using prepareFormat(), (for times where the cursor is at one point and no other text is selected) the font-size will change on occasion to the highest default font inside of the quill minified file, which in version 0.20.1, happens to be 48px. I have tried putting my own numbers into the quilljs FONT_SIZES object, but only sometimes it would select them properly.
The thing I am most confused about is that if i highlight them, the letters will change to exactly what I would like them to be, whereas for the prepareFormat() fails to change it into any number but a preset in FONT_SIZES.
If anyone has a good idea as to what event I should tie prepareFormat() to, please let me know :)
Thanks in advanced!
Quill 0.20.1 uses execCommand which only allows 1-7 as valid font sizes. Quill 1.0 has no such limitation.
I've been playing around with Codename One for a while now, but I can't seem to design a layout that I had planned with the layout managers provided. How should I go about designing the following layout?
I want a component on the left with a specific width, a component on the right with a specific width, and a center component that stretches or shrinks to the space that is leftover by the other two. If this was an html/css table, it would be something like:
<td style="width:50px;"></td><td style="width:auto;"></td><td style="width:50px;"></td>
TableLayout gets close, but the widths are defined in percentages only. BorderLayout and GridLayout bases the sizes on the prefered size of the largest component, but the setPreferedSize() method is deprecated, and setSameWidth() is suggested instead, but that doesn't seem to do what I need it to in this circumstance.
If you want a component to have the right size for the image just place the image as an icon in a label and its preferred size will be the size of the image+padding which should give you exactly the effect you want by default.
Notice that the server sent images should differ in size based on the device DPI otherwise your app might look ridiculous on some devices. See this course for how we handle image requests to the server: https://www.udemy.com/build-mobile-ios-apps-in-java-using-codename-one/