Add a "scroll view" chapter to the first steps document

This commit is contained in:
Markus Gans 2019-03-24 20:15:17 +01:00
parent 93f464f30e
commit 439b8310ef
7 changed files with 148 additions and 6 deletions

View File

@ -1,3 +1,6 @@
2019-03-24 Markus Gans <guru.mail@muenster.de>
* Add a "scroll view" chapter to the first steps document
2019-02-28 Markus Gans <guru.mail@muenster.de> 2019-02-28 Markus Gans <guru.mail@muenster.de>
* Add an lambda expression callback example to the first steps document * Add an lambda expression callback example to the first steps document
@ -10,7 +13,7 @@
and FLineEdit input filters and FLineEdit input filters
2019-02-07 Markus Gans <guru.mail@muenster.de> 2019-02-07 Markus Gans <guru.mail@muenster.de>
* Add a "dynamic layout" Chapter into the first steps document * Add a "dynamic layout" chapter into the first steps document
2019-01-30 Markus Gans <guru.mail@muenster.de> 2019-01-30 Markus Gans <guru.mail@muenster.de>
* Printing an FColorPair object can change the foreground and * Printing an FColorPair object can change the foreground and

View File

@ -9,7 +9,9 @@ EXTRA_DIST = \
class-diagram.txt \ class-diagram.txt \
console_codes-manual.sh \ console_codes-manual.sh \
console_ioctl-manual.sh \ console_ioctl-manual.sh \
faq.md \
fileopen-dialog.png \ fileopen-dialog.png \
first-steps.md \
ncurses.supp \ ncurses.supp \
newfont1.png \ newfont1.png \
newfont2.png \ newfont2.png \
@ -29,7 +31,9 @@ doc_DATA = \
class-diagram.txt \ class-diagram.txt \
console_codes-manual.sh \ console_codes-manual.sh \
console_ioctl-manual.sh \ console_ioctl-manual.sh \
faq.md \
fileopen-dialog.png \ fileopen-dialog.png \
first-steps.md \
ncurses.supp \ ncurses.supp \
newfont1.png \ newfont1.png \
newfont2.png \ newfont2.png \

View File

@ -534,7 +534,7 @@ int main (int argc, char* argv[])
After entering the source code in *callback-lambda.cpp* you can compile After entering the source code in *callback-lambda.cpp* you can compile
the above program with gcc: the above program with gcc:
```cpp ```cpp
g++ -O2 -lfinal callback-lambda.cpp -o callback-lambda g++ -O2 -lfinal -std=c++11 callback-lambda.cpp -o callback-lambda
``` ```
&nbsp; &nbsp;
@ -845,3 +845,124 @@ the above program with gcc:
```cpp ```cpp
g++ -O2 -lfinal -std=c++11 size-adjustment.cpp -o size-adjustment g++ -O2 -lfinal -std=c++11 size-adjustment.cpp -o size-adjustment
``` ```
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 (fc::scrollBarMode)
setVerticalScrollBarMode (fc::scrollBarMode)
```
You pass the scroll bar visibility mode as a value of the enum type
`fc::scrollBarMode`.
```cpp
enum 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)
{
setText ("Dialog");
setGeometry (FPoint(28, 2), FSize(24, 21));
scrollview.setGeometry(FPoint(1, 1), FSize(22, 11));
scrollview.setScrollSize(FSize(60, 27));
setColor (wc.label_inactive_fg, wc.dialog_bg);
scrollview.clearArea();
FColorPair red (fc::LightRed, wc.dialog_bg);
FColorPair black (fc::Black, wc.dialog_bg);
FColorPair cyan (fc::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::get<0>(b), this);
btn->setGeometry(std::get<1>(b), FSize(4, 1));
btn->unsetShadow();
btn->addCallback
(
"clicked",
F_METHOD_CALLBACK (this, &dialogWidget::cb_button),
static_cast<FDataPtr>(&std::get<2>(b))
);
};
}
private:
typedef std::tuple<FString, FPoint, FPoint, FColorPair> direction;
void cb_button (FWidget*, FDataPtr data)
{
FPoint* p = static_cast<FPoint*>(data);
scrollview.scrollTo(*p);
}
FScrollView scrollview{this};
};
int main (int argc, char* argv[])
{
FApplication app(argc, argv);
dialogWidget dialog(&app);
app.setMainWidget(&dialog);
dialog.show();
return app.exec();
}
```
*(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:
```cpp
g++ -O2 -lfinal -std=c++11 scrollview.cpp -o scrollview
```

View File

@ -292,12 +292,19 @@ void FLineEdit::setLabelText (const FString& ltxt)
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FLineEdit::setLabelOrientation(const label_o o) void FLineEdit::setLabelOrientation (const label_o o)
{ {
label_orientation = o; label_orientation = o;
adjustLabel(); adjustLabel();
} }
//----------------------------------------------------------------------
void FLineEdit::setGeometry ( const FPoint& pos, const FSize& size
, bool adjust )
{
FWidget::setGeometry(pos, size, adjust);
keyEnd();
}
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FLineEdit::hide() void FLineEdit::hide()
{ {

View File

@ -161,7 +161,7 @@ void FListBox::showInsideBrackets ( std::size_t index
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FListBox::setGeometry ( const FPoint& pos, const FSize& size void FListBox::setGeometry ( const FPoint& pos, const FSize& size
, bool adjust) , bool adjust )
{ {
// Set the widget geometry // Set the widget geometry

View File

@ -1623,11 +1623,13 @@ void FListView::drawListLine ( const FListViewItem* item
if ( tree_view && col == 1 ) if ( tree_view && col == 1 )
{ {
static constexpr std::size_t checkbox_space = 4;
width -= (indent + 1); width -= (indent + 1);
if ( item->isCheckable() ) if ( item->isCheckable() )
{
static constexpr std::size_t checkbox_space = 4;
width -= checkbox_space; width -= checkbox_space;
}
} }
// Insert alignment spaces // Insert alignment spaces

View File

@ -75,6 +75,9 @@ class FLineEdit : public FWidget
label_left = 1 label_left = 1
}; };
// Using-declaration
using FWidget::setGeometry;
// Constructor // Constructor
explicit FLineEdit (FWidget* = nullptr); explicit FLineEdit (FWidget* = nullptr);
explicit FLineEdit (const FString&, FWidget* = nullptr); explicit FLineEdit (const FString&, FWidget* = nullptr);
@ -116,7 +119,9 @@ class FLineEdit : public FWidget
void setMaxLength (std::size_t); void setMaxLength (std::size_t);
void setCursorPosition (std::size_t); void setCursorPosition (std::size_t);
void setLabelText (const FString&); void setLabelText (const FString&);
void setLabelOrientation(const label_o); void setLabelOrientation (const label_o);
virtual void setGeometry ( const FPoint&, const FSize&
, bool = true ) override;
virtual bool setEnable(bool) override; virtual bool setEnable(bool) override;
virtual bool setEnable() override; virtual bool setEnable() override;
virtual bool unsetEnable() override; virtual bool unsetEnable() override;