Overwriting text
I am making something like a scroll frame, a frame containing several rows of frames that I want to write text in and then scroll through. I can do that fine only each update writes the new text over the top of the old text, making it unreadable. Addons like Auctioneer do this all the time so I must be missing something.
Creating the subframes and text looks like this Code:
function GGCreatePDField(Name, Parent, Point, ofsx , ofsy, fwidth, fheight, text) Code:
for i = 1, displayRows do |
1) You're creating a new font string every time, instead of reusing the old one. Keep track of the already-created rows and only create a new one if you're already using all the existing ones.
2) Your update loop doesn't need to manually increment i -- the whole purpose of a for loop is to do that for you. 3) You're creating multiple objects with the global names "Level" and "LevelName", which is bad for many reasons. These objects don't need names at all, these names are extremely generic and extremely likely to conflict with other addons or the default UI, and since they're all the same they're even conflicting with each other. You also appear to be setting many other generically named variables like "charLevel" and "ofsy" in the global namespace, which is called leaking and is bad. Put "local" keywords in front of each variable you declare, unless it absolutely needs to be global. I'd suggest something more like this: Code:
local rowFrames = {} |
I know the code I posted is whacked, I have been trying a lot of different things, local, named, not named, buttons, frames, creating new, reusing. Just about to delete the whole mess and say it can't be done.
looks like this is what I have been missing f:SetID(i) rowFrames[i] = f |
That didn't work either. In the function below v is set by the scroll bar. Here are screen shots.
After init before scrolling: Post Scroll : code: Code:
function ShowGroupMemberList(v) |
Your caching table and the CreateRow function need to be defined outside of the update function -- otherwise, every time you call the update function, you're creating a new list of rows instead of using the old one, which defeats the purpose of keeping a list of already-created rows in the first place.
Also, your CreateRow function cannot refer to variables that are inside the update function. If you already know you want the first row to be 100px from the left and 0px from the top, just hardcode 110 and 0 as the position offsets. Since each additional row is anchored relative to the previous row, instead of all rows being anchored relative to the parent frame, there's no need to keep track of the y offset or change any positions in the update function. Similarly, you only need to pass the row number to the CreateRow function -- you don't need to pass a reference to the list of created frames, and you don't need to pass any position offsets. The :SetID() call doesn't really matter as far as reusing rows go, but it does mean that if you have a reference to the row frame, you can call :GetID() to find out [b]which[/i] row it is. |
Thanks for your help. I put your function as a separate function, same result, broke into 3 functions same affect, and then decided to put it all in one exactly as you suggested, same effect. Believe me I have coding this for a week and I feel I have already done what you suggest. I have made a slash command for a Field1:SetText("Change") and I get the same thing. I put the entire first pass in the init script then only called a function that had nothing but set text statements, same thing. I don't think hard coding the columns is the answer as you see I have at least 7 other columns to fill in, provided there is a way to actually change the text. I have at least 112 cells to set, which I could hard code and would if it provided a different outcome, but I think I tried that. What you’re telling me is that there is no way to change the text; I can only use the set text function to write text over the existing text. Don’t suggest SetText(nil) cause that does nothing. Frustrated I am.
|
Quote:
She gave you an example and you put the entire thing inside of a function which is overwriting the table that's tracking what rows have already been created every time it's run. Every time you call "ShowGroupMemberList", which I'm guessing is being called every time you scroll, you're wiping out the table that's supposed to be tracking which rows have already been created. The ONLY part that should be inside of that function is this: Lua Code:
|
Just so you know I figured it out, or at least a work around. If you run into this again do not set text when the button/fontstring is created, don't even put a SetText(text). Only set text in the update function
rowFrames[i]:SetText(text) = Good CreateRow[i]:SetText(text) = BAD if you plan on changing later Thanks for your help and guidance. |
Quote:
Quote:
|
If you're not using the buttons for anything other than to display text, why not just create the FontStrings directly on the roster frame?
|
All times are GMT -6. The time now is 12:31 AM. |
vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI