Tripleplay Button: Image button with transparent background - playn

How can I make an image button with transparent background?
The default background is grey color, I created the button with empty text and setIcon, something like this:
backButton = new Button(); //"Back");
backButton.setIcon(backIcon);
iface.createRoot(AxisLayout.vertical(), ROOT, modeLayer).
setStyles(make(VALIGN.top, HALIGN.right)).
setBounds(0, 0, width, height).
add(backButton);
But could not figure out how to make the button to be transparent from the API / source code.
Any help / hint greatly appreciated.

You want to use Style.BACKGROUND.
If you want all buttons in your entire UI to have a blank background, then configure your root stylesheet like so:
Stylesheet ROOT = SimpleStyles.newSheetBuilder().
add(Button.class, Styles.none().
add(Style.BACKGROUND.is(new NullBackground())).
addSelected(Style.BACKGROUND.is(new NullBackground()))).
create();
Root root = iface.createRoot(AxisLayout.vertical(), ROOT, modeLayer).etc().
If you just want a particular button to have a blank background,
configure it on the button:
Styles blankBg = Styles.none().
add(Style.BACKGROUND.is(new NullBackground()))
addSelected(Style.BACKGROUND.is(new NullBackground());
Button backButton = new Button().addStyles(blankBg).setIcon(backIcon);
Note also that SimpleStyles defines the backgrounds for buttons. If you start with a completely blank stylesheet, you can omit background definitions for your buttons and they will be blank.

Related

Codename One CSS Material Icon color not changing

I have created an application to test the new CN1 CSS support.
The plugin is great and everything works fine and out-of-the-box, except that the material icon on a button does not change its color with the button's text color. It just stays always the same (black) color.
Before using the CSS support, I changed the theme editor's default foreground color setting to reach the material icon, but now the theme editor seems to be dis-attached from the styling and it does not have any effect anymore.
Is there a UIID for the icon or any other way to change the color of the material icon?
Here is my code:
FontImage icon = FontImage.createMaterial(FontImage.MATERIAL_CHECK, "TitleCommand", 3);
Button buttonTest = new Button("Test css");
buttonTest.setUIID("ButtonTest");
buttonTest.setIcon(icon);
And the CSS:
ButtonTest {
color: red;
}
try it
FontImage img = FontImage.createMaterial(FontImage.MATERIAL_THUMB_UP, style);
Just to post a complete answer that might be able to guide someone:
Style style = new Style();
style.setBgColor(ColorUtil.GREEN);
style.setFgColor(ColorUtil.WHITE);
style.setBgTransparency(255);
FontImage imageBack = FontImage.createMaterial(FontImage.MATERIAL_NEXT_WEEK, style);

Centering Text on a Button with Offset

I have a variety of ToggleButtons that are loaded with an image. The buttons size is determinated by the image size and the button itself is created by JavaCode. A few buttons have icons (the icon is just part of the loaded image) on either the left or right side.
How can I move the text by a certain value to the left or right so I can center the text again but with the offset of the icon? I don't mind passing the width of the icon as parameter, but I cant find anything to move the text for a certain amount.
The button is created from the green image, the right icon is part of it; total width is 300, icon is taking 100; the text should be centered to the leftover 200. For language setting reason the text itself cant be part of the picture.
you can set the style of the button as followed:
// top right bottom left
btn.setStyle("-fx-padding: 5px 5px 5px 5px;");
EDIT:
You can use an HBox:
HBox hbox = new HBox();
// the text of the "button"
Label lbl_txt = new Label("Text");
// the icon of the "button", i am using Labels for icon(with css)
Label lbl_ico = new Label("ico");
hbox.getChildren().addAll(lbl_txt, lbl_ico);
hbox.setOnMouseClicked(new EventHandler<MouseEvent>() {
#Override
public void handle(MouseEvent t) {
// alternative to Button click
}
});
Everything else is styling with css. ;-)

Flex 4.5: custom background for popups

In Flex, when you use PopUpManager for popup windows, there is a background rectangle appearing over the application and behind the popup window itself. What I need is to override that default overlay rectangle with the custom one (in order to round the corners, apply gradient fill, etc).
How can this be achieved?
You can only change transparency, color and blur with css. See example:
global {
modalTransparency: 0.7;
modalTransparencyBlur: 0;
modalTransparencyColor: "0x000000";
}
Second way (if you want own design with round the corners, apply gradient fill, etc)
Create custom popup window (like TitleWindow) and when popup created or closed, dispatch from window custom event like:
dispatchEvent(new Event('addPopup', true));
In main application listen event:
systemManager.addEventListener("addPopup", onAddHandler, false, 0, true);
And then you can display own layer with custom design.
protected function onAddHandler(event:Event):void
{
// show custom background layer
}

GTK: display a tooltip for a gtkButton in a gtkFixed container with gtkImage as background

