Specifying animations and Toolbar items in the resource editor - codenameone

I'm getting the hang of using themes to change my app's look and feel, but there are still a few mysteries. Right now, in the SocialBoo theme, the button to show the overflow menu is way too small, even though it's the right size in any other theme. Also, the overflow menu pops up with a nice animation on the other themes, but not in the SocialBoo theme. Can anyone tell me how to modify the theme to fix the size of the overflow button and specify an animation for the overflow menu?

SocialBoo is a pretty old demo that still uses the old GUI builder. We are slowly migrating away to the new GUI builder which was slated for the 3.4 release but is currently still considered beta status.
The new GUI builder standardizes on Toolbar which didn't exist when we developed the old GUI builder.
The icons for overflow/side menu can be customized via theme constants specifically sideMenuImage and menuImage.

I was able to partly fix this in code like this:
Hashtable<Object, Object> newThemeProps = new Hashtable<>();
// I need to start these with #, which tells the addThemeProps() method
// that these are theme constants, not theme properties.
// (The # character gets stripped out.)
newThemeProps.put("#menuTransitionIn", "bubble");
newThemeProps.put("#menuTransitionOut", "fade");
UIManager.getInstance().addThemeProps(newThemeProps);
This gave me the animations I wanted. I still don't know how to change this in the resource file.
As for the buttons, I fixed this in the Resource Editor by opening the TitleCommand style and setting the Background Image type to [empty] in the "..." button. This didn't improve the size of the button, but it removed the too-small button image, so it looks more professional. Here's what it looks like before the fix:
This is after the fix:
(Yeah, I added another item to the menu, too.)
It retrospect, I could probably have just checked the Derive button in the Background Image tab.
I also changed the TitleCommand foreground color to white (not shown), because the black buttons were practically invisible.
Finally, I changed the FontImage Icons to white with this piece of code:
/**
* The icon created by this method gets passed to the Command constructor.
*
* #param icon The FontImage constant for the desired icon
* #return The icon as an Image.
*/
#Nullable
public static Image createClearMaterialIcon(char icon) {
materialIconStyle = UIManager.getInstance().getComponentStyle("TitleCommand");
// materialIconStyle.setBgTransparency(0, true);
if (icon == 0) {
return null;
} else {
return FontImage.createMaterial(icon, materialIconStyle);
}
}
The transparency of the style needs to be set to zero (transparent). This can be done using the setBgTransparency() call in the line that's commented out, or it can be done by setting the TitleCommand resource's transparency to 0 in the Color tab.
Thank you, Shai, for pointing me in the right direction.

Related

Why is the Designer in Codename one not reporting the attributes I set?

I started a Codename One project with the "Hello World bare bones". I used to define the styles in the Theme tab from the Designer but now it is becoming tedious.
Actually for some selectors, even if I override (unchecking the Derive box) some properties the style is not changed in the Designer (see below) or in the app itself.
However, in the list of selectors, the color is not the one I selected but the alignment seems to be it.
It seems that the theme is locked somewhere. Do I make a mistake, or should I set a constant to "unlock" the theme, or even should I clear some directories?
Please note that I am using NetBeans with designer V 1.1
.
Edit March 1st 2017
Following #Diamond's great tips, I was able to change the foreground color by setting the Border to empty (instead of NULL). However now the alignment is still not what I expect (see below). How can I do for this property ?
Any help appreciated,
In the Designer, Border is superior to background color and background image. Which means if the border image is set, a background color will have no effect unless the border is just a stroke or line.
Always solve this with these few steps:
Go to the Border tab and uncheck the override.
Click the ... button next to Border Help and a new Dialog will show.
Change the Type (First line) to Empty and click Ok.
Your background color will now have an effect.

WPF menuitem shortcut. Strange behaviour

I create a menu item (context menu if that is of any help) using:
MenuItem menExit = new MenuItem();
menExit.Header = "Exit"; // will be changed later
menExit.Command = UICommands.CmdExit;
menExit.CommandBindings.Add(new CommandBinding(UICommands.CmdExit, CmdExitExecute, CmdExitCanExecute));
menu.Items.Add(menExit);
It works very well with one exception. No matter what CmdExitCanExecute returns, the menu item shortcut is ALWAYS grayed out. Note that the text ("Exit") works as intended (grayed out when CmdExitCanExecute returns false and black when true) but not so the shortcut. To make matters more complicated: the shortcut works when I press the key combination. What do I need to do to make the shortcut show the right color? The menu is shown by right clicking a tray icon, but that shouldn't matter, should it?
I suspect this is how the WPF default style works. If you actually disable a menu item, you will find that the shortcut text is a slightly lighter grey. The shortcut on a non-disabled item is slightly darker grey while the menu item text is black.
The difference is subtle and confusing but I think your MenuItem is working correctly.

