diff --git a/examples/AnimatedHello/Hello.cpp b/examples/AnimatedHello/Hello.cpp index ce3912a59..67cdd5b59 100644 --- a/examples/AnimatedHello/Hello.cpp +++ b/examples/AnimatedHello/Hello.cpp @@ -13,11 +13,7 @@ public: private: String text; - void Animate() { Refresh(); } - public: - typedef HelloWorld CLASSNAME; - HelloWorld& Text(const String& t) { text = t; Refresh(); return *this; } HelloWorld(); @@ -25,31 +21,29 @@ public: HelloWorld::HelloWorld() { - SetTimeCallback(-40, THISBACK(Animate)); + SetTimeCallback(-40, [=] { Refresh(); }); BackPaint(); Zoomable().Sizeable(); - SetRect(0, 0, 260, 80); + SetRect(0, 0, 1000, 300); } void HelloWorld::LeftDown(Point, dword) { - Close(); + EditText(text, "Text to display", "Text"); } void HelloWorld::Paint(Draw& w) { + Font fnt = Roman(64); Size sz = GetSize(); - static int sin_tbl[16] = { - 0, 38, 71, 92, 100, 92, 71, 38, 0, -38, -71, -92, -100, -92, -71, -38 - }; w.DrawRect(sz, White); - Size tsz = GetTextSize(text, Roman(32)); + Size tsz = GetTextSize(text, fnt); Point pos = (sz - tsz) / 2; for(int i = 0; i < text.GetLength(); i++) { int q = (i + GetTickCount() / 40) & 15; - w.DrawText(pos.x, pos.y + sin_tbl[q] * (sz.cy - 32) / 200, - ~text + i, Roman(32), HsvColorf(q / 15.0, 1, 0.5), 1); - pos.x += Roman(32).Info()[text[i]]; + w.DrawText(pos.x, pos.y + sin(GetTickCount() / 100.0 + i / 2.0) * (sz.cy - fnt.GetCy()) / 4, + ~text + i, fnt, HsvColorf(q / 15.0, 1, 0.5), 1); + pos.x += fnt[text[i]]; } } diff --git a/examples/Bombs/main.cpp b/examples/Bombs/main.cpp index 22cda61ea..23f119d33 100644 --- a/examples/Bombs/main.cpp +++ b/examples/Bombs/main.cpp @@ -1,5 +1,10 @@ #include + +#define IMAGECLASS BombsImg +#define IMAGEFILE +#include + using namespace Upp; class Bombs : public TopWindow { @@ -27,21 +32,13 @@ private: int UNIT = 30; - void About(); - - void File(Bar& menu); - void Game(Bar& menu); - void Menu(Bar& menu); - void ShowStatus(); - void Level(Size sz); void Uncover(int x, int y); void Generate(); void UncoverAll(); public: - typedef Bombs CLASSNAME; Bombs(); }; @@ -169,51 +166,29 @@ void Bombs::ShowStatus() status = Format("%d bombs, %d cells remaining", bombs, normal_cells); } -void Bombs::Level(Size sz) -{ - level = sz; -} - -void Bombs::About() -{ - PromptOK("[*A9/ uBombs]&[A5 Ultimate`+`+ example]"); -} - -void Bombs::File(Bar& menu) -{ - menu.Add("Exit", Breaker(IDOK)); - menu.Separator(); - menu.Add("About..", THISBACK(About)); -} - -void Bombs::Game(Bar& menu) -{ - menu.Add("Restart", THISBACK(Generate)); - menu.Separator(); - menu.Add("Easy", THISBACK1(Level, Size(10, 10))) - .Check(level.cx == 10); - menu.Add("Medium", THISBACK1(Level, Size(15, 15))) - .Check(level.cx == 15); - menu.Add("Difficult", THISBACK1(Level, Size(25, 20))) - .Check(level.cx == 25); -} - -void Bombs::Menu(Bar& menu) -{ - menu.Add("File", THISBACK(File)); - menu.Add("Game", THISBACK(Game)); -} - -#define IMAGECLASS BombsImg -#define IMAGEFILE -#include - Bombs::Bombs() { UNIT = DPI(30); level = Size(10, 10); AddFrame(menu); - menu.Set(THISBACK(Menu)); + menu.Set([=](Bar& bar) { + menu.Sub("File", [=](Bar& bar) { + bar.Add("Exit", Breaker(IDOK)); + bar.Separator(); + bar.Add("About..", [] { PromptOK("[*A9/ uBombs]&[A5 Ultimate`+`+ example]"); }); + }); + menu.Sub("Game", [=](Bar& bar) { + bar.Add("Restart", [=] { Generate(); }); + bar.Separator(); + auto Lvl = [&](const char *txt, int cx, int cy) { + bar.Add(txt, [=] { level = Size(cx, cy); }) + .Check(level == Size(cx, cy)); + }; + Lvl("Easy", 10, 10); + Lvl("Medium", 15, 15); + Lvl("Difficult", 25, 20); + }); + }); AddFrame(status); AddFrame(InsetFrame()); Title("uBombs"); diff --git a/examples/CompDir/main.cpp b/examples/CompDir/main.cpp index 66a6a2bd9..42df0f1db 100644 --- a/examples/CompDir/main.cpp +++ b/examples/CompDir/main.cpp @@ -36,7 +36,6 @@ static String ExpandTabs(String line, int tabsize = 4) class DlgCompareDir : public WithCompareDirLayout { public: - typedef DlgCompareDir CLASSNAME; DlgCompareDir(); void Run(); @@ -76,19 +75,19 @@ DlgCompareDir::DlgCompareDir() { CtrlLayout(*this, "Compare directories"); Sizeable().Zoomable(); - refresh <<= THISBACK(CmdRefresh); + refresh << [=] { CmdRefresh(); }; splitter.Vert(tree, editor); editor << lineedit.SizePos() << qtf.SizePos(); qtf.Background(White()); qtf.SetFrame(InsetFrame()); path_a.AddFrame(browse_a); browse_a.SetImage(CtrlImg::right_arrow()); - browse_a <<= THISBACK1(DoBrowse, &path_a); + browse_a << [=] { DoBrowse(&path_a); }; path_b.AddFrame(browse_b); browse_b.SetImage(CtrlImg::right_arrow()); - browse_b <<= THISBACK1(DoBrowse, &path_b); + browse_b << [=] { DoBrowse(&path_b); }; file_mask <<= "*.cpp *.h *.hpp *.c *.C *.cxx *.cc *.lay *.iml *.upp *.sch *.dph"; - tree.WhenCursor = THISBACK(DoTreeCursor); + tree.WhenCursor = [=] { DoTreeCursor(); }; lineedit.SetReadOnly(); lineedit.SetFont(Courier(14)); } diff --git a/examples/Converter/Converter.upp b/examples/Converter/Converter.upp index 9127b8bfd..23bcda86f 100644 --- a/examples/Converter/Converter.upp +++ b/examples/Converter/Converter.upp @@ -1,4 +1,4 @@ -description "Converts metric units and U.S. units (meters / feets etc..)"; +description "Converts metric units and U.S. units (meters / feets etc..)\377"; uses CtrlLib; diff --git a/examples/Converter/converter.lay b/examples/Converter/converter.lay index 8d5998cb9..51fb6710b 100644 --- a/examples/Converter/converter.lay +++ b/examples/Converter/converter.lay @@ -1,11 +1,7 @@ -#ifdef LAYOUTFILE - -LAYOUT(ConverterPaneLayout, 244, 76) - ITEM(LabelBox, title, LeftPosZ(8, 228).TopPosZ(4, 64)) - ITEM(EditDoubleSpin, value, LeftPosZ(16, 144).TopPosZ(20, 19)) - ITEM(SliderCtrl, slider, LeftPosZ(16, 144).TopPosZ(40, 20)) - ITEM(DropList, unit, LeftPosZ(164, 64).TopPosZ(20, 19)) +LAYOUT(ConverterPaneLayout, 280, 76) + ITEM(Upp::LabelBox, title, LeftPosZ(8, 268).TopPosZ(4, 64)) + ITEM(Upp::EditDoubleSpin, value, LeftPosZ(16, 144).TopPosZ(20, 19)) + ITEM(Upp::SliderCtrl, slider, LeftPosZ(16, 252).TopPosZ(40, 20)) + ITEM(Upp::DropList, unit, LeftPosZ(164, 104).TopPosZ(20, 19)) END_LAYOUT -#endif - diff --git a/examples/Converter/main.cpp b/examples/Converter/main.cpp index 371dc5ce0..43ea28dee 100644 --- a/examples/Converter/main.cpp +++ b/examples/Converter/main.cpp @@ -8,33 +8,20 @@ using namespace Upp; #include struct ConverterPane : WithConverterPaneLayout { - ConverterPane *slave; - void AdjustSlave() + ConverterPane *other; + void Sync() { - slave->slider <<= slave->value <<= - IsNull(value) ? 0.0 : (double)~unit * (double)~value / (double)~slave->unit; + other->slider <<= other->value <<= (double)~unit * Nvl((double)~value) / (double)~other->unit; } - void ValueChanged() - { - slider <<= ~value; - AdjustSlave(); - } - void SliderChanged() - { - value <<= ~slider; - AdjustSlave(); - } - - typedef ConverterPane CLASSNAME; ConverterPane() { CtrlLayout(*this); slider.Range(10000); slider <<= value <<= 0; - value <<= THISBACK(ValueChanged); - slider <<= THISBACK(SliderChanged); - unit <<= THISBACK(AdjustSlave); + value << [=] { slider <<= ~value; Sync(); }; + slider << [=] { value <<= ~slider; Sync(); }; + unit << [=] { Sync(); }; } }; @@ -65,10 +52,10 @@ struct Converter : TopWindow us.unit.Add(1613.0, "Miles"); us.unit <<= 0.305; - us.slave = &metric; - metric.slave = &us; + us.other = &metric; + metric.other = &us; - metric.AdjustSlave(); + metric.Sync(); } }; diff --git a/examples/FnGraph/main.cpp b/examples/FnGraph/main.cpp index b3efd1390..2bd60966f 100644 --- a/examples/FnGraph/main.cpp +++ b/examples/FnGraph/main.cpp @@ -139,10 +139,6 @@ struct FnGraph : public TopWindow { int zoom = 9; EditString expression; // function to display - void RefreshExpression() { Refresh(); } - - typedef FnGraph CLASSNAME; - FnGraph(); }; @@ -150,7 +146,7 @@ FnGraph::FnGraph() { Title("Graph of a function"); Add(expression.TopPos(0).HSizePos()); // place widget to the top, horizontally fill the window - expression << THISBACK(RefreshExpression); // when expression changes, repaint the graph + expression << [=] { Refresh(); }; // when expression changes, repaint the graph Sizeable().Zoomable(); // make the window resizable } diff --git a/examples/ImageView/main.cpp b/examples/ImageView/main.cpp index 14f2e4beb..110672664 100644 --- a/examples/ImageView/main.cpp +++ b/examples/ImageView/main.cpp @@ -19,8 +19,6 @@ private: void DirUp(); public: - typedef ImageView CLASSNAME; - void Serialize(Stream& s); void LoadDir(const char *d); void LoadDir() { LoadDir(dir); } @@ -115,12 +113,12 @@ ImageView::ImageView() splitter.SetPos(2700); Add(splitter.SizePos()); - files.WhenEnterItem = THISBACK(Enter); - files.WhenLeftDouble = THISBACK(DoDir); + files.WhenEnterItem = [=] { Enter(); }; + files.WhenLeftDouble = [=] { DoDir(); }; dirup.Height(max(CtrlImg::DirUp().GetSize().cy, Draw::GetStdFontCy() + 6)); dirup.SetImage(CtrlImg::DirUp()); dirup.NormalStyle(); - dirup <<= THISBACK(DirUp); + dirup << [=] { DirUp(); }; files.AddFrame(dirup); Sizeable().Zoomable(); diff --git a/uppsrc/CtrlLib/TreeCtrl.cpp b/uppsrc/CtrlLib/TreeCtrl.cpp index 57b270d74..49cd69e79 100644 --- a/uppsrc/CtrlLib/TreeCtrl.cpp +++ b/uppsrc/CtrlLib/TreeCtrl.cpp @@ -132,6 +132,7 @@ Size TreeCtrl::Item::GetSize(const Display *treedisplay) const sz.cy = max(sz.cy, isz.cy); sz.cx += csz.cx; sz.cy = max(sz.cy, csz.cy); + sz.cy = max(sz.cy, CtrlImg::treeminus().GetHeight(), CtrlImg::treeplus().GetHeight()); sz += Size(2 * margin, 2 * margin); return sz; } @@ -1126,7 +1127,7 @@ void TreeCtrl::Paint(Draw& w) dri.top++; } if(w.IsPainting(0, y, sz.cx, msz.cy) && msz.cy > 0) { - if (multiroot) { + if(multiroot) { if(m.canopen || m.child.GetCount()) { Image im = m.isopen ? CtrlImg::treeminus() : CtrlImg::treeplus(); op -= im.GetSize() / 2;