return to table of content

Show HN: Spot – Simple, cross-platform, reactive desktop GUI toolkit for Go

KingOfCoders
9 replies
1d14h

I applaud your effort, but cross plattform with no Windows support?

jppittma
6 replies
1d14h

Here’s a nickel kid. Get yourself a better computer.

IshKebab
3 replies
22h36m

Oh you mean one that can sleep reliably and has battery life of more than 2 hours?

KingOfCoders
2 replies
14h46m

My desktop has no battery.

IshKebab
1 replies
5h36m

Good for you. My laptop does.

KingOfCoders
0 replies
5h3m

Yes, if you need a laptop for work and can't live without one, there is no other way but to live with the downsides of high costs, small screen and a battery.

Lucky me I no longer have to use a laptop for work and have a desktop without all the downsides.

poisonborz
0 replies
1d

Why is platform shaming tolerated around here

KingOfCoders
0 replies
1d14h

Thanks, I'd wish I could get my G4 Cube back.

atlas_hugged
0 replies
1d9h

Use WSL

RobotToaster
0 replies
1d7h

It looks like it just uses FLTK on windows, they just don't have native support on it.

felipefar
7 replies
1d14h

I'm curious to hear your take on this: what's the advantage of following the virtual control tree approach compared to instead updating directly the controls that are displayed to the user?

da_rob
6 replies
1d13h

For complex scenarios (i.e. the user interacting with the UI while there are some long-running processes in the backround doing this, too), managing the state quickly gets unwiedly: You need to write callback code everywhere that carefully has to inspect the current status of all other activities and might then updates 10s of widgets accordingly.

With the reactive approach you are able to write a single rendering function that describes the interface for any given state and the framework takes care of the rest (when to call that function, what "input" to give it).

It's just way easier to wrap my head around this and after working with React it is hard to go back. Hence the experiment to see if something comparable could be done in Go.

felipefar
4 replies
1d12h

I'm already convinced of the benefit of declarative GUIs over imperative ones. To be clearer, what I mean by declarative GUIs is ones where I can specify that UI elements should be bound to certain values in the memory of my program, so that they don't have to be changed explicitly by imperative code. Ex.:

TextBox { Text: app.currentUser.name }

Instead of having to call setText on that TextBox.

What I'm still missing is why it has to involve a virtual tree being maintained and synchronized with the real GUI tree. The UI engine could implement the above binding by instantiating for the user a callback trigerred when the bound property changes and changing precisely the value currently shown on the screen. Hence, the UI engine is in charge of the callbacks, which keeps the user unburdened by callbacks.

jdthedisciple
0 replies
1d9h

If I'm not mistaken what you describe is pretty much exactly the approach in .NET app development (WPF, MAUI, ...) with C# for the logic and XAML for declarative UI including Binding and it works well and performantly so.

iainmerrick
0 replies
1d10h

SolidJS works pretty much as you describe, and it’s great. It feels like the best bits of React, but object lifetimes and re-rendering and the real UI behavior are all much easier to understand.

(Or at least, to paraphrase Joseph Heller, “it’s intuitive once you get your head around it”)

dweymouth
0 replies
1d3h

This is exactly how the data binding APIs in Fyne (another Go GUI toolkit) work. And it's also an optional feature, so if you want to handle things by registering callbacks and calling setters yourself you can do that too.

da_rob
0 replies
1d11h

The virtual component tree is needed as there is no 1:1 mapping of components to widgets.

Using the virtual tree, you are able to build components which dynamically change the rendered subtree based on the current state.

lenkite
0 replies
1d12h

Thanks for making this library, but IMHO these are distinct concerns. One can leverage a state machine or an ECS library for complex state management. Only basic data binding can be a framework capability if needed.

The web had a lack of options for state management and hence React coupled the two.

Heliodex
6 replies
1d18h

If only I had known about this (or judging by commit history, if it existed) ~3 weeks ago. I've been saying for ages that either React ported to Go or a React-like framework for Go would be an incredible development experience, so this looks perfect (I used to be a big hater of React.js until I was enlightened by React.lua).

rkwz
2 replies
1d16h

I had the same problem - really liked the way I used to do component composition in React, it was hard to go back.

Eventually found a way to do something similar using just the standard Go html/template.

I’ve written about the implementation here:

https://www.sheshbabu.com/posts/react-like-composition-using...

biomcgary
1 replies
1d1h

This a great write-up and similar to an approach that I stumbled upon a few years ago. Have you thought about HTMXing this approach to get away from full page renders?

rkwz
0 replies
5h28m

Thanks! I wanted to use standard Go html/template to see just how bad the re-renders are, and then decide to use htmx. After building the project, I don’t mind the re-renders much as the latency is around 50ms and I don’t see any jank. I might introduce htmx in future

apitman
2 replies
1d18h

Don't leave us hanging! What did you use instead 3 weeks ago?

Heliodex
1 replies
1d17h

Wails <https://wails.io>. I wanted to use Go but wasn't as familiar with native UI as with HTML/CSS/JS, I tried out most of the other popular Go UI frameworks too though they didn't feel as comfortable to use as Spot's React-like model.

Wails is still pretty epic as well though.

parlortricks
0 replies
1d16h

oh this looks great

scosman
5 replies
1d21h

Cool!

What does building for cross platform look like? Would love if there was a command that produced my MacOs .app and Windows exe without me having to dive into package management/containers/signing headaches per platform.

da_rob
3 replies
1d21h

The backends (FLTK/Gocoa) are using CGo, which currently does not support cross-compiling as far as I know.

