PDA

View Full Version : How to make the toolbar to multi lines?



safewolf
10 Oct 2009, 6:17 AM
hi,guys

i have a toolbar now

but the items is too many,and some can not be displayed ,and the toolbar shows a ">>"

i want to make the items in multi-lines that the user don't need to click ">>" to see the other menu items,anybody knows how to do it?

Animal
10 Oct 2009, 6:45 AM
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Toolbar with Menus</title>
<link rel="stylesheet" type="text/css" href="../../resources/css/ext-all.css" />
<script type="text/javascript" src="../../adapter/ext/ext-base.js"></script>
<script type="text/javascript" src="../../ext-all-debug.js"></script>
<script type="text/javascript" src="../form/states.js"></script>
<script type="text/javascript">
Ext.layout.FloatLayout = Ext.extend(Ext.layout.ContainerLayout, {
setContainer: function(ct) {
Ext.layout.FloatLayout.superclass.setContainer.apply(this, arguments);
ct.addClass('ux-float-layout-ct');
},

renderItem : function(c, position, target){
var cl = target.getBox(true).x, cw = target.getWidth(true), r = c.rendered, e, p, pe, w, b;
Ext.layout.FloatLayout.superclass.renderItem.apply(this, arguments);
e = c.getDomPositionEl();
if (!r) {
e.setStyle('float', 'left');
}
e.setStyle('clear', 'none');
w = e.getWidth() + e.getMargins('lr');
if (p = c.previousSibling()) {
pe = p.getDomPositionEl();
b = pe.getBox();
if ((pe.getBox().right + pe.getMargins('lr') - cl + w) > cw) {
e.setStyle('clear', 'left');
}
}
},

isValidParent: function() {
return false;
}
});
Ext.Container.LAYOUTS['float'] = Ext.layout.FloatLayout;

