Lysa UI  0.0
Lysa UI —UI components for the Lysa Engine
RichTextArea Class Reference

Detailed Description

A read-only area displaying word-wrapped text marked up with BBCode.

Supported tags : [b], [i], [u], [s], [color=...], [size=n], [url=target], [code], [left], [center], [right], [br]

+ Inheritance diagram for RichTextArea:

Classes

struct  Chunk
 
struct  Line
 

Public Typedefs

using ColorConverter = std::function< float4 (const float4 &color)>
 Applied to every color read from the markup. More...
 

Public Types

enum class  Align { LEFT, CENTER, RIGHT }
 Horizontal placement of a line. More...
 
- Public Types inherited from Widget
enum  Type {
  WIDGET, PANEL, BOX, LINE,
  FRAME, BUTTON, TOGGLEBUTTON, RADIOBUTTON,
  CHECKBOX, CHECKMARK, CROSSMARK, ARROW,
  TEXT, TEXTEDIT, RICHTEXTAREA, SCROLLBAR,
  SLIDER, COLORSLIDER, COLORWHEEL, KNOB,
  TREEVIEW, IMAGE, POPUP, LIST,
  LISTBOX, SELECTION, PROGRESSBAR, SCROLLCONTAINER,
  MENU, MENUPANEL, MENUBOX, TABBAR,
  TABCONTAINER, DIALOG, FOLDABLECONTAINER, COLORPICKER,
  COLORPICKERBUTTON, SPINBOX, SPINBUTTONS, ICONIMAGE,
  ICONSVG, DROPDOWNLIST, TOOLTIP, GRIDCELL,
  GRID, TABLE
}
 

Public Member Functions

 RichTextArea (const std::string &bbcode="")
 
void setText (const std::string &bbcode)
 
const auto & getText () const
 
void setTextColor (const float4 &color)
 
auto getTextColor () const
 
void setLinkColor (const float4 &color)
 
void setCodeColor (const float4 &color)
 
void setColorConverter (const ColorConverter &converter)
 
void setFonts (const std::shared_ptr< Font > &bold, const std::shared_ptr< Font > &italic=nullptr, const std::shared_ptr< Font > &boldItalic=nullptr, const std::shared_ptr< Font > &mono=nullptr)
 
const auto & getLines () const
 
auto getContentHeight () const
 
float getScrollOffset () const
 
Rect getClientRect () const
 
auto getVScrollBar () const
 
void setResources (const std::string &resScroll)
 
void scrollToTop () const
 
void scrollToBottom () const
 
void setSize (float width, float height) override
 
void setFontScale (float fontScale) override
 
void onResize () override
 
bool onMouseDown (MouseButton button, float x, float y) override
 
bool onMouseUp (MouseButton button, float x, float y) override
 
- Public Member Functions inherited from Widget
 Widget (Type type=WIDGET)
 
 ~Widget () override
 
Type getType () const
 
bool isVisible () const
 
void setVisible (bool show=true)
 
bool isEnabled () const
 
void setEnabled (bool isEnabled=true)
 
virtual void setPos (float x, float y)
 
float getWidth () const
 
float getHeight () const
 
float getRequestedWidth () const
 
float getRequestedHeight () const
 
void setWidth (const float width)
 
void setHeight (const float height)
 
const Rect & getRect () const
 
void setRect (float x, float y, float width, float height)
 
void setRect (const Rect &rect)
 
float getAspectRatio () const
 
Alignment getAlignment () const
 
void setAlignment (Alignment alignment)
 
std::shared_ptr< Font > getFont () const
 
void setFont (const std::shared_ptr< Font > &font)
 
float getFontScale () const
 
bool isFocused () const
 
Widget * getParent () const
 
void setOverlap (const bool overlap)
 
template<typename T , typename... Args>
std::shared_ptr< T > create (const std::string &resource, const Alignment alignment, Args &&...args)
 
template<typename T , typename... Args>
std::shared_ptr< T > create (const Alignment alignment, Args &&...args)
 
template<typename T >
std::shared_ptr< T > add (std::shared_ptr< T > child, const Alignment alignment=Alignment::NONE, const std::string &resource="", const bool overlap=false)
 
template<typename T >
std::shared_ptr< T > addPopup (std::shared_ptr< T > child, const std::string &resource="")
 
template<typename T >
std::shared_ptr< T > addAfter (std::shared_ptr< T > child, const std::shared_ptr< Widget > &after, const Alignment alignment, const std::string &resource="", const bool overlap=false)
 
