bool LineEdit::HandleEventSelf(const SDL_Event& ev) { switch (ev.type) { case SDL_MOUSEBUTTONDOWN: { if (MouseOver(ev.button.x, ev.button.y)) { hasFocus = true; } else { hasFocus = false; } break; } case SDL_KEYDOWN: { if (!hasFocus) break; switch(ev.key.keysym.sym) { case SDLK_BACKSPACE: { if (cursorPos > 0) { content.erase(--cursorPos, 1); } break; } case SDLK_DELETE: { if (cursorPos < content.size()) { content.erase(cursorPos, 1); } break; } case SDLK_ESCAPE: { hasFocus= false; break; } case SDLK_RIGHT: { if (cursorPos < content.size()) ++cursorPos; break; } case SDLK_LEFT: { if (cursorPos > 0) --cursorPos; break; } case SDLK_HOME: { cursorPos = 0; break; } case SDLK_END: { cursorPos = content.size(); break; } case SDLK_RETURN: { DefaultAction(); return true; } default: { uint16_t currentUnicode = ev.key.keysym.unicode; if (currentUnicode >= 32 && currentUnicode <= 126) // only ASCII supported ATM { char buf[2] = {(const char)currentUnicode, 0}; content.insert(cursorPos++, buf); } } } break; } } return false; }
void RichObjectType::DefaultAction(RichObject& data, void *context) const { DefaultAction(data); }