fjvallarino / monomer

An easy to use, cross platform, GUI library for writing Haskell applications.
BSD 3-Clause "New" or "Revised" License
575 stars 42 forks source link

Packaging Roboto into Main Library via String Literal ByteString, additional startAppUIOnly wrapper over startApp #287

Closed liamzee closed 1 year ago

liamzee commented 1 year ago

As I understand it, ease-of-use is a library objective. One issue right now is that a produced binary must include a font in order for any text to display, which makes the library a bit harder to use, as it requires packaging via Cabal or Stack.

To resolve this problem, I've added file-embed (locked to 0.0.15.*) as a dependency, then embedded Roboto-Regular.ttf as a strict ByteString, and modified nanovgrenderer and fontrenderer to add Roboto-Regular in the event that no fonts are configured.

Roboto is also licensed under Apache License 2.0, so I've amended the LICENSE statement to include the required license display.

===

I've also added a function exposed via startAppUIOnly, which calls startApp with a nullary event handler, () / unit as the model and event type, alongside an empty configuration. To get startAppUIOnly to work, you'd only need a UI builder, which simplifies the code needed for the minimal starting app at the cost of reducing functionality.

As stated in the file comments, startAppUIOnly is intended for demonstration and teaching purposes; ideally, we could have schools and universities selecting monomer for a visual introduction to Haskell (if they go with that right now, they're probably going with gloss). Hence, the simplicity desired is basically Pythonic.

liamzee commented 1 year ago

Hold on for a bit, looks like I can't get text to display without setting a default theme, but am too tired to work out what the default theme set-up should be (i.e,

Another factor is, I've been using file-embed for a bit and it seems a good workaround around cabal, at least, being finicky about data-file deployment. It might be useful to put combinators built around file-embed in main-utils; or some other util kit.

There's also a remaining issue, and I'm not so sure whether this is a big deal for Linux or OSX. On Windows, at least, you usually want an icon to make the program look serious, and at least on my Debian GNOME install, I don't see an icon for any app. I haven't figured out how to get the pre-existing functions to accept a ByteString PNG, and that would take time and effort to look into how to get SDL2 to read data instead of a filepath.

===

On the plus side, I've cloned edifice's (Python's declarative GUI framework) todo app with some degree of fidelity. Their example is 41 lines, my clone is 41 lines, and it's mostly the old joke about the ideal Haskell program: "10 lines of language extensions, 20 lines of imports, and 1 line of Perl".

Of course it's not comparable to your version, which shows off monomer's capabilities quite well, but this is in competition with edifice, so length is everything.

If you want to take a look: https://github.com/liamzee/monomer-samples-lz