mirror of
https://github.com/luanti-org/luanti.git
synced 2025-09-30 19:22:14 +00:00
IrrlichtMt: import scrollbar changes
This commit is contained in:
parent
70fbef112c
commit
ecabcb5c58
4 changed files with 64 additions and 0 deletions
|
@ -10,6 +10,9 @@
|
||||||
|
|
||||||
namespace gui
|
namespace gui
|
||||||
{
|
{
|
||||||
|
|
||||||
|
class IGUIScrollBar;
|
||||||
|
|
||||||
class CGUIEditBox : public IGUIEditBox
|
class CGUIEditBox : public IGUIEditBox
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
@ -157,6 +160,8 @@ protected:
|
||||||
void sendGuiEvent(EGUI_EVENT_TYPE type);
|
void sendGuiEvent(EGUI_EVENT_TYPE type);
|
||||||
//! set text markers
|
//! set text markers
|
||||||
void setTextMarkers(s32 begin, s32 end);
|
void setTextMarkers(s32 begin, s32 end);
|
||||||
|
//! update the vertical scrollBar (visibilty & position)
|
||||||
|
void updateVScrollBar();
|
||||||
|
|
||||||
bool processKey(const SEvent &event);
|
bool processKey(const SEvent &event);
|
||||||
//! KEY_LEFT / KEY_RIGHT inputs
|
//! KEY_LEFT / KEY_RIGHT inputs
|
||||||
|
@ -193,6 +198,8 @@ protected:
|
||||||
s32 CursorPos;
|
s32 CursorPos;
|
||||||
s32 HScrollPos, VScrollPos; // scroll position in characters
|
s32 HScrollPos, VScrollPos; // scroll position in characters
|
||||||
u32 Max;
|
u32 Max;
|
||||||
|
u32 VScrollBarWidth = 0;
|
||||||
|
IGUIScrollBar *VScrollBar = nullptr;
|
||||||
|
|
||||||
bool WordWrap = false,
|
bool WordWrap = false,
|
||||||
MultiLine = false,
|
MultiLine = false,
|
||||||
|
|
|
@ -51,6 +51,11 @@ public:
|
||||||
|
|
||||||
//! sets the current position of the scrollbar
|
//! sets the current position of the scrollbar
|
||||||
virtual void setPos(s32 pos) = 0;
|
virtual void setPos(s32 pos) = 0;
|
||||||
|
|
||||||
|
//! For automatic thumb scaling
|
||||||
|
/** Sets the full height (e.g. content to scroll), in pixels.
|
||||||
|
Set to 0 to disable (default). */
|
||||||
|
virtual void setPageSize(s32 size) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // end namespace gui
|
} // end namespace gui
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
#include "IGUISkin.h"
|
#include "IGUISkin.h"
|
||||||
#include "IGUIEnvironment.h"
|
#include "IGUIEnvironment.h"
|
||||||
#include "IGUIFont.h"
|
#include "IGUIFont.h"
|
||||||
|
#include "IGUIScrollBar.h"
|
||||||
#include "IVideoDriver.h"
|
#include "IVideoDriver.h"
|
||||||
#include "rect.h"
|
#include "rect.h"
|
||||||
#include "os.h"
|
#include "os.h"
|
||||||
|
@ -1512,4 +1513,52 @@ void CGUIEditBox::sendGuiEvent(EGUI_EVENT_TYPE type)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CGUIEditBox::updateVScrollBar()
|
||||||
|
{
|
||||||
|
if (!VScrollBar) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// OnScrollBarChanged(...)
|
||||||
|
if (VScrollBar->getPos() != VScrollPos) {
|
||||||
|
s32 deltaScrollY = VScrollBar->getPos() - VScrollPos;
|
||||||
|
CurrentTextRect.UpperLeftCorner.Y -= deltaScrollY;
|
||||||
|
CurrentTextRect.LowerRightCorner.Y -= deltaScrollY;
|
||||||
|
|
||||||
|
s32 scrollymax = getTextDimension().Height - FrameRect.getHeight();
|
||||||
|
if (scrollymax != VScrollBar->getMax()) {
|
||||||
|
// manage a newline or a deleted line
|
||||||
|
VScrollBar->setMax(scrollymax);
|
||||||
|
VScrollBar->setPageSize(s32(getTextDimension().Height));
|
||||||
|
calculateScrollPos();
|
||||||
|
} else {
|
||||||
|
// manage a newline or a deleted line
|
||||||
|
VScrollPos = VScrollBar->getPos();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// check if a vertical scrollbar is needed ?
|
||||||
|
if (getTextDimension().Height > (u32)FrameRect.getHeight()) {
|
||||||
|
FrameRect.LowerRightCorner.X -= VScrollBarWidth;
|
||||||
|
|
||||||
|
s32 scrollymax = getTextDimension().Height - FrameRect.getHeight();
|
||||||
|
if (scrollymax != VScrollBar->getMax()) {
|
||||||
|
VScrollBar->setMax(scrollymax);
|
||||||
|
VScrollBar->setPageSize(s32(getTextDimension().Height));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!VScrollBar->isVisible()) {
|
||||||
|
VScrollBar->setVisible(true);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (VScrollBar->isVisible()) {
|
||||||
|
VScrollBar->setVisible(false);
|
||||||
|
VScrollPos = 0;
|
||||||
|
VScrollBar->setPos(0);
|
||||||
|
VScrollBar->setMax(1);
|
||||||
|
VScrollBar->setPageSize(s32(getTextDimension().Height));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
} // end namespace gui
|
} // end namespace gui
|
||||||
|
|
|
@ -59,6 +59,9 @@ public:
|
||||||
//! sets the position of the scrollbar
|
//! sets the position of the scrollbar
|
||||||
void setPos(s32 pos) override;
|
void setPos(s32 pos) override;
|
||||||
|
|
||||||
|
//! sets the content height to scroll
|
||||||
|
void setPageSize(s32 size) override { }
|
||||||
|
|
||||||
//! updates the rectangle
|
//! updates the rectangle
|
||||||
void updateAbsolutePosition() override;
|
void updateAbsolutePosition() override;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue