1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488
|
First steps with the FINAL CUT widget toolkit
=============================================
Table of Contents
-----------------
<!-- TOC -->
- [Basic functions](#basic-functions)
- [Widgets](#widgets)
- [Widget tree](#widget-tree)
- [How to use the library](#how-to-use-the-library)
- [Memory Management](#memory-management)
- [Event Processing](#event-processing)
- [Event handler reimplementation](#event-handler-reimplementation)
- [Event types](#available-event-types)
- [Timer event](#using-a-timer-event)
- [User event](#using-a-user-event)
- [Signals and Callbacks](#signals-and-callbacks)
- [Default signals](#the-final-cut-widgets-emit-the-following-default-signals)
- [Callback function](#example-of-a-callback-function)
- [Callback lambda expression](#example-of-an-lambda-expression-callback)
- [Callback method](#example-of-a-callback-function)
- [Custom signals](#send-custom-signals)
- [Widget layout](#widget-layout)
- [Coordinates](#coordinates)
- [Lengths](#lengths)
- [Areas](#areas)
- [Dynamic layout](#dynamic-layout)
- [Scroll view](#scroll-view)
<!-- /TOC -->
Basic functions
---------------
FINAL CUT is a library for creating text-based terminal applications.
It runs on several Unix-like platforms. The release of FINAL CUT is
licensed under the terms of the GNU Lesser General Public License v3.0
([GNU LGPL v3](https://www.gnu.org/licenses/lgpl-3.0-standalone.html)),
which allows flexible licensing of applications. FINAL CUT was written
in the programming language [C++](https://en.wikipedia.org/wiki/C%2B%2B).
The object-oriented design allows the creation of fast and lean programs.
FINAL CUT is a [widget toolkit](http://en.wikipedia.org/wiki/Widget_toolkit).
A user interface usually consists of several
[widgets](https://en.wikipedia.org/wiki/Software_widget). FINAL CUT
draws widgets on virtual windows and then mapped them on a virtual
terminal. It uses the terminal capabilities from the
[Termcap library](https://en.wikipedia.org/wiki/Termcap) to display
the character matrix of the virtual terminal on the screen or a terminal
emulator. It uses various optimization methods to improve the drawing speed.
<figure class="image">
<img src="final-cut-application-structure.svg" alt="application structure">
<figcaption>Figure 1. Structure of a FINAL CUT application</figcaption>
</figure>
<br /><br />
Widgets
-------
FINAL CUT has many widgets. It offers buttons, input fields, menus, and
dialog boxes that cover the most common use cases. Widgets are visual
elements that are combined to create user interfaces. Own widgets can be
easily created by creating a derived class of `FWidget` or other existing
widgets. All widgets are instances of
[FWidget](https://codedocs.xyz/gansm/finalcut/classfinalcut_1_1FWidget.html)
or its subclasses.
A widget can contain any number of child widgets. Child widgets are displayed
in the display area of the parent widget. Window widgets based on `FWindow`
have their own virtual display area and are independent of the parent widget.
When a parent widget is disabled, hidden, or deleted, the same operation is
used recursively to all its child widgets. The base class `FObject` implements
the self-organized object tree behavior. For example, `addChild()` removes
the child ownership from an existing parent object before assigning it to
the new target. When a child becomes deleted, the parent-child relationship
causes its reference in the parent object to be removed. An explicit
`delChild()` is no longer required here.
Widget tree
-----------
An `FApplication` widget is the top-level widget of an application. It is
unique and can not have a parent widget. The class `FApplication` manages
all settings and assigns keyboard and mouse input to the different widgets.
<figure class="image">
<img src="final-cut-widget-tree.svg" alt="widget tree">
<figcaption>Figure 2. Widget tree of a FINAL CUT application</figcaption>
</figure>
<br /><br />
The main widget of a FINAL CUT application is the only object that
`FApplication` can have as a child. This main widget is usually a window
object that contains all sub-widgets of the application. A sub-widget can
also be another window.
How to use the library
----------------------
At the beginning of this introduction to the FINAL CUT
we will start with a small example.
The following example creates an empty 30×10 character dialog.
**File:** *dialog.cpp*
```cpp
#include <final/final.h>
auto main (int argc, char* argv[]) -> int
{
finalcut::FApplication app(argc, argv);
finalcut::FDialog dialog(&app);
dialog.setText ("A dialog");
const finalcut::FPoint position{25, 5};
const finalcut::FSize size{30, 10};
dialog.setGeometry (position, size);
finalcut::FWidget::setMainWidget(&dialog);
dialog.show();
return app.exec();
}
```
<figure class="image">
<img src="first-steps_dialog.cpp.png" alt="dialog.cpp">
<figcaption>Figure 3. A blank dialog</figcaption>
</figure>
<br /><br />
*(Note: You can close the dialog with the mouse,
<kbd>Shift</kbd>+<kbd>F10</kbd> or <kbd>Ctrl</kbd>+<kbd>^</kbd>)*
After entering the source code in *dialog.cpp* you can compile
the above program with gcc:
```bash
g++ dialog.cpp -o dialog -O2 -lfinal
```
How it works
------------
```cpp
#include <final/final.h>
```
All final cut programs have to include the *final.h* header.
```cpp
finalcut::FApplication app(argc, argv);
```
This line creates the `finalcut::FApplication` object `app` with
the command line arguments `argc` and `argv`. This object manages
the application main event loop. It receives keyboard and mouse events
and sends them to the target widgets. You have to create an application
object before you can create a widgets object.
The next line
```cpp
finalcut::FDialog dialog(&app);
```
creates the `finalcut::FDialog` object `dialog` with the object `app`
as parent object. The `finalcut::FDialog` class is the base class for
creating dialog windows.
```cpp
dialog.setText ("A dialog");
```
The title bar of the dialog box gets the text "A dialog".
```cpp
finalcut::FPoint position{25, 5};
finalcut::FSize size{30, 10};
dialog.setGeometry (position, size);
```
The dialog window gets a width of 30 and a height of 10 characters.
The position of the window in the terminal is at x=25 and
y=5 (note: x=1 and y=1 represents the upper left corner).
```cpp
finalcut::FWidget::setMainWidget(&dialog);
```
The `dialog` object was now selected as the main widget for the application.
When you close the main widget, the entire application quits.
```cpp
dialog.show();
```
A window or widget is not visible directly after its creation.
Only the call of `show()` makes it (and its child objects,
if available) visible.
```cpp
return app.exec();
```
The last line calls `exec()` to start the application and to return
the result to the operating system. The started application enters
the main event loop. This loop does not end until the window is
closed.
Memory Management
-----------------
To create a hierarchy of FObjects (or derived classes/widgets),
a new FObject has to be initialized with its parent object.
```cpp
FObject* parent = new FObject();
FObject* child = new FObject(parent);
```
When the used memory of a parent FObject gets deallocated, the allocated
memory of its child objects will also be deallocated automatically.
An object can also be assigned to another object later via `addChild()`.
```cpp
FObject* parent = new FObject();
FObject* child = new FObject();
parent->addChild(child);
```
The child object assignment can be removed at any time with
`delChild()`.
```cpp
FObject* parent = new FObject();
FObject* child = new FObject(parent);
parent->delChild(child);
```
If an FObject with a parent gets removed from the hierarchy,
the destructor automatically deletes the object assignment from
its parent object. If a class object doesn't derive from FObject,
you have to implement storage deallocation yourself.
**File:** *memory.cpp*
```cpp
#include <final/final.h>
using namespace finalcut;
auto main (int argc, char* argv[]) -> int
{
FApplication app(argc, argv);
// The object dialog is managed by app
FDialog* dialog = new FDialog(&app);
dialog->setText ("Window Title");
dialog->setGeometry (FPoint{25, 5}, FSize{40, 8});
// The object input is managed by dialog
FLineEdit* input = new FLineEdit("predefined text", dialog);
input->setGeometry(FPoint{8, 2}, FSize{29, 1});
input->setLabelText (L"&Input");
// The object label is managed by dialog
FLabel* label = new FLabel ( "Lorem ipsum dolor sit amet, consectetur "
"adipiscing elit, sed do eiusmod tempor "
"incididunt ut labore et dolore magna aliqua."
, dialog );
label->setGeometry (FPoint{2, 4}, FSize{36, 1});
FWidget::setMainWidget(dialog);
dialog->show();
return app.exec();
}
```
<figure class="image">
<img src="first-steps_memory.cpp.png" alt="memory.cpp">
<figcaption>Figure 4. FObject manages its child objects</figcaption>
</figure>
<br /><br />
*(Note: You can close the window with the mouse,
<kbd>Shift</kbd>+<kbd>F10</kbd> or <kbd>Ctrl</kbd>+<kbd>^</kbd>)*
After entering the source code in *memory.cpp* you can compile
the above program with gcc:
```bash
g++ memory.cpp -o memory -O2 -lfinal
```
Event Processing
----------------
Calling `FApplication::exec()` starts the FINAL CUT main event loop.
While the event loop is running, the system checks all the time whether
an event has occurred and sends it to the application's currently focused
object. The events of the terminal, such as keystrokes, mouse actions, or
terminal size changing, are translated into `FEvent` objects, and are sent to
the active `FObject`. It is also possible to use `FApplication::sendEvent()`
or `FApplication::queueEvent()` to send a specific event to an object.
`FObject`-derived objects process incoming events by reimplementing the
virtual method `event()`. The `FObject` itself can only call its own events
`onTimer()` and `onUserEvent()` and ignores all other events. The
`FObject`-derived class `FWidget` also reimplements the `event()` method
to handle further events. `FWidget` calls the `FWidget::onKeyPress` method
when you press a key, or the `FWidget::onMouseDown` method when you click
a mouse button.
### Event handler reimplementation ###
An event in FINAL CUT is an object that inherits from the base class
`FEvent`. There are several event types, represented by an enum value.
For example, the method `FEvent::type()` returns the type
`Event::MouseDown` when you press down a mouse button.
Some event types have data that cannot be stored in an `FEvent` object.
For example, a click event of the mouse requires to store which button was
triggered and the position of the mouse pointer at that time. In classes
derived from `FEvent`, such as `FMouseEvent()`, we store this data.
Widgets get their events from the `event()` method inherited from `FObject`.
The implementation of `event()` in `FWidget` forwards the most common event
types to specific event handlers such as `FMouseEvent()`, `FKeyEvent()` or
`FResizeEvent()`. There are many other event types. You can create your own
event types and send them to other objects and widgets.
### Available event types ###
```cpp
enum class Event
{
None, // invalid event
KeyPress, // key pressed
KeyUp, // key released
KeyDown, // key pressed
MouseDown, // mouse button pressed
MouseUp, // mouse button released
MouseDoubleClick, // mouse button double click
MouseWheel, // mouse wheel rolled
MouseMove, // mouse move
FocusIn, // focus in
FocusOut, // focus out
ChildFocusIn, // child focus in
ChildFocusOut, // child focus out
FailAtChildFocus, // No further focusable child widgets
TerminalFocusIn, // terminal focus in
TerminalFocusOut, // terminal focus out
WindowActive, // activate window
WindowInactive, // deactivate window
WindowRaised, // raise window
WindowLowered, // lower window
Accelerator, // keyboard accelerator
Resize, // terminal resize
Show, // widget is shown
Hide, // widget is hidden
Close, // widget close
Timer, // timer event occur
User // user defined event
};
```
### Using a timer event ###
The following example starts a periodic timer that triggers an `FTimerEvent()`
every 100 ms. The virtual method `onTimer()` is then called each time in the
same dialog object.
**File:** *timer.cpp*
```cpp
#include <final/final.h>
using namespace finalcut;
class dialogWidget : public FDialog
{
public:
explicit dialogWidget (FWidget* parent = nullptr)
: FDialog{parent}
{
label.setAlignment (Align::Right);
id = addTimer(100);
}
private:
void initLayout()
{
setText ("Dialog");
setGeometry (FPoint{25, 5}, FSize{23, 4});
label.setGeometry (FPoint{1, 1}, FSize{10, 1});
value.setGeometry (FPoint{11, 1}, FSize{10, 1});
FDialog::initLayout();
}
void onTimer (FTimerEvent* ev) override
{
if ( id == ev->getTimerId() && n < 9999999999 )
{
value.setNumber(n);
value.redraw();
n++;
}
}
FLabel label{"Counter: ", this};
FLabel value{"0", this};
long n{0};
int id{0};
};
auto main (int argc, char* argv[]) -> int
{
FApplication app(argc, argv);
dialogWidget dialog(&app);
FWidget::setMainWidget(&dialog);
dialog.show();
return app.exec();
}
```
<figure class="image">
<img src="first-steps_timer.cpp.png" alt="timer.cpp">
<figcaption>Figure 5. FObject::onTimer event handler</figcaption>
</figure>
<br /><br />
*(Note: You can close the window with the mouse,
<kbd>Shift</kbd>+<kbd>F10</kbd> or <kbd>Ctrl</kbd>+<kbd>^</kbd>)*
After entering the source code in *timer.cpp* you can compile
the above program with gcc:
```bash
g++ timer.cpp -o timer -O2 -lfinal -std=c++14
```
### Using a user event ###
You can use the `FUserEvent()` to create a individual event and send it to a
specific object. If you want to create more than one user event, you can
specify an identification number (0 in the example below) to identify the
different events. Afterwards this number can be retrieved with `getUserId()`.
User events should be generated in the main event loop. For this purpose,
the class `FApplication` provides the virtual method
`processExternalUserEvent()`. This method can be overwritten in a derived
class and filled with user code.
The following example reads the average system load and creates a user event
when a value changes. This event sends the current values to an `FLabel`
widget and displays them in the terminal.
**File:** *user-event.cpp*
```cpp
#include <stdlib.h>
#include <final/final.h>
#define _BSD_SOURCE 1
#define _DEFAULT_SOURCE 1
using LoadAvg = double[3];
using namespace finalcut;
class extendedApplication : public FApplication
{
public:
extendedApplication (const int& argc, char* argv[])
: FApplication(argc, argv)
{ }
private:
void processExternalUserEvent() override
{
if ( getMainWidget() )
{
if ( getloadavg(load_avg, 3) < 0 )
FApplication::getLog()->error("Can't get load average values");
if ( last_avg[0] != load_avg[0]
|| last_avg[1] != load_avg[1]
|| last_avg[2] != load_avg[2] )
{
FUserEvent user_event(Event::User, 0);
user_event.setData (load_avg);
FApplication::sendEvent (getMainWidget(), &user_event);
}
for (std::size_t i = 0; i < 3; i++)
last_avg[i] = load_avg[i];
}
}
// Data member
LoadAvg load_avg{}, last_avg{};
};
class dialogWidget final : public FDialog
{
public:
explicit dialogWidget (FWidget* parent = nullptr)
: FDialog{"User event", parent}
{ }
private:
void initLayout()
{
FDialog::setGeometry (FPoint{25, 5}, FSize{40, 6});
loadavg_label.setGeometry (FPoint{2, 2}, FSize{36, 1});
FDialog::initLayout();
}
void onUserEvent (FUserEvent* ev) override
{
const auto& lavg = ev->getData<LoadAvg>();
std::setlocale(LC_NUMERIC, "C");
loadavg_label.clear();
loadavg_label << "Load average: " << lavg[0] << ", "
<< lavg[1] << ", "
<< lavg[2] << " ";
loadavg_label.redraw();
}
FLabel loadavg_label{this};
};
auto main (int argc, char* argv[]) -> int
{
extendedApplication app(argc, argv);
dialogWidget dialog(&app);
FWidget::setMainWidget(&dialog);
dialog.show();
return app.exec();
}
```
<figure class="image">
<img src="first-steps_user-event.cpp.png" alt="user-event.cpp">
<figcaption>Figure 6. User event generation</figcaption>
</figure>
<br /><br />
*(Note: You can close the window with the mouse,
<kbd>Shift</kbd>+<kbd>F10</kbd> or <kbd>Ctrl</kbd>+<kbd>^</kbd>)*
After entering the source code in *user-event.cpp* you can compile
the above program with gcc:
```bash
g++ user-event.cpp -o user-event -O2 -lfinal -std=c++14
```
Signals and Callbacks
---------------------
The callback mechanism is essential for developing applications with
FINAL CUT. Callback routines allow the programmer to connect different
objects (which do not need to know each other). Connected objects notify
each other when an action occurs in a widget. To uniquely identify a widget
action, it uses signal strings. For example, if an `FButton` object gets
clicked by a keyboard or mouse, it sends the string "clicked". A signal
handler explicitly provided by Widget, in the form of a callback function
or a callback method, can react to such a signal.
A callback function has no return value and can have various arguments:
```cpp
void cb_function (FWidget* w, int* i, double* d, ...)
{...}
```
The structure of a callback method is the same:
```cpp
void classname::cb_methode (FWidget* w, int* i, double* d, ...)
{...}
```
We use the `addCallback()` method of the `FWidget` class to connect
to other widget objects.
1. For calling functions or static methods via a pointer:
```cpp
template< typename Function
, typename FunctionPointer<Function>::type = nullptr
, typename... Args >
void FWidget::addCallback ( const FString& cb_signal
, Function&& cb_function
, Args&&... args)
{...}
```
2. For calling functions or static methods via a reference:
```cpp
template< typename Function
, typename FunctionReference<Function>::type = nullptr
, typename... Args >
void FWidget::addCallback ( const FString& cb_signal
, Function& cb_function
, Args&&... args)
{...}
```
3. For calling a member method of a specific instance:
```cpp
template< typename Object
, typename Function
, typename ObjectPointer<Object>::type = nullptr
, typename MemberFunctionPointer<Function>::type = nullptr
, typename... Args >
void FWidget::addCallback ( const FString& cb_signal
, Object&& cb_instance
, Function&& cb_member
, Args&&... args)
{...}
```
4. For calling a std::bind call wrapper or a lambda expression:
```cpp
template< typename Function
, typename ClassObject<Function>::type = nullptr
, typename... Args >
void FWidget::addCallback ( const FString& cb_signal
, Function&& cb_function
, Args&&... args)
{...}
```
5. For calling a std::bind call wrapper to a specific instance:
```cpp
template< typename Object
, typename Function
, typename ObjectPointer<Object>::type = nullptr
, typename ClassObject<Function>::type = nullptr
, typename... Args >
void FWidget::addCallback ( const FString& cb_signal
, Object&& cb_instance
, Function&& cb_function
, Args&&... args)
{...}
```
6. For calling a lambda function that has been stored in a variable
with the keyword auto:
```cpp
template< typename Function
, typename ClassObject<Function>::type = nullptr
, typename... Args >
void FWidget::addCallback ( const FString& cb_signal
, Function& cb_function
, Args&&... args)
{...}
```
With `delCallback(...)` you can remove a connection to a signal handler
or a widget instance. Alternatively, you can use `delCallbacks()` to
remove all existing callbacks from an object.
1. To delete functions or static methods callbacks via a pointer:
```cpp
template< typename FunctionPtr
, typename FunctionPointer<FunctionPtr>::type = nullptr >
void FWidget::delCallback (FunctionPtr&& cb_func_ptr)
{...}
```
2. To delete functions or static methods callbacks via a reference:
```cpp
template< typename Function
, typename FunctionReference<Function>::type = nullptr >
void FWidget::delCallback (Function& cb_function)
{...}
```
3. To delete all callbacks from a specific instance:
```cpp
template< typename Object
, typename ObjectPointer<Object>::type = nullptr >
void FWidget::delCallback (Object&& cb_instance)
{...}
```
4. To delete all callbacks of a signal:
```cpp
void delCallback (const FString& cb_signal)
{...}
```
5. To delete all callbacks of a signal and specific instance:
```cpp
template< typename Object
, typename ObjectPointer<Object>::type = nullptr >
void delCallback (const FString& cb_signal, Object&& cb_instance)
{...}
```
6. To delete all callbacks from a widget:
```cpp
void delCallback()
{...}
```
### The FINAL CUT widgets emit the following default signals ###
<dl>
<dt>FApplication</dt>
<dd>"first-dialog-opened"<br />"last-dialog-closed"</dd>
<dt>FButton</dt>
<dd>"clicked"</dd>
<dt>FCheckMenuItem</dt>
<dd>"clicked"<br />"toggled"</dd>
<dt>FLineEdit</dt>
<dd>"activate"<br />"changed"</dd>
<dt>FListBox</dt>
<dd>"changed"<br />"clicked"<br />"row-changed"<br />"row-selected"</dd>
<dt>FListView</dt>
<dd>"changed"<br />"clicked"<br />"row-changed"</dd>
<dt>FMenu</dt>
<dd>"activate"</dd>
<dt>FMenuItem</dt>
<dd>"activate"<br />"clicked"<br />"deactivate"</dd>
<dt>FRadioMenuItem</dt>
<dd>"clicked"<br />"toggled"</dd>
<dt>FScrollbar</dt>
<dd>"change-value"</dd>
<dt>FSpinBox</dt>
<dd>"changed"</dd>
<dt>FStatusBar</dt>
<dd>"activate"</dd>
<dt>FTextView</dt>
<dd>"changed"</dd>
<dt>FToggleButton</dt>
<dd>"clicked"<br />"toggled"</dd>
<dt>FWidget</dt>
<dd>"destroy"<br />"enable"<br />"disable"<br />"focus-in"<br />"focus-out"<br />"mouse-press"<br />"mouse-release"<br />"mouse-move"<br />"mouse-wheel-down"<br />"mouse-wheel-up"</dd>
</dl>
### Example of a callback function: ###
**File:** *callback-function.cpp*
```cpp
#include <final/final.h>
using namespace finalcut;
void cb_changeText (const FButton& button, FLabel& label)
{
label.clear();
label << "The " << button.getClassName() << " was pressed";
label.redraw();
}
auto main (int argc, char* argv[]) -> int
{
FApplication app(argc, argv);
FDialog dialog(&app);
dialog.setText ("A dialog with callback function");
dialog.setGeometry (FRect{25, 5, 45, 9});
FLabel label (&dialog);
label = "The button has never been pressed before";
label.setGeometry (FPoint{2, 2}, FSize{41, 1});
FButton button (&dialog);
// Character follows '&' will be used as the accelerator key
button = "&Click me";
button.setGeometry (FPoint{15, 5}, FSize{14, 1});
// Connect the button signal "clicked" with the callback function
button.addCallback
(
"clicked", // Callback signal
&cb_changeText, // Function pointer
std::cref(button), // First function argument
std::ref(label) // Second function argument
);
FWidget::setMainWidget(&dialog);
dialog.show();
return app.exec();
}
```
<figure class="image">
<img src="first-steps_callback-function.cpp.png" alt="callback-function.cpp">
<figcaption>Figure 7. Button with a callback function</figcaption>
</figure>
<br /><br />
*(Note: You can close the dialog with the mouse,
<kbd>Shift</kbd>+<kbd>F10</kbd> or <kbd>Ctrl</kbd>+<kbd>^</kbd>)*
After entering the source code in *callback-function.cpp* you can compile
the above program with gcc:
```bash
g++ callback-function.cpp -o callback-function -O2 -lfinal
```
### Example of an lambda expression callback: ###
**File:** *callback-lambda.cpp*
```cpp
#include <final/final.h>
using namespace finalcut;
auto main (int argc, char* argv[]) -> int
{
FApplication app(argc, argv);
FDialog dialog(&app);
dialog.setText ("Lambda expression as callback");
dialog.setGeometry (FRect{25, 5, 45, 9});
FButton button ("&bottom", &dialog);
button.setGeometry (FPoint{15, 5}, FSize{14, 1});
// Connect the button signal "clicked" with the lambda expression
button.addCallback
(
"clicked", // Callback signal
[] (FButton& button, FDialog& dgl) // Lambda function
{
if ( button.getY() != 2 )
{
button.setPos (FPoint{15, 2});
button.setText("&top");
}
else
{
button.setPos (FPoint{15, 5});
button.setText("&bottom");
}
dgl.redraw();
},
std::ref(button), // First function argument
std::ref(dialog) // Second function argument
);
FWidget::setMainWidget(&dialog);
dialog.show();
return app.exec();
}
```
<figure class="image">
<img src="first-steps_callback-lambda.cpp.png" alt="callback-lambda.cpp">
<figcaption>Figure 8. Button with lambda expression callback.</figcaption>
</figure>
<br /><br />
*(Note: You can close the dialog with the mouse,
<kbd>Shift</kbd>+<kbd>F10</kbd> or <kbd>Ctrl</kbd>+<kbd>^</kbd>)*
After entering the source code in *callback-lambda.cpp* you can compile
the above program with gcc:
```bash
g++ callback-lambda.cpp -o callback-lambda -O2 -lfinal -std=c++14
```
### Example of a callback method: ###
**File:** *callback-method.cpp*
```cpp
#include <final/final.h>
using namespace finalcut;
class dialogWidget : public FDialog
{
public:
explicit dialogWidget (FWidget* parent = nullptr)
: FDialog{parent}
{
// Connect the button signal "clicked" with the callback method
button.addCallback
(
"clicked", // Callback signal
finalcut::getFApplication(), // Class instance
&finalcut::FApplication::cb_exitApp, // Method pointer
this // Function argument
);
}
private:
void initLayout()
{
setText ("Callback method");
setGeometry (FPoint{25, 5}, FSize{25, 7});
button.setGeometry (FPoint{7, 3}, FSize{10, 1});
FDialog::initLayout();
}
FButton button{"&Quit", this};
};
auto main (int argc, char* argv[]) -> int
{
FApplication app(argc, argv);
dialogWidget dialog(&app);
FWidget::setMainWidget(&dialog);
dialog.show();
return app.exec();
}
```
<figure class="image">
<img src="first-steps_callback-method.cpp.png" alt="callback-method.cpp">
<figcaption>Figure 9. Button with a callback method</figcaption>
</figure>
<br /><br />
*(Note: You can close the window with the mouse,
<kbd>Shift</kbd>+<kbd>F10</kbd> or <kbd>Ctrl</kbd>+<kbd>^</kbd>)*
After entering the source code in *callback-method.cpp* you can compile
the above program with gcc:
```bash
g++ callback-method.cpp -o callback-method -O2 -lfinal -std=c++14
```
### Send custom signals ###
You can use the `emitCallback()` method to generate a user-defined signal.
You can connect this signal later with the method `addCallback()` to a
self-defined routine.
**File:** *emit-signal.cpp*
```cpp
#include <final/final.h>
using namespace finalcut;
class dialogWidget : public FDialog
{
public:
explicit dialogWidget (FWidget* parent = nullptr)
: FDialog{parent}
{
label.setAlignment (Align::Right);
label.setForegroundColor (FColor::Black);
plus.setNoUnderline();
minus.setNoUnderline();
// Connect the button signal "clicked" with the callback method
plus.addCallback ("clicked", this, &dialogWidget::cb_plus);
minus.addCallback ("clicked", this, &dialogWidget::cb_minus);
// Connect own signals
addCallback ("hot", this, &dialogWidget::cb_set_red);
addCallback ("regular", this, &dialogWidget::cb_set_black);
addCallback ("cold", this, &dialogWidget::cb_set_blue);
}
private:
void initLayout()
{
setGeometry (FPoint{25, 5}, FSize{22, 7});
setText ("Emit signal");
const FSize size{5, 1};
label.setGeometry (FPoint{8, 1}, size);
plus.setGeometry (FPoint{3, 3}, size);
minus.setGeometry (FPoint{3, 3} + FPoint{10, 0}, size);
FDialog::initLayout();
}
void cb_plus()
{
if ( t < 100 )
t++;
if ( t == 30 )
emitCallback("hot");
else if ( t == 1 )
emitCallback("regular");
setTemperature();
}
void cb_minus()
{
if ( t > -99 )
t--;
if ( t == 0 )
emitCallback("cold");
else if ( t == 29 )
emitCallback("regular");
setTemperature();
}
void cb_set_blue()
{
label.setForegroundColor (FColor::Blue);
}
void cb_set_black()
{
label.setForegroundColor (FColor::Black);
}
void cb_set_red()
{
label.setForegroundColor (FColor::Red);
}
void setTemperature()
{
label.clear();
label << t << "°C";
label.redraw();
}
int t = 20;
FLabel label{std::move(FString() << t << "°C"), this};
FButton plus {"&+", this};
FButton minus {"&-", this};
};
auto main (int argc, char* argv[]) -> int
{
FApplication app(argc, argv);
dialogWidget dialog(&app);
FWidget::setMainWidget(&dialog);
dialog.show();
return app.exec();
}
```
<figure class="image">
<img src="first-steps_emit-signal.cpp.png" alt="emit-signal.cpp">
<figcaption>Figure 10. Callbacks with custom signals</figcaption>
</figure>
<br /><br />
*(Note: You can close the window with the mouse,
<kbd>Shift</kbd>+<kbd>F10</kbd> or <kbd>Ctrl</kbd>+<kbd>^</kbd>)*
After entering the source code in *emit-signal.cpp* you can compile
the above program with gcc:
```bash
g++ emit-signal.cpp -o emit-signal -O2 -lfinal -std=c++14
```
Widget layout
-------------
### Coordinates ###
The positioning of a widget in the terminal works via a coordinate
system. It consists of _x_ characters in the horizontal and _y_
characters in the vertical. The upper left corner has the coordinates
(1, 1). With the commands `getDesktopWidth()` and `getDesktopHeight()`,
the width and height of the terminal get retrieved. These two values
result in the position of the lower right terminal corner. The position
of a widget is retrievable with `getX()`, `getY()`, and `getPos()` or
is definable with `setX()`, `setY()`, and `setPos()`. The data type for
each coordinate is an `int`. All positions represent an `FPoint`
object. The positioning of the widget is always relative to its parent
widget. The top parent widget in a chain of children contains the
terminal desktop. There the absolute terminal positions are still
identical to the relative positions (`getPos()` = `getTermPos()`). In
the case of a child widget, the positioning is corresponding to the
upper left corner of the parent widget plus a possible padding space
(can be determined with `getLeftPadding()` and `getTopPadding()`).
If you want to ignore padding spaces, you have to force this with the
`ignorePadding()` method.
<figure class="image">
<img src="widget-coordinates.svg" alt="widget coordinates">
<figcaption>Figure 11. Widget coordinates</figcaption>
</figure>
<br /><br />
```cpp
int getX() const;
int getY() const;
const FPoint getPos() const;
int getTermX() const;
int getTermY() const;
const FPoint getTermPos() const;
virtual void setX (int x, bool adjust = true);
virtual void setY (int y, bool adjust = true);
virtual void setPos (const FPoint& p, bool adjust = true);
```
If you set the value of `adjust` to `false` when calling `setX()`,
`setY()`, or `setPos()`, this will prevent the explicit call of
`adjustSize()` afterward. This is important to avoid `adjustSize()`
loops or to block the `adjustSize()` call from being repeated
unnecessarily often.
### Lengths ###
The dimensions of a widget can be retrieved and defined separately in
width and height. The methods `getWidth()` and `getHeight()`
respectively `setWidth()` and `setHeight()` are used for this. Because
a length cannot be negative, all lengths are of type `std::size_t`.
The maximum size of a child widget automatically results from the size
of the parent widget, which is retrievable with `getClientWidth()` and
`getClientHeight()`. Some widgets have a border, a title bar, or both,
which can reduce the maximum size of the child widget.
        widget width ≥ client widget width<br />
        widget height ≥ client widget height
Corresponding padding space ensures the correct distance here. The
padding space can be retrieved separately for all four sides with
the widget methods `getTopPadding()`, `getLeftPadding()`,
`getBottomPadding()`, and `getRightPadding()`. You can set the
required padding space for the widget using the `setTopPadding()`,
`setLeftPadding()`, `setBottomPadding()` and `setRightPadding()`
methods.
        widget width = left padding + client width + right padding<br />
        widget height = top padding + client height + bottom padding
<figure class="image">
<img src="widget-lengths.svg" alt="widget lengths">
<figcaption>Figure 12. Width and height of a widget</figcaption>
</figure>
<br /><br />
```cpp
std::size_t getWidth() const;
std::size_t getHeight() const;
std::size_t getClientWidth() const;
std::size_t getClientHeight() const;
int getTopPadding() const;
int getLeftPadding() const;
int getBottomPadding() const;
int getRightPadding() const;
virtual void setWidth (std::size_t width, bool adjust = true);
virtual void setHeight (std::size_t height, bool adjust = true);
void setTopPadding (int top, bool adjust = true);
void setLeftPadding (int left, bool adjust = true);
void setBottomPadding (int bottom, bool adjust = true);
void setRightPadding (int right, bool adjust = true);
```
If the value of `adjust` is set to `false` for `setWidth()`,
`setHeight()`, `setTopPadding()`, `setLeftPadding()`,
`setBottomPadding()` or `setRightPadding()`, then `adjustSize()` is
not explicitly called afterward. This is important to prevent
`adjustSize()` loops or to avoid that `adjustSize()` is called
unnecessarily often.
### Areas ###
The terminal area in which a widget appears determines its geometry.
The geometry of a widget is composed of its position and its size.
A widget position is always of object type `FPoint` and a widget
size of type `FSize`. The widget geometry can be retrieved as `FRect`
object via the widget method `getGeometry()` and set with the method
`setGeometry()`. The `getTermGeometry()` method gets the total values
of the terminal geometry.
If you are only interested in the size of a widget, you can also use
the method `getSize()`. To set the widget size, you can use the method
`setSize()`.
The position of a shadow is outside the widget. The shadow size itself
as `FSize` object is retrievable via the `getShadow()` method. You
can set the widget shadow size with the `setShadowSize()` method. If
you want to get the geometry values of a widget, including its shadow,
you can use the method `getGeometryWithShadow()` from the FWidget
class. If you want to have the entire geometry with shadow for the
absolute geometry values as a `FRect` object, you can call the method
`getTermGeometryWithShadow()`.
<figure class="image">
<img src="widget-geometry.svg" alt="widget geometry">
<figcaption>Figure 13. Geometry of widgets</figcaption>
</figure>
<br /><br />
```cpp
const FSize getSize() const;
const FSize getClientSize() const;
const FRect& getGeometry() const;
const FRect& getTermGeometry();
const FSize& getShadow() const;
const FRect& getGeometryWithShadow();
const FRect& getTermGeometryWithShadow();
virtual void setSize (const FSize& size, bool adjust = true);
virtual void setGeometry (const FRect& box, bool adjust = true);
virtual void setGeometry (const FPoint& p, const FSize& s, bool adjust = true);
virtual void setShadowSize (const FSize& size);
```
If you explicitly set the value of `adjust` to `false` when
using the `setSize()`, `setGeometry()` or `setShadowSize()`
mutators, the `adjustSize()` method is no longer called automatically.
This can be used to prevent recursive `adjustSize()` calls or to
avoid unnecessary `adjustSize()` calls.
### Dynamic layout ###
A modern terminal emulation like xterm has no fixed resolution.
They offer the possibility to change the height and width of the
terminal at any time. That triggers a resize-event that calls
the `adjustSize()` method. This method allows adapting the widget
to a changed terminal size. You can override the `adjustSize()`
method to adjust the size and position of the widget. The method
`adjustSize()` will also be called indirectly via calling methods
`setGeometry()`, `setX()`, `setY()`, `setPos()`, `setWidth()`,
`setHeight()`, `setSize()`, `setTopPadding()`, `setLeftPadding()`,
`setBottomPadding()`, `setRightPadding()`, or `setDoubleFlatLine()`.
Scalable dialogs derived from FDialog can change the dialog size by
clicking on the lower right corner of the window. You can intercept
a scaling action by overriding the `setSize()` method and adjusting
the client widgets.
**File:** *size-adjustment.cpp*
```cpp
#include <final/final.h>
using namespace finalcut;
class dialogWidget : public FDialog
{
public:
explicit dialogWidget (FWidget* parent = nullptr)
: FDialog{parent}
{ }
private:
void initLayout()
{
setText ("Dialog");
setResizeable();
button.setGeometry (FPoint{1, 1}, FSize{12, 1}, false);
input.setGeometry (FPoint{2, 3}, FSize{12, 1}, false);
// Set dialog geometry and calling adjustSize()
setGeometry (FPoint{25, 5}, FSize{40, 12});
setMinimumSize (FSize{25, 9});
FDialog::initLayout();
}
inline void checkMinValue (int& n)
{
if ( n < 1 ) // Checks and corrects the minimum value
n = 1;
}
void centerDialog()
{
auto x = int((getDesktopWidth() - getWidth()) / 2);
auto y = int((getDesktopHeight() - getHeight()) / 2);
checkMinValue(x);
checkMinValue(y);
setPos (FPoint{x, y}, false);
}
void adjustWidgets()
{
const auto bx = int(getWidth() - button.getWidth() - 3);
const auto by = int(getHeight() - 4);
button.setPos (FPoint{bx, by}, false);
input.setWidth (getWidth() - 4);
const auto ly = int(getHeight() / 2) - 1;
input.setY (ly, false);
}
void adjustSize() override
{
// Calling super class method adjustSize()
FDialog::adjustSize();
// Centers the dialog in the terminal
centerDialog();
// Adjust widgets before drawing
adjustWidgets();
}
void draw() override
{
// Calling super class method draw()
FDialog::draw();
print() << FPoint{3, 3}
<< FColorPair{FColor::Black, FColor::White}
<< "Text on "
<< FColorPair{FColor::Blue, FColor::Yellow}
<< "top";
}
FLineEdit input{"Middle", this};
FButton button{"&Bottom", this};
};
auto main (int argc, char* argv[]) -> int
{
FApplication app(argc, argv);
dialogWidget dialog(&app);
FWidget::setMainWidget(&dialog);
dialog.show();
return app.exec();
}
```
<figure class="image">
<img src="first-steps_size-adjustment.cpp.png" alt="size-adjustment.cpp">
<figcaption>Figure 14. Dynamic layout</figcaption>
</figure>
<br /><br />
*(Note: You can close the window with the mouse,
<kbd>Shift</kbd>+<kbd>F10</kbd> or <kbd>Ctrl</kbd>+<kbd>^</kbd>)*
After entering the source code in *size-adjustment.cpp* you can compile
the above program with gcc:
```bash
g++ size-adjustment.cpp -o size-adjustment -O2 -lfinal -std=c++14
```
Scroll view
-----------
The scroll view of the `FScrollView` class allows users to view content
that is larger than the visible area. The `FScrollView` widget displays
the horizontal and vertical scroll bar by default, only if the content size
requires it. You can controll this behavior by the two methods
`setHorizontalScrollBarMode()` and `setVerticalScrollBarMode()`.
```cpp
setHorizontalScrollBarMode (finalcut::ScrollBarMode);
setVerticalScrollBarMode (finalcut::ScrollBarMode);
```
You pass the scroll bar visibility mode as a value of the enum type
`finalcut::ScrollBarMode`.
```cpp
enum class ScrollBarMode
{
Auto = 0, // Shows a scroll bar when area is larger than viewport
Hidden = 1, // Never shows a scroll bar
Scroll = 2 // Always shows a scroll bar
};
```
You can add widgets to an `FScrollView` object as child objects and place
them (with a widget positioning method) on the scrollable area. If a client
widget gets the focus, it automatically scrolls the viewport to the focused
widget. You can use the methods `scrollTo()`, `scrollToX()`, `scrollToY()`
and `scrollBy()` to set the scroll position of the viewport directly.
The `FButtonGroup` widget uses `FScrollView` to display more buttons
in the frame than the height allows.
**File:** *scrollview.cpp*
```cpp
#include <utility>
#include <final/final.h>
using namespace finalcut;
class dialogWidget : public FDialog
{
public:
explicit dialogWidget (FWidget* parent = nullptr)
: FDialog{parent}
{
scrollview.setGeometry(FPoint{1, 1}, FSize{22, 11});
scrollview.setScrollSize(FSize{60, 27});
// Attention: getColorTheme() requires an initialized terminal
const auto& wc = getColorTheme();
setColor (wc->label_inactive_fg, wc->dialog_bg);
scrollview.clearArea();
FColorPair red (FColor::LightRed, wc->dialog_bg);
FColorPair black (FColor::Black, wc->dialog_bg);
FColorPair cyan (FColor::Cyan, wc->dialog_bg);
static std::vector<direction> d
{
{"NW", FPoint{3, 13}, FPoint{1, 1}, black},
{"N", FPoint{10, 13}, FPoint{21, 1}, red},
{"NE", FPoint{17, 13}, FPoint{41, 1}, black},
{"W", FPoint{3, 15}, FPoint{1, 10}, black},
{"*", FPoint{10, 15}, FPoint{21, 10}, black},
{"E", FPoint{17, 15}, FPoint{41, 10}, black},
{"SW", FPoint{3, 17}, FPoint{1, 19}, black},
{"S", FPoint{10, 17}, FPoint{21, 19}, cyan},
{"SE", FPoint{17, 17}, FPoint{41, 19}, black}
};
for (auto&& b : d)
{
scrollview.print() << std::get<2>(b) + FPoint{10, 5}
<< std::get<3>(b) << std::get<0>(b);
auto edit = new FLineEdit("direction " + std::get<0>(b), &scrollview);
edit->setGeometry(std::get<2>(b) + FPoint{1, 1}, FSize{17, 1});
auto btn = new FButton(std::move(std::get<0>(b)), this);
btn->setGeometry(std::get<1>(b), FSize{4, 1});
btn->unsetShadow();
btn->addCallback
(
"clicked",
this, &dialogWidget::cb_button, std::get<2>(b)
);
}
}
private:
typedef std::tuple<FString, FPoint, FPoint, FColorPair> direction;
void initLayout()
{
setText ("Dialog");
setGeometry (FPoint{28, 2}, FSize{24, 21});
FDialog::initLayout();
}
void cb_button (const FPoint& p)
{
scrollview.scrollTo(p);
}
FScrollView scrollview{this};
};
auto main (int argc, char* argv[]) -> int
{
FApplication app(argc, argv);
app.initTerminal(); // Terminal initialization
dialogWidget dialog(&app);
FWidget::setMainWidget(&dialog);
dialog.show();
return app.exec();
}
```
<figure class="image">
<img src="first-steps_scrollview.cpp.png" alt="scrollview.cpp">
<figcaption>Figure 15. Dialog with a scrolling viewport</figcaption>
</figure>
<br /><br />
*(Note: You can close the window with the mouse,
<kbd>Shift</kbd>+<kbd>F10</kbd> or <kbd>Ctrl</kbd>+<kbd>^</kbd>)*
After entering the source code in *scrollview.cpp* you can compile
the above program with gcc:
```bash
g++ scrollview.cpp -o scrollview -O2 -lfinal -std=c++14
```
|