virtual void remove (const std::shared_ptr< Widget > &child)
 
virtual void removeAll ()
 
void setPadding (float padding)
 
float getPadding () const
 
float getVBorder () const
 
float getHBorder () const
 
void setVBorder (float size)
 
void setHBorder (float size)
 
bool isDrawBackground () const
 
void setDrawBackground (bool drawBackground)
 
bool isPushed () const
 
bool isPointed () const
 
bool isFreezed () const
 
bool isRedrawOnMouseEvent () const
 
bool isOverlapping () const
 
Rect getChildrenRect () const
 
void setFreezed (const bool f)
 
void setPushed (const bool p)
 
void refresh ()
 
void setResource (std::shared_ptr< UIResource > res)
 
uint32 getGroupIndex () const
 
void setGroupIndex (int32 index)
 
template<typename T >
getUserData () const
 
template<typename T >
std::shared_ptr< T > getPointerUserData () const
 
const std::any & getUserData () const
 
void setUserData (const std::any &data)
 
float getTransparency () const
 
void setTransparency (float alpha)
 
void resizeChildren ()
 
float getChildrenOffsetX () const
 
float getChildrenOffsetY () const
 
void setChildrenOffset (float x, float y)
 
std::shared_ptr< Widget > setFocus (bool focus=true)
 
virtual void onAttach ()
 
virtual void onDetach ()
 
virtual void onShow ()
 
virtual void onHide ()
 
virtual void onMove ()
 
virtual bool onKeyDown (Key key)
 
virtual bool onTextInput (const std::string &text)
 
virtual bool onKeyUp (Key key)
 
virtual bool onMouseMove (uint32 buttonsState, float x, float y)
 
virtual void onMouseLeave ()
 
virtual void onDisable ()
 
virtual void onEnable ()
 
virtual void onGotFocus ()
 
virtual void onLostFocus ()
 
bool getConsumeMouseEvent () const
 
void setConsumeMouseEvent (const bool consumeMouseEvent)
 
const std::list< std::shared_ptr< Widget > > & getChildren () const
 
bool hasChildren () const
 
void subscribe (const event_type &type, unique_id id, EventHandlerCallback callback)
 
void subscribe (const event_type &type, EventHandlerCallback callback)
 
void unsubscribe (unique_id id)
 
bool isAttached () const
 
WindowgetWindow () const
 
StylegetStyle () const
 
Vector2DRenderer & getRenderer () const
 
RenderingWindow & getRenderingWindow () const
 
WindowManagergetWindowManager () const
 

Static Public Attributes

static constexpr float SIZE_REFERENCE {100.0f}
 Value of a [size] tag displaying the text at the size of the widget. More...
 
static constexpr float MIN_SIZE_FACTOR {0.25f}
 Smallest & largest size a [size] tag can ask for. More...
 
static constexpr float MAX_SIZE_FACTOR {4.0f}
 
static constexpr float BOLD_THRESHOLD_DELTA {0.10f}
 Used to emulate bold. More...
 
static constexpr float MIN_BOLD_THRESHOLD {0.05f}
 Used to emulate bold. More...
 
static constexpr float LINE_SPACING {2.0f}
 Vertical space added between two lines of text. More...
 
static constexpr float DECORATION_THICKNESS {1.0f}
 Thickness of the lines drawn by [u] and [s] More...
 
static constexpr float UNDERLINE_POSITION {0.12f}
 Height of the [u] line above the bottom of the text. More...
 
static constexpr float STRIKE_POSITION {0.42f}
 Height of the [s] line above the bottom of the text. More...
 
static constexpr float WHEEL_STEP {0.5f}
 Part of the height of a line of text scrolled by one notch of the mouse wheel. More...
 

Additional Inherited Members

- Protected Attributes inherited from Widget
const Type type
 
Rect rect
 
float requestedWidth {0}
 
float requestedHeight {0}
 
float hborder {0}
 
float vborder {0}
 
float padding {0}
 
bool consumeMouseEvent {false}
 
bool overlap {false}
 
bool focused {false}
 
bool allowFocus {false}
 
bool allowChildren {true}
 
bool drawBackground {true}
 
bool moveChildrenOnPush {false}
 
bool scrollChildren {false}
 
bool skipInvisibleChildren {false}
 
bool redrawOnMouseEvent {false}
 
bool redrawOnMouseMove {false}
 
float transparency {1.0f}
 
Widget * parent {nullptr}
 
