Would it be possible to share your project ?
sure: https://haxeui.org/shared/haxeui-core-bitmap-buttons.zip
Background of the button is not hidden
You need to remove the background with a style (you dont need css for this technically, you could use custom style, but css makes it simpler )
On click position of the background not change
This you will need to use css for since its a state (ie, :down
)
I can’t apply bitmap button data style ( Error: String should be haxe.ui.styles.Style )
Make sure you pull latest haxeui-core and haxeui-openfl
For completeness, here is my full app (2 files):
<vbox style="padding: 5px;">
<style>
.bitmap-button {
color: #ffffff;
background-color: none;
border: none;
padding: 15px 15px;
background-image: lookup('bitmap-button-normal');
background-image-slice-top: lookup('bitmap-button-slice-top');
background-image-slice-left: lookup('bitmap-button-slice-left');
background-image-slice-bottom: lookup('bitmap-button-slice-bottom');
background-image-slice-right: lookup('bitmap-button-slice-right');
}
.bitmap-button .label, .bitmap-button .image {
margin-top: -5px;
}
.bitmap-button:hover {
background-image: lookup('bitmap-button-over');
}
.bitmap-button:down {
background-position: 1px 1px;
}
.bitmap-button:down .label, .bitmap-button:down .image {
margin-top: -4px;
margin-left: 1px;
}
</style>
<hbox>
<button text="Bitmap Button" styleName="bitmap-button" width="120" height="50" />
<vbox>
<button text="Bitmap Button" styleName="bitmap-button" width="240" height="50" />
<button text="Bitmap Button" styleName="bitmap-button" width="240" height="50" />
</vbox>
<button text="Bitmap Button" styleName="bitmap-button" width="200" height="105" />
</hbox>
<hbox>
<button text="Bitmap Button (Autosized)" styleName="bitmap-button" />
<button text="Bitmap Button (Fixed Width)\n\nWith a hard break" width="140" styleName="bitmap-button" />
<grid columns="2">
<button text="Left" styleName="bitmap-button" icon="haxeui-core/styles/default/haxeui_small.png" />
<button text="Right" styleName="bitmap-button" icon="haxeui-core/styles/default/haxeui_small.png" iconPosition="right" />
<button text="Top" styleName="bitmap-button" icon="haxeui-core/styles/default/haxeui_small.png" iconPosition="top" width="100%" />
<button text="Bottom" styleName="bitmap-button" icon="haxeui-core/styles/default/haxeui_small.png" iconPosition="bottom" width="100%" />
</grid>
</hbox>
</vbox>
package ;
import haxe.ui.containers.VBox;
import haxe.ui.styles.StyleLookupMap;
import openfl.display.BitmapData;
import openfl.geom.Matrix;
@:build(haxe.ui.ComponentBuilder.build("assets/main-view.xml"))
class MainView extends VBox {
public function new() {
super();
var scale = .25;
StyleLookupMap.instance.set("bitmap-button-normal", scaleBitmap(BitmapData.fromFile(Sys.getCwd() + "/../../../../assets/buttonBackground.png"), scale));
StyleLookupMap.instance.set("bitmap-button-over", scaleBitmap(BitmapData.fromFile(Sys.getCwd() + "/../../../../assets/buttonBackground_over.png"), scale));
StyleLookupMap.instance.set("bitmap-button-slice-top", 58 * scale);
StyleLookupMap.instance.set("bitmap-button-slice-left", 75 * scale);
StyleLookupMap.instance.set("bitmap-button-slice-bottom", 110 * scale);
StyleLookupMap.instance.set("bitmap-button-slice-right", 400 * scale);
}
private function scaleBitmap(bitmap:BitmapData, scale:Float):BitmapData {
var cx = Std.int(bitmap.width * scale);
var cy = Std.int(bitmap.height * scale);
var scaleX:Float = cx / bitmap.width;
var scaleY:Float = cy / bitmap.height;
var matrix:Matrix = new Matrix();
matrix.scale(scaleX, scaleY);
var resizedBitamp = new BitmapData(cx, cy);
resizedBitamp.draw(bitmap, matrix, null, null, null, true);
return resizedBitamp;
}
}