Editbox/button text align

For help with anything that CEGUI doesn't offer straight out-of-the-box, e.g.:
- Implementation of new features, such as new Core classes, widgets, WindowRenderers, etc. ...
- Modification of any existing features for specific purposes
- Integration of CEGUI in new engines or frameworks and writing of new plugins (Renderer, Parser, ...) or modules

Moderators: CEGUI MVP, CEGUI Team

User avatar
J_A_X
Quite a regular
Quite a regular
Posts: 72
Joined: Wed Jun 29, 2005 13:18
Contact:

Editbox/button text align

Postby J_A_X » Mon Jul 18, 2005 18:10

I just wanted to see if it's possible. I know that the static text is easily alignable, but I wanna know for buttons and edit boxes. I can't seem to find a function/property that does so.

User avatar
CrazyEddie
CEGUI Project Lead
Posts: 6760
Joined: Wed Jan 12, 2005 12:06
Location: England
Contact:

Re: Editbox/button text align

Postby CrazyEddie » Tue Jul 19, 2005 09:10

The only thing we have in the current releases is a "TextXOffset" property which shifts the text by the given offset.

User avatar
J_A_X
Quite a regular
Quite a regular
Posts: 72
Joined: Wed Jun 29, 2005 13:18
Contact:

Re: Editbox/button text align

Postby J_A_X » Tue Jul 19, 2005 13:35

only in the x direction eh?

darn, I needed it for y :/

User avatar
CrazyEddie
CEGUI Project Lead
Posts: 6760
Joined: Wed Jan 12, 2005 12:06
Location: England
Contact:

Re: Editbox/button text align

Postby CrazyEddie » Wed Jul 20, 2005 08:24

There is a patch of the tracker that adds this ability. The patch was done by me (so you know it's good, right ;) ). This will not however be making it to the core system.

http://sourceforge.net/tracker/index.ph ... tid=605424

User avatar
Acrion
Just popping in
Just popping in
Posts: 18
Joined: Tue Jun 28, 2005 18:45
Location: Maine, USA
Contact:

Re: Editbox/button text align

Postby Acrion » Wed Jul 20, 2005 12:15

How will Falagard handle this in relation to your patch? Will they be compatible?
[font=Verdana][size=xx-small]"It's not hard to stand out when the general level of competence is so low" -EMH[/size][/font]
namik@flashmail.com

User avatar
CrazyEddie
CEGUI Project Lead
Posts: 6760
Joined: Wed Jan 12, 2005 12:06
Location: England
Contact:

Re: Editbox/button text align

Postby CrazyEddie » Wed Jul 20, 2005 17:35

The "Falagard" system would not respect these settings, which is one reason they will not be put in.

Currently the "Falagard" system has much better configurability on a per-skinned-type basis. There may be other extended possibilities added also, I have not decided yet :)

Rackle
CEGUI Team (Retired)
Posts: 534
Joined: Mon Jan 16, 2006 11:59
Location: Montréal

Postby Rackle » Fri May 12, 2006 03:15

I was wondering if there was an update for this feature for an EditBox. Having the ability to left align (current implementation) is great for text but when displaying numbers a right alignment is more appropriate. Or maybe there's a function I'm not seeing...

kili
Not too shy to talk
Not too shy to talk
Posts: 45
Joined: Fri Apr 27, 2007 06:17

Postby kili » Thu Feb 12, 2009 11:31

Hi,

I'm trying to add HorzFormatting property to FalEditbox.
In the looknfeel, I wish the Editbox Carat in the right edge
and wrote:

Code: Select all

<ImagerySection name="Carat">
            <ImageryComponent>
                <Area>
         <Dim type="LeftEdge" >
            <UnifiedDim scale="1" offset="-5" type="LeftEdge">
               <DimOperator op="Subtract">
                  <ImageDim imageset="Test" image="EditBoxCarat" dimension="Width" />
               </DimOperator>
            </UnifiedDim>
         </Dim>
                   <!--<Dim type="LeftEdge" ><AbsoluteDim value="0" /></Dim>-->
                    <Dim type="TopEdge" ><AbsoluteDim value="0" /></Dim>
                    <Dim type="Width" ><ImageDim imageset="Test" image="EditBoxCarat" dimension="Width" /></Dim>
                    <Dim type="BottomEdge" ><UnifiedDim scale="1.0" type="BottomEdge" /></Dim>
                </Area>
                <Image imageset="Test" image="EditBoxCarat" />
                <VertFormat type="Stretched" />
                <HorzFormat type="Stretched" />
            </ImageryComponent>
        </ImagerySection>


