Difference between revisions of "Lua:Class:PageControl"
Jump to navigation
Jump to search
AntumDeluge (talk | contribs) m (→Methods) |
m (→Returns) |
||
| (2 intermediate revisions by 2 users not shown) | |||
| Line 1: | Line 1: | ||
[[Category:Lua]] | [[Category:Lua]] | ||
| − | + | {{Class|'''class''' Pagecontrol ''':''' WinControl}} | |
| − | + | The Pagecontrol class represents a control that can hold multiple pages. | |
| − | + | Each page is represented by a [[Lua:Class:TabSheet|TabSheet]]. A Pagecontrol can be created with [[Lua:createPageControl|createPageControl]]. | |
| − | + | ===Inheritance=== | |
| + | {|width="85%" cellpadding="10%" cellspacing="0" border="0" | ||
| + | !align="left"|Class | ||
| + | !align="left"|Inherits From | ||
| + | !style="width: 80%;background-color:white;" align="left"|Description | ||
| + | |- | ||
| + | |Pagecontrol | ||
| + | |WinControl | ||
| + | |Represents a multi-page tab control. | ||
| + | |- | ||
| + | |WinControl | ||
| + | |Control | ||
| + | |Base class for controls that can receive focus and contain child controls. | ||
| + | |- | ||
| + | |Control | ||
| + | |Component | ||
| + | |Base class for visible GUI controls. | ||
| + | |- | ||
| + | |Component | ||
| + | |Object | ||
| + | |Base class for components. | ||
| + | |- | ||
| + | |Object | ||
| + | |None | ||
| + | |Base class for Lua-exposed objects. | ||
| + | |} | ||
== Creation == | == Creation == | ||
| − | + | {{CodeBox|'''function''' createPageControl(''owner'') ''':''' Pagecontrol}} | |
| − | : Returns | + | |
| + | Creates a Pagecontrol object that belongs to the given owner. | ||
| + | |||
| + | ===Function Parameters=== | ||
| + | {|width="85%" cellpadding="10%" cellspacing="0" border="0" | ||
| + | !align="left"|Parameter | ||
| + | !align="left"|Type | ||
| + | !style="width: 80%;background-color:white;" align="left"|Description | ||
| + | |- | ||
| + | |owner | ||
| + | |[[Lua:Class:WinControl|WinControl]] | ||
| + | |The owner of the page control. | ||
| + | |} | ||
| + | |||
| + | ===Returns=== | ||
| + | [[Lua:Class:PageControl|PageControl]] — The created page control object. | ||
== Properties == | == Properties == | ||
| − | ; ShowTabs | + | {|width="85%" cellpadding="10%" cellspacing="0" border="0" |
| − | + | !align="left"|Property | |
| − | : | + | !align="left"|Type |
| + | !style="width: 80%;background-color:white;" align="left"|Description | ||
| + | |- | ||
| + | |ShowTabs | ||
| + | |Boolean | ||
| + | |Determines whether the tabs are shown. | ||
| + | |- | ||
| + | |TabIndex | ||
| + | |Integer | ||
| + | |Gets or sets the currently selected tab index. | ||
| + | |- | ||
| + | |ActivePage | ||
| + | |[[Lua:Class:TabSheet|TabSheet]] | ||
| + | |Returns the currently active tab sheet. | ||
| + | |- | ||
| + | |PageCount | ||
| + | |Integer | ||
| + | |Returns the number of pages. | ||
| + | |- | ||
| + | |Page[index] | ||
| + | |[[Lua:Class:TabSheet|TabSheet]] | ||
| + | |Returns the page at the specified index. | ||
| + | |} | ||
| − | + | == Methods == | |
| − | |||
| − | |||
| − | |||
| − | ; | + | {|width="85%" cellpadding="10%" cellspacing="0" border="0" |
| − | : | + | !align="left"|Method |
| − | + | !align="left"|Return Type | |
| + | !style="width: 80%;background-color:white;" align="left"|Description | ||
| + | |- | ||
| + | |addTab() | ||
| + | |[[Lua:Class:TabSheet|TabSheet]] | ||
| + | |Creates a new TabSheet and adds it to the page control. | ||
| + | |- | ||
| + | |tabRect(index) | ||
| + | |Rect | ||
| + | |Returns a Rect table describing the position of the specified tab. | ||
| + | |} | ||
| − | + | == Rect Table == | |
| − | |||
| − | + | <code>tabRect(index)</code> returns a Rect table. | |
| − | |||
| − | ; | + | {|width="85%" cellpadding="10%" cellspacing="0" border="0" |
| − | + | !align="left"|Field | |
| + | !align="left"|Type | ||
| + | !style="width: 80%;background-color:white;" align="left"|Description | ||
| + | |- | ||
| + | |Left | ||
| + | |Integer | ||
| + | |The left coordinate of the tab rectangle. | ||
| + | |- | ||
| + | |Top | ||
| + | |Integer | ||
| + | |The top coordinate of the tab rectangle. | ||
| + | |- | ||
| + | |Right | ||
| + | |Integer | ||
| + | |The right coordinate of the tab rectangle. | ||
| + | |- | ||
| + | |Bottom | ||
| + | |Integer | ||
| + | |The bottom coordinate of the tab rectangle. | ||
| + | |} | ||
| − | + | == Examples == | |
| − | |||
| − | + | ===Create a Pagecontrol=== | |
| − | + | <syntaxhighlight lang="lua" line highlight="2"> | |
| + | local form = createForm(false) | ||
| + | local pageControl = createPageControl(form) | ||
| − | == | + | pageControl.Left = 10 |
| + | pageControl.Top = 10 | ||
| + | pageControl.Width = 300 | ||
| + | pageControl.Height = 200 | ||
| + | |||
| + | form.show() | ||
| + | </syntaxhighlight> | ||
| + | |||
| + | ===Add pages=== | ||
| + | <syntaxhighlight lang="lua" line highlight="2,4,7"> | ||
| + | local form = createForm(false) | ||
| + | local pageControl = createPageControl(form) | ||
| + | |||
| + | local firstPage = pageControl.addTab() | ||
| + | firstPage.Caption = "General" | ||
| + | |||
| + | local secondPage = pageControl.addTab() | ||
| + | secondPage.Caption = "Advanced" | ||
| + | |||
| + | form.show() | ||
| + | </syntaxhighlight> | ||
| + | |||
| + | ===Select a tab by index=== | ||
| + | <syntaxhighlight lang="lua" line highlight="2,4,5,7"> | ||
| + | local form = createForm(false) | ||
| + | local pageControl = createPageControl(form) | ||
| + | |||
| + | pageControl.addTab().Caption = "First" | ||
| + | pageControl.addTab().Caption = "Second" | ||
| + | |||
| + | pageControl.TabIndex = 1 | ||
| + | |||
| + | form.show() | ||
| + | </syntaxhighlight> | ||
| + | |||
| + | ===Read the active page=== | ||
| + | <syntaxhighlight lang="lua" line highlight="2,4,5,8"> | ||
| + | local form = createForm(false) | ||
| + | local pageControl = createPageControl(form) | ||
| + | |||
| + | pageControl.addTab().Caption = "First" | ||
| + | pageControl.addTab().Caption = "Second" | ||
| + | |||
| + | pageControl.TabIndex = 0 | ||
| + | local activePage = pageControl.ActivePage | ||
| + | |||
| + | print(activePage.Caption) | ||
| + | |||
| + | form.show() | ||
| + | </syntaxhighlight> | ||
| + | |||
| + | ===Hide the tabs=== | ||
| + | <syntaxhighlight lang="lua" line highlight="2,4"> | ||
| + | local form = createForm(false) | ||
| + | local pageControl = createPageControl(form) | ||
| + | |||
| + | pageControl.ShowTabs = false | ||
| + | |||
| + | pageControl.addTab().Caption = "Hidden Tab" | ||
| + | |||
| + | form.show() | ||
| + | </syntaxhighlight> | ||
| + | |||
| + | ===Enumerate pages=== | ||
| + | <syntaxhighlight lang="lua" line highlight="2,4,5,7,8"> | ||
| + | local form = createForm(false) | ||
| + | local pageControl = createPageControl(form) | ||
| + | |||
| + | pageControl.addTab().Caption = "Page A" | ||
| + | pageControl.addTab().Caption = "Page B" | ||
| + | |||
| + | for i = 0, pageControl.PageCount - 1 do | ||
| + | local page = pageControl.Page[i] | ||
| + | |||
| + | print(i .. ": " .. tostring(page.Caption)) | ||
| + | end | ||
| + | |||
| + | form.show() | ||
| + | </syntaxhighlight> | ||
| + | |||
| + | ===Add controls to a TabSheet=== | ||
| + | <syntaxhighlight lang="lua" line highlight="2,4,8"> | ||
| + | local form = createForm(false) | ||
| + | local pageControl = createPageControl(form) | ||
| + | |||
| + | local page = pageControl.addTab() | ||
| + | page.Caption = "Settings" | ||
| − | + | local label = createLabel(page) | |
| − | + | label.Caption = "This label belongs to the tab sheet" | |
| + | label.Left = 10 | ||
| + | label.Top = 10 | ||
| − | + | form.show() | |
| − | + | </syntaxhighlight> | |
| − | + | ===Get a tab rectangle=== | |
| − | + | <syntaxhighlight lang="lua" line highlight="2,4,7"> | |
| + | local form = createForm(false) | ||
| + | local pageControl = createPageControl(form) | ||
| − | = | + | pageControl.addTab().Caption = "General" |
| − | + | local rect = pageControl.tabRect(0) | |
| − | |||
| − | + | print("Left: " .. tostring(rect.Left)) | |
| − | : | + | print("Top: " .. tostring(rect.Top)) |
| + | print("Right: " .. tostring(rect.Right)) | ||
| + | print("Bottom: " .. tostring(rect.Bottom)) | ||
| − | + | form.show() | |
| + | </syntaxhighlight> | ||
| − | < | + | ===Switch to the next tab=== |
| − | + | <syntaxhighlight lang="lua" line highlight="2,4,5,7,8,9"> | |
| − | local form = createForm() | + | local form = createForm(false) |
| + | local pageControl = createPageControl(form) | ||
| − | + | pageControl.addTab().Caption = "First" | |
| − | + | pageControl.addTab().Caption = "Second" | |
| − | |||
| − | + | if pageControl.PageCount > 0 then | |
| − | + | pageControl.TabIndex = (pageControl.TabIndex + 1) % pageControl.PageCount | |
| − | + | end | |
| − | |||
| − | |||
| − | + | form.show() | |
| − | + | </syntaxhighlight> | |
| − | </ | ||
{{LuaSeeAlso}} | {{LuaSeeAlso}} | ||
| − | + | {{Forms}} | |
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
Latest revision as of 20:42, 26 June 2026
The Pagecontrol class represents a control that can hold multiple pages.
Each page is represented by a TabSheet. A Pagecontrol can be created with createPageControl.
Inheritance[edit]
| Class | Inherits From | Description |
|---|---|---|
| Pagecontrol | WinControl | Represents a multi-page tab control. |
| WinControl | Control | Base class for controls that can receive focus and contain child controls. |
| Control | Component | Base class for visible GUI controls. |
| Component | Object | Base class for components. |
| Object | None | Base class for Lua-exposed objects. |
Creation[edit]
Creates a Pagecontrol object that belongs to the given owner.
Function Parameters[edit]
| Parameter | Type | Description |
|---|---|---|
| owner | WinControl | The owner of the page control. |
Returns[edit]
PageControl — The created page control object.
Properties[edit]
| Property | Type | Description |
|---|---|---|
| ShowTabs | Boolean | Determines whether the tabs are shown. |
| TabIndex | Integer | Gets or sets the currently selected tab index. |
| ActivePage | TabSheet | Returns the currently active tab sheet. |
| PageCount | Integer | Returns the number of pages. |
| Page[index] | TabSheet | Returns the page at the specified index. |
Methods[edit]
| Method | Return Type | Description |
|---|---|---|
| addTab() | TabSheet | Creates a new TabSheet and adds it to the page control. |
| tabRect(index) | Rect | Returns a Rect table describing the position of the specified tab. |
Rect Table[edit]
tabRect(index) returns a Rect table.
| Field | Type | Description |
|---|---|---|
| Left | Integer | The left coordinate of the tab rectangle. |
| Top | Integer | The top coordinate of the tab rectangle. |
| Right | Integer | The right coordinate of the tab rectangle. |
| Bottom | Integer | The bottom coordinate of the tab rectangle. |
Examples[edit]
Create a Pagecontrol[edit]
1 local form = createForm(false)
2 local pageControl = createPageControl(form)
3
4 pageControl.Left = 10
5 pageControl.Top = 10
6 pageControl.Width = 300
7 pageControl.Height = 200
8
9 form.show()
Add pages[edit]
1 local form = createForm(false)
2 local pageControl = createPageControl(form)
3
4 local firstPage = pageControl.addTab()
5 firstPage.Caption = "General"
6
7 local secondPage = pageControl.addTab()
8 secondPage.Caption = "Advanced"
9
10 form.show()
Select a tab by index[edit]
1 local form = createForm(false)
2 local pageControl = createPageControl(form)
3
4 pageControl.addTab().Caption = "First"
5 pageControl.addTab().Caption = "Second"
6
7 pageControl.TabIndex = 1
8
9 form.show()
Read the active page[edit]
1 local form = createForm(false)
2 local pageControl = createPageControl(form)
3
4 pageControl.addTab().Caption = "First"
5 pageControl.addTab().Caption = "Second"
6
7 pageControl.TabIndex = 0
8 local activePage = pageControl.ActivePage
9
10 print(activePage.Caption)
11
12 form.show()
Hide the tabs[edit]
1 local form = createForm(false)
2 local pageControl = createPageControl(form)
3
4 pageControl.ShowTabs = false
5
6 pageControl.addTab().Caption = "Hidden Tab"
7
8 form.show()
Enumerate pages[edit]
1 local form = createForm(false)
2 local pageControl = createPageControl(form)
3
4 pageControl.addTab().Caption = "Page A"
5 pageControl.addTab().Caption = "Page B"
6
7 for i = 0, pageControl.PageCount - 1 do
8 local page = pageControl.Page[i]
9
10 print(i .. ": " .. tostring(page.Caption))
11 end
12
13 form.show()
Add controls to a TabSheet[edit]
1 local form = createForm(false)
2 local pageControl = createPageControl(form)
3
4 local page = pageControl.addTab()
5 page.Caption = "Settings"
6
7 local label = createLabel(page)
8 label.Caption = "This label belongs to the tab sheet"
9 label.Left = 10
10 label.Top = 10
11
12 form.show()
Get a tab rectangle[edit]
1 local form = createForm(false)
2 local pageControl = createPageControl(form)
3
4 pageControl.addTab().Caption = "General"
5
6 local rect = pageControl.tabRect(0)
7
8 print("Left: " .. tostring(rect.Left))
9 print("Top: " .. tostring(rect.Top))
10 print("Right: " .. tostring(rect.Right))
11 print("Bottom: " .. tostring(rect.Bottom))
12
13 form.show()
Switch to the next tab[edit]
1 local form = createForm(false)
2 local pageControl = createPageControl(form)
3
4 pageControl.addTab().Caption = "First"
5 pageControl.addTab().Caption = "Second"
6
7 if pageControl.PageCount > 0 then
8 pageControl.TabIndex = (pageControl.TabIndex + 1) % pageControl.PageCount
9 end
10
11 form.show()