mirror of
https://github.com/s00500/ESPUI.git
synced 2024-11-25 03:50:54 +00:00
Reworked removeControl function
This commit is contained in:
parent
7056cdf044
commit
9cb962122c
@ -628,38 +628,30 @@ uint16_t ESPUIClass::addControl(ControlType type, const char* label, const Strin
|
|||||||
|
|
||||||
bool ESPUIClass::removeControl(uint16_t id, bool force_reload_ui)
|
bool ESPUIClass::removeControl(uint16_t id, bool force_reload_ui)
|
||||||
{
|
{
|
||||||
if (nullptr == this->controls)
|
Control* PreviousControl = nullptr;
|
||||||
return false;
|
Control* CurrentControl = this->controls;
|
||||||
|
|
||||||
Control* it = this->controls;
|
while(nullptr != CurrentControl)
|
||||||
|
|
||||||
if (id == it->id)
|
|
||||||
{
|
{
|
||||||
this->controls = it->next;
|
if (id == CurrentControl->id)
|
||||||
delete it;
|
|
||||||
this->controlCount--;
|
|
||||||
if (force_reload_ui)
|
|
||||||
{
|
{
|
||||||
jsonReload();
|
break;
|
||||||
|
}
|
||||||
|
PreviousControl = CurrentControl;
|
||||||
|
CurrentControl = CurrentControl->next;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (nullptr != CurrentControl)
|
||||||
|
{
|
||||||
|
if(nullptr == PreviousControl)
|
||||||
|
{
|
||||||
|
this->controls = CurrentControl->next;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
jsonDom(0);
|
PreviousControl->next = CurrentControl->next;
|
||||||
}
|
}
|
||||||
return true;
|
delete CurrentControl;
|
||||||
}
|
|
||||||
|
|
||||||
Control* it_next = it->next;
|
|
||||||
while (nullptr != it_next && id != it_next->id)
|
|
||||||
{
|
|
||||||
it = it_next;
|
|
||||||
it_next = it_next->next;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (nullptr != it_next)
|
|
||||||
{
|
|
||||||
it->next = it_next->next;
|
|
||||||
delete it_next;
|
|
||||||
this->controlCount--;
|
this->controlCount--;
|
||||||
if (force_reload_ui)
|
if (force_reload_ui)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user