示例#1
0
		//----------------------------------------------------------------------------------
        void TextEntry::OnTextEntered(ChilliSource::UTF8Char character) noexcept
        {
            ChilliSource::Application::Get()->GetTaskScheduler()->ScheduleTask(ChilliSource::TaskType::k_mainThread, [=](const ChilliSource::TaskContext& taskContext)
            {
                std::unique_lock<std::mutex> lock(m_mutex);

                std::string text;

				const ChilliSource::UTF8Char k_backspace = 8;
                if (character != k_backspace)
                {
                    text = ChilliSource::UTF8StringUtils::AppendCopy(character, m_text);
                }
                else
                {
                    s32 length = (s32)ChilliSource::UTF8StringUtils::CalcLength(m_text.begin(), m_text.end());
                    length = std::max(length - 1, 0);
                    text = ChilliSource::UTF8StringUtils::SubString(m_text, 0, (u32)length);
                }

                bool acceptText = true;

                if (m_textBufferChangedDelegate != nullptr)
                {
                    acceptText = m_textBufferChangedDelegate(text);
                }

                if (acceptText == true)
                {
                    m_text = std::move(text);
                }
            });
        }
示例#2
0
		//-------------------------------------------------------
		//-------------------------------------------------------
		void TextEntry::OnTextChanged(const std::string& in_text)
		{
            CS_ASSERT(ChilliSource::Application::Get()->GetTaskScheduler()->IsMainThread(), "Cannot handle system text entry callback outside of main thread.");
			if(m_text == in_text)
				return;

            bool acceptText = true;

            if(m_textBufferChangedDelegate != nullptr)
            {
                acceptText = m_textBufferChangedDelegate(in_text);
            }

            if(acceptText == true)
            {
                m_text = in_text;
            }
            else
            {
            	m_textEntryJI->SetTextBuffer(m_text);
            }
		}