Add support for titles in menus.
Added an addTitle() convenience method. Unfortunately, styling the background of the title either impossible or so deep down the rabbit hole... deeper than this??? git-svn-id: svn+ssh://src.earth.threerings.net/nenya/trunk@806 ed5b42cb-e716-0410-a449-f6a68f950b19
This commit is contained in:
@@ -65,6 +65,9 @@ use namespace mx_internal;
|
||||
* IFlexDisplayObject to use as the icon. This will only be applied if the "icon" property
|
||||
* (which specifies a Class) is not used.
|
||||
*
|
||||
* Another 'type' now supported is "title", which gives the label for that item the style
|
||||
* '.menuTitle' and disables it. Your ".menuTitle" style should use the disabledColor.
|
||||
*
|
||||
* Example dataProvider array:
|
||||
* [ { label: "Go home", icon: homeIconClass,
|
||||
* command: Controller.GO_HOME, arg: homeId },
|
||||
@@ -105,6 +108,26 @@ public class CommandMenu extends Menu
|
||||
return menu;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a title to the TOP of the specified menu.
|
||||
*
|
||||
* @param icon may be a Class or IFlexDisplayObject.
|
||||
*/
|
||||
public static function addTitle (
|
||||
menuItems :Array, title :String, icon :* = null, separatorAfter :Boolean = true) :void
|
||||
{
|
||||
var o :Object = { label: title, type: "title" };
|
||||
if (icon is Class) {
|
||||
o["icon"] = icon;
|
||||
} else if (icon is IFlexDisplayObject) {
|
||||
o["iconObj"] = icon;
|
||||
}
|
||||
if (separatorAfter) {
|
||||
menuItems.unshift({ type: "separator" });
|
||||
}
|
||||
menuItems.unshift(o);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a separator to the specified menu, unless it would not make sense to do so, because
|
||||
* the menu is empty or already ends with a separator.
|
||||
|
||||
@@ -24,6 +24,8 @@ package com.threerings.flex.menuClasses {
|
||||
|
||||
import flash.display.DisplayObject;
|
||||
|
||||
import mx.controls.Menu;
|
||||
import mx.controls.menuClasses.IMenuDataDescriptor;
|
||||
import mx.controls.menuClasses.MenuItemRenderer;
|
||||
|
||||
public class CommandMenuItemRenderer extends MenuItemRenderer
|
||||
@@ -43,6 +45,17 @@ public class CommandMenuItemRenderer extends MenuItemRenderer
|
||||
addChild(DisplayObject(icon));
|
||||
}
|
||||
}
|
||||
|
||||
if (label.visible) {
|
||||
var dataDescriptor :IMenuDataDescriptor = Menu(listData.owner).dataDescriptor;
|
||||
var typeVal :String = dataDescriptor.getType(data);
|
||||
if (typeVal == "title") {
|
||||
dataDescriptor.setEnabled(data, false);
|
||||
label.enabled = false;
|
||||
label.styleName = "menuTitle";
|
||||
invalidateDisplayList();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user