Alignment alignment {Alignment::NONE}
 
std::shared_ptr< UIResourceresource
 
std::list< std::shared_ptr< Widget > > children
 
bool mouseMoveOnFocus {false}
 
float childrenOffsetX {0}
 
float childrenOffsetY {0}
 

Member Typedef Documentation

using ColorConverter = std::function<float4(const float4& color)>

Applied to every color read from the markup.

Member Enumeration Documentation

enum class Align
strong

Horizontal placement of a line.

Enum ValuesDocumentation
LEFT 
CENTER 
RIGHT 

Constructor & Destructor Documentation

RichTextArea ( const std::string &  bbcode = "")

Member Function Documentation

Rect getClientRect ( ) const

Returns the area the text is laid out & drawn in scroll bar excluded.

auto getContentHeight ( ) const
inline

Returns the total height of the text

const auto& getLines ( ) const
inline

Returns the lines of text

float getScrollOffset ( ) const

Returns the height of the text hidden above the top of the client area.

const auto& getText ( ) const
inline

Returns the text.

auto getTextColor ( ) const
inline

Returns the color of the text outside of any [color] tag.

auto getVScrollBar ( ) const
inline

Returns the vertical scroll bar.

bool onMouseDown ( MouseButton  button,
float  x,
float  y 
)
overridevirtual

Event called when a mouse button was pressed inside the Window.

Parameters
buttonThe mouse button.
xMouse X coordinate.
yMouse Y coordinate.
Returns
True if event was handled.

Reimplemented from lysa::ui::Widget::onMouseDown()

bool onMouseUp ( MouseButton  button,
float  x,
float  y 
)
overridevirtual

Event called when a mouse button was released inside the Window.

Parameters
buttonThe mouse button.
xMouse X coordinate.
yMouse Y coordinate.
Returns
True if event was handled.

Reimplemented from lysa::ui::Widget::onMouseUp()

void onResize ( )
overridevirtual

Event called after a size change.

Reimplemented from lysa::ui::Widget::onResize()

void scrollToBottom ( ) const

Scrolls to the last line of the text.

void scrollToTop ( ) const

Scrolls to the first line of the text.

void setCodeColor ( const float4 &  color)

Sets the color of the [code] text.

void setColorConverter ( const ColorConverter converter)

Sets the conversion applied to every color read from the markup.

void setFonts ( const std::shared_ptr< Font > &  bold,
const std::shared_ptr< Font > &  italic = nullptr,
const std::shared_ptr< Font > &  boldItalic = nullptr,
const std::shared_ptr< Font > &  mono = nullptr 
)

Gives the faces used by [b], [i] & [code].

void setFontScale ( float  fontScale)
overridevirtual

Sets the font scale.

Reimplemented from lysa::ui::Widget::setFontScale()

void setLinkColor ( const float4 &  color)

Sets the color of the [url] links.

void setResources ( const std::string &  resScroll)

Sets the UI resources of the scroll bar.

void setSize ( float  width,
float  height 
)
overridevirtual

Resizes the widget, in pixels.

Reimplemented from lysa::ui::Widget::setSize()

void setText ( const std::string &  bbcode)

Sets the text to display.

void setTextColor ( const float4 &  color)

Sets the color of the text outside of any [color] tag.

Member Data Documentation

constexpr float BOLD_THRESHOLD_DELTA {0.10f}
staticconstexpr

Used to emulate bold.

constexpr float DECORATION_THICKNESS {1.0f}
staticconstexpr

Thickness of the lines drawn by [u] and [s]

constexpr float LINE_SPACING {2.0f}
staticconstexpr

Vertical space added between two lines of text.

constexpr float MAX_SIZE_FACTOR {4.0f}
staticconstexpr
constexpr float MIN_BOLD_THRESHOLD {0.05f}
staticconstexpr

Used to emulate bold.

constexpr float MIN_SIZE_FACTOR {0.25f}
staticconstexpr

Smallest & largest size a [size] tag can ask for.

constexpr float SIZE_REFERENCE {100.0f}
staticconstexpr

Value of a [size] tag displaying the text at the size of the widget.

constexpr float STRIKE_POSITION {0.42f}
staticconstexpr

Height of the [s] line above the bottom of the text.

constexpr float UNDERLINE_POSITION {0.12f}
staticconstexpr

Height of the [u] line above the bottom of the text.

constexpr float WHEEL_STEP {0.5f}
staticconstexpr

Part of the height of a line of text scrolled by one notch of the mouse wheel.