From 05cbe9db645a9ad96c178279c87a75126ab3c7e0 Mon Sep 17 00:00:00 2001 From: Ray Greenwell Date: Thu, 16 Apr 2009 01:42:48 +0000 Subject: [PATCH] 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 --- src/as/com/threerings/flex/CommandMenu.as | 23 +++++++++++++++++++ .../menuClasses/CommandMenuItemRenderer.as | 13 +++++++++++ 2 files changed, 36 insertions(+) diff --git a/src/as/com/threerings/flex/CommandMenu.as b/src/as/com/threerings/flex/CommandMenu.as index c7c07766..571a2fb8 100644 --- a/src/as/com/threerings/flex/CommandMenu.as +++ b/src/as/com/threerings/flex/CommandMenu.as @@ -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. diff --git a/src/as/com/threerings/flex/menuClasses/CommandMenuItemRenderer.as b/src/as/com/threerings/flex/menuClasses/CommandMenuItemRenderer.as index 490e81ee..831ec544 100644 --- a/src/as/com/threerings/flex/menuClasses/CommandMenuItemRenderer.as +++ b/src/as/com/threerings/flex/menuClasses/CommandMenuItemRenderer.as @@ -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(); + } + } } } }