GTK+ - setting the color of a button (in C)

So my problem is as follows - I need to create buttons in my GTK/C program that are simple clickable, colored tiles. I found this thread GTK Modifying Background Color of GtkButton and a few other resources that supply a very similar answer, but no matter what I do the set_fg function does nothing and set_bg function either sets a thin frame around the button/widget - which itself stays gray - or also does nothing. Can anyone please help me solve this problem or give me a reasonable alternative to creating a set of colored tiles that can be clicked on and that can dynamically change color?

ImageViewer in WPF

Hi everyone I would like to implement an ImageViewer (like the one in Facebook for example) in a WPF application
I already have a ListBox whith my pictures, it works well. But I would like to add pop "image full size" when the user double click on one of them. (something like in FB, with a fade out of the background etc).
Currently I'm thinking of to use a Window...Do you have a better idea of what I should use ?
i would probably use a window for that as well. Then you can easily put an opacity animation when the window loads to give it the fade in and fade out effect
You could also use a Popup control.
It comes with some some built in (but very limited) animations, like fade, see PopupAnimation.
I'd try that and if it doesn't fit your needs, I second bflosabre91 oppionion and would use a separate opacity animated window.
But bear in mind that with an additional window you could have negative side effects e.g always sync the window positions correctly, handle task switches (ie. correctly hide the window in the taskbar/tasklist)

How to make label transparent without any flickering at load time

I have a panel and on that I've a picturebox. There are around 20 labels that I've to show in the panel. I want the background of Label to be transparent ie the image in picturebox is shown and the label displays only the text.
Now since labels do not exhibit true transparency I made the labels child of picturebox
this.lbl1.Parent = pictureBox1;
This has solved my immediate problem but now when the form loads, all the labels take a while to become visible and do so one at a time. I'd appreciate if you guys can give some solution for this.
Thanks in advance
The standard cure for flicker is double-buffering. But that cannot solve this kind of flicker. It is a different kind, caused by having multiple windows overlapping each other. Each label is its own window. When the form needs to paint itself, it draws its background leaving holes for the child windows. Each child window then takes a turn drawing itself. And their child windows draw themselves next. Etcetera.
This becomes noticeable when one control takes a while to draw, no doubt your picture box. Especially when it displays a large image that needs to be resized. The holes for the child windows stay unpainted while the picture box draws. They have a white background, black when you use the form's TransparencyKey or Opacity property. This can contrast badly with the image in your picture box, that effect is perceived by the user as flicker.
One immediate cure is to not use controls so you don't pay for their window. A Label is very convenient but it is a massive waste of system resources to burn up a window just to display a string. You can simply implement the picture box' Paint event and draw the strings with TextRenderer.DrawText(). PictureBox has double-buffering turned on by default so the image as well as the text is drawn completely smoothly, no more flicker. The obvious disadvantage is that you lose the convenience of point-and-click, you have to write code.
There are other fixes possible. One of them is to prevent the picture box from leaving holes for the child windows. It will draw the entire image, the labels pop on top of them. That's still flicker but not nearly as noticeable. Add a new class to your project and paste this code:
using System;
using System.Windows.Forms;
internal class MyPictureBox : PictureBox {
protected override CreateParams CreateParams {
get {
var parms = base.CreateParams;
parms.Style &= ~0x02000000; // Turn off WS_CLIPCHILDREN
return parms;
}
}
}
Compile and drop the new picture box control from the top of the toolbox onto your form.
Yet another possible workaround is to make the form and all of its children double-buffered. This doesn't speed up the painting at all but all of the windows get rendered into a memory buffer, the result is blitted to the screen. You'll notice a delay but the window suddenly pops on the screen. This is called compositing. Winforms doesn't support this directly since it can have side-effects but it is easy to enable. Paste this code into your form class:
protected override CreateParams CreateParams {
get {
CreateParams cp = base.CreateParams;
cp.ExStyle |= 0x02000000; // Turn on WS_EX_COMPOSITED
return cp;
}
}
Supported by XP and later. Watch out for painting artifacts.
or you can ditch the labels and draw the text yourself:
private void pictureBox1_Paint(object sender, PaintEventArgs e)
{
TextRenderer.DrawText(e.Graphics, "Label1", SystemFonts.DefaultFont,
new Point(10, 10), Color.Black, Color.Empty);
}
The label does not support transparency, you must create your own unique custom control, you can see these code examples.
http://www.codeproject.com/KB/dotnet/transparent_controls_net.aspx http://www.codeproject.com/KB/vb/uLabelX.aspx
Bye

Resources