From 6dbc6676bec048a307b8419c3a7501c3c56f6744 Mon Sep 17 00:00:00 2001 From: thrust26 Date: Thu, 15 Oct 2020 09:40:52 +0200 Subject: [PATCH] allow disabling scroll bars in ListWidget --- src/debugger/gui/CartDebugWidget.cxx | 9 +++- src/debugger/gui/CartRamWidget.cxx | 10 ++++- src/gui/CheckListWidget.cxx | 6 ++- src/gui/ListWidget.cxx | 63 ++++++++++++++++++---------- src/gui/ListWidget.hxx | 3 +- src/gui/StringListWidget.cxx | 11 +++-- src/gui/StringListWidget.hxx | 3 +- 7 files changed, 71 insertions(+), 34 deletions(-) diff --git a/src/debugger/gui/CartDebugWidget.cxx b/src/debugger/gui/CartDebugWidget.cxx index b04000328..778a70c50 100644 --- a/src/debugger/gui/CartDebugWidget.cxx +++ b/src/debugger/gui/CartDebugWidget.cxx @@ -69,11 +69,16 @@ int CartDebugWidget::addBaseInformation(size_t bytes, const string& manufacturer const StringList& sl = bs.stringList(); uInt32 lines = uInt32(sl.size()); if(lines < 3) lines = 3; - if(lines > maxlines) lines = maxlines; + bool useScrollbar = false; + if(lines > maxlines) + { + lines = maxlines; + useScrollbar = true; + } new StaticTextWidget(_boss, _font, x, y + 1, "Description "); myDesc = new StringListWidget(_boss, _nfont, x+lwidth, y - 1, - fwidth, lines * myLineHeight, false); + fwidth, lines * myLineHeight, false, useScrollbar); myDesc->setEditable(false); myDesc->setEnabled(false); myDesc->setList(sl); diff --git a/src/debugger/gui/CartRamWidget.cxx b/src/debugger/gui/CartRamWidget.cxx index 76c8e972a..0ab421df3 100644 --- a/src/debugger/gui/CartRamWidget.cxx +++ b/src/debugger/gui/CartRamWidget.cxx @@ -65,12 +65,18 @@ CartRamWidget::CartRamWidget( StringParser bs(desc, (fwidth - ScrollBarWidget::scrollBarWidth(_font)) / myFontWidth); const StringList& sl = bs.stringList(); uInt32 lines = uInt32(sl.size()); + bool useScrollbar = false; + if(lines < 2) lines = 2; - if(lines > maxlines) lines = maxlines; + if(lines > maxlines) + { + lines = maxlines; + useScrollbar = true; + } new StaticTextWidget(_boss, _font, xpos, ypos + 1, "Description "); myDesc = new StringListWidget(boss, nfont, xpos+lwidth, ypos - 1, - fwidth, lines * myLineHeight, false); + fwidth, lines * myLineHeight, false, useScrollbar); myDesc->setEditable(false); myDesc->setEnabled(false); myDesc->setList(sl); diff --git a/src/gui/CheckListWidget.cxx b/src/gui/CheckListWidget.cxx index 1e6db844a..f2cba25b6 100644 --- a/src/gui/CheckListWidget.cxx +++ b/src/gui/CheckListWidget.cxx @@ -141,8 +141,10 @@ void CheckListWidget::drawWidget(bool hilite) } // Only draw the caret while editing, and if it's in the current viewport - if(_editMode && (_selectedItem >= _scrollBar->_currentPos) && - (_selectedItem < _scrollBar->_currentPos + _rows)) + if(_editMode && + (!(_useScrollbar) || + (_selectedItem >= _scrollBar->_currentPos) && + (_selectedItem < _scrollBar->_currentPos + _rows))) drawCaret(); } diff --git a/src/gui/ListWidget.cxx b/src/gui/ListWidget.cxx index 1ac71eb35..1d9d8ee3c 100644 --- a/src/gui/ListWidget.cxx +++ b/src/gui/ListWidget.cxx @@ -26,8 +26,9 @@ // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ListWidget::ListWidget(GuiObject* boss, const GUI::Font& font, - int x, int y, int w, int h) - : EditableWidget(boss, font, x, y, 16, 16) + int x, int y, int w, int h, bool useScrollbar) + : EditableWidget(boss, font, x, y, 16, 16), + _useScrollbar(useScrollbar) { _flags = Widget::FLAG_ENABLED | Widget::FLAG_CLEARBG | Widget::FLAG_RETAIN_FOCUS; _bgcolor = kWidColor; @@ -39,13 +40,18 @@ ListWidget::ListWidget(GuiObject* boss, const GUI::Font& font, _rows = h / _lineHeight; // Set real dimensions - _w = w - ScrollBarWidget::scrollBarWidth(_font); _h = h + 2; // Create scrollbar and attach to the list - _scrollBar = new ScrollBarWidget(boss, font, _x + _w, _y, - ScrollBarWidget::scrollBarWidth(_font), _h); - _scrollBar->setTarget(this); + if(_useScrollbar) + { + _w = w - ScrollBarWidget::scrollBarWidth(_font); + _scrollBar = new ScrollBarWidget(boss, font, _x + _w, _y, + ScrollBarWidget::scrollBarWidth(_font), _h); + _scrollBar->setTarget(this); + } + else + _w = w - 1; } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -168,10 +174,13 @@ void ListWidget::recalc() _editMode = false; - _scrollBar->_numEntries = int(_list.size()); - _scrollBar->_entriesPerPage = _rows; - // disable scrollbar if no longer necessary - scrollBarRecalc(); + if(_useScrollbar) + { + _scrollBar->_numEntries = int(_list.size()); + _scrollBar->_entriesPerPage = _rows; + // disable scrollbar if no longer necessary + scrollBarRecalc(); + } // Reset to normal data entry abortEditMode(); @@ -182,9 +191,12 @@ void ListWidget::recalc() // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void ListWidget::scrollBarRecalc() { - _scrollBar->_currentPos = _currentPos; - _scrollBar->recalc(); - sendCommand(ListWidget::kScrolledCmd, _currentPos, _id); + if(_useScrollbar) + { + _scrollBar->_currentPos = _currentPos; + _scrollBar->recalc(); + sendCommand(ListWidget::kScrolledCmd, _currentPos, _id); + } } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -230,7 +242,8 @@ void ListWidget::handleMouseUp(int x, int y, MouseButton b, int clickCount) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void ListWidget::handleMouseWheel(int x, int y, int direction) { - _scrollBar->handleMouseWheel(x, y, direction); + if(_useScrollbar) + _scrollBar->handleMouseWheel(x, y, direction); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -354,8 +367,11 @@ bool ListWidget::handleEvent(Event::Type e) if (_selectedItem != oldSelectedItem) { - _scrollBar->draw(); - scrollToSelected(); + if(_useScrollbar) + { + _scrollBar->draw(); + scrollToSelected(); + } sendCommand(ListWidget::kSelectionChangedCmd, _selectedItem, _id); } @@ -408,14 +424,17 @@ void ListWidget::scrollToCurrent(int item) else if (_currentPos + _rows > int(_list.size())) _currentPos = int(_list.size()) - _rows; - int oldScrollPos = _scrollBar->_currentPos; - _scrollBar->_currentPos = _currentPos; - _scrollBar->recalc(); + if(_useScrollbar) + { + int oldScrollPos = _scrollBar->_currentPos; + _scrollBar->_currentPos = _currentPos; + _scrollBar->recalc(); - setDirty(); + setDirty(); - if(oldScrollPos != _currentPos) - sendCommand(ListWidget::kScrolledCmd, _currentPos, _id); + if(oldScrollPos != _currentPos) + sendCommand(ListWidget::kScrolledCmd, _currentPos, _id); + } } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/gui/ListWidget.hxx b/src/gui/ListWidget.hxx index 75d2600ae..96d4f036c 100644 --- a/src/gui/ListWidget.hxx +++ b/src/gui/ListWidget.hxx @@ -42,7 +42,7 @@ class ListWidget : public EditableWidget public: ListWidget(GuiObject* boss, const GUI::Font& font, - int x, int y, int w, int h); + int x, int y, int w, int h, bool useScrollbar = true); ~ListWidget() override = default; int rows() const { return _rows; } @@ -100,6 +100,7 @@ class ListWidget : public EditableWidget int _selectedItem{-1}; int _highlightedItem{-1}; bool _editMode{false}; + bool _useScrollbar{true}; ScrollBarWidget* _scrollBar{nullptr}; diff --git a/src/gui/StringListWidget.cxx b/src/gui/StringListWidget.cxx index 0c0a8ba08..ba112ff46 100644 --- a/src/gui/StringListWidget.cxx +++ b/src/gui/StringListWidget.cxx @@ -24,8 +24,9 @@ // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - StringListWidget::StringListWidget(GuiObject* boss, const GUI::Font& font, - int x, int y, int w, int h, bool hilite) - : ListWidget(boss, font, x, y, w, h), + int x, int y, int w, int h, bool hilite, + bool useScrollbar) + : ListWidget(boss, font, x, y, w, h, useScrollbar), _hilite(hilite) { _bgcolorlo = kDlgColor; @@ -107,8 +108,10 @@ void StringListWidget::drawWidget(bool hilite) } // Only draw the caret while editing, and if it's in the current viewport - if(_editMode && (_selectedItem >= _scrollBar->_currentPos) && - (_selectedItem < _scrollBar->_currentPos + _rows)) + if(_editMode && + (!(_useScrollbar) || + (_selectedItem >= _scrollBar->_currentPos) && + (_selectedItem < _scrollBar->_currentPos + _rows))) drawCaret(); } diff --git a/src/gui/StringListWidget.hxx b/src/gui/StringListWidget.hxx index 490c6b6a2..eed279aeb 100644 --- a/src/gui/StringListWidget.hxx +++ b/src/gui/StringListWidget.hxx @@ -25,7 +25,8 @@ class StringListWidget : public ListWidget { public: StringListWidget(GuiObject* boss, const GUI::Font& font, - int x, int y, int w, int h, bool hilite = true); + int x, int y, int w, int h, bool hilite = true, + bool useScrollbar = true); ~StringListWidget() override = default; void setList(const StringList& list);