I'm working on an engine for my game (in C++). I've done the graphics related stuff and I've started working on UI (user interface). When I was working on buttons I've realized that hardcoding every kind of button would not be possible (or would be too many classes) as I have buttons with only labels, with colored backgrounds, with texture backgrounds and so on...
So I think what I need are Components. I just build the button I want:
UIButton* btn = new UIButton(); btn->AddRenderComponent(new DrawRectComponent(...)); btn->AddRenderComponent(new DrawStringComponent(...)); btn->AddLogicComponent(new SendEventOnClickComponent(...));
My problem is that I don't know how to tell the component objects what fields should they use from the UI elements? For example position and size (which could change dinamically). Should I use references for example?
Also it would be good if I could not only use this in the UI, but a similar component system could be used in other parts of the engine (at entities for example).