1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-07-22 17:18:39 +00:00

Formspec: textarea with scrollbar improvements

Increase scrollrate depending on fontsize

Scroll on mousewheel

Allow scrolling and marking text on non writable textareas

Update lua api about readonly mode

Show scrollbar if text overflows
This commit is contained in:
adrido 2017-10-09 06:57:18 +02:00 committed by Loic Blot
parent 9b8fa99fe3
commit e6e5fa3bf8
No known key found for this signature in database
GPG key ID: EFAA458E8C153987
5 changed files with 46 additions and 30 deletions

View file

@ -260,7 +260,7 @@ void intlGUIEditBox::setTextAlignment(EGUI_ALIGNMENT horizontal, EGUI_ALIGNMENT
//! called if an event happened.
bool intlGUIEditBox::OnEvent(const SEvent& event)
{
if (IsEnabled && m_writable)
if (IsEnabled)
{
switch(event.EventType)
@ -780,7 +780,7 @@ void intlGUIEditBox::draw()
if (Border)
{
if (m_writable) {
if (m_writable) {
skin->draw3DSunkenPane(this, skin->getColor(EGDC_WINDOW),
false, true, FrameRect, &AbsoluteClippingRect);
}
@ -944,8 +944,7 @@ void intlGUIEditBox::draw()
font->getKerningWidth(L"_", CursorPos-startPos > 0 ? &((*txtLine)[CursorPos-startPos-1]) : 0);
if (m_writable) {
if (focus && (porting::getTimeMs() - BlinkStartTime) % 700 < 350)
{
if (focus && (porting::getTimeMs() - BlinkStartTime) % 700 < 350) {
setTextRect(cursorLine);
CurrentTextRect.UpperLeftCorner.X += charcursorpos;
@ -1086,6 +1085,14 @@ bool intlGUIEditBox::processMouse(const SEvent& event)
calculateScrollPos();
return true;
}
break;
case EMIE_MOUSE_WHEEL:
if (m_vscrollbar) {
s32 pos = m_vscrollbar->getPos();
s32 step = m_vscrollbar->getSmallStep();
m_vscrollbar->setPos(pos - event.MouseInput.Wheel * step);
}
break;
default:
break;
}
@ -1433,9 +1440,8 @@ void intlGUIEditBox::calculateScrollPos()
VScrollPos = 0;
// todo: adjust scrollbar
if (m_vscrollbar) {
if (m_vscrollbar)
m_vscrollbar->setPos(VScrollPos);
}
}
//! set text markers
@ -1467,20 +1473,31 @@ void intlGUIEditBox::sendGuiEvent(EGUI_EVENT_TYPE type)
//! Create a vertical scrollbar
void intlGUIEditBox::createVScrollBar()
{
s32 fontHeight = 1;
if (OverrideFont) {
fontHeight = OverrideFont->getDimension(L"").Height;
} else {
if (IGUISkin* skin = Environment->getSkin()) {
if (IGUIFont* font = skin->getFont()) {
fontHeight = font->getDimension(L"").Height;
}
}
}
irr::core::rect<s32> scrollbarrect = FrameRect;
scrollbarrect.UpperLeftCorner.X += FrameRect.getWidth() - m_scrollbar_width;
m_vscrollbar = Environment->addScrollBar(false, scrollbarrect, getParent(), getID());
m_vscrollbar->setVisible(false);
m_vscrollbar->setSmallStep(1);
m_vscrollbar->setLargeStep(1);
m_vscrollbar->setSmallStep(3 * fontHeight);
m_vscrollbar->setLargeStep(10 * fontHeight);
}
//! Update the vertical scrollbar (visibilty & scroll position)
void intlGUIEditBox::updateVScrollBar()
{
if (!m_vscrollbar) {
if (!m_vscrollbar)
return;
}
// OnScrollBarChanged(...)
if (m_vscrollbar->getPos() != VScrollPos) {