Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add example code for gioui #80

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Conversation

karelbilek
Copy link
Contributor

@karelbilek karelbilek commented Feb 16, 2024

For some reason, I could not run main.go on macOS from terminal. However, when I made a simple gioui gui app, it worked.

I am adding it as it's useful for quick testing and actually seeing how the dialog runs.

gioui is a simple UX framework that is multiplatform; what I like about it is you just need go with cgo to build it, the app code is just go, and there are no other steps.

(Cross-building is still not really possible, though, as it is using cgo.)

I have made example_gioui a separate module so adding dialog as a dependency doesn't grab all gioui with it, just because of the example.

For some reason, I could not run main.go on macOS from terminal. However, when I made a simple gioui gui app, it worked.

I am adding it as it's useful for quick testing and actually seeing how the dialog runs.

gioui is a simple UX framework that is multiplatform; what I like about it is you just need go with cgo
to build it, the app code is just go, and there are no other steps.

(Cross-building is still not really possible, though, as it is using cgo.)

I have made example_gioui a separate module so installing dialog doesn't have all gioui as a dependency.
@karelbilek
Copy link
Contributor Author

hmm, maybe it would be better to figure out what the gioui magic does so it can be replicated here... instead of adding the whole thing

@karelbilek
Copy link
Contributor Author

Ah figured it out, it's actually very simple, will make a PR

@karelbilek karelbilek closed this Feb 17, 2024
@sqweek
Copy link
Owner

sqweek commented Feb 18, 2024

gioui is great! I would not object to having an example ready to go :)

Is the additional module necessary? None of the existing examples are separate modules but afaik they don't pull their extra dependencies in for users that don't try to run the examples (eg. example/wde/)

@karelbilek
Copy link
Contributor Author

karelbilek commented Feb 18, 2024 via email

@karelbilek karelbilek reopened this Feb 18, 2024
@sqweek
Copy link
Owner

sqweek commented Feb 18, 2024

Look at example/wde/main.go -- it includes these imports:

import (
        "github.com/skelterjohn/go.wde" // nolint: goimports
        _ "github.com/skelterjohn/go.wde/init"
)

Which are not part of dialog's go.mod¹ and as far as I'm aware they don't get pulled in when you go get github.com/sqweek/dialog -- can you check go.mod for your project and/or your local filesystem to see if skelterjohn/go.wde is present?

Because they are in a subdir you'd need to import (or go get) github.com/sqweek/dialog/example/wde for them to become relevant. ie. I'm pretty sure you can just make a new directory example/gioui/ for this code.

¹ actually dialog's go.mod only includes Titanrain/w32 which seems wrong in the general sense because this is only a dependency on windows. Most of my experience with go was before the module system was introduced so I'm not quite sure what the correct thing to do here is

@karelbilek
Copy link
Contributor Author

Dialog's go.mod is not really correct; if you do go mod tidy with new go, it will get filled correctly

@karelbilek
Copy link
Contributor Author

karelbilek commented Feb 19, 2024

If you do go mod tidy right now, you will get this in go.mod

module github.com/sqweek/dialog

go 1.22.0

require (
        github.com/TheTitanrain/w32 v0.0.0-20180517000239-4f5cfb03fabf
        github.com/skelterjohn/go.wde v0.0.0-20190318181201-adc3f78cdb45
)

require (
        github.com/AllenDang/w32 v0.0.0-20180428130237-ad0a36d80adc // indirect
        github.com/BurntSushi/freetype-go v0.0.0-20160129220410-b763ddbfe298 // indirect
        github.com/BurntSushi/graphics-go v0.0.0-20160129215708-b43f31a4a966 // indirect
        github.com/BurntSushi/xgb v0.0.0-20210121224620-deaf085860bc // indirect
        github.com/BurntSushi/xgbutil v0.0.0-20190907113008-ad855c713046 // indirect
)

However, you are correct that the dependents will not get it if it's just in example/. My bad.

So I will just put it in example/gioui (btw the wde example doesn't seem to work for me at all)

Also use this opportunity to update go.mod
@karelbilek
Copy link
Contributor Author

I put it to example/gioui in this PR (and also updated go.mod while I was at it, with go1.21.7 as it's the latest oldstable)

@sqweek
Copy link
Owner

sqweek commented Feb 26, 2024

Haha damn, I tried to test this but:

$ go run main.go
go: errors parsing go.mod:
C:\code\go\src\github.com\sqweek\dialog\go.mod:3: invalid go version '1.21.7': must match format 1.23

I edited go.mod to read 1.21 but then:

$ go run main.go
# gioui.org/internal/debug
C:\src\go\pkg\mod\gioui.org@v0.5.0\internal\debug\debug.go:20:17: undefined: atomic.Bool
note: module requires Go 1.19

I have go 1.18 😅

@sqweek
Copy link
Owner

sqweek commented Feb 26, 2024

If you do go mod tidy right now, you will get this in go.mod

module github.com/sqweek/dialog

go 1.22.0

require (
        github.com/TheTitanrain/w32 v0.0.0-20180517000239-4f5cfb03fabf
        github.com/skelterjohn/go.wde v0.0.0-20190318181201-adc3f78cdb45
)

Ah ok, no that's not right either go.wde shouldn't be listed at all. Will have to look into how to do submodules properly in modern go.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants