Skip to content

RichEditor

richEditor · Components · interactive

A rich text editor: blocks of text, marks over ranges, and a toolbar.

Import

cpp
#include "gbui/widgets/richEditor.hpp"

Example

Nothing is downloaded until you press it.

cpp
RichEditorResult richEditor(Ui& ui, const Interaction& input, std::string_view id, RichDocument& document, RichEditorState& state, const RichEditorOptions& options = {});

Draws the editor and edits document in place. What this is and is not. It is a block editor: paragraphs, headings, lists, quotes and code blocks, with bold, italic, underline, strikethrough, inline code and links over ranges within a block. Typing, splitting a block with Return and merging with Backspace all work, and the toolbar is the caller's to compose. It is not finished, and the gaps are worth naming rather than discovering: no images — the painter cannot decode one yet; no undo; the caret moves by character and by block, not by visual line, so a block that wraps is edited by a caret that does not know where the lines are; and there is no nesting of lists. Each of those is a piece of work of its own, and three of them want engine features that do not exist.

API

RichEditorOptions

OptionTypeDefaultWhat it does
toolbarstd::vector<ToolbarItem>Empty takes defaultToolbar(). Anything else is exactly what is drawn, in that order — which is how a caller adds its own buttons, drops the ones it does not want, or reorders the rest.
blockChoicesstd::vector<BlockChoice>What the BlockStyle dropdown lists. Empty takes defaultBlockChoices().
showToolbarbooltrueOff leaves the keys and the document and nothing to click, which is what an editor whose buttons live somewhere else wants.
placeholderstd::string_view"Write something…"
minHeightfloat220.0f
heightfloatkAuto
growfloat0.0f
namestd::string_viewWhat is being written — "Release notes", "Comment". An editor with no name is the largest unlabelled thing on most screens.

Released under the LGPL-3.0-or-later licence.