void TextBox::scrollToCaret() { Widget *par = getParent(); if (par == NULL) { return; } ScrollArea* scrollArea = dynamic_cast<ScrollArea *>(par); if (scrollArea != NULL) { Rectangle scroll; scroll.x = getFont()->getWidth(mTextRows[mCaretRow].substr(0, mCaretColumn)); scroll.y = getFont()->getHeight() * mCaretRow; scroll.width = 6; scroll.height = getFont()->getHeight() + 2; // add 2 for some extra space scrollArea->scrollToRectangle(scroll); } }
void ListBox::setSelected(int selected) { if (mListModel == NULL) { mSelected = -1; } else { if (selected < 0) { mSelected = -1; } else if (selected >= mListModel->getNumberOfElements()) { mSelected = mListModel->getNumberOfElements() - 1; } else { mSelected = selected; } Widget *par = getParent(); if (par == NULL) { return; } ScrollArea* scrollArea = dynamic_cast<ScrollArea *>(par); if (scrollArea != NULL) { Rectangle scroll; scroll.y = getFont()->getHeight() * mSelected; scroll.height = getFont()->getHeight(); scrollArea->scrollToRectangle(scroll); } } setDirty(true); }