diff --git a/ChangeLog b/ChangeLog index 5c15cb1e..e1f2767b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,6 @@ +2019-03-24 Markus Gans + * Add a "scroll view" chapter to the first steps document + 2019-02-28 Markus Gans * Add an lambda expression callback example to the first steps document @@ -10,7 +13,7 @@ and FLineEdit input filters 2019-02-07 Markus Gans - * 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 * Printing an FColorPair object can change the foreground and diff --git a/doc/Makefile.am b/doc/Makefile.am index 90b9f8dd..5843c239 100644 --- a/doc/Makefile.am +++ b/doc/Makefile.am @@ -9,7 +9,9 @@ EXTRA_DIST = \ class-diagram.txt \ console_codes-manual.sh \ console_ioctl-manual.sh \ + faq.md \ fileopen-dialog.png \ + first-steps.md \ ncurses.supp \ newfont1.png \ newfont2.png \ @@ -29,7 +31,9 @@ doc_DATA = \ class-diagram.txt \ console_codes-manual.sh \ console_ioctl-manual.sh \ + faq.md \ fileopen-dialog.png \ + first-steps.md \ ncurses.supp \ newfont1.png \ newfont2.png \ diff --git a/doc/first-steps.md b/doc/first-steps.md index 136d7a99..6c56a369 100644 --- a/doc/first-steps.md +++ b/doc/first-steps.md @@ -534,7 +534,7 @@ int main (int argc, char* argv[]) After entering the source code in *callback-lambda.cpp* you can compile the above program with gcc: ```cpp -g++ -O2 -lfinal callback-lambda.cpp -o callback-lambda +g++ -O2 -lfinal -std=c++11 callback-lambda.cpp -o callback-lambda ```   @@ -845,3 +845,124 @@ the above program with gcc: ```cpp 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 +#include + +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 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(&std::get<2>(b)) + ); + }; + } + + private: + typedef std::tuple direction; + + void cb_button (FWidget*, FDataPtr data) + { + FPoint* p = static_cast(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, +Shift+F10 or Ctrl+^)* + + +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 +``` diff --git a/src/flineedit.cpp b/src/flineedit.cpp index b60bb43a..184e92e3 100644 --- a/src/flineedit.cpp +++ b/src/flineedit.cpp @@ -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; adjustLabel(); } +//---------------------------------------------------------------------- +void FLineEdit::setGeometry ( const FPoint& pos, const FSize& size + , bool adjust ) +{ + FWidget::setGeometry(pos, size, adjust); + keyEnd(); +} //---------------------------------------------------------------------- void FLineEdit::hide() { diff --git a/src/flistbox.cpp b/src/flistbox.cpp index 2ce836d3..51eb7490 100644 --- a/src/flistbox.cpp +++ b/src/flistbox.cpp @@ -161,7 +161,7 @@ void FListBox::showInsideBrackets ( std::size_t index //---------------------------------------------------------------------- void FListBox::setGeometry ( const FPoint& pos, const FSize& size - , bool adjust) + , bool adjust ) { // Set the widget geometry diff --git a/src/flistview.cpp b/src/flistview.cpp index c1946e3d..e11eb8f6 100644 --- a/src/flistview.cpp +++ b/src/flistview.cpp @@ -1623,11 +1623,13 @@ void FListView::drawListLine ( const FListViewItem* item if ( tree_view && col == 1 ) { - static constexpr std::size_t checkbox_space = 4; width -= (indent + 1); if ( item->isCheckable() ) + { + static constexpr std::size_t checkbox_space = 4; width -= checkbox_space; + } } // Insert alignment spaces diff --git a/src/include/final/flineedit.h b/src/include/final/flineedit.h index fd58ffed..b108d673 100644 --- a/src/include/final/flineedit.h +++ b/src/include/final/flineedit.h @@ -75,6 +75,9 @@ class FLineEdit : public FWidget label_left = 1 }; + // Using-declaration + using FWidget::setGeometry; + // Constructor explicit FLineEdit (FWidget* = nullptr); explicit FLineEdit (const FString&, FWidget* = nullptr); @@ -116,7 +119,9 @@ class FLineEdit : public FWidget void setMaxLength (std::size_t); void setCursorPosition (std::size_t); 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() override; virtual bool unsetEnable() override;