class ffw::GuiScrollable
Class List > ffw :: GuiScrollable
Create a scrollable widget. More...
Inherits the following classes: ffw::GuiWidget
Inherited by the following classes: ffw::GuiScrollableLayout, ffw::GuiScrollableTextInput
Classes
Type | Name |
---|---|
struct | Style |
Public Functions
Type | Name |
---|---|
GuiScrollable (GuiWindow * context, GuiWidget * widget, bool hori, bool vert) | |
virtual | ~GuiScrollable () = default |
virtual ffw::Pointf | getMinimumWrapSize () override |
void | setScrollbarThickness (float px) |
void | setScrollValues (float hori, float vert) |
ffw::Pointf | getScrollValues () const |
float | getScrollbarThickness () const |
ffw::GuiScrollBar * | getVscroll () |
const ffw::GuiScrollBar * | getVscroll () const |
ffw::GuiScrollBar * | getHscroll () |
const ffw::GuiScrollBar * | getHscroll () const |
void | setScrollIncrements (const float inc) |
float | getScrollIncrements () const |
void | setStyle (const GuiScrollable::Style * style, bool defaults = false) |
Protected Functions
Type | Name |
---|---|
ffw::GuiWidget * | getInnerAsWidget () |
const ffw::GuiWidget * | getInnerAsWidget () const |
Detailed Description
This widget accepts any kind of widgets. If the inner widget exceeds the size of the scrollable widget, the scrollbars will enable. Using the scrollbars, the inner widget is moved up or down, or sideways. You can configure which scrollbars are meant to be shown via the constructor. A class ffw::GuiScrollableLayout is available which uses ffw::GuiScrollable with ffw::GuiLayout as the inner widget.
auto gui = ffw::GuiWindowNanoVG(nvg);
auto root = gui.getLayout();
// Creates a verticall layout with a scrollbar on the right.
// 3rd parameter -> bottom scrollbar
// 4th parameter -> right scrollbar
auto scrollable = new ffw::GuiScrollableLayout(&gui, ffw::GuiOrientation::VERTICAL, false, true);
scrollable->setSize(ffw::guiPercent(100.0f), ffw::guiPercent(100.0f));
// Get the inner widget that will be scrolled.
// In this case it's the layout.
auto layout = scrollable->getInner();
const auto goDown = new ffw::GuiButton(&gui, "Click to scroll to 50%");
goDown->addEventCallback([=](ffw::GuiEvent e) {
// Returns the maximum scroll values.
// Note that the returned type is ffw::Pointf and the x
// component (minimum scrollbar range) is always going to be zero!
// The y component (maximum scroll range) is what you need.
const auto max = scrollable->getVscroll()->getRange();
// Scroll down 50%
// This only works after gui.update() has been called
// at least once! The update() function will update
// the scrollbars.
// Therefore we are putting this in a button callback.
scrollable->getVscroll()->setValue(max.y / 2.0f);
}, ffw::GuiEventType::ACTION);
layout->addWidget(goDown);
for (auto i = 0; i < 32; i++) {
const auto button = new ffw::GuiButton(&gui, "Button #" + std::to_string(i));
layout->addWidget(button);
}
root->addWidget(scrollable);
// Do not free the created widgets! They will be deleted by the gui window!
while(true){
// Render the gui
}
Public Functions Documentation
function GuiScrollable
ffw::GuiScrollable::GuiScrollable (
GuiWindow * context,
GuiWidget * widget,
bool hori,
bool vert
)
function ~GuiScrollable
virtual ffw::GuiScrollable::~GuiScrollable () = default
function getMinimumWrapSize
virtual ffw::Pointf ffw::GuiScrollable::getMinimumWrapSize ()
Implements GuiWidget::getMinimumWrapSize
function setScrollbarThickness
void ffw::GuiScrollable::setScrollbarThickness (
float px
)
function setScrollValues
void ffw::GuiScrollable::setScrollValues (
float hori,
float vert
)
function getScrollValues
ffw::Pointf ffw::GuiScrollable::getScrollValues () const
function getScrollbarThickness
float ffw::GuiScrollable::getScrollbarThickness () const
function getVscroll (1/2)
ffw::GuiScrollBar * ffw::GuiScrollable::getVscroll ()
function getVscroll (2/2)
const ffw::GuiScrollBar * ffw::GuiScrollable::getVscroll () const
function getHscroll (1/2)
ffw::GuiScrollBar * ffw::GuiScrollable::getHscroll ()
function getHscroll (2/2)
const ffw::GuiScrollBar * ffw::GuiScrollable::getHscroll () const
function setScrollIncrements
void ffw::GuiScrollable::setScrollIncrements (
const float inc
)
function getScrollIncrements
float ffw::GuiScrollable::getScrollIncrements () const
function setStyle
void ffw::GuiScrollable::setStyle (
const GuiScrollable::Style * style,
bool defaults = false
)
Protected Functions Documentation
function getInnerAsWidget (1/2)
ffw::GuiWidget * ffw::GuiScrollable::getInnerAsWidget ()
function getInnerAsWidget (2/2)
const ffw::GuiWidget * ffw::GuiScrollable::getInnerAsWidget () const
The documentation for this class was generated from the following file: include/ffw/gui/guiscrollable.h