mirror of
https://github.com/ArthurSonzogni/FTXUI.git
synced 2024-11-25 20:27:31 +08:00
Button: invoke on_click
at the end. (#807)
Some users might destroy `this`, which would result in UAF. In the future, we should consider alternatives like posting a task to the main loop, or rely on users for this. Fixed:https://github.com/ArthurSonzogni/FTXUI/issues/804
This commit is contained in:
parent
91a162a30e
commit
5112d9139d
@ -98,10 +98,13 @@ class ButtonBase : public ComponentBase, public ButtonOption {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void OnClick() {
|
void OnClick() {
|
||||||
on_click();
|
|
||||||
animation_background_ = 0.5F; // NOLINT
|
animation_background_ = 0.5F; // NOLINT
|
||||||
animation_foreground_ = 0.5F; // NOLINT
|
animation_foreground_ = 0.5F; // NOLINT
|
||||||
SetAnimationTarget(1.F); // NOLINT
|
SetAnimationTarget(1.F); // NOLINT
|
||||||
|
|
||||||
|
// TODO(arthursonzogni): Consider posting the task to the main loop, instead
|
||||||
|
// of invoking it immediately.
|
||||||
|
on_click(); // May delete this.
|
||||||
}
|
}
|
||||||
|
|
||||||
bool OnEvent(Event event) override {
|
bool OnEvent(Event event) override {
|
||||||
@ -110,7 +113,7 @@ class ButtonBase : public ComponentBase, public ButtonOption {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (event == Event::Return) {
|
if (event == Event::Return) {
|
||||||
OnClick();
|
OnClick(); // May delete this.
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
@ -127,7 +130,7 @@ class ButtonBase : public ComponentBase, public ButtonOption {
|
|||||||
if (event.mouse().button == Mouse::Left &&
|
if (event.mouse().button == Mouse::Left &&
|
||||||
event.mouse().motion == Mouse::Pressed) {
|
event.mouse().motion == Mouse::Pressed) {
|
||||||
TakeFocus();
|
TakeFocus();
|
||||||
OnClick();
|
OnClick(); // May delete this.
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user