Talk:VGUI2 Programming Best Practices
I'm confused why panel position, layout should be data driven. Suppose I want the panel to change size/layout based on user choices as they access the panel? Can that be done through .res files? Why is this considered a best practice? --Daktor 20:04, 4 Dec 2006 (PST)
- Data driven is considered a "best practice" because you don't have to recompile the DLL every time you want to move the panel about. Even in your example, the initial position should be data driven, and you would save any changes to a user file. —Kateye 19:19, 5 Dec 2006 (PST)
- Thanks for the reply, that makes sense. However, it seems like there are many cases where a .res file specification cannot achieve the desired functionality. However, the article says you should not hard-code values in any case. Is there always a way to specify in a .res file the exact same functionality that can be achieved through code?
- Here is an example of something that cannot be specified in a .res file (I think):
- Suppose you have a series of panels which the player can dynamically add/remove text from. When the player adds/removes text, the panel and each of it's parents (up to a certain level in the hierarchy) resize to handle the new size of the text. --Daktor 05:12, 6 Dec 2006 (PST)
- No, there isn't always a way to specify in a res file how to do something in code. There isn't supposed to be. That's what code is for. If you need dynamics, you write it in code and recompile the DLL. But any variables that you use in your dynamics (Say, how much you should pad around the text) should be externalized into a file. The actual behavior is put into code.
- The layout of most panels are going to be static, and even those that aren't the "layout" is still going to be defined by the data they are given, which they will work with in order to determine their behavior and final layout.
- Data Driven design means that you keep your data outside of the binary. You don't hardcode magic numbers (unless it is truly necessary). It doesn't mean you move behavior outside the code. Use code for behavior, and external files for data.
- —Kateye 17:05, 6 Dec 2006 (PST)
- Ahh... ok that clears things up. Thanks for the help! --Daktor 18:47, 6 Dec 2006 (PST)