project-navigation
Personal tools

Author Topic: Text truncation  (Read 4599 times)

Amtep

  • Guest
Text truncation
« on: October 18, 2008, 12:21:42 am »
I've been working on the text rendering code. The next feature I'd like to do is to allow text to be truncated instead of linewrapped, in such a way that the truncated text is visually marked with something like an ellipsis ("..."). Text truncation is useful in places where there is limited space, such as tables and button texts. It would be nicer if we never have to truncate, but with all the supported languages and multi-use strings such as item names, it is hard to be sure.

I've made a first draft patch for it, which adds a R_FontDrawLine function that is designed for single-line text and uses it in a couple of places. I've made it take a "trunc string" from the caller, which can be an ellipsis if desired. The reason for taking the string for the caller is that it makes it translatable. Some languages have different conventions for this, and in any case it is nice if the English locale can use the Unicode ellipsis instead of three ASCII dots. This makes three reasonable values for the trunc parameter:

  _("...")
  ""
  NULL

The third one means line-wrap as usual, though of course R_FontDrawLine will still only print the first line.

Now I'm wondering how to add the truncation string to the menu system. I would like to do something like this in menu_buy.ufo:

    text market
    {
        color   "0 .78 0 1"
        num     TEXT_MARKET_NAMES
        height  "28"
        format  "25 0"
        pos     "55 40"
        size    "265 700"
        click
        wheel   { cmd "market_scroll" }
        mousefx true
        truncate "_..."
    }

This menu node contains item names separated by newlines, and adding the truncate value would mean the text should be rendered line by line with long lines truncated with _("...") as a visual marker. It will get a column like this:

  Short item
  Long item name
  Really long ite...

Questions:

How do I add a string value to text nodes? I couldn't figure it out from the code.

Should it be a string value? Or is a numeric code enough? (say, 0 = don't truncate, 1 = truncate silently, 2 = truncate with ellipsis)

Is R_FontDrawLine useful or should everything continue to go through the general-purpose R_FontDrawString?  (which is getting long in the parameter list)


[attachment deleted by admin]

Offline Mattn

  • Administrator
  • PHALANX Commander
  • *****
  • Posts: 4831
  • https://github.com/mgerhardy/vengi
    • View Profile
    • Vengi Voxel Tools
Re: Text truncation
« Reply #1 on: October 18, 2008, 07:47:01 am »
Code: [Select]
i would vote for something like [¢ode]truncate "stringID"
please don't add the ellipsis string to every truncate attribute:
some possible values for "stringID":
* ellipsis
* normal (or whatever name fits better)
* none

that way you can set this once and don't have to fet your R_FontDrawLine everytime with it (only once per language change e.g.)

the other question: have a look at client/menu/m_parse.c line 59
either add it with V_STRING or introduce a new value type like V_TRUNCATE (we did this for some menu parameters already)

hope that helps...


Amtep

  • Guest
Re: Text truncation
« Reply #2 on: October 18, 2008, 09:08:03 am »
Ok, that sounds promising. It does make sense to not push this kind of detail all the way up to the menu files. Instead of "truncate none" which I think looks a bit odd, I'd like to use a scheme like this:

longlines wrap   (the default)
longlines chop
longlines ellipsis

I think this shows more easily to the reader of the .ufo file what is going on. The only problem is that not everyone can spell ellipsis :) And again that's a bit of a low level detail. The important thing is that it gets chopped in a more visually appealing way. So I'd like to find a better name for this.

When you mention setting it once per language change, do you mean actually calling something like R_FontSetEllipsis(_("...")) after every setlocale? Actually this might be a good idea if it can be made part of a general "adjust for new language" function, which can also deal with reregistering the fonts. (Currently the font paths are translatable so that for example Chinese can specify a different font file, but the new paths are not sent to the renderer when the language changes.)

Offline Mattn

  • Administrator
  • PHALANX Commander
  • *****
  • Posts: 4831
  • https://github.com/mgerhardy/vengi
    • View Profile
    • Vengi Voxel Tools
Re: Text truncation
« Reply #3 on: October 18, 2008, 10:12:23 am »
yes, the longlines stuff looks good

R_InitFontsForLocale or something like that. It should set all the stuff that needs changing, like e.g. the translateable fonts and the ellipsis (e.g. - not sure if there is more)

Amtep

  • Guest
Re: Text truncation
« Reply #4 on: October 18, 2008, 07:58:57 pm »
This is implemented :)

Offline bayo

  • Professional loser
  • Project Coder
  • Captain
  • ***
  • Posts: 733
    • View Profile
Re: Text truncation
« Reply #5 on: October 20, 2008, 01:58:46 pm »
Amtep> Can you check my trunk "ufoai_menu" to see if i dont remove your change. Specially the file m_node_text.c

Amtep

  • Guest
Re: Text truncation
« Reply #6 on: October 20, 2008, 03:46:34 pm »
This is not truncation-related, but the node->num == TEXT_MESSAGESYSTEM case in MN_DrawTextNode2 needs my changes from m_draw.c.

Offline bayo

  • Professional loser
  • Project Coder
  • Captain
  • ***
  • Posts: 733
    • View Profile