Ext.onReady(function(){
Ext.QuickTips.init();

// Menus can be prebuilt and passed by reference
var dateMenu = new Ext.menu.DateMenu({
handler: function(dp, date){
Ext.example.msg('Date Selected', 'You chose {0}.', date.format('M j, Y'));
}
});

var colorMenu = new Ext.menu.ColorMenu({
handler: function(cm, color){
Ext.example.msg('Color Selected', 'You chose {0}.', color);
}
});

var store = new Ext.data.ArrayStore({
fields: ['abbr', 'state'],
data : Ext.exampledata.states // from states.js
});

var combo = new Ext.form.ComboBox({
store: store,
displayField: 'state',
typeAhead: true,
mode: 'local',
triggerAction: 'all',
emptyText: 'Select a state...',
selectOnFocus: true,
width: 135,
getListParent: function() {
return this.el.up('.x-menu');
},
iconCls: 'no-icon'
});

var menu = new Ext.menu.Menu({
id: 'mainMenu',
style: {
overflow: 'visible' // For the Combo popup
},
items: [
combo, // A Field in a Menu
{
text: 'I like Ext',
checked: true, // when checked has a boolean value, it is assumed to be a CheckItem
checkHandler: onItemCheck
}, '-', {
text: 'Radio Options',
menu: { // <-- submenu by nested config object
items: [
// stick any markup in a menu
'<b class="menu-title">Choose a Theme</b>',
{
text: 'Aero Glass',
checked: true,
group: 'theme',
checkHandler: onItemCheck
}, {
text: 'Vista Black',
checked: false,
group: 'theme',
checkHandler: onItemCheck
}, {
text: 'Gray Theme',
checked: false,
group: 'theme',
checkHandler: onItemCheck
}, {
text: 'Default Theme',
checked: false,
group: 'theme',
checkHandler: onItemCheck
}
]
}
},{
text: 'Choose a Date',
iconCls: 'calendar',
menu: dateMenu // <-- submenu by reference
},{
text: 'Choose a Color',
menu: colorMenu // <-- submenu by reference
}
]
});

var tb = new Ext.Toolbar({
id: 'tb',
layout: 'float'
});
tb.render('toolbar');

tb.add({
text:'Button w/ Menu',
iconCls: 'bmenu', // <-- icon
menu: menu // assign menu by instance
}, {
text: 'Users',
iconCls: 'user',
menu: {
xtype: 'menu',
plain: true,
items: {
xtype: 'buttongroup',
title: 'User options',
autoWidth: true,
columns: 2,
defaults: {
xtype: 'button',
scale: 'large',
width: '100%',
iconAlign: 'left'
},
items: [{
text: 'User<br/>manager',
iconCls: 'edit'
},{
iconCls: 'add',
width: 'auto',
tooltip: 'Add user'
},{
colspan: 2,
text: 'Import',
scale: 'small'
},{
colspan: 2,
text: 'Who is online?',
scale: 'small'
}]
}
}
},
new Ext.Toolbar.SplitButton({
text: 'Split Button',
handler: onButtonClick,
tooltip: {text:'This is a an example QuickTip for a toolbar item', title:'Tip Title'},
iconCls: 'blist',
// Menus can be built/referenced by using nested menu config objects
menu : {
items: [{
text: '<b>Bold</b>', handler: onItemClick
}, {
text: '<i>Italic</i>', handler: onItemClick
}, {
text: '<u>Underline</u>', handler: onItemClick
}, '-', {
text: 'Pick a Color',
handler: onItemClick,
menu: {
items: [
new Ext.ColorPalette({
listeners: {
select: function(cp, color){
Ext.example.msg('Color Selected', 'You chose {0}.', color);
}
}
}), '-',
{
text: 'More Colors...',
handler: onItemClick
}
]
}
}, {
text: 'Extellent!',
handler: onItemClick
}]
}
}), '-', {
text: 'Toggle Me',
enableToggle: true,
toggleHandler: onItemToggle,
pressed: true
});

menu.addSeparator();
// Menus have a rich api for
// adding and removing elements dynamically
var item = menu.add({
text: 'Dynamically added Item'
});
// items support full Observable API
item.on('click', onItemClick);

// items can easily be looked up
menu.add({
text: 'Disabled Item',
id: 'disableMe' // <-- Items can also have an id for easy lookup
// disabled: true <-- allowed but for sake of example we use long way below
});
// access items by id or index
menu.items.get('disableMe').disable();

// They can also be referenced by id in or components
tb.add('-', {
icon: 'list-items.gif', // icons can also be specified inline
cls: 'x-btn-icon',
tooltip: '<b>Quick Tips</b><br/>Icon only button with tooltip'
}, '-');

var scrollMenu = new Ext.menu.Menu();
for (var i = 0; i < 50; ++i){
scrollMenu.add({
text: 'Item ' + (i + 1)
});
}

tb.add(new Ext.form.TextField());

// scrollable menu
tb.add({
icon: 'preview.png',
cls: 'x-btn-text-icon',
text: 'Scrolling Menu',
menu: scrollMenu
});

// add a combobox to the toolbar
var combo = new Ext.form.ComboBox({
store: store,
displayField: 'state',
typeAhead: true,
mode: 'local',
triggerAction: 'all',
emptyText:'Select a state...',
selectOnFocus:true,
width:135
});
tb.addField(combo);

tb.add({
text: 'Another'
}, {
text: 'Yet another'
}, {
text: 'Still another'
}, {
text: 'The last one!'
});

tb.doLayout();

// functions to display feedback
function onButtonClick(btn){
Ext.example.msg('Button Click','You clicked the "{0}" button.', btn.text);
}

function onItemClick(item){
Ext.example.msg('Menu Click', 'You clicked the "{0}" menu item.', item.text);
}

function onItemCheck(item, checked){
Ext.example.msg('Item Check', 'You {1} the "{0}" menu item.', item.text, checked ? 'checked' : 'unchecked');
}

function onItemToggle(item, pressed){
Ext.example.msg('Button Toggled', 'Button "{0}" was toggled to {1}.', item.text, pressed);
}

});
</script>
<link rel="stylesheet" type="text/css" href="menus.css" />
<!-- Common Styles for the examples -->
<link rel="stylesheet" type="text/css" href="../shared/examples.css" />
<style type="text/css">
.ux-float-layout-ct .xtb-sep {
font-size: inherit;
margin-top: 0.3em;
}
</style>
</head>
<body>
<h1>FloatLayout Toolbar with Menus</h1>
<p>The js is inline.</p>
<div id="container">
<div id="toolbar"></div>
</div>
<br /><br /><br /><br /><br />
</body>
</html>

Condor
10 Oct 2009, 8:39 AM
Or use a ButtonGroup instead of a Toolbar.

Animal
10 Oct 2009, 9:05 AM
You have to declare the number of columns with a ButtonGroup because it is a table layout. Not flexible enough.

wm003
13 Nov 2009, 1:16 AM
You can also create a second (third/fourth...) toolbar at rendering event:


listeners: {
"render": function() {
this.second_tbar = new Ext.Toolbar({
renderTo: this.tbar, // render to existing tbar element
items: [{
xtype:'button',
text: 'another button in another toolbar',
handler: function() {
Ext.Msg.alert('Attention','You clicked a button in a second toolbar!');
}
}]
});
}
}

wm003
13 Nov 2009, 9:27 AM
You can create a second (third/fourth...) toolbar at rendering event:


