35#include <NDEVR/Model.h>
36#include <NDEVR/TextConstructor.h>
37#include <NDEVR/Font.h>
38#include <NDEVR/StringEnum.h>
47 enum TextControlSequence
53 , e_set_underline =
'_'
54 , e_set_overstrike =
'-'
55 , e_set_alignment =
'a'
56 , e_set_font_size =
's'
57 , e_set_fixed_width =
'w'
58 , e_set_tab_advance =
't'
60 class TextConstructor;
71 class NDEVR_DESIGN_API Text :
public Model
82 Text(
const Model& model);
88 void setText(
const TranslatedString& text,
bool update_now =
false);
94 void setText(
const StringView& text,
bool update_now =
false);
100 void setText(
const Buffer<TextBlock>& text,
bool update_now =
false);
111 void setAlignment(uint01 alignment,
bool update_now =
false);
117 uint01 alignment()
const {
return m_alignment; }
127 void setInsertionAlignment(uint01 alignment,
bool update_now =
false);
137 Model textObject()
const;
142 void setCursor(uint04 cursor_position);
151 bool needsUpdate()
const;
156 void updateTranslation();
162 void setConstrainedSize(
const Vector<2, fltp08>& size);
167 void setMaximumSize(
const Vector<2, fltp08>& size);
172 void setReferenceSize(
const Vector<2, fltp08>& size);
178 Vector<2, fltp08> getConstrainedSize();
183 Vector<2, fltp08> getMaximumSize();
188 Vector<2, fltp08> getReferenceSize();
196 void setForwardBias(fltp08 forward_bias);
201 void setLineSpaceFactor(fltp08 line_space);
206 fltp08 lineSpaceFactor()
const;
211 StringView plainText()
const;
216 const Buffer<TextBlock>& blocks()
const {
return m_text_blocks; };
222 Buffer<TextBlock> autoInsertNewLines()
const;
228 void autoReserveLines(Buffer<TextBlock>& blocks);
234 void setFont(
const Font& font,
bool repaint_now =
false);
243 void saveBlockMetaData();
254 Model getLine(uint04 index);
260 Model getLetterAt(uint04 string_position)
const;
268 Model getLetterAt(uint04 string_position,
const Buffer<TextBlock>& blocks)
const;
273 static constexpr StringView TypeName() {
return "text"; }
278 void setFaceCamera(
bool face_camera);
284 void setScaleToCamera(
bool face_camera);
289 void setFillBackground(
bool fill_background);
294 static fltp04 DefaultScaler() {
return .01f; }
310 bool setupLetter(
const ConstPointer<TextConstructor>& printer, Model& letter, wchar value, fltp08 hor_advance, fltp08 scale,
const Font& font);
317 void setupCursor(
const Matrix<fltp08>& matrix,
const Vector<2, fltp08>& cursor_location,
const Font& font);
322 void findCursor(
bool create_if_not_exists);
326 void updateBackground();
332 Buffer<TextBlock> m_text_blocks;
333 Vector<2, fltp08> m_constrained_size;
334 Vector<2, fltp08> m_maximum_size;
335 Vector<2, fltp08> m_reference_size;
340 uint01 m_insertion_alignment;
341 mutable fltp08 m_line_space_factor;
342 fltp08 m_forward_bias = 0.0;
343 bool m_has_background =
false;
344 bool m_has_read_metadata =
false;
352#define TEXT_MODEL_PARAMS(X) \
353 X(e_constrained_size) \
355 X(e_reference_size) \
356 X(e_translated_text) \
359 X(e_line_space_factor) \
361 NDEVR_DEFINE_STRING_STREAM(TextProperty, TEXT_MODEL_PARAMS)
364 template<>
struct PropertySpec<TextProperty::e_constrained_size> {
using type = Vector<2, fltp08>; };
365 template<>
struct PropertySpec<TextProperty::e_maximum_size> {
using type = Vector<2, fltp08>; };
366 template<>
struct PropertySpec<TextProperty::e_reference_size> {
using type = Vector<2, fltp08>; };
367 template<>
struct PropertySpec<TextProperty::e_translated_text> {
using type = TranslatedString; };
370 template<>
struct PropertySpec<TextProperty::e_text_blocks> {
using type = Buffer<TextBlock>; };
371 template<>
struct PropertySpec<TextProperty::e_font> {
using type = Font; };
392 template<TextProperty t_property,
class t_value_type>
393 static void Set(DesignInfo*
object,
const t_value_type& value)
395 Text text = Text(Model(*
object));
396 if constexpr (t_property == TextProperty::e_constrained_size)
397 text.setConstrainedSize(value);
398 if constexpr (t_property == TextProperty::e_font)
400 if constexpr (t_property == TextProperty::e_line_space_factor)
401 text.setLineSpaceFactor(value);
402 if constexpr (t_property == TextProperty::e_maximum_size)
403 text.setMaximumSize(value);
404 if constexpr (t_property == TextProperty::e_reference_size)
406 if constexpr (t_property == TextProperty::e_translated_text)
408 if constexpr (t_property == TextProperty::e_text_blocks)
410 if constexpr (t_property == TextProperty::e_text)
413 text.saveBlockMetaData();
423 template<TextProperty t_property>
424 static decltype(
auto)
Get(
const DesignInfo*
object)
426 Text text = Text(Model(*
object));
428 if constexpr (t_property == TextProperty::e_constrained_size)
429 return text.getConstrainedSize();
430 if constexpr (t_property == TextProperty::e_font)
432 if constexpr (t_property == TextProperty::e_line_space_factor)
433 return text.lineSpaceFactor();
434 if constexpr (t_property == TextProperty::e_maximum_size)
435 return text.getMaximumSize();
436 if constexpr (t_property == TextProperty::e_reference_size)
437 return text.getReferenceSize();
438 if constexpr (t_property == TextProperty::e_translated_text)
439 return TranslatedString(text.plainText());
440 if constexpr (t_property == TextProperty::e_text_blocks)
441 return text.blocks();
442 if constexpr (t_property == TextProperty::e_text)
443 return text.plainText();
453 template<TextProperty t_property,
class t_value_type>
454 static decltype(
auto)
Get(
const DesignInfo*
object)
A core class that represents a node on model hierarchy.
Typed interface for getting and setting design object properties by enum.
static decltype(auto) Get(const DesignInfo *object, t_property_enum property)
Gets the value of a property from a design object using a runtime property enum.
static void Set(DesignInfo *object, t_property_enum property, const t_value_type &value)
Sets the value of a property on a design object using a runtime property enum.
The primary namespace for the NDEVR SDK.
@ type
The type identifier string for this model node.
float fltp04
Defines an alias representing a 4 byte floating-point number Bit layout is as follows: -Sign: 1 bit a...
uint32_t uint04
-Defines an alias representing a 4 byte, unsigned integer -Can represent exact integer values 0 throu...
double fltp08
Defines an alias representing an 8 byte floating-point number.
uint8_t uint01
-Defines an alias representing a 1 byte, unsigned integer -Can represent exact integer values 0 throu...
@ e_text
Open in text mode.
Maps a compile-time property enum value to its corresponding C++ storage type.