-
10 Jul 2012 6:30 AM #1
Answered: Custom Style for Button on toolbar
Answered: Custom Style for Button on toolbar
I have a series of Buttons in a toolbar component. I need to style the buttons: I have my own images for normal and active states and do not want to use any of the Sencha pictos icons nor do I want a background gradient or border for the button. I have set up Compass / scss which generates a css file for theming but I'm not sure if thats the way I need to do this . I also would like to use an image directory of my choosing. What is the best way to accomplish this?
-
Best Answer Posted by jerome76
You don't really have to go about Compass or scss. If you want, and this is what I did, create a .css file with all the css for the button you'd like. You can use this as an example:
(taken from sencha-touch.css [debug])
You can go into your own .css file and edit it to look something simple like:Code:/* line 56, ../themes/stylesheets/sencha-touch/default/widgets/_buttons.scss */ .x-button { -webkit-background-clip: padding; background-clip: padding-box; -webkit-border-radius: 0.4em; border-radius: 0.4em; display: -webkit-box; display: box; -webkit-box-align: center; box-align: center; min-height: 1.8em; padding: .3em .6em; position: relative; overflow: hidden; -webkit-user-select: none; } /* line 55, ../themes/stylesheets/sencha-touch/default/_mixins.scss */ .x-button, .x-toolbar .x-button { border: 1px solid #999999; border-top-color: #a6a6a6; color: black; }
Then when you create a button, you can add a 'cls' to it. Adding the 'cls' will add the css onto what is default for the button already (included in the main .css file you use).Code:.mybutton-red { background-image: url('path/to/image.png'); /* If you add your image [button.png] to, let's say, resources/images, and your .css is located in resources/css, you will have to set it like url('../images/button.png') */ }
Code:{ xtype: 'button', cls: 'mybutton-red', text: 'I am red', }
-
10 Jul 2012 6:53 AM #2Sencha - Community Support Team
- Join Date
- May 2012
- Location
- Istanbul
- Posts
- 1,331
- Vote Rating
- 77
- Answers
- 124
use html config
use html config
hi Mike,
You can use html config for display images and custom style. For example..
For more information see http://docs.sencha.com/touch/2-0/#!/...olbar-cfg-htmlCode:Ext.toolbar({ items:[ { width:100, html: '<div style='background-color:green;'><img src='/yourImage'> Sample Button</div>' } ] })sword-it.com, Sencha Developer House in Turkey - Istanbul University Technopark Suite 204.
-
10 Jul 2012 7:00 AM #3
You don't really have to go about Compass or scss. If you want, and this is what I did, create a .css file with all the css for the button you'd like. You can use this as an example:
(taken from sencha-touch.css [debug])
You can go into your own .css file and edit it to look something simple like:Code:/* line 56, ../themes/stylesheets/sencha-touch/default/widgets/_buttons.scss */ .x-button { -webkit-background-clip: padding; background-clip: padding-box; -webkit-border-radius: 0.4em; border-radius: 0.4em; display: -webkit-box; display: box; -webkit-box-align: center; box-align: center; min-height: 1.8em; padding: .3em .6em; position: relative; overflow: hidden; -webkit-user-select: none; } /* line 55, ../themes/stylesheets/sencha-touch/default/_mixins.scss */ .x-button, .x-toolbar .x-button { border: 1px solid #999999; border-top-color: #a6a6a6; color: black; }
Then when you create a button, you can add a 'cls' to it. Adding the 'cls' will add the css onto what is default for the button already (included in the main .css file you use).Code:.mybutton-red { background-image: url('path/to/image.png'); /* If you add your image [button.png] to, let's say, resources/images, and your .css is located in resources/css, you will have to set it like url('../images/button.png') */ }
Code:{ xtype: 'button', cls: 'mybutton-red', text: 'I am red', }
-
10 Jul 2012 9:43 AM #4
Thanks for the suggestions. I decided to use compass after all to encode my icons in base 64 so they draw immediately when my app comes up. Only issue is the icon is drawn in white not color, I assuming this is because the sencha theme is overriding it . Any ideas why ?
In my scss file:
Then for my button code:Code:@mixin custom-iconmask($name) { .x-tab .x-button-icon.#{$name}, .x-button .x-button-icon.x-icon-mask.#{$name} { -webkit-mask-image: inline-image('icons/' + $name + '.png'); } } @include custom-iconmask('custom_icon'); @include custom-iconmask('custom_icon_active');
Code:Ext.define('epiduo_ped.view.Main', { extend: 'Ext.Panel', config: { itemId: 'main', fullscreen: true, layout: 'fit', items: [{ xtype: 'toolbar', docked: 'bottom', items: [{ xtype: 'button', iconCls: 'custom_icon', iconMask: true, text: '', ui:'plain', handler: function(){ Main.back(this); } },
-
10 Jul 2012 9:55 AM #5
Yeah I believe the icon mask is only rendered in black or white, but you can add a color gradient to it with the css.
-
10 Jul 2012 10:21 AM #6
hmmm, will the gradient make it render exactly as is (in color)? Otherwise how do I render my icons exactly as they are?
-
10 Jul 2012 11:06 AM #7
The gradiant will overlay the white or black. I'm not sure about the color being as is. If you want it the way you created the color, you could always use the <img> tag in the text config of the button or a css class to add to the button with a background-image property, etc.
-
10 Jul 2012 12:24 PM #8
I'm trying to hold on to the base64 approach if I can, else I guess I will have to fall back to creating a class background-image. With that said, is below possible? It doesn't seem to be working, but not sure if I'm executing it correctly:
Code:.my_class{ width: 21px; height: 50px; background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABUAAAAyCAYAAACzvpAYAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAA2hpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuMC1jMDYxIDY0LjE0MDk0OSwgMjAxMC8xMi8wNy0xMDo1NzowMSAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4gPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIgeG1sbnM6eG1wTU09Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9tbS8iIHhtbG5zOnN0UmVmPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvc1R5cGUvUmVzb3VyY2VSZWYjIiB4bWxuczp4bXA9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC8iIHhtcE1NOk9yaWdpbmFsRG9jdW1lbnRJRD0ieG1wLmRpZDpGNzdGMTE3NDA3MjA2ODExOTdBNUU2RjU1OTJGRkRERSIgeG1wTU06RG9jdW1lbnRJRD0ieG1wLmRpZDo4NUMwM0RDMDgyOUUxMUUxQTE1QkEzMTk1QUYwN0VFMCIgeG1wTU06SW5zdGFuY2VJRD0ieG1wLmlpZDo4NUMwM0RCRjgyOUUxMUUxQTE1QkEzMTk1QUYwN0VFMCIgeG1wOkNyZWF0b3JUb29sPSJBZG9iZSBQaG90b3Nob3AgQ1M1LjEgTWFjaW50b3NoIj4gPHhtcE1NOkRlcml2ZWRGcm9tIHN0UmVmOmluc3RhbmNlSUQ9InhtcC5paWQ6MDE4MDExNzQwNzIwNjgxMTkxNDA5RkEzODM1Rjc1OTMiIHN0UmVmOmRvY3VtZW50SUQ9InhtcC5kaWQ6Rjc3RjExNzQwNzIwNjgxMTk3QTVFNkY1NTkyRkZEREUiLz4gPC9yZGY6RGVzY3JpcHRpb24+IDwvcmRmOlJERj4gPC94OnhtcG1ldGE+IDw/eHBhY2tldCBlbmQ9InIiPz6/nbgFAAAA9klEQVR42uzY0Q2DIBAG4MP0vY7QDWQENtARukFX6Aau0E7gCu0GjNBOUDegRwIJxSuK4tv9CdEofgqniSqMMSCEgLlgP4WLk2sNtjrYfUfj5vrBIYHYgy/YLCZnzvmMD6bA3izPMPH+oDnpYrQiQAl5GeMNFdGpzkT1EjQ3Moni0GtX8Zy0VFHC9cGsy5Wsvr25zfp83Cgn1W83zKsFO2pO1caCNT+oeyTlRlT5KfBXei50a8kQPUKZqBCVUDAV7BCPvgp5Y4i+C6F69+EzyiijjDLKKKOMMroe1dTnYGYe/pVUpH4iuA+D+C1bY/8x8Z8AvgIMAD21Jt9dWl/IAAAAAElFTkSuQmCC'); }Code:items: [{ xtype: 'toolbar', docked: 'bottom', items: [{ xtype: 'button', cls: 'my_class', text: '', ui:'plain', handler: function(){ Main.back(this); } ...
-
10 Jul 2012 1:16 PM #9
Gave up on the base64 . background-image worked, but its cropping my image in the toolbar. I'll create another post for that though. -thx
-
16 Aug 2012 7:00 AM #10
It's possible to use full color icons with a very simple custom mixin.
http://scydev.ch/index.php?option=co...mid=59&lang=deCode:/** * Includes a base64-encoded color icon for use within tab bars and buttons * * @include pictos-icon('attachment'); * * @param {string} $name The name of the icon to be included. This is to match the name of the icon file (located at resources/themes/images/default/pictos) without its extention (.png). */ @mixin pictos-icon($name) { .x-button-icon.#{$name}, .x-button .x-button-icon.x-icon-mask.#{$name} { background-image: theme_image($theme-name, "pictos/" + $name + ".png"); } }


Reply With Quote