示例#1
0
	void Textfield::add_string(const std::string& str)
	{
		for (char c : str)
		{
			if (belowlimit())
			{
				text.insert(markerpos, 1, c);
				markerpos++;
				modifytext(text);
			}
		}
	}
示例#2
0
	void Textfield::sendkey(Keyboard::Keytype type, int32_t key, bool pressed)
	{
		switch (type)
		{
		case Keyboard::ACTION:
			if (pressed)
			{
				switch (key)
				{
				case Keyboard::LEFT:
					if (markerpos > 0)
					{
						markerpos--;
					}
					break;
				case Keyboard::RIGHT:
					if (markerpos < text.size())
					{
						markerpos++;
					}
					break;
				case Keyboard::BACK:
					if (text.size() > 0 && markerpos > 0)
					{
						text.erase(markerpos - 1, 1);
						markerpos--;
						modifytext(text);
					}
					break;
				case Keyboard::RETURN:
					if (onreturn)
					{
						(*onreturn)(text);
						text = "";
						markerpos = 0;
						modifytext(text);
					}
					break;
				case Keyboard::SPACE:
					if (belowlimit())
					{
						text.insert(markerpos, 1, ' ');
						markerpos++;
						modifytext(text);
					}
					break;
				}
			}
			break;
		case Keyboard::LETTER:
		case Keyboard::NUMBER:
			if (!pressed)
			{
				int8_t c = static_cast<int8_t>(key);
				if (belowlimit())
				{
					text.insert(markerpos, 1, c);
					markerpos++;
					modifytext(text);
				}
			}
			break;
		}
	}
示例#3
0
	void Textfield::settext(string t)
	{
		modifytext(t);
		markerpos = text.size();
	}
示例#4
0
	void Textfield::change_text(const std::string& t)
	{
		modifytext(t);
		markerpos = text.size();
	}
示例#5
0
	void Textfield::send_key(KeyType::Id type, int32_t key, bool pressed)
	{
		switch (type)
		{
		case KeyType::ACTION:
			if (pressed)
			{
				switch (key)
				{
				case KeyAction::LEFT:
					if (markerpos > 0)
					{
						markerpos--;
					}
					break;
				case KeyAction::RIGHT:
					if (markerpos < text.size())
					{
						markerpos++;
					}
					break;
				case KeyAction::BACK:
					if (text.size() > 0 && markerpos > 0)
					{
						text.erase(markerpos - 1, 1);
						markerpos--;
						modifytext(text);
					}
					break;
				case KeyAction::RETURN:
					if (onreturn && text.size() > 0)
					{
						onreturn(text);
						text = "";
						markerpos = 0;
						modifytext(text);
					}
					break;
				case KeyAction::SPACE:
					if (markerpos > 0 && belowlimit())
					{
						text.insert(markerpos, 1, ' ');
						markerpos++;
						modifytext(text);
					}
					break;
				default:
					if (callbacks.count(key))
					{
						callbacks.at(key)();
					}
					break;
				}
			}
			break;
		case KeyType::LETTER:
		case KeyType::NUMBER:
			if (!pressed)
			{
				int8_t c = static_cast<int8_t>(key);
				if (belowlimit())
				{
					text.insert(markerpos, 1, c);
					markerpos++;
					modifytext(text);
				}
			}
			break;
		}
	}