{"id":13366524,"url":"https://github.com/dtylman/Gowd","last_synced_at":"2025-03-12T18:31:14.531Z","repository":{"id":44424250,"uuid":"86594955","full_name":"dtylman/gowd","owner":"dtylman","description":"Build cross platform GUI apps with GO and HTML/JS/CSS (powered by nwjs)","archived":false,"fork":false,"pushed_at":"2023-02-24T18:58:10.000Z","size":11940,"stargazers_count":425,"open_issues_count":7,"forks_count":43,"subscribers_count":25,"default_branch":"master","last_synced_at":"2024-07-31T01:25:46.212Z","etag":null,"topics":["desktop","golang","nwjs-application"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dtylman.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2017-03-29T14:50:53.000Z","updated_at":"2024-06-19T10:28:07.000Z","dependencies_parsed_at":"2024-01-08T15:34:36.783Z","dependency_job_id":null,"html_url":"https://github.com/dtylman/gowd","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dtylman%2Fgowd","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dtylman%2Fgowd/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dtylman%2Fgowd/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dtylman%2Fgowd/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dtylman","download_url":"https://codeload.github.com/dtylman/gowd/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":221309831,"owners_count":16795818,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["desktop","golang","nwjs-application"],"created_at":"2024-07-30T00:01:26.311Z","updated_at":"2024-10-24T11:30:19.749Z","avatar_url":"https://github.com/dtylman.png","language":"Go","funding_links":[],"categories":["GUI"],"sub_categories":["高级控制台界面","高級控制台界面"],"readme":"# gowd\n\nBuild cross platform GUI apps with GO and HTML/JS/CSS (powered by [nwjs](https://nwjs.io/))\n\n[![CircleCI](https://circleci.com/gh/dtylman/gowd.svg?style=svg)](https://circleci.com/gh/dtylman/gowd)\n[![Go Report Card](https://goreportcard.com/badge/github.com/dtylman/gowd)](https://goreportcard.com/report/github.com/dtylman/gowd)\n[![GoDoc](https://godoc.org/github.com/dtylman/gowd?status.svg)](http://godoc.org/github.com/dtylman/gowd)\n\n### How to use this library:\n\n1. Download and install [nwjs](https://nwjs.io/)\n1. Install this library `go get github.com/dtylman/gowd`\n1. Clone this repo.\n1. Place `package.json`, `index.html`, `main.go` and `main.js` from [template](cmd/template/) in a new folder. \n1. `go build`\n1. Edit `main.js` and set `goBinary` to your your executable name:\n    ```javascript\n    var goBinary = \"./template\"; //or template.exe\n    ```\n1. Run `nw .`, the hello world template should appear:\n![hello-world](cmd/template/hello-world.png)\n\n### Usage\n\nSimplest \"hello world\":\n```go\n\nimport \"github.com/dtylman/gowd\"\n\nfunc main() {\n\tbody, err := gowd.ParseElement(\"\u003ch1\u003eHello world\u003c/h1\u003e\", nil)\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\tgowd.Run(body)\n}\n\n```\n\nAdding a button:\n\n```go\n\nimport (\n\t\"github.com/dtylman/gowd\"\n)\n\nfunc main() {\n\tbody, err := gowd.ParseElement(\"\u003ch1\u003eHello world\u003c/h1\u003e\", nil)\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\tp := body.AddElement(gowd.NewElement(\"p\"))\n\tbtn := p.AddElement(gowd.NewElement(\"button\"))\n\tbtn.SetText(\"Click me\")\n\tbtn.OnEvent(gowd.OnClick, btnClicked)\n\tgowd.Run(body)\n}\n\nfunc btnClicked(sender *gowd.Element, event *gowd.EventElement) {\n\tsender.SetText(\"Clicked!\")\n}\n```\n\nCreating and binding from HTML:\n```go\nimport (\n\t\"github.com/dtylman/gowd\"\n\t\"fmt\"\n)\n\nfunc main() {\n\tbody, err := gowd.ParseElement(\"\u003ch1\u003eHello world\u003c/h1\u003e\", nil)\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\tp := body.AddElement(gowd.NewElement(\"p\"))\n\tem := gowd.NewElementMap()\n\tp.AddHtml(`\u003cselect id=\"select1\"\u003e\n\t\t\u003coption value=\"\" disabled=\"disabled\" selected=\"selected\"\u003ePlease select a name\u003c/option\u003e\n\t\t\u003coption value=\"1\"\u003eOne\u003c/option\u003e\n\t\t\u003coption value=\"2\"\u003eTwo\u003c/option\u003e\n\t\t\u003c/select\u003e`, em)\n\tem[\"select1\"].OnEvent(gowd.OnChange, btnClicked)\n\tem[\"select1\"].Object = body\n\tgowd.Run(body)\n}\n\nfunc btnClicked(sender *gowd.Element, event *gowd.EventElement) {\n\tbody := sender.Object.(*gowd.Element)\n\tbody.AddElement(gowd.NewStyledText(fmt.Sprintf(\"Selected %s\", event.GetValue()), gowd.BoldText))\n\tbody.AddElement(gowd.NewElement(\"br\"))\n}\n```\n\nUsing bootstrap:\n\n'gowd' supports creating bootstrap elements using the [bootstrap](bootstrap/) package.\n\nFirst, add bootsrap css and js to your `index.html` file:\n```html\n    \u003cscript type=\"text/javascript\" src=\"js/jquery.min.js\"\u003e\u003c/script\u003e\n    \u003clink rel=\"stylesheet\" type=\"text/css\" href=\"css/bootstrap.min.css\"/\u003e\n    \u003cscript type=\"text/javascript\" src=\"js/bootstrap.min.js\"\u003e\u003c/script\u003e\n```\n\nThen you can create bootsrap items:\n\n```go\n\nimport (\n\t\"github.com/dtylman/gowd\"\n\n\t\"github.com/dtylman/gowd/bootstrap\"\n\t\"time\"\n\t\"fmt\"\n)\n\nvar body *gowd.Element\n\nfunc main() {\n\t//creates a new bootstrap fluid container\n\tbody = bootstrap.NewContainer(false)\n\t// add some elements using the object model\n\tdiv := bootstrap.NewElement(\"div\", \"well\")\n\trow := bootstrap.NewRow(bootstrap.NewColumn(bootstrap.ColumnLarge, 6, div))\n\tbody.AddElement(row)\n\t// add some other elements from HTML\n\tdiv.AddHTML(`\u003cdiv class=\"dropdown\"\u003e\n\t\u003cbutton class=\"btn btn-primary dropdown-toggle\" type=\"button\" data-toggle=\"dropdown\"\u003eDropdown Example\n\t\u003cspan class=\"caret\"\u003e\u003c/span\u003e\u003c/button\u003e\n\t\u003cul class=\"dropdown-menu\" id=\"dropdown-menu\"\u003e\n\t\u003cli\u003e\u003ca href=\"#\"\u003eHTML\u003c/a\u003e\u003c/li\u003e\n\t\u003cli\u003e\u003ca href=\"#\"\u003eCSS\u003c/a\u003e\u003c/li\u003e\n\t\u003cli\u003e\u003ca href=\"#\"\u003eJavaScript\u003c/a\u003e\u003c/li\u003e\n\t\u003c/ul\u003e\n\t\u003c/div\u003e`, nil)\n\t// add a button to show a progress bar\n\tbtn := bootstrap.NewButton(bootstrap.ButtonPrimary, \"Start\")\n\tbtn.OnEvent(gowd.OnClick, btnClicked)\n\trow.AddElement(bootstrap.NewColumn(bootstrap.ColumnLarge, 4, bootstrap.NewElement(\"div\", \"well\", btn)))\n\n\t//start the ui loop\n\tgowd.Run(body)\n}\n\n// happens when the 'start' button is clicked\nfunc btnClicked(sender *gowd.Element, event *gowd.EventElement) {\n\t// adds a text and progress bar to the body \n\ttext := body.AddElement(gowd.NewStyledText(\"Working...\", gowd.BoldText))\n\tprogressBar := bootstrap.NewProgressBar()\n\tbody.AddElement(progressBar.Element)\n\t\n\t// makes the body stop responding to user events\n\tbody.Disable()\n\t\n\t// clean up - remove the added elements\n\tdefer func() {\n\t\tbody.RemoveElement(text)\n\t\tbody.RemoveElement(progressBar.Element)\n\t\tbody.Enable()\n\t}()\n\n\t// render the progress bar\n\tfor i := 0; i \u003c= 123; i++ {\n\t\tprogressBar.SetValue(i, 123)\n\t\ttext.SetText(fmt.Sprintf(\"Working %v\", i))\n\t\ttime.Sleep(time.Millisecond * 20)\n\t\t// this will cause the body to be refreshed\n\t\tbody.Render()\n\t}\n\n}\n```\n\nThis will yield the following app:\n\n![Simple](docs/template.gif)\n\nMore a more advanced usage, see the [Todo](cmd/todomvc/readme.md) sample\n\n![TodoMVC](docs/todomvc.gif)\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdtylman%2FGowd","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdtylman%2FGowd","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdtylman%2FGowd/lists"}