1class DropdownPrefab
extends ScriptedWidgetEventHandler
5 protected ScrollWidget m_Scroller;
6 protected Widget m_ContentContainer;
9 protected Widget m_Button;
10 protected Widget m_Holder;
11 protected TextWidget m_Text;
12 protected ImageWidget m_ImageExpand;
13 protected ImageWidget m_ImageCollapse;
15 protected bool m_IsExpanded;
18 void DropdownPrefab( Widget root,
string text =
"" )
21 m_Root =
GetGame().GetWorkspace().CreateWidgets(
"gui/layouts/new_ui/dropdown_prefab/dropdown_prefab.layout", root );
23 m_Scroller = ScrollWidget.Cast(
m_Root.FindAnyWidget(
"dropdown_container" ) );
24 m_ContentContainer =
m_Root.FindAnyWidget(
"dropdown_content" );
25 m_Text = TextWidget.Cast(
m_Root.FindAnyWidget(
"dropdown_text" ) );
26 m_Holder =
m_Root.FindAnyWidget(
"holder" );
29 m_Button =
m_Root.FindAnyWidget(
"dropdown_selector_button" );
30 m_ImageExpand = ImageWidget.Cast(
m_Root.FindAnyWidget(
"expand_image" ) );
31 m_ImageCollapse = ImageWidget.Cast(
m_Root.FindAnyWidget(
"collapse_image" ) );
40 Widget child = m_ContentContainer.GetChildren();
43 if( m_Content.Find( child ) > -1 )
45 m_Content.Insert( child );
49 m_ContentContainer.Update();
53 m_ContentContainer.GetScreenSize(
x,
y );
54 if(
y > m_Scroller.GetContentHeight() )
56 m_Scroller.SetAlpha( 1 );
60 m_Scroller.SetAlpha( 0 );
64 int AddElement(
string text, Widget content = null )
66 ButtonWidget element = ButtonWidget.Cast(
GetGame().GetWorkspace().CreateWidgets(
"gui/layouts/new_ui/dropdown_prefab/dropdown_element.layout", m_ContentContainer ) );
68 textWidget.SetText( text );
72 element.AddChild( content,
false );
74 m_ContentContainer.Update();
79 m_Content.Insert( element );
80 return m_Content.Count() - 1;
83 void RemoveElement(
int index )
85 if( 0 < index && index < m_Content.Count() )
87 delete m_Content.Get( index );
88 m_ContentContainer.Update();
98 m_IsExpanded = !m_IsExpanded;
99 m_Scroller.Show( m_IsExpanded );
100 m_ImageExpand.Show( !m_IsExpanded );
101 m_ImageCollapse.Show( m_IsExpanded );
108 void SetText(
string text )
110 m_Text.SetText( text );
113 override bool OnClick( Widget w,
int x,
int y,
int button )
115 int index = m_Content.Find( w );
118 m_OnSelectItem.Invoke( index );
119 m_IsExpanded =
false;
120 m_Scroller.Show( m_IsExpanded );
121 m_ImageExpand.Show( !m_IsExpanded );
122 m_ImageCollapse.Show( m_IsExpanded );
130 if ( (w == m_Button || w == m_Text || w == m_Holder) && button ==
MouseState.LEFT )
132 m_IsExpanded = !m_IsExpanded;
133 m_Scroller.Show( m_IsExpanded );
134 m_ImageExpand.Show( !m_IsExpanded );
135 m_ImageCollapse.Show( m_IsExpanded );
139 m_ContentContainer.Update();
ScriptInvoker Class provide list of callbacks usage:
Result for an object found in CGame.IsBoxCollidingGeometryProxy.
override bool OnClick(Widget w, int x, int y, int button)
buttons clicks
proto native CGame GetGame()
bool OnMouseButtonDown(Widget w, int x, int y, int button)