I want to position a gtkButton on top of a gtkImage. I do this putting both inside a gtkFixed container. The problem now is that the button's tooltip is not shown anymore, when there is an image in the background. Without the image it works fine. How can I get the tooltip to be shown?
I am an R programmer so the below code is R-Gtk binding style, but should still convey the idea:
library(RGtk2)
w = gtkWindow()
image = gtkImage(file="tmp_1.png")
btn = gtkButton("Test")
gtkWidgetSetTooltipText(btn, "test")
fx = gtkFixed()
gtkFixedPut(fx, image, 10, 10)
gtkFixedPut(fx, btn, 10,10)
gtkContainerAdd(w, fx)
gtkWidgetShowAll(w)
Any ideas?
TIA.
You should use GtkOverlay widget. You add your GtkImage widget as main child of the overlay and the button with gtk_overlay_add_overlay.
That should work, and that's the preferred way of doing it.

Flex 3 - Change box border colors

I have a question that might seem "basic" but I just cannot figure out how to do it...
I have a box and I'd like to change the borderColor. Till there, nothing special. Just a box.bordercolor = xxxxxx...
BUT, I'd like to have the top and bottom border with one color, and the left and right border with another color... And that's the part where I'm stuck.
Any tips? Suggestions?
Thanks for your help and time! ;)
Regards,
BS_C3
#Senz
Hi!
Unfortunately, I won't be able to share the code without making it "incomprehensible"...
But this is the idea... We have 2 main components: ArrowButton and Navigator.
ArrowButton is a hbox containing a label and an image (this image is the arrow tip and it changes depeding on the state of the ArrowButton).
Navigator is a hbox containing a series of ArrowButton. An ArrowButton overlaps the arrowButton on its right in order to create the pointed end of the button.
And then you just create a whole bunch of functionnalities around these components.
I hope this helps... Do not hesitate if you have some more questions =)
Regards.
I noticed you are asking about the Flex 3 SDK. Skins are a good approach. They have changed somewhat in Flex 4(for the better IMHO). If you are wanting to use the Flex Drawing API, then just extend the Box class into a custom class that would look something like this:
public class MultiColorBorderBox extends Box
{
// You could add getters/setters or constructor parameters to be able to change these values.
private var topColor:uint = 0xFF0000;
private var rightColor:uint = 0x00FF00;
private var bottomColor:uint = 0x0000FF;
private var leftColor:uint = 0xFF00FF;
private var borderWidth:Number = 20;
public function MultiColorBorderBox()
{
super();
}
override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void
{
super.updateDisplayList(unscaledWidth, unscaledHeight);
// This just ensures you dont have content under your border
this.setStyle("paddingLeft", borderWidth);
this.setStyle("paddingRight", borderWidth);
this.setStyle("paddingTop", borderWidth);
this.setStyle("paddingBottom", borderWidth);
var g:Graphics = this.graphics; // This creates a new Graphics object and sets it to the MultiColorBorderBox graphics object. Since Box (superclass) descends from a Sprite object, it has a graphics object automatically.
g.clear();
g.moveTo(0,0); // Moves the position to the top left corner
g.lineStyle(borderWidth, topColor); // Sets the line style with the width and color
g.lineTo(unscaledWidth, 0); // Draws the top border from top left to top right corners
g.lineStyle(borderWidth, rightColor); // Changes the line style
g.lineTo(unscaledWidth, unscaledHeight); // Draws the line from top right to bottom right
g.lineStyle(borderWidth, bottomColor); //Changes the bottom border style
g.lineTo(0, unscaledHeight); // Draws the line from bottom right to bottom left
g.lineStyle(borderWidth, leftColor); // Changes the border color
g.lineTo(0,0); // Closes the box by drawing from bottom left to top left
}
I'm pretty sure you're going to have to create a borderSkin to accomplish this. I believe these are created in an external program, such as Flash Professional; but more info is in the docs.
I don't think that Flex makes any distinction between top/bottom borders and left/right borders. Creating a skin would certainly be the nifty-slick way to do it. A programmatic way might be to use box.graphics to draw your border by hand. I'd start by trying to override the updateDisplayList() function to draw your border...
I finally did a pretty simple thing.
I guess I wasn't detailed enough regarding the specifications.
The actual aim was to create a navigator with arrow shaped buttons.
Each button had to be highlighted when it was selected. And this http://www.freeimagehosting.net/uploads/bcd0d762d7.jpg is how the navigator looked like.
Each button is actually an HBox containing a Box (with a label) and an Image (for the arrow tip), with a horizontalGap = 0.
I didn't think about adding a glowfilter to the button. So I was trying to just change the colors of the top and bottom part of the Box...
So, the glowfilter in the button worked pretty well.
Sorry for the lack of explanations about the context >_< And thanks for your answers!!
Regards.

Resources