CommonCtrl.MainMenu

Main menu, using buttons with top level menu item, and a tree view internally for child level menus. It has a modern appearance.

Title Main menu, using buttons with top level menu item, and a tree view internally for child level menus. It has a modern appearance.
Author(s) LiXizhi
Date 2007/12/30
File script/ide/MainMenu.lua

Description

Member Functions

MainMenu:new

 common control library
NPL.load("(gl)script/ide/common_control.lua");
NPL.load("(gl)script/ide/TreeView.lua");

 define a new control in the common control libary

 default member attributes
local MainMenu = {
   -- the top level control name
   name = "MainMenu1",
   -- normal window size
   left = 0,
   top = 0,
   width = 400,
   height = 22, 
   -- popup menu default height
   popmenu_height = 22,
   parent = nil,
   -- this is the maximum height, a scroll bar will be used if there are too many menu items. 
   MaxHeight = 500, 
   -- this is the minimum height of the content menu, unless there are so few items to display
   MinHeight = 40, 
   PopMenuWidth = 200,
   -- auto positioning method: it can be 
   -- "_lt": left top, where the mouse x, y will be the left top point of the menu container. This is the default mode.
   -- "_lb": left bottom, where the mouse x, y will be the left bottom point of the menu container. 
   AutoPositionMode = "_lt", 
   -- the background of menu container, default to null.
   container_bg = nil, 
   -- popmenu background
   popmenu_container_bg = "Texture/3DMapSystem/ContextMenu/BG2.png:8 8 8 8",
   -- The root tree node. containing all tree node data
   RootNode = nil, 
   -- Default height of Tree Node
   DefaultNodeHeight = 22,
   -- default icon size
   DefaultIconSize = 16,
   -- default indentation
   DefaultIndentation = 16,
   -- half space between the text of top level menu item
   DefaultMenuTextMargin = 5,
   -- color of the main menu item text
   TextColor = "24 57 124",
   -- color of the selected main menu item text
   SelectedTextColor = nil,
   -- default menu item font
   font = nil,
   -- the background image to be displayed when mouse over an top level menu item.
   -- please note that: MouseOverItemBG does not support 9 tile ":" texture name yet.
   -- MouseOverItemBG = "Texture/3DMapSystem/common/ThemeLightBlue/menuitem_over.png: 2 2 2 2",
   UnSelectedMenuItemBG = "",
   SelectedMenuItemBG = "Texture/3DMapSystem/common/ThemeLightBlue/menuitem_selected.png: 2 2 2 2",
   -- top level menu item spacing. 
   ItemSpacing = 0,
   -- Gets or sets a function by which the individual TreeNode control is drawn. The function should be of the format:
   -- function DrawNodeEventHandler(parent,treeNode) end, where parent is the parent container in side which contents should be drawn. And treeNode is the TreeNode object to be drawn
   -- if DrawNode is nil, the default MainMenu.DrawMenuItemHandler function will be used. 
   DrawNodeHandler = nil,
   -- Force no clipping or always using fast render. Unless you know that the unit scroll step is interger times of all TreeNode height. You can disable clipping at your own risk. 
   -- Software clipping is always used to clip all invisible TreeNodes. However, this option allows you to specify whether to use clipping for partially visible TreeNode. 
   NoClipping = nil,
   -- a function of type function (MenuItem, param1) or nil. this function will be called for each menuitem onclick except the group node.
   onclick = nil,
   -------------------------------------------
   -- private functions
   -------------------------------------------
   IsModified = true,
   -- current selected top level menu item index
   SelectedIndex = nil,
}
MainMenu = MainMenu;

constructor

syntax

function MainMenu:new (o)

parameters

o  

MainMenu:Destroy

Destroy the UI control

syntax

function MainMenu:Destroy ()

MainMenu:Show

it will automatically update items if the mainmenu is shown for the first time.

  • param bShow : boolean to show or hide. if nil, it will toggle current setting.

syntax

function MainMenu:Show(bShow)

parameters

bShow boolean to show or hide. if nil, it will toggle current setting.

MainMenu:Update

call this function when ever the top level menu item is changed. There is no need to call this function, if one only updated sub menu items.

syntax

function MainMenu:Update()

MainMenu:GetSelectedIndex

get the selected first level menu item index

syntax

function MainMenu:GetSelectedIndex()

MainMenu:SetSelectedIndex

set the selected first level menu item index.

  • param index : index of the item
  • param bNotRefreshUI : true to refresh the UI.

syntax

function MainMenu:SetSelectedIndex(index, bNotRefreshUI)

parameters

index index of the item
bNotRefreshUI  

MainMenu:UpdateTopLevelMenu

after the content of a tree node is changed, one may need to call this function at the root node

syntax

function MainMenu:UpdateTopLevelMenu()

MainMenu.OnClickTopLevelMenuItem

handler to select a top level menu item.

syntax

function MainMenu.OnClickTopLevelMenuItem(sCtrlName, index)

parameters

sCtrlName  
index  

MainMenu.OnMouseUpCont

this is a click outside the pop menu container, we will therefore close the container.

syntax

function MainMenu.OnMouseUpCont(sCtrlName)

parameters

sCtrlName  

MainMenu.OnMouseMoveCont

automatically switch to another menu item.

syntax

function MainMenu.OnMouseMoveCont(sCtrlName)

parameters

sCtrlName  

MainMenu.OnClose

close the given control

syntax

function MainMenu.OnClose(sCtrlName)

parameters

sCtrlName  

MainMenu.OnToggleNode

private function: called by default TreeNode UI

syntax

function MainMenu.OnToggleNode(sCtrlName, nodePath)

parameters

sCtrlName  
nodePath  

MainMenu.OnClickNode

private function: called by default TreeNode UI

syntax

function MainMenu.OnClickNode(sCtrlName, nodePath)

parameters

sCtrlName  
nodePath  

MainMenu.DrawMenuItemHandler

default node renderer: it display a clickable check box for expandable node, followed by node text

syntax

function MainMenu.DrawMenuItemHandler(_parent,treeNode)

parameters

parent  
treeNode  
Topic revision: r1 - 2008-02-29 - LiXizhi
 
This site is powered by the TWiki collaboration platform Powered by PerlCopyright © 2008-2022 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback