Thread Tools Display Modes
04-10-15, 12:57 AM   #1
gmarco
An Onyxian Warder
 
gmarco's Avatar
AddOn Author - Click to view addons
Join Date: Dec 2009
Posts: 362
reduce targetname or spellname

Hi all,

I am beginning to try to write my layout for OUF following the GitHub wiki and the samples code from the classic, lily and others layouts too.

Now I'd like to ask how can I reduce the len of the tag name under a given size because they are too longs and doesn't fit in my frame.

I want basically apply something like:

Lua Code:
  1. self:Tag(self.Info,strsub('[name]',1,15))

that obviusly seems not to work for me :-)

It doesn't give an error ... and you get the pg name ...
But if you write it in this way:

Lua Code:
  1. self:Tag(self.Info,strsub('[name]',1,2))

it prints:

[n

intead :-))



Also same thing for spell name if possible (that in my opionion is even more complicated :-)

Lua Code:
  1. self.Castbar.Text = self.Castbar:CreateFontString(nil, 'OVERLAY')

So a long spell (or a long target name ...) should be written "A very long name not yet finished here ..." adding if possible "..." at the end for the missing part.

Thanks all ....
__________________
This is Unix-Land. In quiet nights, you can hear the Windows machines reboot.

Last edited by gmarco : 04-10-15 at 01:02 AM.
  Reply With Quote
04-10-15, 08:55 AM   #2
p3lim
A Pyroguard Emberseer
 
p3lim's Avatar
AddOn Author - Click to view addons
Join Date: Feb 2007
Posts: 1,710
Disable word wrap and add points to both the right and the left side of a fontstring to have it automatically truncate with a "..." suffix.

As for the name, you could do the same, but if you really want to use substr, you need to do it within the tag's function, not where you assign the tag by name in the layout.
  Reply With Quote
04-10-15, 10:53 AM   #3
Naisz
A Deviate Faerie Dragon
 
Naisz's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2015
Posts: 12
I had some sort of the same problem a while ago, as i started writing my own oUF-Layout.
I found this way in the official lua-api.

Lua Code:
  1. oUF.Tags.Events['name:normal'] = 'UNIT_NAME_UPDATE'
  2. oUF.Tags.Methods['name:normal'] = function(unit)
  3.     local name = UnitName(unit)
  4.     return string.sub(name,1,16)
  5. end

This simply shortens the name to 16 digits beginning with the first.

Hope this can help you.

greetings
  Reply With Quote
04-10-15, 11:10 AM   #4
gmarco
An Onyxian Warder
 
gmarco's Avatar
AddOn Author - Click to view addons
Join Date: Dec 2009
Posts: 362
Hi,

this do exactly the jobs :-)

I attach 2 screenshots from before and after the fix :-)

Lua Code:
  1. oUF.Tags.Events['name:normal'] = 'UNIT_NAME_UPDATE'
  2. oUF.Tags.Methods['name:normal'] = function(unit)
  3.     local name = UnitName(unit)
  4.     return string.sub(name,1,22) .. "..."
  5. end





Is there something also for spellname ? :-)

"Pietra del Ritorno alla Guarnigione" is quite long also :-)



Thanks very much to both if you really.
__________________
This is Unix-Land. In quiet nights, you can hear the Windows machines reboot.

Last edited by gmarco : 04-10-15 at 11:14 AM.
  Reply With Quote
04-10-15, 09:57 PM   #5
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
If you want the name to truncate with a "..." after it, do not use tags; this just adds a lot of overhead calling the tag function and string.sub all the time. Just set anchors on your font string:

Lua Code:
  1. -- You already have something like this:
  2. nameFontString:SetPoint("LEFT", healthBar, 5, 0)
  3. -- Add a second anchor to limit the width:
  4. nameFontString:SetPoint("RIGHT", healthFontString, "LEFT", -5, 0)
  5. -- And tell it to truncate instead of wrap if the text is too long:
  6. nameFontString:SetWordWrap(false)
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.
  Reply With Quote
04-13-15, 08:56 AM   #6
gmarco
An Onyxian Warder
 
gmarco's Avatar
AddOn Author - Click to view addons
Join Date: Dec 2009
Posts: 362
Thanks Phanx,

Really appreciated.

Infact it is a thing I saw sometime but I didn't understand what it was :-)

Thanks again ... rewrote incoming :-)
__________________
This is Unix-Land. In quiet nights, you can hear the Windows machines reboot.
  Reply With Quote
04-13-15, 09:31 AM   #7
gmarco
An Onyxian Warder
 
gmarco's Avatar
AddOn Author - Click to view addons
Join Date: Dec 2009
Posts: 362
Lua Code:
  1. self.Info = self.Health:CreateFontString(nil, 'OVERLAY')
  2. self.Info:SetFont( START_font , START_fs , '')
  3. self:Tag(self.Info,'[level] [name]')
  4. self.Info:SetPoint('LEFT',self.Health,'LEFT', 5, 0)
  5. self.Info:SetPoint("RIGHT", self.Health, "RIGHT", -45, 0)
  6. self.Info:SetWordWrap(false)       
  7. self.Info:SetJustifyH("LEFT")

Works like a charm Phanx :-)

Fixed also castbars :-)

Thanks again Phanxs :-))

__________________
This is Unix-Land. In quiet nights, you can hear the Windows machines reboot.

Last edited by gmarco : 04-13-15 at 09:43 AM.
  Reply With Quote
04-13-15, 09:50 AM   #8
gmarco
An Onyxian Warder
 
gmarco's Avatar
AddOn Author - Click to view addons
Join Date: Dec 2009
Posts: 362
Originally Posted by p3lim View Post
Disable word wrap and add points to both the right and the left side of a fontstring to have it automatically truncate with a "..." suffix.

As for the name, you could do the same, but if you really want to use substr, you need to do it within the tag's function, not where you assign the tag by name in the layout.
Hi p3lim,

Thanks for your tips too,
finally I have understood it is the same suggestion Phanx pointed out some comments after, but I didn't get before because for me it was not so easy to fully understand it without reading some code sample to associate to it.

Thanks again ... even if a bit in late :-)
__________________
This is Unix-Land. In quiet nights, you can hear the Windows machines reboot.
  Reply With Quote

WoWInterface » Featured Projects » oUF (Otravi Unit Frames) » reduce targetname or spellname

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off