Add callback to IGUIStaticText to allow text handling
This commit is contained in:
parent
33a4369a71
commit
c76d41c903
@ -8,6 +8,7 @@
|
||||
#include "IGUIElement.h"
|
||||
#include "SColor.h"
|
||||
|
||||
#include <functional>
|
||||
#include <vector>
|
||||
|
||||
namespace irr
|
||||
@ -123,6 +124,7 @@ namespace gui
|
||||
virtual void clearGlyphLayouts() = 0;
|
||||
virtual void setUseGlyphLayoutsOnly(bool gls_only) = 0;
|
||||
virtual bool useGlyphLayoutsOnly() const = 0;
|
||||
virtual void setMouseCallback(std::function<bool(IGUIStaticText* text, SEvent::SMouseInput)> cb) {}
|
||||
};
|
||||
|
||||
|
||||
|
@ -375,6 +375,24 @@ void CGUIStaticText::deserializeAttributes(io::IAttributes* in, io::SAttributeRe
|
||||
}
|
||||
|
||||
|
||||
bool CGUIStaticText::OnEvent(const SEvent& event)
|
||||
{
|
||||
if (IsEnabled)
|
||||
{
|
||||
switch(event.EventType)
|
||||
{
|
||||
case EET_MOUSE_INPUT_EVENT:
|
||||
{
|
||||
if (m_callback && m_callback(this, event.MouseInput))
|
||||
return true;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
return IGUIElement::OnEvent(event);
|
||||
}
|
||||
|
||||
} // end namespace gui
|
||||
} // end namespace irr
|
||||
|
||||
|
@ -110,7 +110,9 @@ namespace gui
|
||||
virtual void clearGlyphLayouts() { m_glyph_layouts.clear(); }
|
||||
virtual void setUseGlyphLayoutsOnly(bool gls_only) { m_use_glyph_layouts_only = gls_only; }
|
||||
virtual bool useGlyphLayoutsOnly() const { return m_use_glyph_layouts_only; }
|
||||
|
||||
//! called if an event happened.
|
||||
virtual bool OnEvent(const SEvent& event);
|
||||
virtual void setMouseCallback(std::function<bool(IGUIStaticText* text, SEvent::SMouseInput)> cb) { m_callback = cb; }
|
||||
private:
|
||||
|
||||
//! Breaks the single text line.
|
||||
@ -131,6 +133,7 @@ namespace gui
|
||||
//! If true, setText / updating this element will not reshape with Text object
|
||||
bool m_use_glyph_layouts_only;
|
||||
std::vector<GlyphLayout> m_glyph_layouts;
|
||||
std::function<bool(IGUIStaticText* text, irr::SEvent::SMouseInput)> m_callback;
|
||||
};
|
||||
|
||||
} // end namespace gui
|
||||
|
Loading…
Reference in New Issue
Block a user