Partially done.
This commit is contained in:
21
dw/layout.cc
21
dw/layout.cc
@ -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)
|
Layout::Layout (std::unique_ptr< Platform > platform, bool limit)
|
||||||
{
|
{
|
||||||
this->platform = std::move( platform );
|
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.
|
* 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);
|
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))
|
if (anchorsTable.contains (name))
|
||||||
return NULL;
|
return std::nullopt;
|
||||||
else {
|
else {
|
||||||
auto anchor = std::make_unique< Anchor >();
|
auto anchor = std::make_unique< Anchor >();
|
||||||
char *const rv= anchor->name = dStrdup (name);
|
std::string rv= anchor->name= name;
|
||||||
anchor->widget = widget;
|
anchor->widget = widget;
|
||||||
anchor->y = y;
|
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();
|
Anchor *const anchor = anchorsTable.at( name ).get();
|
||||||
assert (anchor);
|
assert (anchor);
|
||||||
@ -762,7 +757,7 @@ void Layout::changeAnchor (Widget *widget, char* name, int y)
|
|||||||
updateAnchor ();
|
updateAnchor ();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Layout::removeAnchor (Widget *widget, char* name)
|
void Layout::removeAnchor (Widget *widget, const std::string &name)
|
||||||
{
|
{
|
||||||
anchorsTable.erase( name );
|
anchorsTable.erase( name );
|
||||||
}
|
}
|
||||||
|
12
dw/layout.hh
12
dw/layout.hh
@ -150,11 +150,9 @@ private:
|
|||||||
class Anchor: public lout::object::Object
|
class Anchor: public lout::object::Object
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
char *name;
|
std::string name;
|
||||||
Widget *widget;
|
Widget *widget;
|
||||||
int y;
|
int y;
|
||||||
|
|
||||||
~Anchor ();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
std::unique_ptr< Platform > platform;
|
std::unique_ptr< Platform > platform;
|
||||||
@ -236,10 +234,10 @@ private:
|
|||||||
|
|
||||||
/* Widget */
|
/* Widget */
|
||||||
|
|
||||||
char *addAnchor (Widget *widget, const char* name);
|
std::optional< std::string > addAnchor (Widget *widget, const std::string &name);
|
||||||
char *addAnchor (Widget *widget, const char* name, int y);
|
std::optional< std::string > addAnchor (Widget *widget, const std::string &name, int y);
|
||||||
void changeAnchor (Widget *widget, char* name, int y);
|
void changeAnchor (Widget *widget, const std::string &name, int y);
|
||||||
void removeAnchor (Widget *widget, char* name);
|
void removeAnchor (Widget *widget, const std::string &name);
|
||||||
void setCursor (style::Cursor cursor);
|
void setCursor (style::Cursor cursor);
|
||||||
void updateCursor ();
|
void updateCursor ();
|
||||||
void queueDraw (int x, int y, int width, int height);
|
void queueDraw (int x, int y, int width, int height);
|
||||||
|
@ -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
|
* Return true on success, and false, when this anchor had already been
|
||||||
* added to the widget tree.
|
* 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;
|
int y;
|
||||||
bool result;
|
bool result;
|
||||||
|
|
||||||
@ -2574,7 +2574,7 @@ bool Textblock::addAnchor (const char *name, core::style::Style *style)
|
|||||||
} else
|
} else
|
||||||
copy = Widget::addAnchor (name);
|
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
|
* \todo It may be necessary for future uses to save the anchor in
|
||||||
* some way, e.g. when parts of the widget tree change.
|
* some way, e.g. when parts of the widget tree change.
|
||||||
|
@ -505,7 +505,7 @@ protected:
|
|||||||
|
|
||||||
struct Anchor
|
struct Anchor
|
||||||
{
|
{
|
||||||
char *name;
|
std::string_view name;
|
||||||
int wordIndex;
|
int wordIndex;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -890,7 +890,7 @@ public:
|
|||||||
inline void addText (const char *text, core::style::Style *style)
|
inline void addText (const char *text, core::style::Style *style)
|
||||||
{ addText (text, strlen(text), style); }
|
{ addText (text, strlen(text), style); }
|
||||||
void addWidget (core::Widget *widget, core::style::Style *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 addSpace (core::style::Style *style);
|
||||||
void addBreakOption (core::style::Style *style, bool forceBreak);
|
void addBreakOption (core::style::Style *style, bool forceBreak);
|
||||||
void addParbreak (int space, core::style::Style *style);
|
void addParbreak (int space, core::style::Style *style);
|
||||||
|
@ -394,16 +394,16 @@ protected:
|
|||||||
virtual void enterNotifyImpl (EventCrossing *event);
|
virtual void enterNotifyImpl (EventCrossing *event);
|
||||||
virtual void leaveNotifyImpl (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); }
|
{ 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); }
|
{ 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); }
|
{ layout->changeAnchor (this, name, y); }
|
||||||
|
|
||||||
inline void removeAnchor (char* name)
|
inline void removeAnchor (const std::string &name)
|
||||||
{ if (layout) layout->removeAnchor (this, name); }
|
{ if (layout) layout->removeAnchor (this, name); }
|
||||||
|
|
||||||
//inline void updateBgColor () { layout->updateBgColor (); }
|
//inline void updateBgColor () { layout->updateBgColor (); }
|
||||||
|
Reference in New Issue
Block a user