Requested anchor RAIIed.
This commit is contained in:
20
dw/layout.cc
20
dw/layout.cc
@ -281,7 +281,6 @@ Layout::Layout (std::unique_ptr< Platform > platform, bool limit)
|
||||
DBG_OBJ_SET_NUM ("hScrollbarThickness", hScrollbarThickness);
|
||||
DBG_OBJ_SET_NUM ("vScrollbarThickness", vScrollbarThickness);
|
||||
|
||||
requestedAnchor = NULL;
|
||||
scrollIdleId = -1;
|
||||
scrollIdleNotInterrupted = false;
|
||||
|
||||
@ -332,9 +331,6 @@ Layout::~Layout ()
|
||||
delete view;
|
||||
delete textZone;
|
||||
|
||||
if (requestedAnchor)
|
||||
free (requestedAnchor);
|
||||
|
||||
DBG_OBJ_DELETE ();
|
||||
}
|
||||
|
||||
@ -410,7 +406,7 @@ void Layout::removeWidget ()
|
||||
view->setViewportSize (viewportWidth, viewportHeight, 0, 0);
|
||||
view->queueDrawTotal ();
|
||||
|
||||
setAnchor (NULL);
|
||||
setAnchor (std::nullopt);
|
||||
updateAnchor ();
|
||||
|
||||
emitter.emitCanvasSizeChanged (canvasWidth, canvasAscent, canvasDescent);
|
||||
@ -724,13 +720,11 @@ int Layout::currVScrollbarThickness()
|
||||
/**
|
||||
* Sets the anchor to scroll to.
|
||||
*/
|
||||
void Layout::setAnchor (const char *anchor)
|
||||
void Layout::setAnchor (const std::optional< std::string_view > anchor)
|
||||
{
|
||||
_MSG("setAnchor (%s)\n", anchor);
|
||||
_MSG("setAnchor (%s)\n", anchor.value_or("").string().c_str());
|
||||
|
||||
if (requestedAnchor)
|
||||
free (requestedAnchor);
|
||||
requestedAnchor = anchor ? dStrdup (anchor) : NULL;
|
||||
requestedAnchor = anchor;
|
||||
updateAnchor ();
|
||||
}
|
||||
|
||||
@ -776,9 +770,9 @@ void Layout::removeAnchor (Widget *widget, char* name)
|
||||
void Layout::updateAnchor ()
|
||||
{
|
||||
Anchor *anchor= nullptr;
|
||||
if (requestedAnchor and anchorsTable.contains( requestedAnchor ) )
|
||||
if (requestedAnchor and anchorsTable.contains( requestedAnchor.value() ) )
|
||||
{
|
||||
anchor= anchorsTable[ requestedAnchor ].get();
|
||||
anchor= anchorsTable[ requestedAnchor.value() ].get();
|
||||
}
|
||||
|
||||
if (anchor == NULL) {
|
||||
@ -1292,7 +1286,7 @@ void Layout::scrollPosChanged (View *view, int x, int y)
|
||||
scrollX = x;
|
||||
scrollY = y;
|
||||
|
||||
setAnchor (NULL);
|
||||
setAnchor( std::nullopt );
|
||||
updateAnchor ();
|
||||
}
|
||||
}
|
||||
|
@ -182,7 +182,7 @@ private:
|
||||
VPosition scrollTargetVpos;
|
||||
int scrollTargetX, scrollTargetY, scrollTargetWidth, scrollTargetHeight;
|
||||
|
||||
char *requestedAnchor;
|
||||
std::optional< std::string > requestedAnchor;
|
||||
int scrollIdleId, resizeIdleId;
|
||||
bool scrollIdleNotInterrupted;
|
||||
|
||||
@ -300,7 +300,7 @@ public:
|
||||
void scrollTo (HPosition hpos, VPosition vpos,
|
||||
int x, int y, int width, int height);
|
||||
void scroll (ScrollCommand);
|
||||
void setAnchor (const char *anchor);
|
||||
void setAnchor (std::optional< std::string_view > anchor);
|
||||
|
||||
/* View */
|
||||
|
||||
|
Reference in New Issue
Block a user