19#ifndef ZXWIDGET_TEXTEDITOR
20#define ZXWIDGET_TEXTEDITOR
46 const std::string & tooltiptext =
"",
62 const std::string &
text(
void)
const {
return(ltext_.linearText()); }
65 void setText(
const std::string & txt);
74 std::pair<bool,const CharRect *>
hasFocusZone(
void)
const noexcept override
75 {
return(std::make_pair(
true,&editablerect_.
get())); }
77 const char *
className(
void)
const noexcept {
return(
"TextEditortWidget"); }
88 enum Direction { ADV_RIGHT, ADV_LEFT, ADV_UP, ADV_DOWN,
89 ADV_BEGINLINE, ADV_ENDLINE,
93 LinedText(
bool edit): editable_{edit},
94 area_{0,0},cursor_{0,0,true},cursorshow_{false} {}
98 void set(
const std::string & txt);
99 const std::string & linearText(
void)
const noexcept {
return(text_); }
100 size_t numberOfLines(
void)
const noexcept {
return(linestarts_.size());}
102 void print(Screen & scr,
size_t firstline,
bool enabled =
true);
104 void setCursorShow(
bool show)
noexcept { cursorshow_ = show; }
105 void setCursor(
size_t line,
size_t column)
106 { setCursorAtCoords(line,column); }
107 void moveCursor(Direction dir = ADV_RIGHT);
108 size_t cursorLine(
void)
const noexcept {
return(cursor_.line); }
109 size_t cursorColumn(
void)
const noexcept {
return(cursor_.col); }
110 bool cursorAtEnd(
void)
const noexcept {
return(cursor_.atend); }
111 bool cursorShown(
void)
const noexcept {
return(cursorshow_); }
113 void insertText(
const std::string &
text);
114 void deletePrevChar(
void);
116 std::string to_string(
void)
const;
120 static constexpr bool isSpace(
char c)
noexcept {
return(c ==
CHRSPC); }
122 const bool editable_;
125 std::vector<size_t> linestarts_;
134 size_t lineLength(
size_t line)
const;
135 size_t cursorPos(
void)
const noexcept
136 {
return(cursor_.atend ? text_.size() :
137 linestarts_[cursor_.line] + cursor_.col); }
138 void setCursorAtPos(
size_t s);
139 void setCursorAtCoords(
size_t line,
size_t col);
140 void updateLining(
size_t fromline = 0);
141 size_t actualLineEnd(
size_t linestart,
size_t lineend)
const;
142 void printCursor(Screen & scr,
size_t firstline,
bool enabled);
145 static const std::vector<uint8_t> kUDGs;
147 const bool editable_;
149 TypingZone editablerect_;
153 bool findMouseClickInLinedText(
const EventData & evdata,
154 size_t & line,
size_t & column)
const;
155 void adjustViewport(
bool upordown,
bool oneline);
157 int processEvent(
const EventData & evdata, Widget * who)
override;
158 std::string to_string(
void)
const;
const CharRect & get(void) const noexcept
Return the current typing zone (updated by derived classes).
void move(IntDist xdiff, IntDist ydiff) noexcept
< Shift typing zone.
A widget that shows an area for editing multi-line text with word-wrapping.
Area< CharDistT, CharDistT > CharArea
Shortcut for this kind of area.
int16_t IntDist
Positive and negative distances on screen.
The main namespace of the library, that spans across all the zx modules.
constexpr uint8_t CHRSPC
space