mirror of
https://github.com/ultimatepp/ultimatepp.git
synced 2026-05-15 06:05:58 -06:00
.reference
git-svn-id: svn://ultimatepp.org/upp/trunk@11351 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
parent
5ef1d5b9e1
commit
0978c90a4b
6 changed files with 68 additions and 47 deletions
|
|
@ -1,4 +1,4 @@
|
|||
description "Columns with widget class in ArrayCtrl";
|
||||
description "Columns with widget factory - GetCtrl, different widgets in single column\377";
|
||||
|
||||
uses
|
||||
CtrlLib;
|
||||
|
|
|
|||
|
|
@ -4,14 +4,32 @@ using namespace Upp;
|
|||
|
||||
GUI_APP_MAIN
|
||||
{
|
||||
ArrayCtrl a;
|
||||
a.AddColumn("Text").Ctrls<EditString>();
|
||||
ArrayCtrl list;
|
||||
list.AddColumn("Trivial").Ctrls<EditString>(); // specify type of widget as template argument
|
||||
list.AddColumn("Factory").With( // class factory creates widget - allows customization of widget
|
||||
[](One<Ctrl>& x) {
|
||||
x.Create<Option>().NoWantFocus();
|
||||
}
|
||||
);
|
||||
list.AddColumn("Lined").WithLined( // passes the row index as the first argument
|
||||
[](int line, One<Ctrl>& x)
|
||||
{
|
||||
if(line & 1)
|
||||
x.Create<EditString>();
|
||||
else
|
||||
x.Create<Option>().SetLabel("Line " + AsString(line));
|
||||
}
|
||||
);
|
||||
|
||||
for(int i = 0; i < 300; i++)
|
||||
a.Add(AsString(i));
|
||||
a.SetLineCy(Draw::GetStdFontCy() + 8);
|
||||
list.Add(AsString(i), i & 1, AsString(i));
|
||||
for(int i = 1; i < 300; i += 3)
|
||||
list.GetCtrl(i, 0)->Disable();
|
||||
|
||||
list.SetLineCy(Draw::GetStdFontCy() + DPI(8));
|
||||
|
||||
TopWindow app;
|
||||
app.Add(a.SizePos());
|
||||
app.Add(list.SizePos());
|
||||
app.Sizeable();
|
||||
app.Run();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,11 +0,0 @@
|
|||
description "Columns with widget factory - GetCtrl, different widgets in single column\377";
|
||||
|
||||
uses
|
||||
CtrlLib;
|
||||
|
||||
file
|
||||
main.cpp;
|
||||
|
||||
mainconfig
|
||||
"" = "GUI";
|
||||
|
||||
|
|
@ -1,30 +0,0 @@
|
|||
#include <CtrlLib/CtrlLib.h>
|
||||
|
||||
using namespace Upp;
|
||||
|
||||
void WidgetFactory(int line, One<Ctrl>& x)
|
||||
{
|
||||
if(line & 1)
|
||||
x.Create<EditString>();
|
||||
else
|
||||
x.Create<Option>().SetLabel("Line " + AsString(line));
|
||||
}
|
||||
|
||||
GUI_APP_MAIN
|
||||
{
|
||||
ArrayCtrl list;
|
||||
list.Appending().Removing();
|
||||
list.AddColumn("Text").Ctrls(WidgetFactory);
|
||||
|
||||
for(int i = 0; i < 300; i++)
|
||||
list.Add(AsString(i));
|
||||
for(int i = 1; i < 300; i += 3)
|
||||
list.GetCtrl(i, 0)->Disable();
|
||||
|
||||
list.SetLineCy(Draw::GetStdFontCy() + 8);
|
||||
|
||||
TopWindow app;
|
||||
app.Add(list.SizePos());
|
||||
app.Sizeable();
|
||||
app.Run();
|
||||
}
|
||||
9
reference/ArrayCtrlSorting/ArrayCtrlSorting.upp
Normal file
9
reference/ArrayCtrlSorting/ArrayCtrlSorting.upp
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
uses
|
||||
CtrlLib;
|
||||
|
||||
file
|
||||
main.cpp;
|
||||
|
||||
mainconfig
|
||||
"" = "GUI";
|
||||
|
||||
35
reference/ArrayCtrlSorting/main.cpp
Normal file
35
reference/ArrayCtrlSorting/main.cpp
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
#include <CtrlLib/CtrlLib.h>
|
||||
|
||||
using namespace Upp;
|
||||
|
||||
GUI_APP_MAIN
|
||||
{
|
||||
ArrayCtrl list;
|
||||
list.AddColumn("Trivial").Sorting();
|
||||
|
||||
list.AddColumn("With function")
|
||||
.SortingBy( // sort with sorting function
|
||||
[](int a, int b) -> int {
|
||||
int q = SgnCompare(a % 100, b % 100);
|
||||
if(q) return q;
|
||||
return SgnCompare(a, b);
|
||||
}
|
||||
)
|
||||
.SortDefault(); // set his column to be the initial sorting column;
|
||||
|
||||
list.AddColumn("Line comparison").SortingLined( // row indices passed to predicate
|
||||
[&list](int i, int j) -> bool {
|
||||
return int(list.Get(i, 0)) + int(list.Get(i, 1)) // sort by sum of first two columns
|
||||
< int(list.Get(i, 0)) + int(list.Get(i, 1));
|
||||
}
|
||||
);
|
||||
|
||||
for(int i = 0; i < 300; i++)
|
||||
list.Add((int)Random(1000), (int)Random(10000), 0);
|
||||
|
||||
TopWindow app;
|
||||
app.Add(list.SizePos());
|
||||
app.Sizeable();
|
||||
list.DoColumnSort(); // sort by current sorting column (which is "With function" column because of SortDefault
|
||||
app.Run();
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue