WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Lua/XML Help (https://www.wowinterface.com/forums/forumdisplay.php?f=16)
-   -   supernoob questions about strings and font in editbox (https://www.wowinterface.com/forums/showthread.php?t=57197)

MooreaTv 06-13-19 02:10 AM

supernoob questions about strings and font in editbox
 
Hi there,

I'm trying to do 2 things and banging my head against the wall:

a) I'd like put a fixed font in a (static dialog) editBox
I found in Fonts.xml a handful of huge fonts like System_world and in FontStyles.xml it's referenced as CombatText

If I e:SetFontObject(CombatTextFont) it is huge
How can I set a smaller version of the same font (I don't want to ship custom fonts with my addon, just use any non proportional font)

b) I would like to change the width of the box (and the height too if I change the font), I found
e:SetWidth(width)
and also that I am supposed to use :GetStringWidth() on a FontString but I can't seem to extract/find the fontstring that must be somewhere inside the EditBox :-(
(for height it'll be editBox:SetHeight() once I find where to call :GetStringHeight())


I feel I'm very close yet so far... halp! please !

thanks!

edit: solved below. also forgot to give some context on why I want a) and b): it's for something that the user need to copy from the game and happens to have a maximum character length (thus there is no resizing needed once the right size is found)

ps: the code I am trying to make work is https://github.com/mooreatv/DynamicB...I.lua#L85-L103

Fizzlemizz 06-13-19 10:42 AM

Maybe something more like a scrolling text box so you don't have to worry about sizes.

Lua Code:
  1. local backdrop = {
  2.         bgFile = "Interface/BUTTONS/WHITE8X8",
  3.         edgeFile = "Interface/GLUES/Common/Glue-Tooltip-Border",
  4.         tile = true,
  5.         edgeSize = 8,
  6.         tileSize = 8,
  7.         insets = {
  8.             left = 5,
  9.             right = 5,
  10.             top = 5,
  11.             bottom = 5,
  12.         },
  13.     }
  14.      
  15.      
  16.     local f = CreateFrame("Frame", "MyScrollMessageTextFrame", UIParent)
  17.     f:SetSize(150, 150)
  18.     f:SetPoint("CENTER")
  19.     f:SetFrameStrata("BACKGROUND")
  20.     f:SetBackdrop(backdrop)
  21.     f:SetBackdropColor(0, 0, 0)
  22.     f.Close = CreateFrame("Button", "$parentClose", f)
  23.     f.Close:SetSize(24, 24)
  24.     f.Close:SetPoint("TOPRIGHT")
  25.     f.Close:SetNormalTexture("Interface/Buttons/UI-Panel-MinimizeButton-Up")
  26.     f.Close:SetPushedTexture("Interface/Buttons/UI-Panel-MinimizeButton-Down")
  27.     f.Close:SetHighlightTexture("Interface/Buttons/UI-Panel-MinimizeButton-Highlight", "ADD")
  28.     f.Close:SetScript("OnClick", function(self)
  29.         self:GetParent():Hide()
  30.     end)
  31.     f.Select = CreateFrame("Button", "$parentSelect", f, "UIPanelButtonTemplate")
  32.     f.Select:SetSize(14, 14)
  33.     f.Select:SetPoint("RIGHT", f.Close, "LEFT")
  34.     f.Select:SetText("S")
  35.     f.Select:SetScript("OnClick", function(self)
  36.         self:GetParent().Text:HighlightText() -- parameters (start, end) or default all
  37.         self:GetParent().Text:SetFocus()
  38.     end)
  39.      
  40.     f.SF = CreateFrame("ScrollFrame", "$parent_DF", f, "UIPanelScrollFrameTemplate")
  41.     f.SF:SetPoint("TOPLEFT", f, 12, -30)
  42.     f.SF:SetPoint("BOTTOMRIGHT", f, -30, 10)
  43.     f.Text = CreateFrame("EditBox", nil, f)
  44.     f.Text:SetMultiLine(true)
  45.     f.Text:SetSize(180, 170)
  46.     f.Text:SetPoint("TOPLEFT", f.SF)
  47.     f.Text:SetPoint("BOTTOMRIGHT", f.SF)
  48.     f.Text:SetMaxLetters(99999)
  49.     f.Text:SetFontObject(GameFontNormal)
  50.     f.Text:SetAutoFocus(false)
  51.     f.Text:SetScript("OnEscapePressed", function(self) self:ClearFocus() end)
  52.     f.SF:SetScrollChild(f.Text)
  53.      
  54.     f.Text:SetText("bfs fasjdf dsaf adsj fasjkf bsafjsaf bjs fasjkf bjsf basf badsjkf dsakfbhaskf asjkf asjkf skaf sak fsk fdsaf kkl l fjds rewpwfrjpo foewf jjfwe fpwfevzv mcvn  qo fnaw[ffgngnerf we foiweffgorenfg[f fewfn sdskfn asdf sp ffq[ofkgbhp    i regp nIF N 'OFGRE  NG;G KG IGN ;EFPIREG REG  ZG;  ergregp esg gg-ero  rdf45540 4y   q8wffn ")

Look in SharedXML\SharedFontStyles.xml for lots of GameFont font objects.

MooreaTv 06-13-19 09:22 PM

Thanks Fizzle for the reply but that wasn't what I was after. But I did manage to get what I needed working after all, which I'll explain below for the sake of future searches:

for a) well there is actually no fixed (non proportional) font in wow default, the one marked fixedSize=true is actually seemingly only fixed width for digits but "W" there is much wider than say "i"

So I added a custom font to my addon because I found an otf one that is only 14.5 kbytes

To scale an existing font you basically have to do something like
Lua Code:
  1. DB.fixedFont = CreateFont("DynBoxerFixedFont")
  2. DB.fixedFont:SetFont(CombatTextFont:GetFont(), 12)

for b) the main trick is you need to call :CreateFontString() for example:
Lua Code:
  1. DB.fontString = DB:CreateFontString()  -- DB is a frame (in addition to a namespace/table)
  2.   DB.fontString:SetFontObject(font)
  3.   DB.fontString:SetText(newText)
  4.   local width = DB.fontString:GetStringWidth()
  5.   DB:Debug("Width with new font is %", width)
  6.   e:SetWidth(width + 4) -- + some or highlights hides most of it/it doesn't fit

The code in action before/after:



and an example of actual id generated:



The code doing all that including tabbing between the 2 dialogs, forcing selection, allowing enter or any key to regen new ids, etc... is on

https://github.com/mooreatv/DynamicB...xer/DBoxUI.lua

Fizzlemizz 06-13-19 09:44 PM

Cool. I caught only a bit of the Discord that looked like you were trying to get text into a format the user could select and copy to the clipboard. Obviously I missed parts 1 and 3 :).

MooreaTv 06-13-19 10:40 PM

Yeah I forgot to give the context on my initial "after a long night" post, sorry about that fizzle!


All times are GMT -6. The time now is 05:34 PM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI