Partially done.

This commit is contained in:
2025-08-21 19:19:28 -04:00
parent 92d679e098
commit a41d0b067d
5 changed files with 23 additions and 30 deletions

View File

@ -248,13 +248,6 @@ bool Layout::LinkEmitter::emitClick (Widget *widget, int link, int img,
// ---------------------------------------------------------------------
Layout::Anchor::~Anchor ()
{
free(name);
}
// ---------------------------------------------------------------------
Layout::Layout (std::unique_ptr< Platform > platform, bool limit)
{
this->platform = std::move( platform );
@ -731,18 +724,20 @@ void Layout::setAnchor (const std::optional< std::string_view > anchor)
/**
* Used, when the widget is not allocated yet.
*/
char *Layout::addAnchor (Widget *widget, const char* name)
std::optional< std::string >
Layout::addAnchor (Widget *widget, const std::string &name)
{
return addAnchor (widget, name, -1);
}
char *Layout::addAnchor (Widget *widget, const char* name, int y)
std::optional< std::string >
Layout::addAnchor (Widget *widget, const std::string &name, int y)
{
if (anchorsTable.contains (name))
return NULL;
return std::nullopt;
else {
auto anchor = std::make_unique< Anchor >();
char *const rv= anchor->name = dStrdup (name);
std::string rv= anchor->name= name;
anchor->widget = widget;
anchor->y = y;
@ -753,7 +748,7 @@ char *Layout::addAnchor (Widget *widget, const char* name, int y)
}
}
void Layout::changeAnchor (Widget *widget, char* name, int y)
void Layout::changeAnchor (Widget *widget, const std::string &name, int y)
{
Anchor *const anchor = anchorsTable.at( name ).get();
assert (anchor);
@ -762,7 +757,7 @@ void Layout::changeAnchor (Widget *widget, char* name, int y)
updateAnchor ();
}
void Layout::removeAnchor (Widget *widget, char* name)
void Layout::removeAnchor (Widget *widget, const std::string &name)
{
anchorsTable.erase( name );
}

View File

@ -150,11 +150,9 @@ private:
class Anchor: public lout::object::Object
{
public:
char *name;
std::string name;
Widget *widget;
int y;
~Anchor ();
};
std::unique_ptr< Platform > platform;
@ -236,10 +234,10 @@ private:
/* Widget */
char *addAnchor (Widget *widget, const char* name);
char *addAnchor (Widget *widget, const char* name, int y);
void changeAnchor (Widget *widget, char* name, int y);
void removeAnchor (Widget *widget, char* name);
std::optional< std::string > addAnchor (Widget *widget, const std::string &name);
std::optional< std::string > addAnchor (Widget *widget, const std::string &name, int y);
void changeAnchor (Widget *widget, const std::string &name, int y);
void removeAnchor (Widget *widget, const std::string &name);
void setCursor (style::Cursor cursor);
void updateCursor ();
void queueDraw (int x, int y, int width, int height);

View File

@ -2555,11 +2555,11 @@ void Textblock::addWidget (core::Widget *widget, core::style::Style *style)
* Return true on success, and false, when this anchor had already been
* added to the widget tree.
*/
bool Textblock::addAnchor (const char *name, core::style::Style *style)
bool Textblock::addAnchor (const std::string &name, core::style::Style *style)
{
DBG_OBJ_ENTER ("construct.word", 0, "addAnchor", "\"%s\", %p", name, style);
DBG_OBJ_ENTER ("construct.word", 0, "addAnchor", "\"%s\", %p", name.c_str(), style);
char *copy;
std::optional< std::string > copy;
int y;
bool result;
@ -2574,7 +2574,7 @@ bool Textblock::addAnchor (const char *name, core::style::Style *style)
} else
copy = Widget::addAnchor (name);
if (copy == NULL)
if (not copy.has_value())
/**
* \todo It may be necessary for future uses to save the anchor in
* some way, e.g. when parts of the widget tree change.

View File

@ -505,7 +505,7 @@ protected:
struct Anchor
{
char *name;
std::string_view name;
int wordIndex;
};
@ -890,7 +890,7 @@ public:
inline void addText (const char *text, core::style::Style *style)
{ addText (text, strlen(text), style); }
void addWidget (core::Widget *widget, core::style::Style *style);
bool addAnchor (const char *name, core::style::Style *style);
bool addAnchor (const std::string &name, core::style::Style *style);
void addSpace (core::style::Style *style);
void addBreakOption (core::style::Style *style, bool forceBreak);
void addParbreak (int space, core::style::Style *style);

View File

@ -394,16 +394,16 @@ protected:
virtual void enterNotifyImpl (EventCrossing *event);
virtual void leaveNotifyImpl (EventCrossing *event);
inline char *addAnchor (const char* name)
inline std::optional< std::string > addAnchor (const std::string &name)
{ return layout->addAnchor (this, name); }
inline char *addAnchor (const char* name, int y)
inline std::optional< std::string > addAnchor (const std::string &name, int y)
{ return layout->addAnchor (this, name, y); }
inline void changeAnchor (char* name, int y)
inline void changeAnchor (const std::string &name, int y)
{ layout->changeAnchor (this, name, y); }
inline void removeAnchor (char* name)
inline void removeAnchor (const std::string &name)
{ if (layout) layout->removeAnchor (this, name); }
//inline void updateBgColor () { layout->updateBgColor (); }