24#define ZXGUIVER "3.0.0"
79 { scr.
colors() = {(forborder ?
122 "; decorations ink: " +
126 "; cursor colors: " +
131 static std::string endistext(
const std::string & entxt,
132 const std::string & distxt)
133 {
return(entxt +
" (enabled) or " + distxt +
" (disabled)"); }
154 const CharRect &
get(
void)
const noexcept {
return(typing_zone_); }
159 { typing_zone_.corner.addDiff(xdiff,ydiff); }
189 Label(
const std::string & initlabel) { set(initlabel); }
192 Label(
const char * initlabel) { set(initlabel); }
195 void set(
const std::string & label);
199 void set(
const char * label);
203 const std::string &
get(
void)
const noexcept {
return(label_); }
258 static const uint8_t IT_ANY_VISIBILITY = IT_VISIBLE | IT_INVISIBLE;
261 static const uint8_t IT_ANY_MARKABILITY = IT_MARKED | IT_UNMARKED;
264 static const uint8_t IT_ALL = IT_ANY_VISIBILITY | IT_ANY_MARKABILITY;
267 static const uint8_t IT_ALL_VISIBLE = IT_VISIBLE | IT_ANY_MARKABILITY;
277 size_t who,
unsigned marking = 0);
286 unsigned marking = 0,
IniPos inip = BEGIN);
298 unsigned newmarking = 0) noexcept;
306 Iterator & operator=(
const Iterator & oth)
307 {
if (
this != &oth) copyFrom(oth);
return(*
this); }
308 Iterator & operator=(Iterator && oth)
309 {
if (
this != &oth) { moveFrom(std::move(oth)); }
return(*
this); }
312 uint8_t
conditions(
void)
const noexcept {
return(conditions_); }
315 unsigned marking(
void)
const noexcept {
return(marking_); }
367 void checkderef(
void)
const;
368 bool testconditions(
void)
const noexcept;
369 void copyFrom(
const Iterator & oth)
noexcept;
370 void moveFrom(
Iterator && oth)
noexcept;
384 const Observer & obs = kNullObserver );
390 const Observer & obs = kNullObserver)
noexcept;
401 const Observer & obs = kNullObserver);
420 void checkMarking(
unsigned marking)
const;
423 void checkIndex(
size_t who)
const;
426 size_t size(
void)
const noexcept;
432 bool empty(
void)
const noexcept {
return(size() == 0); }
435 CharArea areaForEntireList(
void)
const;
441 const Observer & observer(
void)
const noexcept {
return(obs_); }
444 void changeObserver(
const Observer & obs) { obs_ = obs; }
452 Iterator begin(uint8_t conditions = Iterator::IT_ALL,
453 unsigned marking = 0)
const;
460 size_t sizeByIterator(Iterator it)
const noexcept;
465 size_t longestLabel(Iterator it)
const noexcept;
472 virtual std::string labelText(
size_t who)
const;
477 Label & label(
size_t who);
483 bool marked(
size_t who,
unsigned marking = 0)
const;
487 bool visible(
size_t who)
const;
497 bool mark(
size_t who,
unsigned marking = 0);
502 bool markAll(
unsigned marking = 0);
506 bool unmark(
size_t who,
unsigned marking = 0);
511 bool unmarkAll(
unsigned marking = 0);
516 void toggle(
size_t who,
unsigned marking = 0);
520 void toggleAll(
unsigned marking = 0);
525 virtual void setVisible(
size_t who);
528 virtual void setInvisible(
size_t who);
531 virtual void toggleVisible(
size_t who);
535 virtual void clear(
void);
538 size_t push_back(
const Label & l) {
return(insert(l,size())); }
548 {
for (
const auto & l: v) push_back(l); }
550 virtual size_t insert(
const Label & l,
size_t beforewho);
557 {
for (
const auto & l: v) { insert(l,beforewho); ++beforewho; } }
559 virtual void erase(
size_t who);
564 bool eraseMarked(
unsigned marking = 0);
575 virtual void sort(
char mode =
'A', std::vector<size_t> * order =
nullptr);
583 void fillWithFiles(
const std::filesystem::path & path = {},
584 char mode =
'T',
bool onlyfiles =
false,
585 std::vector<std::string> * entries =
nullptr);
602 virtual std::string to_string(
void)
const;
617 IndsRange(
size_t b,
size_t e):begin_{b},end_{e}
618 {
if (b > e)
RUNTIMEEXCEP(
"Invalid index range for labellist"); }
621 {
if (i.
empty()) clear();
625 size_t begin(
void)
const noexcept {
return(begin_); }
626 size_t end(
void)
const noexcept {
return(end_); }
628 bool empty(
void)
const noexcept {
return(begin_ == end_); }
629 size_t length(
void)
const noexcept
630 {
return(empty() ? 0 : end_ - begin_); }
632 size_t first(
void)
const
633 {
if (empty())
RUNTIMEEXCEP(
"Empty labellist range has no first");
635 size_t last(
void)
const
636 {
if (empty())
RUNTIMEEXCEP(
"Empty labellist range has no last");
638 size_t nth(
size_t offset)
const
639 {
size_t i{first() + offset};
641 RUNTIMEEXCEP(
"Invalid offset within a labellist range");
644 void clear(
void) { begin_ = 0; end_ = 0; }
646 void expand(
size_t l)
647 {
if (l == 0)
return;
648 if (empty())
RUNTIMEEXCEP(
"Cannot expand empty labellist range");
651 void contract(
size_t l)
652 {
if (l == 0)
return;
654 RUNTIMEEXCEP(
"Cannot contract labellist range so much");
660 for (
size_t f = begin_; f < end_; ++f) res.push_back(f);
664 {
return(empty() ?
IntervalType{0,0,IntervalCl::OPENED} :
667 std::string to_string(
void)
const
668 {
return(
"labellist-range(" +
669 (empty() ?
"empty)" : std::to_string(first()) +
" to " +
670 std::to_string(last()) +
"; " +
671 std::to_string(length()) +
679 using Marks = std::vector<bool>;
685 std::vector<Marks> markings_;
688 IndsRange sectrange_;
695 size_t actualPos(
size_t p)
const noexcept
696 {
return(owner_ ? p : sectrange_.nth(p)); }
697 void checkOtherCompatibility(
const LabelList & oth)
const;
698 void checkMultiple(
unsigned marking = 0)
const;
700 void overwriteElement(
const LabelList & oth,
size_t pos,
size_t dest);
701 void overwriteSection(
const LabelList & oth);
733 lastadded_{lt.size()} {}
739 size_t add(
const Label & l);
748 void add(
const Label::Vector & v) {
for (
const auto & l: v) add(l); }
751 void openSubtree(
void);
754 void closeSubtree(
void);
768 const Observer & obs = kNullObserver);
780 const std::string &
preffixChars(
void)
const noexcept {
return(chars_); }
795 size_t * posdeploy =
nullptr)
const;
810 {
return(preffixForLabel(who) + LabelList::labelText(who)); }
823 { checkIndex(parent);
return(!subtreeRange(parent,
false).empty()); }
831 Indexes * indexmap =
nullptr)
const;
860 { changeSubtreeVisible(who,
true,
true); }
865 { changeSubtreeVisible(who,
false,
true); }
870 { toggleSubtreeVisible(who,
true); }
879 std::vector<size_t> * order =
nullptr)
override;
890 std::vector<size_t> depths_;
893 void retrieveObserver(
const Observer & obs,
char reason);
895 IndsRange subtreeRange(
size_t pos,
bool withparent =
true)
const;
896 size_t parent(
size_t pos)
const;
897 size_t prevSibling(
size_t pos)
const;
898 size_t nextSibling(
size_t pos)
const;
899 size_t lastRoot(
void)
const;
907 void toggleSubtreeVisible(
size_t root,
bool withroot);
908 void changeSubtreeVisible(
size_t root,
bool visi,
bool withroot);
926 const Observer & obs = kNullObserver);
953 size_t * posdeploy =
nullptr)
const override;
972 std::string getlastdirname(
const std::filesystem::path & path);
974 std::vector<std::string> entries_;
975 std::vector<bool> explored_;
980 void insert_children(
size_t p);
981 void erase_children(
size_t p)
override;
985 using LabelTree::insert;
986 using LabelTree::insert_child;
987 using LabelTree::erase;
988 using LabelTree::setVisible;
989 using LabelTree::setInvisible;
990 using LabelTree::toggleVisible;
991 using LabelTree::changeVisibilityDepth;
992 using LabelTree::sort;
ELEMTYPE maximum(void) const noexcept
Return the maximum value.
ELEMTYPE minimum(void) const noexcept
Return the minimum value.
bool empty(void) const noexcept
Return true if the interval is empty.
An interval, typically numeric, either closed, opened or semi-closed.
#define RUNTIMEEXCEP(txt)
Raise a runtime exception with the given std::string TXT + additional info.
Iterator & operator++(void) noexcept
Prefix increment for the iterator.
std::string preffixForLabel(size_t who, size_t *posdeploy=nullptr) const override
Return the preffix corresponding to that label (see LabelTree).
void clear(void)
Clear the entire content of the tree.
TypingZone(void)
Default constructor.
BasicColor maindisink
For the ink of main disabled elements.
bool hasChildren(size_t parent) const
< Return whether the given element has any children.
void setBackgroundColorsFor(Screen &scr) const
< Put the background colors in SCR.
const size_t kNumOfMarkings
Number of independent markings for labels.
const std::string & get(void) const noexcept
Get the current label text.
LabelList * clone(void) const override
Clone operation for being overriden in derived classes to return them.
void set(const std::string &label)
Set the label text to LABEL.
size_t depth(void) const
Return the depth of the tree, i.e., the maximum depth in it.
Iterator(const Iterator &oth, uint8_t newconds, unsigned newmarking=0) noexcept
Construct iterator to the same label as OTH but with another view.
uint8_t conditions(void) const noexcept
Return the conditions for which the iterator was created.
Iterator(void)
Default constructor: end iterator.
const std::string kMarkingMultips
Multiple selection mode of markings.
size_t operator*(void) const
Return the actual position of the label in the label list.
BrightColor typingmarkpaper
For marking some part of the typing areas.
size_t advance(size_t n) noexcept
Advance the iterator N steps; return the no. of steps not advanced.
void set(const char *label)
Set the label text to LABEL.
const CharRect & get(void) const noexcept
Return the current typing zone (updated by derived classes).
LabelList(const std::string &markingmultips, const Observer &obs=kNullObserver)
Constructor: empty list and marks.
LabelList(const Label::Vector &labels, const std::string &markingmultips, const Observer &obs=kNullObserver)
Constructor from a vector of labels.
size_t depth(size_t pos) const
Return the depth of the given element in the tree (from 0 for root).
void toggleVisible(size_t who) override
< Toggle visibility for WHO and all its children.
BrightColor typingpaper
For the paper of typing areas.
void setMainColorsFor(Screen &scr, bool enabled) const
< Put the main colors in SCR.
bool isParent(size_t who) const
Return TRUE if the given index is the parent directory of the tree.
IniPos
Iterator to create.
@ BEGIN
One that points to the first index in view.
size_t readStartingPath(const std::filesystem::path &p)
Clear the content of the list and fill it with the 1st level dirs in P.
LabelList * clone(void) const override
Clone operation for being overriden in derived classes to return them.
void append(LabelList &&oth)
Move the content of OTH to the end of this.
void clear(Screen &globscr, const WinColors &wincols, bool enabled)
Draw an empty typing zone in the current zone within GLOBSCR.
virtual void changeVisibilityDepth(size_t fromdepth, bool visib)
Set visibility to VISIB for all elements with depth >= FROMDEPTH.
BrightColor backpaper
For the background paper and bright.
std::vector< size_t > Indexes
A set of unique absolute indexes on the list.
size_t insert(const Label &l, size_t beforewho) override
Insert the new label previously to BEFOREWHO, with its same depth.
static const WinColors kDark
Colors for dark background, with bright.
std::string to_string(void) const
< Return textual information about the colors.
Label(const std::string &initlabel)
Constructor from string.
AttrColors title
For paper, ink, bright of title (flash ignored)
void erase(size_t who) override
Erase WHO and all its children, at all depths.
virtual std::string preffixForLabel(size_t who, size_t *posdeploy=nullptr) const
Return the preffix corresponding to that label.
Iterator & operator--(void) noexcept
Prefix decrement for the iterator.
bool operator==(const Iterator &oth) const
Return TRUE if both iterators are end or point to the same element.
Label(const char *initlabel)
Constructor from char array.
std::function< void(char)> Observer
void setVisible(size_t who) override
< Set visibility for WHO and all its children.
uint8_t attrForBackground(void) const
< Return an attribute suitable for filling a background attrmap.
void move(IntDist xdiff, IntDist ydiff) noexcept
< Shift typing zone.
static const Observer kNullObserver
An observer that does nothing.
bool operator!=(const Iterator &oth) const
Return TRUE if any of them is not end or point to diffrnt elements.
static bool labelSatisfiesCondition(uint8_t conditions, const LabelList &l, size_t who, unsigned marking=0)
Test whether that label satisfies the given conditions.
DepthFirstInserter(LabelTree <, size_t parentpos=0)
Constructor to insert elements as subtree of PARENTPOS in LT.
std::string to_string(void) const
Return a text describing the iterator.
LabelList(LabelList &&oth)
Move constructor eaves OTH in undefined state if OTH has no ownership.
void setTitleColorsFor(Screen &scr, bool forborder=false) const
< Put the title colors in SCR.
int operator-(const Iterator &rhs) const
Return the distance from OTH to THIS (negative if OTH comes before)
std::filesystem::path absolutePath(size_t who) const
Return the absolute path in the disk corresponding to the WHO label.
AttrColors cursor
For a cursor marking something.
std::vector< Label > Vector
A vector of labels.
virtual ~LabelList(void)
Destructor.
void sort(char mode='A', std::vector< size_t > *order=nullptr) override
Do sort only if there is only one level in the tree; otherwise, throw.
BasicColor decdisink
For the ink of disabled decorations.
std::string to_string(void) const override
Return a (potentially long) text with all entries of the list and mrkrs.
const std::string & preffixChars(void) const noexcept
Return the current preffixes used by labelText();.
unsigned marking(void) const noexcept
Return the marking for which the iterator was created.
void setInvisible(size_t who) override
< Unset visibility for WHO and all its children.
LabelTree(const std::string &markingmultips, const Observer &obs=kNullObserver)
Constructor: empty tree.
void setTypingColorsFor(Screen &scr, bool enabled) const
< Put the colors for a typing area in SCR.
void setDecorColorsFor(Screen &scr, bool enabled) const
< Put the decorations colors in SCR.
LabelTree subtree(size_t parent, bool withparent=false, Indexes *indexmap=nullptr) const
Return a tree copied from the subtree of PARENT, with or without it.
AttrColors tooltip
Colors for the tooltip.
size_t retreat(size_t n) noexcept
Retreat the iterator N steps; return the no. of steps not retreatd.
BrightColor typingdispaper
For the paper of disabled typing areas.
BasicColor decink
For the ink of enabled decorations.
static const WinColors kLight
Colors for light background, with bright.
virtual void erase_children(size_t who)
Erase all children of WHO, at all depths, if any.
LabelList & operator=(LabelList &&oth)
Move copy leaves OTH in undefined state if OTH has no ownership.
virtual void toggleFolding(size_t who)
Toggle visibility of children of WHO for folding/unfolding it.
Indexes firstBorn(size_t parent) const
Return the set of indexes (ordered) for the firstborns of PARENT.
void changePreffixChars(const std::string &preffixchars)
Set the chars used as preffixes by labelText().
void set(const CharRect &zone) noexcept
Change current typing zone.
void setCursorColorsFor(Screen &scr) const
< Put the cursor colors in SCR.
Label(void)
Default constructor: empty label.
Iterator(const LabelList &l, uint8_t conditions=IT_ALL, unsigned marking=0, IniPos inip=BEGIN)
Construct an iterator for scanning label indexes in the given list.
void clear(void) override
Clear the content of the entire list, markings and visibilities.
BasicColor mainink
For the ink of main enabled elements.
void toggleFolding(size_t who) override
Fold or unfold the given parent directory.
LabelList(LabelList &oth, size_t begin, size_t length, const Observer &obs=kNullObserver) noexcept
Constructor: sublist taken from indexes [begin,begin+length) from OTH.
LabelDirBrowser(const std::string &markingmultips, const Observer &obs=kNullObserver)
Constructor. Empty directory.
virtual size_t insert_child(const Label &l, size_t parent)
Insert the new label as the last child of PARENT, that must exist.
std::string labelText(size_t who) const override
< Return the label of the text including a preffix indicating the tree.
A non-empty label for a widget.
A tree of labels that correspond to the entries in a directory tree.
A list of labels to be displayed vertically, with possible marks on them.
A range of indexes covering some part of the list.
Bidirectional iterator to scan indexes in the list under a given view.
A tree of labels based on LabelList.
Inserter of elements into the tree structure.
A zone of a widget where the user can type.
Colors used in a GUI window.
std::string to_string(bool shorttxt=false) const
Return a descriptive text of this color specification.
std::string to_string(void) const
Return the name for this color.
bool bright(void) const noexcept
Get the bright level.
BasicColor color(void) const noexcept
Get the basic color.
std::string to_string(void) const
Return a descriptive string for this color.
BasicColor contrasting(void) const noexcept
Return the basic color that contrasts with this one.
Complete color specification for an attr (character) cell on the zx screen.
One of the 8 basic colors of the ZX, not considering bright or flash.
A value of bright that is different to the same value of flash, inv or over.
A basic color plus a bright level (on / off).
A value of flash that is different to the same value of bright, inv or over.
A printcolor for ink as a different type from a color for paper.
A value of inv that is different to the same value of flash, bright or over.
A value of over that is different to the same value of flash, bright or inv.
A printcolor for paper as a different type from a color for ink.
int16_t IntDist
Positive and negative distances on screen.
Colors & colors(void) noexcept
Get reference to the current colors that can be used to write and read.
The class that provides the main support for managing the ZX screen.
The main namespace of the library, that spans across all the zx modules.