listeners: {
"render": function() {
this.second_tbar = new Ext.Toolbar({
renderTo: this.tbar, // render to existing tbar element
items: [{
xtype:'button',
text: 'another button in another toolbar',
handler: function() {
Ext.Msg.alert('Attention','You clicked a button in a second toolbar!');
}
}]
});
}
}

agalue
8 Dec 2009, 12:19 PM
Animal,

I like your solution, but when I want to remove a button from the toolbar, extjs throws an exception because Ext.layout.FloatLayout conflicts with multidom.js (a library used by ManagedIframe 2.x):

'this.dom is undefined'.

Any suggestion?

Animal
8 Dec 2009, 12:55 PM
Set a breakpoint there and debug it. Only you can do this.

Animal
8 Dec 2009, 1:38 PM
Try this:



Ext.layout.FloatLayout = Ext.extend(Ext.layout.ContainerLayout, {
setContainer: function(ct) {
var ce = ct.getLayoutTarget();
this.padding = this.parseMargins(this.padding||'0');
this.padding.top += ce.getPadding('t');
this.padding.left += ce.getPadding('l');
Ext.layout.FloatLayout.superclass.setContainer.apply(this, arguments);
ct.addClass('ux-float-layout-ct');
},

renderAll: function(ct) {
var ce = this.container.getLayoutTarget(), nh;
this.cw = ce.getWidth(true) + ce.getPadding('r');
this.top = this.padding.top;
this.left = this.padding.left;
this.contentHeight = 0;
this.rowHeight = 0;
Ext.layout.FloatLayout.superclass.renderAll.apply(this, arguments);
this.contentHeight += this.rowHeight;
if ((nh = this.contentHeight + this.padding.top + this.padding.bottom + ce.getPadding('tb')) != ct.getHeight()) {
ct.setHeight(nh);
ct.ownerCt && ct.ownerCt.doLayout();
}
},

renderItem : function(c, position, target){
var r = c.rendered,
e, p, pe, w, nextLeft;
delete c.removeMode;
Ext.layout.FloatLayout.superclass.renderItem.apply(this, arguments);
e = c.getPositionEl();
if (!r) {
e.setStyle('position', 'absolute');
}
w = e.getWidth();

// Wrap to the next line if necessary
if (this.left + w > this.cw) {
this.left = this.padding.left;
this.top += this.rowHeight;
this.contentHeight += this.rowHeight;
this.rowHeight = 0;
}
e.setStyle({
top: this.top + 'px',
left: this.left + 'px'
});
this.rowHeight = Math.max(this.rowHeight, e.getHeight() + e.getMargins('tb'));

// Move onwards
this.left = this.left + w;
},

isValidParent: function() {
return false;
}
});
Ext.Container.LAYOUTS['float'] = Ext.layout.FloatLayout;

agalue
8 Dec 2009, 2:10 PM
Thanks you very much for your help Animal,

The new code works perfect!

vizcano
16 Dec 2009, 6:17 AM
Hi

I've tried to apply float layout to HtmlEditor overriding createToolbar method but the result is that the toolbar loses its height and i only see the "font type" combobox, the rest of my buttons have desapeared...

Could you help me?

Animal
16 Dec 2009, 7:15 AM
this code should be setting its height:



renderAll: function(ct) {
var ce = this.container.getLayoutTarget(), nh;
this.cw = ce.getWidth(true) + ce.getPadding('r');
this.top = this.padding.top;
this.left = this.padding.left;
this.contentHeight = 0;
this.rowHeight = 0;
Ext.layout.FloatLayout.superclass.renderAll.apply(this, arguments);
this.contentHeight += this.rowHeight;
if ((nh = this.contentHeight + this.padding.top + this.padding.bottom + ce.getPadding('tb')) != ct.getHeight()) {
ct.setHeight(nh);
ct.ownerCt && ct.ownerCt.doLayout();
}
},


Break there and see what it's doing

vizcano
16 Dec 2009, 7:42 AM
I get this values

contentHeight =0,
paddingtop=2,
paddingbottom=0,
getpadding=4

so nh=6 is it the supossed output?

Animal
16 Dec 2009, 7:58 AM
You'll have to see how it's building the content height.

It tracks the max height of elements in each row:



this.rowHeight = Math.max(this.rowHeight, e.getHeight() + e.getMargins('tb'));


Of course if you are in a display:none element e.getHeight() will probably return 0

vizcano
17 Dec 2009, 9:10 AM
I've tried to solve it doing "doLayout" when my last HtmlEditor plugin is loaded, and also from firebug terminal when the editor is shown and it gets the new height but the toolbar is shown like this: http://www.pharmabox.net/descargas/toolbat_htmleditor.JPG

Could u help me, please? Thanks a lot

lakshmi
19 Jan 2010, 5:15 AM
It was really helpful for me too.