Created
March 21, 2016 18:01
-
-
Save codenameone/5c44d837d3582b11deed to your computer and use it in GitHub Desktop.
Sample code for the new BubbleTransition effect in Codename One
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Form hi = new Form("Bubble"); | |
Button showBubble = new Button("+"); | |
showBubble.setName("BubbleButton"); | |
Style buttonStyle = showBubble.getAllStyles(); | |
buttonStyle.setBorder(Border.createEmpty()); | |
buttonStyle.setFgColor(0xffffff); | |
buttonStyle.setBgPainter((g, rect) -> { | |
g.setColor(0xff); | |
int actualWidth = rect.getWidth(); | |
int actualHeight = rect.getHeight(); | |
int xPos, yPos; | |
int size; | |
if(actualWidth > actualHeight) { | |
yPos = rect.getY(); | |
xPos = rect.getX() + (actualWidth - actualHeight) / 2; | |
size = actualHeight; | |
} else { | |
yPos = rect.getY() + (actualHeight - actualWidth) / 2; | |
xPos = rect.getX(); | |
size = actualWidth; | |
} | |
g.setAntiAliased(true); | |
g.fillArc(xPos, yPos, size, size, 0, 360); | |
}); | |
hi.add(showBubble); | |
hi.setTintColor(0); | |
showBubble.addActionListener((e) -> { | |
Dialog dlg = new Dialog("Bubbled"); | |
dlg.setLayout(new BorderLayout()); | |
SpanLabel sl = new SpanLabel("This dialog should appear with a bubble transition from the button", "DialogBody"); | |
sl.getTextUnselectedStyle().setFgColor(0xffffff); | |
dlg.add(BorderLayout.CENTER, sl); | |
dlg.setTransitionInAnimator(new BubbleTransition(500, "BubbleButton")); | |
dlg.setTransitionOutAnimator(new BubbleTransition(500, "BubbleButton")); | |
dlg.setDisposeWhenPointerOutOfBounds(true); | |
dlg.getTitleStyle().setFgColor(0xffffff); | |
Style dlgStyle = dlg.getDialogStyle(); | |
dlgStyle.setBorder(Border.createEmpty()); | |
dlgStyle.setBgColor(0xff); | |
dlgStyle.setBgTransparency(0xff); | |
dlg.showPacked(BorderLayout.NORTH, true); | |
}); | |
hi.show(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Sample usage of BubbleTransition.
From the Codename One project