Hacker News new | ask | show | jobs
by luzifer42 1402 days ago
The canvas is a powerful tool, especially if you do a lot of graphical work. Rendering the entire UI yourself, gives you complete freedom of layout management. Plus, you avoid any DOM manipulation, directly or through a myriad of JavaScript frameworks. Remember: there is no silver bullet. Example: https://www.isochart.com
3 comments

My interpretation of "it's hysterical to use canvas" was that it would be hysterical to draw content elsewhere and then send it to the browser for display.

Implementing something that looks like and behaves like a web page in a canvas on a web page is a "of course it's possible, but there must be a better solution" moment.

If you then have to pay for the amount of RAM of your central layout/rendering process, it would make it hysterical, as in "maybe we could pay less for RAM if we figured out how to offload layout and rendering to the client".

There's probably a niche for this still, because Java isn't inherently bad (pun intended), and if you run out of time but keep getting requirements, this thing could make your existing app be more like a web page, but if you're starting from scratch, why wouldn't you not use this?

Using canvas for fast visualizations is good! As you say, it's fast, you have layout management, and lower-level control of how things load and paint.

Using canvas for the entire UI...is not good. You have to reinvent _everything_, poorly. You have no accessibility support. Text selection doesn't exist, things look and behave kind of "off" from what people expect.

All that so you can avoid spending a few hours learning some CSS? Not sure it's worth it.

You really need a good reason to choose a non native language (e.g. not JavaScript for the Browser). One reason might be that you target other platforms too (cross-platform). In that case, you are outside of the browser anyway and you need to come up with solutions to these problems. Implementing those in a consistent way across all platforms for your product is not generally a bad idea. The alternative is an inconsistent but native UX for each platform.
Isn't WebAssembly the clear answer here? You can bind to JavaScript so you can still have all that comes with a browser environment, while still being able to use a different language. Performance may not be as good depending on what you're doing, but it's certainly better than reinventing a whole UI framework in a canvas.
But you also lose a ton of browser features such as options to open links in new tabs or download them, spell checking, search for selected text, find in page, shortcuts to jump to links... You can reimplement each specific feature but you will never get all of the features in every browser.