Ticket #8391: 0001-Fix-alignment-in-TextControl-widgets-fixes-8391.patch

File 0001-Fix-alignment-in-TextControl-widgets-fixes-8391.patch, 2.0 KB (added by MrPingouin, 5 years ago)
  • src/kits/interface/TextInput.cpp

    From 73ea36decace616f1da0e154de9544dc758e6124 Mon Sep 17 00:00:00 2001
    From: Laurent Chea <contact@laurentchea.com>
    Date: Thu, 4 Dec 2014 22:44:25 +0100
    Subject: [PATCH] Fix alignment in TextControl widgets (fixes #8391)
    
    ---
     src/kits/interface/TextInput.cpp | 33 +++++++++++++++++++++++++++------
     1 file changed, 27 insertions(+), 6 deletions(-)
    
    diff --git a/src/kits/interface/TextInput.cpp b/src/kits/interface/TextInput.cpp
    index 9b1b570..d9e4a96 100644
    a b _BTextInput_::KeyDown(const char* bytes, int32 numBytes)  
    118118    }
    119119}
    120120
     121
    121122void
    122123_BTextInput_::MakeFocus(bool state)
    123124{
    _BTextInput_::MinSize()  
    155156{
    156157    BSize min;
    157158    min.height = ceilf(LineHeight(0) + 2.0);
    158         // we always add at least one pixel vertical inset top/bottom for
    159         // the text rect.
     159    // we always add at least one pixel vertical inset top/bottom for
     160    // the text rect.
    160161    min.width = min.height * 3;
    161162    return BLayoutUtils::ComposeSize(ExplicitMinSize(), min);
    162163}
    _BTextInput_::AlignTextRect()  
    170171    // the text rect to be in the middle, normally this means there
    171172    // is one pixel spacing on each side
    172173    BRect textRect(Bounds());
    173     textRect.left = 0.0;
    174     float vInset = max_c(1, floorf((textRect.Height() - LineHeight(0)) / 2.0));
     174    float vInset = max_c(1,
     175            floorf((textRect.Height() - LineHeight(0)) / 2.0));
    175176    float hInset = 2;
     177    float textFontWidth = TextRect().right;
     178
     179    if (be_control_look != NULL)
     180    {
     181        switch(Alignment())
     182        {
     183            case B_ALIGN_LEFT:
     184                hInset = be_control_look->DefaultLabelSpacing();
     185                break;
     186
     187            case B_ALIGN_RIGHT:
     188                hInset  = textRect.right - textFontWidth;
     189                hInset -= be_control_look->DefaultLabelSpacing();
     190                break;
    176191
    177     if (be_control_look != NULL)
    178         hInset = be_control_look->DefaultLabelSpacing();
     192            case B_ALIGN_CENTER:
     193                hInset = (textRect.right - textFontWidth)/ 2.0;
     194                break;
     195
     196            default:
     197                break;
     198        }
     199    }
    179200
    180201    textRect.InsetBy(hInset, vInset);
    181202    SetTextRect(textRect);