mirror of
				https://github.com/luanti-org/luanti.git
				synced 2025-11-04 01:05:48 +01:00 
			
		
		
		
	IrrlichtMt: import scrollbar changes
This commit is contained in:
		@@ -10,6 +10,9 @@
 | 
			
		||||
 | 
			
		||||
namespace gui
 | 
			
		||||
{
 | 
			
		||||
 | 
			
		||||
class IGUIScrollBar;
 | 
			
		||||
 | 
			
		||||
class CGUIEditBox : public IGUIEditBox
 | 
			
		||||
{
 | 
			
		||||
public:
 | 
			
		||||
@@ -157,6 +160,8 @@ protected:
 | 
			
		||||
	void sendGuiEvent(EGUI_EVENT_TYPE type);
 | 
			
		||||
	//! set text markers
 | 
			
		||||
	void setTextMarkers(s32 begin, s32 end);
 | 
			
		||||
	//! update the vertical scrollBar (visibilty & position)
 | 
			
		||||
	void updateVScrollBar();
 | 
			
		||||
 | 
			
		||||
	bool processKey(const SEvent &event);
 | 
			
		||||
	//! KEY_LEFT / KEY_RIGHT inputs
 | 
			
		||||
@@ -193,6 +198,8 @@ protected:
 | 
			
		||||
	s32 CursorPos;
 | 
			
		||||
	s32 HScrollPos, VScrollPos; // scroll position in characters
 | 
			
		||||
	u32 Max;
 | 
			
		||||
	u32 VScrollBarWidth = 0;
 | 
			
		||||
	IGUIScrollBar *VScrollBar = nullptr;
 | 
			
		||||
 | 
			
		||||
	bool WordWrap = false,
 | 
			
		||||
		MultiLine = false,
 | 
			
		||||
 
 | 
			
		||||
@@ -51,6 +51,11 @@ public:
 | 
			
		||||
 | 
			
		||||
	//! sets the current position of the scrollbar
 | 
			
		||||
	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
 | 
			
		||||
 
 | 
			
		||||
@@ -7,6 +7,7 @@
 | 
			
		||||
#include "IGUISkin.h"
 | 
			
		||||
#include "IGUIEnvironment.h"
 | 
			
		||||
#include "IGUIFont.h"
 | 
			
		||||
#include "IGUIScrollBar.h"
 | 
			
		||||
#include "IVideoDriver.h"
 | 
			
		||||
#include "rect.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
 | 
			
		||||
 
 | 
			
		||||
@@ -59,6 +59,9 @@ public:
 | 
			
		||||
	//! sets the position of the scrollbar
 | 
			
		||||
	void setPos(s32 pos) override;
 | 
			
		||||
 | 
			
		||||
	//! sets the content height to scroll
 | 
			
		||||
	void setPageSize(s32 size) override { }
 | 
			
		||||
 | 
			
		||||
	//! updates the rectangle
 | 
			
		||||
	void updateAbsolutePosition() override;
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user