Donner SVG Editor & Engine
SVG-native editor and embeddable SVG2 + CSS3 engine in C++20, with GPU (WebGPU) and compact CPU renderers, built for correctness, security, and performance.
Loading...
Searching...
No Matches
TextFormatBarPresenter.h File Reference

TextFormatBarPresenter renders a contextual floating text-formatting bar below the canvas tool palette. The bar is shown only while text styling is in context: when the canvas selection is a single <text> element or an in-canvas text editing session is active. It offers a searchable font-family picker (each known family previewed in its own face, with a free-text fallback for families the editor lacks), a font-size combo with drag and preset behavior, and Bold/Italic/Underline toggles. More...

#include <array>
#include <functional>
#include <string>
#include <vector>
#include "donner/svg/SVGElement.h"
#include "donner/svg/resources/FontCatalogTypes.h"
Include dependency graph for TextFormatBarPresenter.h:
This graph shows which files directly or indirectly include this file:

Classes

struct  donner::editor::FormatBarFontFamily
 One selectable font family in the format bar's family picker. More...
struct  donner::editor::FormatBarState
 Snapshot of the current text formatting context, driving the bar's controls. More...
struct  donner::editor::FormatBarActions
 Edge-triggered requests emitted by the format bar in one frame. Each set* / toggle* flag is true only on the frame the user committed the control. More...
class  donner::editor::TextFormatBarPresenter
 Contextual text-formatting bar shown as a floating canvas toolbar. More...

Namespaces

namespace  donner
 Top-level Donner namespace, which is split into different sub-namespaces such as donner::svg and donner::css.

Functions

std::vector< FormatBarFontFamilydonner::editor::BuildFormatBarFamilies (const std::vector< svg::FontFamilyInfo > &catalogFamilies, const std::function< ImFont *(const svg::FontFamilyInfo &)> &previewForFamily)
 Build the picker's family list from a catalog listing (see FontCatalog::families(), which already orders Embedded before System and sorts within each group). Each entry keeps its CSS family name and source; previewFont is filled from previewForFamily for families the editor has a loaded face for, and left null otherwise (the entry then renders in the default UI font). Families the catalog lacks are still reachable through the bar's free-text box, so this list is additive, not a whitelist.
bool donner::editor::FormatBarShouldShow (bool hasSingleTextSelection, bool textEditingActive)
 Whether the format bar should be shown, given the styling context.
void donner::editor::ReadTextFormatState (const svg::SVGElement &text, FormatBarState *state)
 Populate the attribute-derived fields (fontFamily, fontSize, hasFontSize, bold, italic, underline) of state from a single selected/edited <text> element. Reads under a scoped read access so it is safe while the live editor keeps the document in ConcurrentDom. Leaves visible, families, and boldToggleFont untouched (owned by the shell).
bool donner::editor::ApplyFormatBarActionsToSelection (const FormatBarActions &actions, const FormatBarState &state, bool routeTogglesToSelection, EditorApp &app)
 Route the attribute-write half of the bar's actions onto the app's current selection (the TextInspectorPanel seam): font family, font size, and - when routeTogglesToSelection is true - the B/I/U toggles. During an editing session the shell handles B/I/U through TextTool instead and passes routeTogglesToSelection=false, so this only writes family/size.

Variables

constexpr std::array< int, 12 > donner::editor::kFormatBarFontSizePresets
 Common font-size presets offered by the size combo (document units).

Detailed Description

TextFormatBarPresenter renders a contextual floating text-formatting bar below the canvas tool palette. The bar is shown only while text styling is in context: when the canvas selection is a single <text> element or an in-canvas text editing session is active. It offers a searchable font-family picker (each known family previewed in its own face, with a free-text fallback for families the editor lacks), a font-size combo with drag and preset behavior, and Bold/Italic/Underline toggles.

Following the MenuBarPresenter pattern, the presenter is a thin, testable surface: render() draws the imgui controls and returns edge-triggered FormatBarActions, which the shell routes to the existing styling commands. B/I/U during an editing session go through the TextTool style toggles; family, size, and the selection-only B/I/U path go through the TextInspectorPanel attribute-write seam (setAttributeOnSelection). This bar is a second surface over those commands, not a new styling pipeline.

Function Documentation

◆ ApplyFormatBarActionsToSelection()

bool donner::editor::ApplyFormatBarActionsToSelection ( const FormatBarActions & actions,
const FormatBarState & state,
bool routeTogglesToSelection,
EditorApp & app )

Route the attribute-write half of the bar's actions onto the app's current selection (the TextInspectorPanel seam): font family, font size, and - when routeTogglesToSelection is true - the B/I/U toggles. During an editing session the shell handles B/I/U through TextTool instead and passes routeTogglesToSelection=false, so this only writes family/size.

Toggle-off writes the "normal"/"none" value (rather than removing the attribute) to stay on the pure attribute-write path; the value that flips is derived from state's current B/I/U flags.

Returns
true if any document mutation was queued.

◆ FormatBarShouldShow()

bool donner::editor::FormatBarShouldShow ( bool hasSingleTextSelection,
bool textEditingActive )
nodiscard

Whether the format bar should be shown, given the styling context.

The bar is contextual: it appears while the selection is a single <text> element, or while an in-canvas text editing session is active (which also makes that element the selection, but the session predicate is kept explicit so the bar stays up through selection churn during editing).

Parameters
hasSingleTextSelectionTrue when exactly one <text> is selected.
textEditingActiveTrue when an in-canvas text session owns the caret.

Variable Documentation

◆ kFormatBarFontSizePresets

std::array<int, 12> donner::editor::kFormatBarFontSizePresets
inlineconstexpr
Initial value:
= {8, 9, 10, 11, 12, 14,
16, 18, 24, 36, 48, 72}

Common font-size presets offered by the size combo (document units).