Skip to content

Comments

Proof of concept of MVVM refactoring: ruler#2003

Open
Lehonti wants to merge 2 commits intoPintaProject:masterfrom
Lehonti:refactoring/ruler_mvvm_demo
Open

Proof of concept of MVVM refactoring: ruler#2003
Lehonti wants to merge 2 commits intoPintaProject:masterfrom
Lehonti:refactoring/ruler_mvvm_demo

Conversation

@Lehonti
Copy link
Contributor

@Lehonti Lehonti commented Feb 23, 2026

As discussed in #1879

This is a rough demo of how I imagine the refactoring to MVVM would go. A few explanations:

  • Notice that RulerModel is in the Pinta.Core project
  • RulerModel might look boring and/or pointless, but the reason is that it does not need to be more complex. The model in MVVM does not notify listeners, or knows anything about how it will be rendered. Its only job is to guard internal state consistency.
  • Expanding on the previous point, since in this case all properties are independent of each other, and all representable values are valid, no validations are needed. Sure, we could throw an exception if someone tries to assign double.NaN to Position, or something like (MetricType)992635 to Metric, but I think that it's quite safe in general.
  • In the future, for more complex state management, we would most likely have to go beyond plain setters and getters, and use methods with parameters instead.
  • Expanding further, my long-term vision for the model would be something like a PintaEngine or PintaKernel that can hold the entirety of the internal state of Pinta without even needing to reference GUI libraries to function (although, practically, it would need to reference Cairo)
  • The code of the ruler can be refactored further, but I am skipping all of those changes because I want this specific pull request to be illustrative

@badcel
Copy link
Contributor

badcel commented Feb 24, 2026

I have a comment but won't be able to write it down until later today. Do you mind holding this back a bit?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants