JavaFx Repaint Canvas on StyleCssClass Change - css

To change the stylesheet to a dark one in my code I execute in Scene :
getStylesheets().add(FxFrame.class.getResource("/css/dark.css").toExternalForm())
This works fine.
I also have a canvas where some colors are configured using:
final StyleablePropertyFactory<FxDrawCanvas> FACTORY = new StyleablePropertyFactory<FxDrawCanvas>(FxDrawCanvas.getClassCssMetaData());
StyleableProperty<Color> calloutBackground1Color = FACTORY.createStyleableColorProperty(FxDrawCanvas.this, "callout-background1-color", "callout-background1-color", s -> s.calloutBackground1Color, Color.web("0xffffff" ));
The canvas should be repainted when the stylesheet css gets changed. How may I make the canvas aware of scene css change ?
Is possible to listen on css stylesheet changes in the canvas ?
Or fire any event in the scene which the canvas can intercept ?

Related

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
}

tripleplay Animator add layer

I have the following (pseudo) code
root = _iface.createRoot(...)
Label l = new Label("hello world");
anim = Animator.create();
anim.delay(1500).then().add(root.layer, l.layer);
anim.delay(1000).then().action(new Runnable() {
public void run() {
// root.add(l);
System.out.println("it works");
}
});
the it work's line gets printed ok, so I assume I'm updating the animation right, but the label is never added to the scene!
If I uncomment the root.add(l) inside the Runnable it works as expected (the label is added after 1 second), but it doesn't get added with anim.delay(1500).then().add(root.layer, l.layer);
any idea whay I'm doing wrong?
You can't just add the layer of a TPUI Widget to another layer and expect the Widget to render properly. A widget must be added to its parent via Group.add.
The animation code you are using is more designed for animating raw PlayN layer's than UI elements. UI elements are generally laid out using a LayoutManager which controls where the layer is positioned. If you tried to animate the layer directly, you would confuse the layout manager and generally mess everything up.
That said, it's pretty safe to animate the Root of the interface, because that anchors a whole UI into the PlayN scene graph.
If you really want to try what you're doing above, don't use Animator.add use:
action(new Runnable() {
root.add(l);
});
(like you have above) which properly adds the Label to the Root, and triggers validation and rendering of the Label.

add uicomponent inside a sprite

i want to add UIComponent inside a spite. here is the code:
private function make() : void {
var circle : Sprite = new Sprite();
circle.graphics.beginFill(0xFF0000, 0.2);
circle.graphics.drawCircle(0, 0, 20);
var button : Button = new Button();
button.label = "testing...";
var wrapper : UIComponent = new UIComponent();
circle.addChild( button );
wrapper.addChild( circle );
addChild( wrapper );
}
the problem is that button is added, but is not displayed. if i do reversed - add sprite to uicomponent - everything works fine, but this way it doesn't work. i tried to use invalidate functions for button etc... even tried making "circle" as UIMovieClip, but no luck - button is still invisible. also if i simply do "addChild( button );" - it is shown, what the... please help, what i am doing wrong? how can i add a button inside a sprite?
Short answer, you can't. What you CAN do is instead of using Sprite, you use UIComponent for your circle.
The reason for this is that UIComponent has A LOT of code that changes how it behaves, including how to add and layout children. You could essentially take the same code to a Sprite since UIComponent does extend it, however that would be VERY redundant. This works great for me:
private function make() : void {
var circle : UIComponent= new UIComponent();
circle.graphics.beginFill(0xFF0000, 0.2);
circle.graphics.drawCircle(0, 0, 20);
var button : Button = new Button();
button.label = "testing...";
var wrapper : UIComponent = new UIComponent();
circle.addChild( button );
wrapper.addChild( circle );
addChild( wrapper );
}
Unfortunately, in order to use Sprite the way you are trying to do it, you would have to extend Sprite and implement IUIComponent.
Taken from the Flex 3 Language Reference:
Note: While the child argument to the
method is specified as of type
DisplayObject, the argument must
implement the IUIComponent interface
to be added as a child of a container.
All Flex components implement this
interface.
Sprite does not implement IUIComponent, so you are experiencing a pretty typical issue. UIComponent's don't typically have speed issues when compared to Sprites, so I would recommend just drawing on your UIComponent.
As stated before, you /could/ extend Sprite to implement IUIComponent, but it's a pain.
Hope this helps!

in flex, onMouseOut is triggered on Child

In flex, I am using the following code:
mx:HBox id="box1" mouseOver="onBox('box1')" mouseOut="outofBox('box1')"
// adding label
// closing HBox
onBox adds an image as child of box1:
var crossImage:Image = new Image();
crossImage.source = "cross.png";
crossImage.id = "cross";
box1.addChild(crossImage);
and outofBox removes them.
I believe that image is child of HBox so mouseOut should not be triggered when I hover the mouse over image. But, the moment I hover my mouse pointer over image, mouseOut is triggered. Why is it so?
Set the mouseChildren property of the container to false

Flex: changing Flex component styles in AS3

in MXML, there is a Button class which you can instantiate like so:
<mx:Button id="something />
but what if you wanted to dynamically build this in AS3 and add it to the Flex app dynamically, without the use of components (just AS3) and then modify Flex's styles, for example, here you access the Button's properties and set them:
var btn:Button = new Button();
btn.height = 50;
btn.width = 75;
btn.x = 100;
btn.y = 40;
but how would you go about changing the Style, for example:
btn.downSkin = "something";
btn.color = "0xfffff";
I'm sort of starting to lean towards making a flex component in MXMLand than just making it visible true/false, but i like the fact that i create an object in AS3 and then destroy it when I don't need it anymore, than create it again once needed.
This page has a solution to the problem:
Setting and getting Style attributes in ActionScript:
// setting a components styleName to reference a CSS class
component.styleName = "highlight";
// set a Button's background color and font size
submitButton.setStyle( "backgroundColor", 0x000000 );
submitButton.setStyle( "fontSize", 14 );
// get a TextArea's font family and color
textArea.getStyle( "fontFamily" );
textArea.getStyle( "color" );
You could use CSS, either inline or as an external CSS file. That way you don't have to set the properties manually every time you create a button.
/* CSS file */
Button {
borderColor: red;
}
Check out Styling Button control, by Peter deHaan (also read the comments in that post).

Resources