CustomWidgets.Examples: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
(Created page with "This is examples page == Adding Check Box to cell of Table View == thumb|right|Code Example This example creates window with Table View, wh...")
 
No edit summary
 
(4 intermediate revisions by the same user not shown)
Line 1: Line 1:
__NOTOC__
This is examples page
This is examples page


== Adding Check Box to cell of Table View ==
== Adding Check Box to cell of Table View ==
[[Image:CustomCheckBoxInCell.png|thumb|right|Code Example]]
[[Image:CWExampleCell.png|thumb|right|Code Example]]
This example creates window with Table View, where you can locate, for example, Custom Check Box:
This example creates window with Table View, where you can locate, for example, Custom Check Box, Custom Button, or Custom Edit:


<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
local Window = CustomWindow.create(50, 50, 250, 220, "Example")
local Window = CustomWindow.create(50, 50, 250, 220, "Example")
local TabView = CustomTableView.create(5, 25, 240, 190, false, Window)
local TView = CustomTableView.create(5, 25, 240, 190, false, Window)


TabView:addColumn("Column", 80)
Window:setColorScheme(Themes.Dark.Purple)
local Column = TabView:addColumn("Another Column", 120)
 
TView:addColumn("Column", 80)
local Column = TView:addColumn("Another Column", 120)


for i = 1, 10 do
for i = 1, 10 do


if i == 3 then
if i >= 2 and i <= 4 then
Line = TabView:addLine(30)
Line = TView:addLine(30)
else
else
TabView:addLine(21)
TView:addLine(21)
end
end


for j = 1, TabView:getColumnsCount() do
for j = 1, TView:getColumnsCount() do


TabView:setCellText(i, j, i.." "..j)
TView:setCellText(i, j, i.." "..j)
end
end
end
end


local Cell = TabView:getCell(Line, Column)
local Cell = TView:getCell(3, Column)
Cell:setEnabled(true)
Cell:setText("")
 
local CheckBox = CustomCheckBox.create(2, 4, 90, 22, "Hello", false, Cell)
 
local Cell = TView:getCell(Line, Column)
Cell:setEnabled(true)
Cell:setText("")
 
local Button = CustomButton.create(2, 4, 90, 22, "Hello", false, Cell)
 
local Cell = TView:getCell(2, Column)
Cell:setEnabled(true)
Cell:setEnabled(true)
Cell:setText("")
Cell:setText("")


local CheckBox = CustomCheckBox.create(2, 4, 40, 22, "", false, Cell)
local Edit = CustomEdit.create(2, 4, 90, 22, "Hello", false, Cell)
</syntaxhighlight>
 
 
 
== Table Views Example with Adding and Removing Lines ==
[[Image:CTabViewAddRemoveExample.png|thumb|right|Code Example]]
This example creates window with Table View, where you can with buttons add and remove lines (for checking bugs), theme editor by combobox:
 
<syntaxhighlight lang="lua">
local CurrentTheme = Themes.Light.Purple
 
local ThemeBox = {
["Dark Red"] = Themes.Dark.Red,
["Dark Green"] = Themes.Dark.Green,
["Dark Blue"] = Themes.Dark.Blue,
["Dark Purple"] = Themes.Dark.Purple,
["Dark Gray"] = Themes.Dark.Gray,
 
["Light Red"] = Themes.Light.Red,
["Light Green"] = Themes.Light.Green,
["Light Blue"] = Themes.Light.Blue,
["Light Purple"] = Themes.Light.Purple,
["Light Gray"] = Themes.Light.Gray,
}
 
local Window = CustomWindow.create(50, 50, 300, 300, "Example")
local TView = CustomTableView.create(5, 25, 290, 240, false, Window)
local ButtonA = CustomButton.create(150, 270, 70, 25, "Add", false, Window)
local ButtonD = CustomButton.create(225, 270, 70, 25, "Remove", false, Window)
local Combo = CustomComboBox.create(5, 270, 140, 25, "Select Theme...", false, Window)
 
Window:setColorScheme(CurrentTheme)
Combo:setMaxHeight(450)
 
TView:addColumn("First")
TView:setColumnWidth("First", 90)
 
TView:addColumn("Second")
TView:setColumnWidth("Second", 200)
 
local n = 1
local k = 1
for i = 1, 10 do
TView:addLine(25)
TView:setCellText(i, 1, tostring(i).." Line")
TView:setCellText(i, 2, tostring(n))
n = n+1
k = k+1
end
 
for i in pairs(ThemeBox) do
Combo:addItem(i)
end
 
ButtonA:addEvent("onClientGUIClick", function()
local line = TView:addLine(25)
TView:setCellText(line, 1, "Added Line "..tostring(k))
TView:setCellText(line, 2, tostring(n))
n = n+1
k = k+1
 
print(": Added line "..k)
end)
 
ButtonD:addEvent("onClientGUIClick", function()
if TView:getSelectedLine() then
local line = TView:getSelectedLine()
local cnt = TView:getLinesCount()
 
TView:removeLine(line)
 
k = k-1
print(": Removed line "..line, ": Lines count - "..cnt)
end
end)
 
Combo:addEvent("onCustomComboBoxSelectItem", function()
if Combo:getSelectedItem() ~= nil then
CurrentTheme = themes[Combo:getSelectedItem().Text]
end
Window:setColorScheme(CurrentTheme)
end)
</syntaxhighlight>
</syntaxhighlight>
== See Also ==
{{CWSFUNCS}}

Latest revision as of 03:58, 27 August 2018

