I am writing an application which is used for drawing widgets/menus/controls etc to create application mockups. Each screen is represented as collection of widgets, and each widget is simple class e.g.
class Model(object):
def __init__(self):
self.widgets = []
class Widget(object):
def __init__(self):
self.x, self.y = 0, 0
self.w, self.h = 100,20
self.text = "Widget"
Now user can edit x,y,w,h in editor and it is rendered in many views(places), rendering itself may change w and h because we want to at least show best fit. e.g. text "Widget" may need width 200 or 205 in different views
Question:
So problem is rendering/view itself modifes the model, how to avoid that? For now I have main view and main model, any other view if wants to render copies model and renders it hence avoiding the change in main model.
This approach is simple and code remains simple but needs a unnecessary copy of model, I have thought of many ways to avoid that but all will complicate code and may not be that efficient because anyway if model is not copied render-time-attributes needs to be placed somewhere e.g. in each renderer for each widget.
I am implementing it in python but that is not relevant for the answer.