-
16 Nov 2010 2:31 PM #1
Image buttons in Sencha Touch?
Image buttons in Sencha Touch?
I'm brand new to Ext and Sencha Touch, so forgive my n00biness
I've got an existing html5 app that I'm trying to rewrite using Sencha Touch. My app contains custom buttons that I originally created by styling html anchor tags (i.e. I set the background-image for the <a /> elements) and then handling the click event with jquery event handlers and doing whatever I want with the events.
I'm trying to figure out what the analogous Sencha Touch recipe for this is... should I use an Ext.Button and set the icon for it? It seems like an icon button is more like a button with an icon inside of it... Should I just type out the old HTML in my index.html and then retrieve that element from the page in the js?
I'd rather add my buttons to the page programmatically, but I can't quite figure out what Element/Widget to use.
Thanks in advance for any advice/tips.
-
18 Nov 2010 2:05 AM #2
There are several approaches that work. However, the cleanest way would probably be to use an Ext.Button, assign a class to it ("cls: 'myBtnClass',", say), and then style it via your app-specific CSS file. The icon: paramater is (as you've worked out) a red herring.
If your buttons all share certain features it can be helpful to first subclass the native classes (.x-button, .x-button-action and so on, in the various combinations that apply) in your own CSS, and then have simpler classes for each specific button.
And, of course, you can just modify sencha.css if you prefer, although you'll want to prettify/un-minify it first.
-
18 Nov 2010 5:01 AM #3
But why is this not working?
Application JavaScript:
CSS:Code:Ext.setup({ onReady: function() { var rootPanel = new Ext.Panel({ fullscreen: true, dockedItems:[{ xtype: 'toolbar', dock: 'top', items: [{ xtype: 'button', cls: 'btnAction' }] }] }); } });
Code:.btnAction { background: url(../action.png); width: 40px; height: 40px; }
-
18 Nov 2010 5:37 AM #4
The answer can be found by walking the DOM using Web Inspector - your CSS isn't quite where you'd expect (or, arguably, it should) be in the cascade and so is being overridden.
But, changetoCode:.btnAction {...}and you should be cooking with gas...Code:.x-button.btnAction.x-button-normal {...}
Alternatively - and, perhaps, more elegantly - use the !important declaration to override the override:Safari's (or Chrome's) Web Inspector is utterly essential for debugging - and designing - CSS for Sencha Touch, IME.Code:.btnAction { background: url(../action.png) !important; width: 40px; height: 40px; }
Best,
Mike
-
18 Nov 2010 5:59 AM #5
Thanks for your reply!
A button is placed in the toolbar at the top now...but without the 'good' dimensions, even without the 'width' and 'height' properties.
Picture
It seems that the icon itself is bigger than it's 'viewport' and lies 'behind' the outline of the button.
-
18 Nov 2010 6:53 AM #6
Er... you're using a 60x60 pixel background on a 40x40 pixel button. It will fall off the bottom and sides unless you use size it:
Code:.btnAction { background: url(../action.png) !important; background-size: 40px 40px; width: 40px; height: 40px; }
However, you're probably better off using WebKit's CSS3 selectors and doing something like this:which gives you a 30x30 pixel image on a 40x40 pixel button, together with a handsome fading effect (thanks to the use of a -webkit-gradient with alpha transparency as the background-image, masked by the -webkit-mask).Code:.btnAction { padding: 5px !important; width: 40px; height: 40px; -webkit-mask-image: url('../action.png') !important; -webkit-mask-size: 30px 30px; -webkit-mask-repeat: no-repeat; -webkit-mask-origin: content; background-image: -webkit-gradient(linear, 0% 0%, 0% 100%, from(rgba(255, 255, 255, 0.7)), to(rgba(255, 255, 255, 0.9))) !important; background-color: #000000 !important; }
The CSS3 selectors provide for a lot more flexibility and are well worth learning (and using) in the Sencha Touch context. It pays to be aware that Android's implementation of them is slightly less complete than iOS/Mobile Safari's, however.
-
18 Nov 2010 8:08 AM #7
I will look into CSS3 selectors I think...thank you for your reply!
-
6 Feb 2011 6:54 PM #8
I've just been trying to do pretty much the same thing, but with the twist that i needed to programmatically set the image URL because it is to be a DVD cover (so that rules out CSS). Here's how i did it:
1: In my index.html i included jquery:
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.0/jquery.min.js"></script>
2: In my JS, i made a button like so:
{ width:235, height:160, xtype: 'button', id:"movie_id_xxx", cls:'myimagebutton', handler: myHandler },
Then later on, immediately after adding the button to the page, i set the image url like so:
$('#movie_id_xxx').css('background','url(img/shows/something.jpg)');
3: In my CSS:
.myimagebutton {
border:0;
border-radius:0;
-webkit-box-shadow:0 0 10px #000;
}
.myimagebutton.x-button-pressed {
-webkit-box-shadow: 0 0 10px #ff0;
}
Works so far, and is pretty simple!
-
2 Aug 2011 12:05 PM #9
Use CSS encoding..
Use CSS encoding..
For example...
In a button definition
Reference the KitchenSink demo for over all usage context.
cls:'demobtn',
In CSS...
.demobtn
{
margin: 3% 5%;
background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAYAAADgdz34AAAAUklEQVRIDWNgoDFgBJnPz8d3HkgZ0MIumAX/aWE4yEwmWhkMM3fUAlhI4KRHgwhn0MAkRoMIFhI46dEgwhk0MInRIIKFBE56NIhwBg1MYugHEQCQzwKBoNiZjAAAAABJRU5ErkJggg==);
}
-
20 Jan 2012 2:21 AM #10
login page alignment for sencha touch1.1.1 application
login page alignment for sencha touch1.1.1 application
Hi All,
i have created Login page in sencha touch app. For this i have used xtype: "vbox"
(1)i want the CUID, Pssword be left side and edittext boxes @ right side, and also buttons are in column i want them to be in row.
(2)i want to reduce the size od edittext box.
(3)want to remove background box for CUID and Password
Here is my code.
Ext.setup({
onReady: function(){
new Ext.Panel({
fullscreen: true,
items: [{
xtype: "form",
layout: "vbox",
autoscroll: "stretch",
items: [
{
xtype: "toolbar",
title: "Login",
cls: "txtlogin"
},
{
xtype: "textfield",
name: "name",
label: "CUID",
cls: "txtField",
placeholder: "Enter your CUID here"
},
{
xtype: "passwordfield",
name: "password",
label: "Password",
placeholder: "Enter your password"
},
{
xtype: "button",
cls: "btnLogin",
ui: "normal",
text: "Login"
/*align: "right"*/
},
{
xtype: "button",
cls: "btnReset",
ui: "normal",
text: "Reset"
}
]
}]
});
}
});
Any suggestions, advise would be appreciable
please help me...
Similar Threads
-
Is Sencha working on native wrappers to package Sencha Touch apps for app stores?
By olin in forum Sencha Touch 1.x: DiscussionReplies: 10Last Post: 20 Jan 2012, 10:10 AM -
Sencha Touch on iPhone v1 / iPod touch v1 ?
By palnap in forum Sencha Touch 1.x: DiscussionReplies: 4Last Post: 28 Oct 2010, 5:30 PM -
[CLOSED-267] Sencha Touch API docs lacking some "Sencha Platform" content?
By charris in forum Sencha Touch 1.x: BugsReplies: 2Last Post: 9 Sep 2010, 10:24 AM


Reply With Quote