---++!! !CommonCtrl.dropdownlistbox %TOC{title="Contents:"}% %STARTINCLUDE% ---++ a dropdown listbox control using a textbox, a button and a listbox | *Title* | a dropdown listbox control using a textbox, a button and a listbox | | *Author(s)* | LiXizhi | | *Date* | 2007/4/1 | | *File* | script/ide/dropdownlistbox.lua | ---+++ Description %T% __Sample Code__ <verbatim> NPL.load("(gl)script/ide/dropdownlistbox.lua"); local ctl = CommonCtrl.dropdownlistbox:new{ name = "dropdownlistbox1", alignment = "_lt", left=0, top=0, width = 300, height = 26, parent = nil, items = {"line1", "line2", "line3", "line4", values=nil,}, }; ctl:Show(); </verbatim> ---+++ Member Functions ---++++ !dropdownlistbox:new <verbatim> common control library NPL.load("(gl)script/ide/common_control.lua"); define a new control in the common control libary default member attributes local dropdownlistbox = { -- the top level control name name = "dropdownlistbox1", -- normal window size alignment = "_lt", left = 0, top = 0, width = 300, height = 26, buttonwidth = 20, -- the drop down button width dropdownheight = 150, -- the drop down list box height. parent = nil, -- appearance container_bg = nil, -- the background of container that contains the editbox and the dropdown button. editbox_bg = nil, -- edit box background texture dropdownbutton_bg = "Texture/DropDownBox.png:4 5 4 5",-- drop down button background texture listbox_bg = nil, -- list box background texture -- data -- an array of text, one needs to call RefreshListBox() manually, if one changes the items after the list box is displayed for the first time. -- items.values can be nil or a table mapping items name to item value. if items.values is nil, the GetValue() method will default to GetText(). items = {values=nil,}, text = "", -- current text -- onchange event, it can be nil, a string to be executed or a function of type void ()(sCtrlName, item) -- it will be called when the user select an item or pressed Enter in the editbox. One may call GetText() to retrieve text in the handler onselect= nil, -- it is a function to format the a selected item text to be displayed in the editbox. It takes a string and returns a string, such as fucntion(text) return text.." Seconds" end -- if this is nil, the original item text is displayed at the editbox. FuncTextFormat=nil, -- whether we allow user to enter text into the editbox AllowUserEdit = true, -- if true the drop down list box button is disabled. IsReadonly = nil, listbox_cont_id = -1, listbox_id = -1, button_id = -1, editbox_id = -1, }</verbatim> CommonCtrl.dropdownlistbox = dropdownlistbox; constructor __syntax__ <verbatim>function dropdownlistbox:new (o)</verbatim> __parameters__ | *o* | | ---++++ !dropdownlistbox:Destroy Destroy the UI control __syntax__ <verbatim>function dropdownlistbox:Destroy ()</verbatim> ---++++ !dropdownlistbox:Show * _param_ __bShow__ : boolean to show or hide. if nil, it will toggle current setting. __syntax__ <verbatim>function dropdownlistbox:Show(bShow)</verbatim> __parameters__ | *bShow* | boolean to show or hide. if nil, it will toggle current setting. | ---++++ !dropdownlistbox:GetText returns the text of the selected item, return "" if nothing is selected. __syntax__ <verbatim>function dropdownlistbox:GetText()</verbatim> ---++++ !dropdownlistbox:SetText set text __syntax__ <verbatim>function dropdownlistbox:SetText(text)</verbatim> __parameters__ | *text* | | ---++++ !dropdownlistbox:GetValue get the value if items.values is a table. __syntax__ <verbatim>function dropdownlistbox:GetValue()</verbatim> ---++++ !dropdownlistbox:SetValue set the value if items.values is a table. __syntax__ <verbatim>function dropdownlistbox:SetValue(value)</verbatim> __parameters__ | *value* | | ---++++ !dropdownlistbox:GetEnabled return whether the listbox is enabled __syntax__ <verbatim>function dropdownlistbox:GetEnabled()</verbatim> ---++++ !dropdownlistbox:SetEnabled set whether the listbox is enabled __syntax__ <verbatim>function dropdownlistbox:SetEnabled(bEnable)</verbatim> __parameters__ | *bEnable* | | ---++++ !dropdownlistbox:RefreshListBox OBSOLETED: this function is not needed any more. It does nothing. __syntax__ <verbatim>function dropdownlistbox:RefreshListBox()</verbatim> ---++++ !dropdownlistbox:RefillListBox refill the listbox content using the items. __syntax__ <verbatim>function dropdownlistbox:RefillListBox()</verbatim> ---++++ !dropdownlistbox.OnClickDropDownButton called when the drop down button is clicked. __syntax__ <verbatim>function dropdownlistbox.OnClickDropDownButton(sCtrlName)</verbatim> __parameters__ | *sCtrlName* | | ---++++ !dropdownlistbox.OnMouseUpListBoxCont called when the user select a list box item __syntax__ <verbatim>function dropdownlistbox.OnMouseUpListBoxCont(sCtrlName)</verbatim> __parameters__ | *sCtrlName* | | ---++++ !dropdownlistbox.OnTextChange called when the text has changed __syntax__ <verbatim>function dropdownlistbox.OnTextChange(sCtrlName)</verbatim> __parameters__ | *sCtrlName* | | ---++++ !dropdownlistbox.OnSelectListBox called when the user select a list box item __syntax__ <verbatim>function dropdownlistbox.OnSelectListBox(sCtrlName)</verbatim> __parameters__ | *sCtrlName* | | ---++++ !dropdownlistbox:InsertItem insert item to back: if already exist, it does nothing. * _param_ __item__ : string item * _param_ __bNoUpdate__ : if true, the list box is not refreshed even a new item is added. * _return_ __the__ : index of the inserted item. __syntax__ <verbatim>function dropdownlistbox:InsertItem(item, bNoUpdate)</verbatim> __parameters__ | *item* | string item | | *bNoUpdate* | | | *return* | index of the inserted item. | %STOPINCLUDE%
E
dit
|
A
ttach
|
P
rint version
|
H
istory
: r1
|
B
acklinks
|
V
iew topic
|
Ra
w
edit
|
M
ore topic actions
Topic revision: r1 - 2008-02-29
-
LiXizhi
Home
Site map
CCWeb web
HaqiTeen web
Main web
ParaEngine web
TWiki web
Main Web
Users
Groups
Index
Search
Changes
Notifications
RSS Feed
Statistics
导航页WebTopMenu
Preferences
开发指南
Getting Started
ParacraftSDK
NPL
MCML
NPL Reference Manual
美术Mod
Account
Log In
English
简体中文
簡體中文
E
dit
A
ttach
Copyright © 2008-2024 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki?
Send feedback