but the carat's width enlarged from 6 pixel to 120 pixel in this line:

Code: Select all

float caratWidth = caratImagery.getBoundingRect(*w, textArea).getWidth();


Is there anything wrong?

ps. What I add to the Editbox is

Code: Select all

<Property name="HorzFormatting" value="RightAligned" />
in looknfeel and
FalagardEditboxProperties::HorzFormatting

User avatar
CrazyEddie
CEGUI Project Lead
Posts: 6760
Joined: Wed Jan 12, 2005 12:06
Location: England
Contact:

Postby CrazyEddie » Fri Feb 13, 2009 09:45

Hi,

This particular issue was raised in this thread: http://www.cegui.org.uk/phpBB2/viewtopic.php?t=3651

No further advance has been made with regards to this issue, though I do agree it's something that needs addressing (a mantis ticket has now been added so it's not forgotten, though no ETA on resolution).

CE.

kili
Not too shy to talk
Not too shy to talk
Posts: 45
Joined: Fri Apr 27, 2007 06:17

Postby kili » Fri Feb 13, 2009 10:13

This is my code today, HTH.
ps. there is a bug, I comment it below.

Code: Select all

void FalagardEditbox::render()
    {
      Editbox* w = (Editbox*)d_window;
        const StateImagery* imagery;

        // draw container etc
        // get WidgetLookFeel for the assigned look.
        const WidgetLookFeel& wlf = getLookNFeel();
        // try and get imagery for the approprite state.
        imagery = &wlf.getStateImagery(w->isDisabled() ? "Disabled" : (w->isReadOnly() ? "ReadOnly" : "Enabled"));

        // peform the rendering operation for the container.
        imagery->render(*w);

        // get destination area for text
        const Rect textArea(wlf.getNamedArea("TextArea").getArea().getPixelRect(*w));

        //
        // Required preliminary work for text rendering operations
        //
        Font* font = w->getFont();

        // no font == no more rendering
        if (!font)
            return;

        // This will point to the final string to be used for rendering.  Useful because it means we
        // do not have to have duplicate code or be copying d_text for handling masked/unmasked text.
        String* editText;

        // Create a 'masked' version of the string if needed.
        String maskedText, windowText;
        if (w->isTextMasked())
        {
            maskedText.insert(0, w->getText().length(), w->getMaskCodePoint());
            editText = &maskedText;
        }
        // text not masked to editText will be the windows d_text String.
        else
        {
            windowText = w->getText();
            editText = &windowText;
        }

      // get carat imagery
        const ImagerySection& caratImagery = wlf.getImagerySection("Carat");
        // store carat width
        float caratWidth = caratImagery.getBoundingRect(*w, textArea).getWidth();

        // calculate best position to render text to ensure carat is always visible
        float textOffset;   
        float extentToCarat;
      float fTextLen;         //Total text length

      extentToCarat = font->getTextExtent(editText->substr(0, w->getCaratIndex()));
      fTextLen = font->getTextExtent(editText->substr(0));

      if(d_lastTextOffset == -1000.0f)      //begin
      {
         if(d_horzFormatting == RightAligned)
            d_lastTextOffset = textArea.getWidth() - fTextLen - caratWidth;
         else
            d_lastTextOffset = 0.0;
      }

        // if box is inactive
        if (!w->hasInputFocus())
        {
         textOffset = d_lastTextOffset;
        }
        // if carat is to the left of the box
        else if ((d_lastTextOffset + extentToCarat) < 0)
        {
            textOffset = -extentToCarat;
        }
        // if carat is off to the right.
        else if ((d_lastTextOffset + extentToCarat) >= (textArea.getWidth() - caratWidth))
        {
         if(d_horzFormatting == RightAligned)
            textOffset = textArea.getWidth() - fTextLen - caratWidth;
         else
            textOffset = textArea.getWidth() - extentToCarat - caratWidth;
        }
        // else carat is already within the box
        else
        {
         //"BUG"-> if carat is off to the left, and right key pressed, this line causes it.
         if(d_horzFormatting == RightAligned)
            textOffset = textArea.getWidth() - fTextLen - caratWidth;
         else
            textOffset = d_lastTextOffset;
        }

        ColourRect colours;
        float alpha_comp = w->getEffectiveAlpha();

        //
        // Draw label text
        //
        // setup initial rect for text formatting
        Rect text_part_rect(textArea);
        // allow for scroll position
      text_part_rect.d_left += textOffset;
        // centre text vertically within the defined text area
        text_part_rect.d_top += (textArea.getHeight() - font->getFontHeight()) * 0.5f;      

        // get unhighlighted text colour (saves accessing property twice)
        colour unselectedColour(getUnselectedTextColour());
        // draw pre-highlight text
        String sect = editText->substr(0, w->getSelectionStartIndex());
        colours.setColours(unselectedColour);
        colours.modulateAlpha(alpha_comp);

      if(d_horzFormatting == RightAligned)      //kili 20090213
         text_part_rect.d_right = text_part_rect.d_left + font->getTextExtent(sect);
       //w->getRenderCache().cacheText(sect, font, LeftAligned, text_part_rect, 0, colours, &textArea);
      w->getRenderCache().cacheText(sect, font, (TextFormatting)d_horzFormatting, text_part_rect, 0, colours, &textArea);      //kili 20090212

        // adjust rect for next section
        text_part_rect.d_left += font->getTextExtent(sect);

        // draw highlight text   
        sect = editText->substr(w->getSelectionStartIndex(), w->getSelectionLength());
        colours.setColours(getSelectedTextColour());
        colours.modulateAlpha(alpha_comp);

      if(d_horzFormatting == RightAligned)      //kili 20090213
         text_part_rect.d_right = text_part_rect.d_left + font->getTextExtent(sect);

        //w->getRenderCache().cacheText(sect, font, LeftAligned, text_part_rect, 0, colours, &textArea);
      w->getRenderCache().cacheText(sect, font, (TextFormatting)d_horzFormatting, text_part_rect, 0, colours, &textArea);      //kili 20090212

        // adjust rect for next section
        text_part_rect.d_left += font->getTextExtent(sect);

        // draw post-highlight text
        sect = editText->substr(w->getSelectionEndIndex());
        colours.setColours(unselectedColour);
        colours.modulateAlpha(alpha_comp);

      if(d_horzFormatting == RightAligned)      //kili 20090213
         text_part_rect.d_right = text_part_rect.d_left + font->getTextExtent(sect);

        //w->getRenderCache().cacheText(sect, font, LeftAligned, text_part_rect, 0, colours, &textArea);
      w->getRenderCache().cacheText(sect, font, (TextFormatting)d_horzFormatting, text_part_rect, 0, colours, &textArea);      //kili 20090212

        // remember this for next time.
        d_lastTextOffset = textOffset;

        // see if the editbox is active or inactive.
        bool active = (!w->isReadOnly()) && w->hasInputFocus();

        //
        // Render selection imagery.
        //
        if (w->getSelectionLength() != 0)
        {
            // calculate required start and end offsets of selection imagery.
            float selStartOffset = font->getTextExtent(editText->substr(0, w->getSelectionStartIndex()));
            float selEndOffset   = font->getTextExtent(editText->substr(0, w->getSelectionEndIndex()));

            // calculate area for selection imagery.
            Rect hlarea(textArea);
            hlarea.d_left += textOffset + selStartOffset;
            hlarea.d_right = hlarea.d_left + (selEndOffset - selStartOffset);

            // render the selection imagery.
            wlf.getStateImagery(active ? "ActiveSelection" : "InactiveSelection").render(*w, hlarea, 0, &textArea);
        }

        //
        // Render carat
        //
        if (active)
        {
            Rect caratRect(textArea);
            caratRect.d_left += extentToCarat + textOffset;
      
        caratImagery.render(*w, caratRect, 0, 0, &textArea);
        }
    }

    size_t FalagardEditbox::getTextIndexFromPosition(const Point& pt) const
    {
        Editbox* w = (Editbox*)d_window;
        //
        // calculate final window position to be checked
        //
        float wndx = CoordConverter::screenToWindowX(*w, pt.d_x);

        wndx -= d_lastTextOffset;
      if(wndx < 0 )      //kili 20090212
         wndx = 0;
        //
        // Return the proper index
        //
        if (w->isTextMasked())
        {
            return w->getFont()->getCharAtPixel(String(w->getText().length(), w->getMaskCodePoint()), wndx);
        }
        else
        {
            return w->getFont()->getCharAtPixel(w->getText(), wndx);
        }
    }



and the looknfeel different with TaharezLook is

Code: Select all

<Property name="HorzFormatting" value="RightAligned" />



:oops:

User avatar
CrazyEddie
CEGUI Project Lead
Posts: 6760
Joined: Wed Jan 12, 2005 12:06
Location: England
Contact:

Postby CrazyEddie » Fri Feb 13, 2009 14:28

Thanks, I'll try it out once I get time to work on this side of things :)

CE.


Return to “Modifications / Integrations / Customisations”

Who is online

Users browsing this forum: No registered users and 12 guests