Extending base components #349
Unanswered
NicholasLWebster
asked this question in
Q&A
Replies: 1 comment
-
I'd use VerticalStackPanel instead of Panel as container. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I’d like to start by saying this library is freaking awesome and has saved me a crazy amount of time on my game project which is heavy on GUI. So, thanks!
The set of general base components is pretty solid but I’ve found myself wanted to extend it. Specifically I want to add a component that is a HorizontalProgressBar with a label. I know I could create a class that extends panel, and then add the bar to the panel and then add a label to the panel. But I don’t like that because I want this to be a very generalized component that can be referenced and used following the same patterns as the base components.
Let me explain further what I mean by “referenced and used following the same patterns as the base components”. If I wanted to add a progress bar to my GUI, I’d simple instantiate a new Horizontal or Vertical ProgressBar and add it to whatever part of the GUI I’m working on. I’d size it by setting the Height and Width and it would work fantastic. However, if I created a class called LabeledHorizontalProgressBar that extends Panel and contains a Label and a HorizontalProgressBar, when I need to adjust the size the behavior I’d expect is to update the Height and Width properties on my LabeledHorizontalProgressBar and have those values cascade to the HorizontalProgressBar and Label. As it stands it looks like I’d have to update the height and width on the child ProgressBar and Label either by exposing them as public or some other abstraction that would make it impossible for me to have my LabeledHorizontalProgressBar inherit from a base component.
Hopefully that makes sense. Here’s an example of how I’d like to be able to reference it from code:
var labeledProgressBar = new LabeledHorizontalProgressBar { Width = someNumber // I'd like doing this to set the width for the progress bar and the label }
I was wondering if you had any suggestions on the best way to implement this while observing the established pattern for the other base components?
Beta Was this translation helpful? Give feedback.
All reactions