35 std::span<const std::byte>
data;
67 static constexpr int32_t
kUnbounded = std::numeric_limits<int32_t>::max();
238 std::vector<FontFaceSource> faces;
239 faces.reserve(faceFiles.size());
240 for (std::string_view file : faceFiles)
263 template<
typename T,
typename Converter = TextConverter<T>>
267 bool started =
false;
269 std::string shownText;
270 if (editText ==
nullptr)
271 shownText = converter.Format(value,
false);
273 *editText = converter.Format(value,
true);
274 std::string& text = editText ? *editText : shownText;
278 if (edited && converter.Parse(text, value))
292 value = std::clamp(value, config.minVal, config.maxVal);
348 virtual std::optional<MouseCursor>
LinkCursorAt(
ID elementId, int32_t localX, int32_t localY)
const = 0;
396 std::span<const VisualShadow> shadows = {}) = 0;
434 virtual std::string
Copy() = 0;
437 virtual std::string
Cut() = 0;
440 virtual void Paste(std::string_view text) = 0;
Owns the per-frame state objects and runs their BeginFrame / EndFrame in order.
Definition gui_state_manager.h:65
A graphics backend: the device, the window contexts that render the GUI's windows,...
Definition gui_graphics_context.h:60
The clipboard text editors copy to and paste from; GUIApplication::SetClipboard sets one (default: SD...
Definition gui_clipboard.h:14
Text and icon registration, measurement, rendering and editing.
Definition gui_text_system.h:178
virtual void SetLanguage(std::string_view languageTag)=0
The default language as a BCP 47 tag ("ja", "zh-Hant", "ko"), for text whose style has no language of...
virtual void OnMouseScroll(ID windowId, tachyon::int2 screenPos, tachyon::float2 scrollOffset, KeyModifier modifiers)=0
Mouse wheel input for text editors.
virtual std::optional< IntRect > GetCaretScreenRect() const =0
The active editor's caret in absolute screen coordinates (through any zoom/pan), to place the IME can...
virtual void OnMouseButton(ID windowId, tachyon::int2 screenPos, MouseButtons button, KeyModifier modifiers, MouseAction action)=0
Mouse buttons for text editors: caret placement, selection, drag-drop.
virtual TextID GetTextID(ID elementId) const =0
The TextID elementId registered this frame, or TextID::Invalid.
virtual void UnregisterIcon(IconID iconId)=0
Lets go of an icon from RegisterIconFromPixels: its image slot is freed, the ID draws nothing from th...
virtual void SetTextColor(TextID textId, VisualColorStyleIndex color)=0
Draw a registered text in color instead of its style's text color, until it is registered again (call...
TextID RegisterText(ID elementId, std::string_view text, StyleRef styleIndex, ElementState state)
Definition gui_text_system.h:249
virtual int32_t GetTextHeightWithoutIcon(TextID textId) const =0
How high textId's text is unwrapped, in pixels, without the icon it was registered with (which its me...
virtual std::string * ValueEditText(ID elementId, bool &started)=0
The text the focused field elementId edits, kept while it has the focus (its value isn't formatted ag...
virtual IconID RegisterIconFromSVGFile(const char *path)=0
Registers an icon from an SVG file, named by its path.
virtual void SetCaretColor(VisualColorStyleIndex color)=0
The text caret's color (the theme's –caret). Set again after the style manager is cleared.
virtual TextID RegisterEditableRichText(ID elementId, const std::span< ContentRun > &contentRuns, TextEditBehavior behavior, StyleRef styleIndex, ElementState state, bool &wasModified)=0
Registers rich text that renders like RegisterRichText but can also be selected and copied (the runs'...
virtual intptr_t HitTestContent(TextID textId, int32_t localX, int32_t localY) const =0
The contentId of the run at (localX, localY), element-local; 0 if none.
virtual TextMeasurement MeasureText(TextID textId, const TextWrapContext &wrapContext) const =0
The measurement of textId wrapped to wrapContext.maxWidth, in pixels.
virtual IconID RegisterIconFromSVG(const char *name, const char *svg_data, size_t svg_size)=0
Registers an icon from SVG data under a unique name.
virtual bool ReplayAtlasTouches(ID)
Definition gui_text_system.h:220
virtual void Paste(std::string_view text)=0
Inserts text into the active editor at the caret, replacing the selection.
virtual FontID RegisterFontFamily(std::string_view familyName, std::span< const FontFaceSource > faces)=0
Registers a font family from its faces (regular, bold, italic, ...); each face's weight and style com...
virtual void OnMouseMove(ID windowId, tachyon::int2 screenPos, MouseButtons button, KeyModifier modifiers)=0
Mouse movement for text selection and drag-drop.
virtual bool TryGetTextDragHoverTarget(ID windowId, tachyon::int2 screenSpace, ID &outTargetId) const =0
While text is dragged, sets outTargetId to the drop target under the cursor (ID::Invalid if none) and...
virtual void RequestSelectAll(ID elementId)=0
Selects all text of the editor elementId the next time it renders.
virtual bool TryGetTextDragCursor(ID windowId, tachyon::int2 screenSpace, MouseCursor &outCursor) const =0
The mouse cursor to show while text is dragged; true when it overrides the hover cursor.
virtual IconMeasurement MeasureIcon(IconID iconId) const =0
The natural size of iconId, in pixels.
virtual std::string Copy()=0
The active editor's selected text.
virtual TextMeasurement GetTextMeasurement(TextID textId) const =0
The unwrapped measurement of textId, in pixels; cached until its text or style changes.
virtual bool IsHoveringSelectedText(ID textEditorId, ID windowId, tachyon::int2 screenSpace) const =0
True when the screen point screenSpace is over selected text in textEditorId.
virtual void SetUndoHistory(class UndoHistory *history)=0
Where committed text edits go as undo steps (none: not recorded).
virtual IconID RegisterIconFromPixels(const char *name, uint2 size, std::span< const uint8_t > rgba)=0
Registers an icon from size.x x size.y RGBA pixels (straight alpha, rows from the top) under a unique...
TextID RegisterEditableNumber(ID elementId, T &value, TextEditBehavior behavior, StyleRef styleIndex, ElementState state, bool &wasModified, NumericFieldConfig< T > config={})
Registers an editable number, clamped to config's [minVal, maxVal] after an edit.
Definition gui_text_system.h:285
virtual bool IsTextEditor(ID elementId) const =0
True when elementId registered editable text this frame.
virtual void Shutdown()=0
TextID RegisterEditableValue(ID elementId, T &value, TextEditBehavior behavior, StyleRef styleIndex, ElementState state, bool &wasModified, const Converter &converter=DefaultTextConverter< T >())
Registers a field that edits value as text: converter formats it and parses the edits back (see TextC...
Definition gui_text_system.h:264
virtual TextID RegisterRichText(ID elementId, const std::span< ContentRun > &contentRuns, StyleRef styleIndex, ElementState state)=0
Registers text made of runs: styled text, inline icons and links.
virtual std::optional< IntRect > GetCursorRect(ID textEditorId)=0
Takes a pending EnsureCursorVisible request for textEditorId and returns the caret rect,...
virtual void OnKeyboard(ID windowId, KeyCode key, int repeat, KeyModifier modifiers, KeyAction action)=0
Keyboard input for the active text editor.
virtual ~ITextSystem()=default
virtual void SetHoveredContent(TextID textId, intptr_t contentId)=0
Sets the hovered run of textId (by contentId), drawn in its hover style; 0 for none.
virtual void BeginAtlasRecord(ID)
Records the glyph and icon atlas entries a cached scope's primitives use, until EndAtlasRecord.
Definition gui_text_system.h:218
virtual bool IsValidIcon(IconID iconId) const =0
True when iconId is a registered icon.
virtual void RenderText(TextID textId, IntRect rect, IntRect innerRect, IntRect clipRect, float pixelScale=1.f, const float3x2 &screenToLayout=float3x2::Identity())=0
Draws textId into rect (renderer space, window-local), clipped to clipRect.
virtual void BeginFrame(int2 screenMousePos, MouseButtons mouseButtons, uint32_t timeMs)=0
Starts a frame, before the UI is built: clears the per-frame editor registrations that this frame's R...
virtual std::optional< MouseCursor > LinkCursorAt(ID elementId, int32_t localX, int32_t localY) const =0
The cursor of the link at (localX, localY), element-local (its LinkStyle::cursor); none when there's ...
virtual IconMeasurement GetIconMeasurement(IconID iconId) const =0
The natural size of iconId, in pixels (same as MeasureIcon).
virtual void SwitchTextEditor(ID from, ID to)=0
The focused text field changed (GUIStateManager::TextEditorFocus): commit from (ID::Invalid if none) ...
virtual TextEditUpdate ConsumeTextEditUpdate(TextID textId, std::string &outText)=0
Takes the pending edit of textId: the edited text goes to outText, the result says whether it changed...
virtual TextID RegisterEditableText(ID elementId, std::string &text, TextEditBehavior behavior, StyleRef styleIndex, ElementState state, bool &wasModified, const ITextValidator *validator=nullptr)=0
Registers text as editable by elementId; wasModified is set when an edit changed it.
virtual bool Initialize(GraphicsContext *graphicsContext, StyleManager *styleManager, TextAtlasManager *textAtlasManager, GUIStateManager *guiStateManager, IClipboard *clipboard)=0
virtual void ClearCache()=0
Drops every registered text and the live editor; earlier TextIDs become invalid.
virtual void SetFallbackFontDirectory(std::string_view directory)=0
Where the optional fallback fonts are: Noto, for other scripts, emoji and symbols.
virtual TextID RegisterText(ID elementId, IconID iconId, std::string_view text, StyleRef styleIndex, ElementState state)=0
Registers static text, with an optional icon, for elementId.
virtual bool DoesTextEditorAcceptTabs(ID elementId) const =0
True when the editor elementId inserts tabs (TextEditBehavior::AcceptTabs).
virtual bool UpdateText(TextID textId, std::string_view text)=0
Replaces the text of textId; true when it changed.
FontID RegisterFontFamily(std::string_view familyName, std::span< const std::string_view > faceFiles)
Definition gui_text_system.h:236
virtual void RenderIcon(IconID iconId, IntRect rect, IntRect clipRect, VisualColorStyleIndex tint, std::span< const VisualShadow > shadows={})=0
Draws iconId fitted into rect (aspect kept, centered), clipped to clipRect.
virtual std::string_view GetText(TextID textId) const =0
The text registered as textId.
virtual void EndAtlasRecord()
Definition gui_text_system.h:219
virtual void SetFontDirectory(std::string_view directory)=0
Where the built-in fonts are (default "fonts", relative to the working directory): Inter for text and...
virtual void EnsureCursorVisible(ID textEditorId)=0
Asks for the caret of textEditorId to be scrolled into view; editor input calls it when the caret mov...
virtual std::string Cut()=0
Removes the active editor's selected text and returns it.
What an editable field takes as text, asked while it is edited.
Definition gui_text_converter.h:19
Bakes serializable Styles into deduplicated runtime layout/visual styles; a StyleRef holds indices in...
Definition gui_style_manager.h:39
Definition gui_text_atlas_manager.h:17
What text is measured and laid out from: font, metrics and decoration lines.
Definition gui_style_text.h:260
uint64_t GetHashCode() const noexcept
The app's undo history: steps that each undo and redo one change.
Definition gui_undo_history.h:18
ElementFlags
What an element is and how it behaves, combined with |.
Definition gui_element_flags.h:18
@ None
Definition gui_element_flags.h:19
MouseCursor
Mouse cursor shown over an element (CSS: cursor).
Definition gui_style.h:478
VisualColorStyleIndex
Index into StyleManager's color style pool; Invalid (0) draws nothing (transparent).
Definition gui_style.h:33
FontID
Handle for a font family registered with ITextSystem::RegisterFontFamily().
Definition gui_style_text.h:20
TextID
Handle for text registered with the text system (ITextSystem::RegisterText and friends).
Definition gui_style_text.h:13
IconID
Handle for an icon registered with ITextSystem::RegisterIconFromSVG / RegisterIconFromSVGFile.
Definition gui_style_text.h:15
ElementState
Interaction state bits of an element; they pick the Style::states variant it draws with.
Definition gui_style.h:42
@ Pointer
Pointing hand for clickable items.
Definition gui_style.h:483
@ Invalid
Definition gui_style_text.h:15
const TextConverter< T > & DefaultTextConverter()
The converter a field uses for T when it is given none.
Definition gui_text_converter.h:74
TextEditBehavior
Definition gui_text_system.h:99
@ ReadOnly
selectable and copyable, but not editable
Definition gui_text_system.h:104
@ Multiline
Enter inserts a newline instead of committing.
Definition gui_text_system.h:102
@ ContinuousUpdate
update the text on every keystroke, not only on commit
Definition gui_text_system.h:101
@ AcceptTabs
Tab inserts a tab character instead of moving focus.
Definition gui_text_system.h:103
#define TACHYON_ENUM_OPERATORS(EnumType)
Definition gui_enum_operators.h:6
uint64_t Calculate(std::string_view str)
FNV-1a hash of str; same result as CalculateConst.
Definition gui_hash.h:29
constexpr uint64_t Combine(uint64_t a, uint64_t b)
Order-dependent combine; repeated values don't cancel out.
Definition gui_hash.h:65
Definition gui_logging.h:24
One run of rich text: a piece of text or an inline icon.
Definition gui_text_system.h:125
Type
Definition gui_text_system.h:128
@ Icon
Definition gui_text_system.h:128
@ Text
Definition gui_text_system.h:128
const TextStyle * textStyleOverride
Text style of this run in place of the element's (font, size, weight, ...); null uses the element's.
Definition gui_text_system.h:143
float iconWidth
CSS px, or kSizeAuto.
Definition gui_text_system.h:134
std::string_view text
Text runs.
Definition gui_text_system.h:131
LinkStyle linkStyle
Definition gui_text_system.h:139
Type type
Definition gui_text_system.h:129
uint64_t GetHashCode() const
Definition gui_text_system.h:145
static constexpr float kSizeAuto
size the icon automatically
Definition gui_text_system.h:126
IconID iconID
Icon runs.
Definition gui_text_system.h:132
float iconHeight
CSS px, or kSizeAuto.
Definition gui_text_system.h:135
intptr_t contentId
non-zero makes the run hittable (HitTestContent returns it)
Definition gui_text_system.h:137
bool isLink
drawn as a link: underlined, in linkStyle's colors
Definition gui_text_system.h:138
One face of a font family: a font file, or font data in memory that stays valid while the family is r...
Definition gui_text_system.h:33
std::span< const std::byte > data
Definition gui_text_system.h:35
std::string_view file
Definition gui_text_system.h:34
A 64-bit element ID whose bit layout depends on its IDMode.
Definition gui_id.h:23
Definition gui_text_system.h:183
bool textChanged
Definition gui_text_system.h:184
constexpr bool HasUpdate() const
Definition gui_text_system.h:187
bool textCommitted
Definition gui_text_system.h:185
Definition gui_text_system.h:54
constexpr bool IsEmpty() const
Definition gui_text_system.h:59
int32_t width
Definition gui_text_system.h:55
int32_t height
Definition gui_text_system.h:56
constexpr int2 Size() const
Definition gui_text_system.h:58
Definition gui_base_types.h:407
Colors of a link run, normal and hovered.
Definition gui_text_system.h:115
color4b color
Definition gui_text_system.h:116
color4b hoverColor
Definition gui_text_system.h:117
bool operator==(const LinkStyle &) const noexcept=default
MouseCursor cursor
over the link
Definition gui_text_system.h:118
Drag speed and range of a numeric Field, specialized per value type.
Definition gui_numeric_field_config.h:19
A registered style, as StyleManager::Register returns it: indices into the shared style pools,...
Definition gui_style_ref.h:25
Definition gui_text_system.h:66
constexpr int2 MinSize() const
Definition gui_text_system.h:74
constexpr int2 MaxSize() const
Definition gui_text_system.h:75
int32_t maxWidth
max-content width: the widest line without wrapping
Definition gui_text_system.h:70
constexpr bool IsEmpty() const
Definition gui_text_system.h:76
int32_t minWidth
min-content width: widest unbreakable run; maxWidth when it can't wrap
Definition gui_text_system.h:69
static constexpr int32_t kUnbounded
Definition gui_text_system.h:67
int32_t minHeight
height of the text laid out at maxWidth
Definition gui_text_system.h:71
int32_t maxHeight
same as minHeight
Definition gui_text_system.h:72
Definition gui_text_system.h:84
uint32_t maxLines
Definition gui_text_system.h:87
int32_t maxWidth
Definition gui_text_system.h:85
bool operator==(const TextWrapContext &) const =default
uint64_t GetHashCode() const
Definition gui_text_system.h:91
int32_t maxHeight
Definition gui_text_system.h:86
Definition gui_base_types.h:384
Definition gui_base_types.h:121
2D affine transform matrix (2 rows x 3 columns): x' = r0.x*x + r0.y*y + r0.z y' = r1....
Definition gui_base_types.h:219
static constexpr float3x2 Identity()
Definition gui_base_types.h:228
Integer 2D vector.
Definition gui_base_types.h:19
Definition gui_base_types.h:75