Skip to content

Commit

Permalink
[GuiAdvancedScrollText] Base scrollbar click change on text size (#2021)
Browse files Browse the repository at this point in the history
Co-authored-by: oznogon <[email protected]>
  • Loading branch information
csibbitt and oznogon authored Oct 18, 2023
1 parent 6eb8449 commit 9934dda
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
10 changes: 10 additions & 0 deletions src/gui/gui2_advancedscrolltext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ GuiAdvancedScrollText::GuiAdvancedScrollText(GuiContainer* owner, string id)
{
scrollbar = new GuiScrollbar(this, id + "_SCROLL", 0, 1, 0, nullptr);
scrollbar->setPosition(0, 0, sp::Alignment::TopRight)->setSize(50, GuiElement::GuiSizeMax);
// Calculate scrolling a one-line entry by scrollbar arrow buttons.
scrollbar->setClickChange(sp::RenderTarget::getDefaultFont()->prepare("1", 32, text_size, rect.size, sp::Alignment::TopLeft).getUsedAreaSize().y);
}

GuiAdvancedScrollText* GuiAdvancedScrollText::addEntry(string prefix, string text, glm::u8vec4 color, unsigned int seq)
Expand All @@ -23,6 +25,13 @@ unsigned int GuiAdvancedScrollText::getEntryCount() const
return entries.size();
}

GuiAdvancedScrollText* GuiAdvancedScrollText::setTextSize(float text_size)
{
this->text_size = std::max(1.0F, text_size);
scrollbar->setClickChange(sp::RenderTarget::getDefaultFont()->prepare("1", 32, text_size, rect.size, sp::Alignment::TopLeft).getUsedAreaSize().y);
return this;
}

string GuiAdvancedScrollText::getEntryText(int index) const
{
if (index < 0 || index >= static_cast<int>(getEntryCount()))
Expand Down Expand Up @@ -126,5 +135,6 @@ void GuiAdvancedScrollText::onDraw(sp::RenderTarget& renderer)
if (auto_scroll_down)
scrollbar->setValue(scrollbar->getValue() + diff);
}

scrollbar->setVisible(rect.size.y > 100);
}
2 changes: 1 addition & 1 deletion src/gui/gui2_advancedscrolltext.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class GuiAdvancedScrollText : public GuiElement
GuiAdvancedScrollText* disableAutoScrollDown() { auto_scroll_down = false; return this; }

GuiAdvancedScrollText* addEntry(string prefix, string text, glm::u8vec4 color, unsigned int seq);
GuiAdvancedScrollText* setTextSize(float text_size) { this->text_size = text_size; return this; }
GuiAdvancedScrollText* setTextSize(float text_size);

unsigned int getEntryCount() const;
string getEntryText(int index) const;
Expand Down

0 comments on commit 9934dda

Please sign in to comment.