https://github.com/roblillack/spot Skip to content Navigation Menu Toggle navigation Sign in * Product + Actions Automate any workflow + Packages Host and manage packages + Security Find and fix vulnerabilities + Codespaces Instant dev environments + Copilot Write better code with AI + Code review Manage code changes + Issues Plan and track work + Discussions Collaborate outside of code Explore + All features + Documentation + GitHub Skills + Blog * Solutions For + Enterprise + Teams + Startups + Education By Solution + CI/CD & Automation + DevOps + DevSecOps Resources + Learning Pathways + White papers, Ebooks, Webinars + Customer Stories + Partners * Open Source + GitHub Sponsors Fund open source developers + The ReadME Project GitHub community articles Repositories + Topics + Trending + Collections * Pricing Search or jump to... Search code, repositories, users, issues, pull requests... Search [ ] Clear Search syntax tips Provide feedback We read every piece of feedback, and take your input very seriously. [ ] [ ] Include my email address so I can be contacted Cancel Submit feedback Saved searches Use saved searches to filter your results more quickly Name [ ] Query [ ] To see all available qualifiers, see our documentation. Cancel Create saved search Sign in Sign up You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session. Dismiss alert {{ message }} roblillack / spot Public * Notifications * Fork 4 * Star 602 * React-like desktop GUI toolkit for Go License MIT license 602 stars 4 forks Branches Tags Activity Star Notifications * Code * Issues 1 * Pull requests 3 * Discussions * Actions * Projects 0 * Security * Insights Additional navigation options * Code * Issues * Pull requests * Discussions * Actions * Projects * Security * Insights roblillack/spot This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository. main BranchesTags Go to file Code Folders and files Name Name Last commit Last commit message date Latest commit History 28 Commits examples examples resources resources ui ui LICENSE.txt LICENSE.txt README.md README.md component.go component.go go.mod go.mod go.sum go.sum hooks.go hooks.go hooks_test.go hooks_test.go nodes.go nodes.go rendercontext.go rendercontext.go setup.go setup.go utils.go utils.go View all files Repository files navigation * README * MIT license [2024-05-13-demo-video] Spot Go Reference Go Report Card Spot is a simple, cross-platform, reactive GUI toolkit for Go using native widgets where available. It is designed to be easy to use and to provide a consistent API across different platforms. Example package main import ( "fmt" "github.com/roblillack/spot" "github.com/roblillack/spot/ui" ) func main() { ui.Init() spot.MountFn(func(ctx *spot.RenderContext) spot.Component { counter, setCounter := spot.UseState[int](ctx, 0) buttonTitle := "Click me!" if counter > 0 { buttonTitle = fmt.Sprintf("Clicked %d times!", counter) } return &ui.Window{ Title: "Hello World!", Width: 200, Height: 125, Children: []spot.Component{ &ui.Button{ X: 25, Y: 50, Width: 150, Height: 25, Title: buttonTitle, OnClick: func() { setCounter(counter + 1) }, }, }, } }) ui.Run() } Features * Simple: You can add Spot as a simple dependency to your project and start building your UI right away. No need to use additional tools or code generation steps. Just write Go code and get a native GUI application as a self-contained binary. * Cross-platform: Spot uses native widgets where available and automatically selects the best backend for the platform you are running on at compile time. Currently, two backend implementations are provided: one based on FLTK using go-fltk and one based on Cocoa using (a modified version of) gocoa. * Reactive: Spot automatically updates the UI when the state of the application changes. You just provide side-effect free rendering functions and manage the state of your application using the UseState hook. * Broad widget support: Spot provides a wide range of UI controls out of the box, including buttons, labels, text inputs, sliders, dropdowns, and more. See the full list: List of supported UI controls. FAQs What does "reactive" mean? In the context of Spot, reactive means that the UI is automatically updated when the state of the application changes. This is achieved by re-building an immutable component tree upon state changes which can quickly be compared to the previous state in order to determine what UI controls need to be updated. In the web world, this idea is often called a "virtual DOM" and Spot actually started as an experiment to bring this concept to Go by implementing a React-like GUI library for the desktop. By using a reactive model, the developer does not need to worry about updating the UI manually. Instead, the developer can focus on the application logic and let Spot take care of updating the UI. What are the "native widgets" that Spot uses? Currently, Spot uses a Cocoa backend on macOS and a FLTK-based one on all other platforms. Optionally, FLTK can be used on the Mac, too. Better support for Windows is planned for the future. Can I implement my own hooks? Yes, just like in React, you can implement your own hooks. Just create a function which takes a *spot.RenderContext as first argument and use this to "hook" into the Spot lifecycle by calling spot.UseState, spot.UseEffect, etc. Convention here is to prefix the function with Use.... How do I write custom components? There are a few different ways to separate your UI into components in Spot; for some ideas, check out the custom-components example. The main way to write custom components is to create a struct that implements the spot.Component interface. This interface has a single method, Render(ctx *spot.RenderContext) spot.Component, which is called to render the component. Components created like this can be used in the same way as the built-in ones. Look at the BlinkingButton component in the example to see how this is done. Can I use Spot with a completely different widget library than the provided one? Yes, you can. You just need to create some structs that implement the spot.Component interface and which take care of managing the native widgets. Can I use spot/ui, but with a different backend than Cocoa or FLTK? Currently, these are the only backends that are supported. But feel free to create a PR if you want to add support for another backend. *hint hint* What's the difference between spot/ui and spot? spot is the core package that provides the reactive model and the rendering functionality. It is backend-agnostic and can be used with any set of controls which implement the spot.Control interface. spot/ui is a package that provides a set of pre-built cross-platform GUI controls that which can be used with spot. What's the difference between a "component" and a "control"? In Spot, a component is a logical unit of the application that contains business logic and state. Any component is made out of other componens and can ultimately be rendered down to a single or multiple "controls". A control is special kind component is mounted to the UI tree and represents a visual element on the screen. Usually a control is backed by a native implementation of the GUI backend, like a button, a label, or a text input. What do the terms "make", "render", "build", "mount", and "update" mean in the context of Spot? * Make: The process of creating a new component instance. This is done by creating a reference to an instance of a struct that implements the spot.Component interface or by calling spot.Make with a render function. * Render: The process of applying a component's state to its building blocks and hereby returning another component instance. This is done by calling the Render method on a component instance. * Build: The process of creating a new UI tree from a component instance. This is done by recursively rendering a component to create a tree of controls. This can be done by calling spot.Build with a component instance or spot.BuildFn with a render function. * Mount: The process of creating real UI controls from a (virtual) tree of controls. This is done by calling Mount on a tree node or spot.Mount with a component instance or spot.MountFn with a render function. * Update: The process of updating a tree of (mounted) controls. This is done by calling Update on a tree node. Features, Spot does not have right now * Automatic layouting * Multiple windows * Modal dialogs * Resizable windows * Menu bars * Custom widgets * Access to native widgets * Drag and drop * Internationalization List of supported UI controls Explanation of the status column: Not implemented / Work in progress / [?][?] Partially implemented / Done Name Description Native controls used Status Button Simple button to initiate Fl_Button an action NSButton Control offering the user a Fl_Check_Button Checkbox choice between two mutually NSButton ( exclusive options NSButtonTypeSwitch) ComboBox A combined dropdown menu ComboBox Not with text input NSComboBox started Fl_Dial Dial Circular status control NSProgressIndicator [?][?] (with NSCircular style) Drop-down menu to select a Fl_Choice Dropdown single item out of multiple NSComboBox options Image An image control Image Not NSImageView started Label Simple, non-editable text Fl_Box label NSTextField Scrollable control which Fl_Select_Browser/ ListBox allows the user to select a Fl_Multi_Browser single or multible items NSTableView from a given list Progress bar control to Fl_Progress ProgressBar visualize the progression NSProgressIndicator of a long-running operation Slider Horizontal slider input Fl_Slider control NSSlider Spinner Number input control with Fl_Spinner up/down buttons NSTextField+NSStepper TextField Control for single-line Fl_Input text input NSTextField TextView/ General-purpose text box to Text TextEditor view/edit multi-line text NSTextView content Control representing a Fl_Window Window (top-level) window on the NSWindow screen Potential future backends to look at * Native Windows controls: https://github.com/rodrigocfd/windigo About React-like desktop GUI toolkit for Go Topics golang gui cocoa fltk Resources Readme License MIT license Activity Stars 602 stars Watchers 4 watching Forks 4 forks Report repository Releases 2 v0.2.0 Latest May 24, 2024 + 1 release Languages * Go 100.0% Footer (c) 2024 GitHub, Inc. Footer navigation * Terms * Privacy * Security * Status * Docs * Contact * Manage cookies * Do not share my personal information You can't perform that action at this time.