Donner SVG 0.8.0
0.8.0 ยท ebf353960.8.0 main
SVG editor and embeddable C⁠+⁠+⁠20 engine.
Loading...
Searching...
No Matches
InspectorNumericInput.h File Reference
#include <optional>
#include <string_view>
#include "donner/base/Length.h"
Include dependency graph for InspectorNumericInput.h:
This graph shows which files directly or indirectly include this file:

Classes

struct  donner::editor::InspectorTextParser
 Converts the typed text of a numeric field to its value, or returns std::nullopt to reject it. More...
struct  donner::editor::InspectorNumericEdit
 Outcome of one frame of an Inspector numeric field. More...
struct  donner::editor::InspectorLengthEdit
 Outcome of one frame of an Inspector length field. More...

Namespaces

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

Functions

std::optional< Lengthd > donner::editor::ParseInspectorLength (std::string_view text, LengthUnit defaultUnit)
 Parse a length typed into an Inspector field.
std::optional< double > donner::editor::ParseInspectorNumber (std::string_view text)
 Parse a plain number typed into an Inspector field; a unit suffix is rejected, not dropped.
std::optional< double > donner::editor::ParseInspectorDegrees (std::string_view text)
 Parse a rotation typed into an Inspector field: a number of degrees, optionally followed by the deg unit the field displays.
InspectorNumericEdit donner::editor::DragInspectorNumber (const char *label, double *value, float speed, const char *format, const InspectorTextParser &parse, const char *hint, const EditorTheme &theme)
 Draggable numeric field whose typed text is interpreted by parse.
InspectorLengthEdit donner::editor::InputInspectorLength (const char *label, const Lengthd &current, LengthUnit bareNumberUnit, bool allowNegative, const EditorTheme &theme)
 Text field for a CSS length, displayed with one decimal place and its unit, e.g.

Variables

constexpr const char * donner::editor::kInspectorLengthHint
 Tooltip shown while a length field's text is rejected.
constexpr const char * donner::editor::kInspectorNumberHint = "Enter a number without a unit"
 Tooltip shown while a plain-number field's text is rejected.
constexpr const char * donner::editor::kInspectorDegreesHint = "Enter an angle in degrees"
 Tooltip shown while a rotation field's text is rejected.

Function Documentation

◆ DragInspectorNumber()

InspectorNumericEdit donner::editor::DragInspectorNumber ( const char * label,
double * value,
float speed,
const char * format,
const InspectorTextParser & parse,
const char * hint,
const EditorTheme & theme )

Draggable numeric field whose typed text is interpreted by parse.

Behaves like ImGui::DragScalar over a double, except that text typed into the field (after a click, double-click or Ctrl+click) is interpreted by parse. ImGui's own parsing keeps only the leading number and silently drops anything after it, such as a unit. Text that parse rejects leaves the value unchanged and outlines the field in the theme's destructive color, with hint as its tooltip. Text the user has not changed is not re-parsed, so entering and leaving the field does not round the value to its displayed precision.

Parameters
labelImGui label and ID of the field.
valueValue to display and edit.
speedDrag speed, in value units per pixel.
formatprintf-style display format.
parseInterprets typed text.
hintTooltip explaining what the field accepts, shown while its text is rejected.
themeActive editor theme.
Returns
Whether the value changed and whether the typed text is currently rejected.

◆ InputInspectorLength()

InspectorLengthEdit donner::editor::InputInspectorLength ( const char * label,
const Lengthd & current,
LengthUnit bareNumberUnit,
bool allowNegative,
const EditorTheme & theme )

Text field for a CSS length, displayed with one decimal place and its unit, e.g.

2.0mm.

Typed text is interpreted by donner::editor::ParseInspectorLength with bareNumberUnit as the default, so a bare number keeps the authored unit and a typed unit replaces it. Rejected text outlines the field like donner::editor::DragInspectorNumber.

Parameters
labelImGui label and ID of the field.
currentValue displayed while the field is not being edited.
bareNumberUnitUnit for a typed bare number, normally the unit before editing began.
allowNegativeWhether negative lengths are accepted; otherwise they are rejected.
themeActive editor theme.
Returns
The newly typed length, if any, and whether the typed text is currently rejected.

◆ ParseInspectorDegrees()

std::optional< double > donner::editor::ParseInspectorDegrees ( std::string_view text)
nodiscard

Parse a rotation typed into an Inspector field: a number of degrees, optionally followed by the deg unit the field displays.

Other units are rejected, not dropped.

Parameters
textText typed by the user.
Returns
The angle in degrees, or std::nullopt if text is not a finite angle in degrees.

◆ ParseInspectorLength()

std::optional< Lengthd > donner::editor::ParseInspectorLength ( std::string_view text,
LengthUnit defaultUnit )
nodiscard

Parse a length typed into an Inspector field.

Accepts a CSS <length-percentage> such as 1in, 2.5mm or 50%, using donner::parser::LengthParser, or a bare number. A bare number takes defaultUnit, so editing a value keeps the unit it was authored in; a typed unit replaces it. Surrounding whitespace is ignored. Anything else, including an unknown unit or a space before the unit, is rejected rather than truncated to its leading number.

Parameters
textText typed by the user.
defaultUnitUnit for a bare number.
Returns
The typed length, or std::nullopt if text is not a finite length.

◆ ParseInspectorNumber()

std::optional< double > donner::editor::ParseInspectorNumber ( std::string_view text)
nodiscard

Parse a plain number typed into an Inspector field; a unit suffix is rejected, not dropped.

Parameters
textText typed by the user.
Returns
The number, or std::nullopt if text is not a single finite number.

Variable Documentation

◆ kInspectorLengthHint

const char* donner::editor::kInspectorLengthHint
inlineconstexpr
Initial value:
=
"Enter a number, optionally with a unit such as px, in, cm, mm, pt, pc, em, ex or %"

Tooltip shown while a length field's text is rejected.