Пример #1
0
void TextBox::OnTextInput(const SDL_TextInputEvent& textEvent)
{
    GetWindow()->SetCursorHidden(true);
    if (m_position == m_text.size())
        m_text.append(textEvent.text);
    else
        m_text.insert(m_position, textEvent.text);

    auto charWidth = GetWindow()->GetFont()->GetTextSize(textEvent.text);
    MoveCaret(charWidth);

    ++m_position;
    m_texture = GetWindow()->CreateTextureForText(m_text, GetWindow()->GetFont(), GetForegroundColor(), GetBackgroundColor());
}
Пример #2
0
int32 SPopup::OnPaint(const FPaintArgs& Args, const FGeometry& AllottedGeometry, const FSlateRect& MyClippingRect, FSlateWindowElementList& OutDrawElements, int32 LayerId, const FWidgetStyle& InWidgetStyle, bool bParentEnabled) const
{
	FArrangedChildren ArrangedChildren(EVisibility::Visible);
	this->ArrangeChildren(AllottedGeometry, ArrangedChildren);

	// There may be zero elements in this array if our child collapsed/hidden
	if (ArrangedChildren.Num() > 0)
	{
		check(ArrangedChildren.Num() == 1);
		FArrangedWidget& TheChild = ArrangedChildren[0];

		FWidgetStyle CompoundedWidgetStyle = FWidgetStyle(InWidgetStyle)
			.BlendColorAndOpacityTint(ColorAndOpacity.Get())
			.SetForegroundColor(GetForegroundColor());

		// An SPopup just queues up its children to be painted after everything in this window is done painting.
		OutDrawElements.QueueDeferredPainting(
			FSlateWindowElementList::FDeferredPaint(TheChild.Widget, Args.WithNewParent(this), TheChild.Geometry, MyClippingRect, CompoundedWidgetStyle, ShouldBeEnabled(bParentEnabled))
		);
	}
	return LayerId;
}
Пример #3
0
void TextBox::KeydownBackspace()
{
    if (m_position == 0)
        return;

    auto charWidth = static_cast<int>(GetWindow()->GetFont()->GetCharSize(m_text[m_position - 1]));
    assert(charWidth > 0);

    if (m_position == m_text.size())
        m_text.pop_back();
    else
        m_text.erase(m_position - 1, 1);

    m_texture = GetWindow()->CreateTextureForText(m_text, GetWindow()->GetFont(), GetForegroundColor(), GetBackgroundColor());
    --m_position;

    // don't move the caret if the string is bigger than the text box
    if (m_texture.GetWidth() < GetLocation().w - (TextOffsetX * 2) + CaretWidth)
    {
        MoveCaret(-charWidth);
    }
    else if (m_clipOffset > 0)
    {
        if (m_clipOffset < charWidth)
        {
            // if there is a single character being clipped
            // move the caret by the number of visible pixels.
            MoveCaret(-(charWidth - m_clipOffset));
            m_clipOffset = 0;
        }
        else
        {
            m_clipOffset -= charWidth;
        }
    }
}
Пример #4
0
void TextBox::KeydownDelete()
{
    if (m_position < m_text.size())
    {
        m_text.erase(m_position, 1);
        m_texture = GetWindow()->CreateTextureForText(m_text, GetWindow()->GetFont(), GetForegroundColor(), GetBackgroundColor());
    }
}