This is examples page

Adding Check Box to cell of Table View

Code Example

This example creates window with Table View, where you can locate, for example, Custom Check Box, Custom Button, or Custom Edit:

local Window = CustomWindow.create(50, 50, 250, 220, "Example")
local TView = CustomTableView.create(5, 25, 240, 190, false, Window)

Window:setColorScheme(Themes.Dark.Purple)

TView:addColumn("Column", 80)
local Column = TView:addColumn("Another Column", 120)

for i = 1, 10 do

	if i >= 2 and i <= 4 then
		Line = TView:addLine(30)
	else
		TView:addLine(21)
	end

	for j = 1, TView:getColumnsCount() do

		TView:setCellText(i, j, i.." "..j)
	end
end

local Cell = TView:getCell(3, Column)
Cell:setEnabled(true)
Cell:setText("")

local CheckBox = CustomCheckBox.create(2, 4, 90, 22, "Hello", false, Cell)

local Cell = TView:getCell(Line, Column)
Cell:setEnabled(true)
Cell:setText("")

local Button = CustomButton.create(2, 4, 90, 22, "Hello", false, Cell)

local Cell = TView:getCell(2, Column)
Cell:setEnabled(true)
Cell:setText("")

local Edit = CustomEdit.create(2, 4, 90, 22, "Hello", false, Cell)


Table Views Example with Adding and Removing Lines

Code Example

This example creates window with Table View, where you can with buttons add and remove lines (for checking bugs), theme editor by combobox:

local CurrentTheme = Themes.Light.Purple

local ThemeBox = {
	["Dark Red"] = Themes.Dark.Red,
	["Dark Green"] = Themes.Dark.Green,
	["Dark Blue"] = Themes.Dark.Blue,
	["Dark Purple"] = Themes.Dark.Purple,
	["Dark Gray"] = Themes.Dark.Gray,

	["Light Red"] = Themes.Light.Red,
	["Light Green"] = Themes.Light.Green,
	["Light Blue"] = Themes.Light.Blue,
	["Light Purple"] = Themes.Light.Purple,
	["Light Gray"] = Themes.Light.Gray,
}

local Window = CustomWindow.create(50, 50, 300, 300, "Example")
local TView = CustomTableView.create(5, 25, 290, 240, false, Window)
local ButtonA = CustomButton.create(150, 270, 70, 25, "Add", false, Window)
local ButtonD = CustomButton.create(225, 270, 70, 25, "Remove", false, Window)
local Combo = CustomComboBox.create(5, 270, 140, 25, "Select Theme...", false, Window)

Window:setColorScheme(CurrentTheme)
Combo:setMaxHeight(450)

TView:addColumn("First")
TView:setColumnWidth("First", 90)

TView:addColumn("Second")
TView:setColumnWidth("Second", 200)

local n = 1
local k = 1
for i = 1, 10 do
	TView:addLine(25)
	TView:setCellText(i, 1, tostring(i).." Line")
	TView:setCellText(i, 2, tostring(n))
	n = n+1
	k = k+1
end

for i in pairs(ThemeBox) do
	Combo:addItem(i)
end

ButtonA:addEvent("onClientGUIClick", function()
	local line = TView:addLine(25)
	TView:setCellText(line, 1, "Added Line "..tostring(k))
	TView:setCellText(line, 2, tostring(n))
	n = n+1
	k = k+1

	print(": Added line "..k)
end)

ButtonD:addEvent("onClientGUIClick", function()
	if TView:getSelectedLine() then
		local line = TView:getSelectedLine()
		local cnt = TView:getLinesCount()

		TView:removeLine(line)

		k = k-1
		print(": Removed line "..line, ": Lines count - "..cnt)
	end
end)

Combo:addEvent("onCustomComboBoxSelectItem", function()
	if Combo:getSelectedItem() ~= nil then
		CurrentTheme = themes[Combo:getSelectedItem().Text]
	end
	Window:setColorScheme(CurrentTheme)
end)


See Also

Resource Wiki with content located here: Resource:CustomWidgets

Custom Widgets

This methods working for all elements except CustomDialogs and CustomTooltips

Set Functions

Get Functions

Event Functions


Custom Windows

Create Function

Set Functions

Get Functions

Event Functions


Custom Buttons

Create Function

Set Functions

Get Functions

Event Functions


Custom Progress Bars

Create Function

Set Functions

Get Functions

Event Functions


Custom Scroll Bars

Create Function

Set Functions

Get Functions


Custom Edit Boxes

All functions, what has mark CustomEditBox available for CustomEdit, CustomMemo and CustomSpinner.

Create Functions

Set Functions

Get Functions

Event Functions


Custom Check Boxes

Create Function

Set Functions

Get Functions

Event Functions


Custom Combo Boxes

Create Function

Set Functions

Get Functions

Event Functions


Custom Tabbed Panels

Create Function

Set Functions

Get Functions

Event Functions


Custom Labels

Create Function

Set Functions

Get Functions

Event Functions


Custom Dialogs

Create Function

Event Functions


Custom Tool Tips

Create Function

Set Function

Get Function


Custom Loadings

Create Function

Set Functions

Get Functions


Custom Scroll Panes

Create Function

Set Functions

Get Functions

Event Functions


Custom Table Views

Create Function

Set Functions

Get Functions

Event Functions


Custom Static Images

Create Function

Set Function

Get Function

Event Functions


Custom Text Boxes

Create Function

Set Function

Get Function


Custom Events


Other about Custom Widgets