mirror of
https://github.com/meshtastic/firmware.git
synced 2026-11-06 06:14:45 -05:00
- VirtualKeyboard::handleLongPress VK_ESC invoked the onTextEntered member std::function directly, but that callback path reaches OnScreenKeyboardModule::stop(), which destroys the keyboard - and with it the std::function whose invocation is still on the stack. handlePress and submitText already deliberately copy-and-clear before invoking for exactly this reason (CannedMessageModule documents the same hazard); do the same here. - OnScreenKeyboardModule's keyboard becomes unique_ptr, replacing the delete-in-destructor / delete-then-new-in-start / delete-in-stop bookkeeping that runs on every keyboard open/close. The NotificationRenderer legacy hook receives a non-owning raw pointer, as before.
45 lines
1.1 KiB
C++
45 lines
1.1 KiB
C++
#pragma once
|
|
|
|
#include "configuration.h"
|
|
#if HAS_SCREEN
|
|
|
|
#include "graphics/Screen.h" // InputEvent
|
|
#include "graphics/VirtualKeyboard.h"
|
|
#include <OLEDDisplay.h>
|
|
#include <functional>
|
|
#include <memory>
|
|
#include <string>
|
|
|
|
namespace graphics
|
|
{
|
|
class OnScreenKeyboardModule
|
|
{
|
|
public:
|
|
static OnScreenKeyboardModule &instance();
|
|
|
|
void start(const char *header, const char *initialText, uint32_t durationMs,
|
|
std::function<void(const std::string &)> callback);
|
|
|
|
void stop(bool callEmptyCallback);
|
|
|
|
void handleInput(const InputEvent &event);
|
|
static bool processVirtualKeyboardInput(const InputEvent &event, VirtualKeyboard *keyboard);
|
|
bool draw(OLEDDisplay *display);
|
|
|
|
private:
|
|
OnScreenKeyboardModule() = default;
|
|
~OnScreenKeyboardModule();
|
|
OnScreenKeyboardModule(const OnScreenKeyboardModule &) = delete;
|
|
OnScreenKeyboardModule &operator=(const OnScreenKeyboardModule &) = delete;
|
|
|
|
void onSubmit(const std::string &text);
|
|
void onCancel();
|
|
|
|
std::unique_ptr<VirtualKeyboard> keyboard;
|
|
std::function<void(const std::string &)> callback;
|
|
};
|
|
|
|
} // namespace graphics
|
|
|
|
#endif // HAS_SCREEN
|