atomic14 / diy-esp32-epub-reader

An ESP32 e-reader
MIT License
333 stars 46 forks source link

Split the rendering of the display from the model objects #32

Open cgreening opened 2 years ago

cgreening commented 2 years ago

It would be good to move towards the MVC (Model View Controller) pattern for the UI to make the code a bit cleaner. At the moment classes like the EpubList and EpubReader have everything in them with some of the controller code in the main.cpp as well.

Ideally, we'd have a model class that contains the state, a controller class that responds to user events and updates the model and then a view class that renders the current state of the model.

User Event (touch, button_press) -> Controller -> Model Update -> View Rendered

This will be a fairly chunky refactor.

martinberlin commented 2 years ago

A though about this idea, there is also LVGL that is a library that can help with this concept: https://github.com/martinberlin/lv_port_esp32-epaper/ That is my fork that works with EPDiy to render and detect touch in this epaper.

The thing is that of course to use that will add a lot of code and reduce our own space to code. But the benefit is that it has that what you describe, kind of Model-View with ready made UX elements and also allows you to make Buttons that are directly attached to callback functions (With much more events, like onPress, onRelease, etc) This is just a pointer and idea so you try it out and maybe just get some ideas from Lvgl.

This is an article I wrote about it with some video demos.