So you still need to have a build pipeline with multiple operating systems, signing/notarization tools, etc. :(

mappu
1 replies
1d19h

You can cross-compile Cgo, you "just" need a C compiler and linker that works for the target platform. osxcross, xgo have some or maybe you can set CC=zig cc.

For macOS you need signing/notarization tools either when building natively or when cross-compiling, it's not any different. `rcodesign` has made this process much easier in recent years.

apitman
0 replies
1d18h

+1 for `CC=zig cc`. Feels like magic

scosman
0 replies
1d20h

Too bad.

I swear half the electron apps use it for ease of Xplatform build.

I’d love something like this for giving my CLIs UIs.

felipefar
0 replies
1d14h

That'd be amazing not only for go apps but for software built on other languages as well. I'd pay for a good, straightforward build packing + crash reporting + autoupdater solution for my apps.

allanrbo
5 replies
1d21h

Was looking for something like this some years back. Though I wanted Windows support too. Ended up switching to C++ to use wxWidgets, giving me small self contained binaries.

da_rob
2 replies
1d21h

Big fan of WxWindows, I'm just too invested into Go these days. :)

Self-contained Spot "Hello World" is 2.3MiB on my Mac. Not pretty, but works for me.

da_rob
0 replies
1d10h

Geez, look at the build instructions! It all went downhill when they switched from Motif to GTK.

zerr
0 replies
1d10h

There is wxGo, but sadly the project is not maintained.

mappu
0 replies
1d19h

go-fltk does build and run on Windows, pretty well actually.

For a native toolkit, I was impressed to see FLTK supports Ctrl-+ and Ctrl+- to zoom the entire application like a browser. And https://github.com/fltk-rs/fltk-theme?tab=readme-ov-file#wid... really improved my impression of how "native" FLTK can be made to look.

On a related note, I discovered GoVCL https://z-kit.cc/en/ recently and am interested to try it out.

da_rob
0 replies
1d21h

No, it just means that the main goroutine should not be moved onto another OS thread to ensure that it is always the same OS thread which will run UI updates.

This is necessary for most UI libraries and in Spot's case implemented for both the FLTK and the Cocoa backend.

kdma
1 replies
1d7h

Just for curioristy why did you adopot a react-like model and not implement react-dom as projects like react native do?

bsimpson
0 replies
1d3h

React Native runs in JavaScript. This is in Go.

heywire
1 replies
1d18h

I’ll have to give this a look! I’ve been looking for a simple way to use Go to write an internal development tool which is basically just a form with some buttons and text fields. I tried Gio, but had a hard time with wrapping my head around it. Right now I’m using wails and like it much better. This looks interesting and worth a look!

da_rob
0 replies
1d13h

Perfect use-case, IMHO! Looking forward to hear your thoughts ocne you tried it.

getcrunk
1 replies
1d14h

Fltk supports windows. Will you be using another solution and that’s why u don’t support windows yet?

da_rob
0 replies
1d13h

Given the right C compiler and everything, Spot should work without changes on Windows (and select the FLTK) backend.

My (low prio, though) goal is to implement a Win32-based backend, though, the first step is done: https://github.com/roblillack/spot/pull/4

bsimpson
0 replies
1d3h

It's strange to see "inspired by Material Design," and then a bunch of controls that look nothing like Material.

ASalazarMX
1 replies
1d23h

I don't know how to take this in. On one side, it's great to have a cross-platform GUI toolkit that's easy to use; on the other side, it feels like a React-like UI is contrary to the spirit of simplicity and resource efficiency of Go.

I'm sure it has its perfect use cases, though.

da_rob
0 replies
1d22h

While I agree, that the virtual widget tree has a certain overhead, the typical desktop app you would create with Spot probably does not have 1000s of components—more like ten to twenty probably. Compare that to the immediate mode GUIs that currently are en vogue, that re-render all controls all the time.

Spot does not have any optimizations regarding render performance at the moment and it might never be necessary to add them.

On the other hand, due to the reactive programming model, I really like how state management get a lot clearer—especially when working with multiple goroutines.

zem
0 replies
1d12h

interesting that this uses fltk; I've seen very few language bindings to it

sandreas
0 replies
19h26m

Looks great! Thanks for sharing.

Would you consider listing the supported platforms in the readme? I think that would be a pretty interesting piece of information:

  - Windows
  - Linux
  - macOS
  - *BSD
  - Android
  - iOS
  - Web
  - Tizen
Maybe like it's on flutter docs: https://docs.flutter.dev/reference/supported-platforms

jakjak123
0 replies
1d19h

Very cool idea!

If someone implements GTK I would absolutely use it, its just fltk is no fun in Linux world

iamcalledrob
0 replies
1d7h

I have been looking for something like this in Go for a while. I think there's a real opportunity for Go to provide a great developer experience for cross platform UI due to how simple the build process is. Speaking from experience, half the pain of cross platform development is managing build complexity, which Go basically eliminates.

I'm curious how you'll end up solving for cross-platform layout when native controls have different intrinsic sizes per platform?

This is something I haven't seen solved super well in cross platform toolkits.

Wishing you luck though.

gloosx
0 replies
11h28m

This looks really cool but a bit incomplete and messy without XML-like syntax sugar for composing component functions. Is it even possible to extend Go like the JSX?

Fire-Dragon-DoL
0 replies
14h16m

Main problem is that when you release on desktop, a web version is usually desirable (except for very niche apps that interact a lot with the OS).

Alternatively, something that targets many platforms, including mobile.

I've been searching for something for quite a while and the closest is qt and react native, both painful choices for various reasons