Quantcast
Set default text in a text box - WoWInterface
Thread Tools Display Modes
07-02-21, 12:04 AM   #1
Walkerbo
A Flamescale Wyrmkin
 
Walkerbo's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2010
Posts: 142
Set default text in a text box

Hi all

I have a frame that can be scaled via a text box.
When I reload I need the text box to be filled with the saved scale.

The frame does correctly scale based on the saved scale on reload however I have not been able to fill the text box with the saved scale value on login.

I get no errors and even when I try to hard-set a number in the text box it remains empty.

Here is my table of variables;
Lua Code:
  1. local NewbDevBoxOptionsTable = {
  2.     ButtonFrameScale = 1,
  3.     ButtonFrameOpacity = 1,
  4.     ButtonIsVisable = true
  5. }
My update frame scale;
Lua Code:
  1. local function updateButtonFrameScale(updateScaleNumber)
  2.     if updateScaleNumber >= 301 then -- if the entered number is too high
  3.         updateScaleNumber = 300
  4.     elseif updateScaleNumber <= 49 then -- if the entered number is too low
  5.         updateScaleNumber = 50
  6.     end
  7.     NewbDevBoxOptionsTable.ButtonFrameScale = updateScaleNumber / 100
  8.     NewbDevBoxButtonFrame:SetScale(NewbDevBoxOptionsTable.ButtonFrameScale)
  9.     NewbDevBoxInterfaceFrame.ScaleTextBox:SetNumber(updateScaleNumber)
  10. end
and setting the frame scale on player login
Lua Code:
  1. if event == "PLAYER_LOGIN" then
  2. NewbDevBoxButtonFrame:SetScale(NewbDevBoxOptionsTable.ButtonFrameScale)
  3. NewbDevBoxInterfaceFrame.ScaleTextBox:SetNumber(NewbDevBoxOptionsTable.ButtonFrameScale * 100)
and here is my textbox setup
Lua Code:
  1. NewbDevBoxInterfaceFrame.ScaleTextBox =
  2.     CreateFrame("EditBox", "NewbDevBoxInterfaceFrameScaleTextBox", NewbDevBoxInterfaceFrame, "OptionsBoxTemplate")
  3. NewbDevBoxInterfaceFrame.ScaleTextBox:SetPoint(
  4.     "TOPLEFT",
  5.     NewbDevBoxInterfaceFrameKeybindsButton,
  6.     "BOTTOMLEFT",
  7.     0,
  8.     NumberList.textBoxYGap
  9. )
  10. NewbDevBoxInterfaceFrame.ScaleTextBox:SetFontObject(TextDimensionList.checkBoxFont)
  11. NewbDevBoxInterfaceFrame.ScaleTextBox:SetNumeric(true)
  12. NewbDevBoxInterfaceFrame.ScaleTextBox:SetSize(NumberList.scaleTextBoxWidth, NumberList.scaleTextBoxHeight)
  13. NewbDevBoxInterfaceFrame.ScaleTextBox:SetMaxLetters(3)
  14. NewbDevBoxInterfaceFrame.ScaleTextBox:SetAutoFocus()
  15. NewbDevBoxInterfaceFrame.ScaleTextBox:SetJustifyH("CENTER")
  16. NewbDevBoxInterfaceFrame.ScaleTextBox:SetScript(
  17.     "OnEnterPressed",
  18.     function(self)
  19.         scaleNumber = tonumber(NewbDevBoxInterfaceFrame.ScaleTextBox:GetText())
  20.         self:ClearFocus()
  21.         updateButtonFrameScale(scaleNumber)
  22.     end
  23. )

I have not been able to work out why this is not working correctly, it is probably staring me in the face yet I cannot see where I have stuffed up.
__________________
"As someone once told me, frames are just special types of tables, and tables are special types of pointers."
Fizzlemizz
  Reply With Quote
07-02-21, 02:16 AM   #2
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,439
In your setup you're not initialising the editbox with any text:
Code:
NewbDevBoxInterfaceFrame.ScaleTextBox:SetText(NewbDevBoxOptionsTable.ButtonFrameScale)
But then again, your NewbDevBoxOptionsTable is a local table so the information in it will not be saved between sessions.

I might be missing something...
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.
  Reply With Quote
07-02-21, 02:37 AM   #3
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,439
One other possibility, if your addon is LOD (eg. a config. addon loaded via a slash command or some other) then it might never see the "PLAYER_LOGIN" event.
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.

Last edited by Fizzlemizz : 07-02-21 at 07:45 AM.
  Reply With Quote
07-02-21, 06:58 PM   #4
Walkerbo
A Flamescale Wyrmkin
 
Walkerbo's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2010
Posts: 142
Hi Fizzlemizz

Sorry for the delayed reply.

I once again failed to link my full code.

My pastebin links to my lua, toc

The table of variables is a global table named in my toc.

The playerlogin event fires correctly as I have my setups within the event and they all seem to work correctly.

Now typing in the text box has stopped working due to my trying to fix, so I more than likely have broken the text boxes even more.
__________________
"As someone once told me, frames are just special types of tables, and tables are special types of pointers."
Fizzlemizz
  Reply With Quote
07-02-21, 11:05 PM   #5
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,439
I had to change some fontobjects you created to use GameFontNormal so I'm not sure about the actual EditBox size but that's another thing this might hightlight.

In your PLAYER_LOGIN you can use.

Code:
NewbDevBoxInterfaceFrame.ScaleTextBox:SetNumber(NewbDevBoxOptionsTable.ButtonFrameScale * 100)
NewbDevBoxInterfaceFrame.ScaleTextBox:SetCursorPosition(1)
NewbDevBoxInterfaceFrame.OpacityTextBox:SetNumber(NewbDevBoxOptionsTable.ButtonFrameOpacity * 100)
NewbDevBoxInterfaceFrame.OpacityTextBox:SetCursorPosition(1)
Which should show some of the numbers at least.
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.

Last edited by Fizzlemizz : 07-03-21 at 01:47 PM.
  Reply With Quote
07-03-21, 05:58 PM   #6
Walkerbo
A Flamescale Wyrmkin
 
Walkerbo's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2010
Posts: 142
Hi Fizzlemizz

Cracked it!

You provided the answer, I simply took it to the end.
Lua Code:
  1. NewbDevBoxInterfaceFrame.ScaleTextBox:SetCursorPosition(0)

Now it works perfectly, regardless of the font object, as long as the text box is big enough to accommodate the font size.

Thanks for your help
__________________
"As someone once told me, frames are just special types of tables, and tables are special types of pointers."
Fizzlemizz
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Set default text in a text box

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