Skip to content

Commit 280aca6

Browse files
authored
refactor: [API CHANGE] make Gio optional (gioui-plugins#40)
1 parent 56031d3 commit 280aca6

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

75 files changed

+1847
-763
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ Of course, `pingpong` has no use in real-world applications, but it can be used
7272
| **[WebViewer](https://github.com/gioui-plugins/gio-plugins/tree/main/webviewer)** | Display in-app webview using the native webview implementation on each platform. | _Android, iOS, macOS, Windows, WebAssembly_ |
7373
| **[Hyperlink](https://github.com/gioui-plugins/gio-plugins/tree/main/hyperlink)** | Open hyperlinks in the default browser. | _Android, iOS, macOS, Windows, WebAssembly_ |
7474
| **[Explorer](https://github.com/gioui-plugins/gio-plugins/tree/main/explorer)** | Opens the native file-dialog, to read/write files. | _Android, iOS, macOS, Windows, WebAssembly_ |
75-
75+
| **[Safedata](https://github.com/gioui-plugins/gio-plugins/tree/main/safedata)** | Read/Write files into the secure storage of the device. | _Android, iOS, macOS, Windows, WebAssembly_ |
7676
**We have few plugins planned:**
7777

7878
Some plugins are planned, but not yet implemented, follow the development at https://github.com/orgs/gioui-plugins/projects/1. Also,

explorer/README.md

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,32 @@ Opens the native file-dialog/file-picker.
88

99
## Usage
1010

11+
## Freestanding
12+
13+
- `exporer.NewExplorer`:
14+
- Creates a instance of Explorer struct, given the config.
15+
- `explorer.Configure`:
16+
- Updates the current Explorer with the given config.
17+
- `explorer.OpenFile`:
18+
- Opens the native file dialog to open a single file.
19+
- `explorer.SaveFile`:
20+
- Opens the native file dialog to save a single file.
21+
22+
## Gio
23+
24+
## Non-Plugin:
25+
26+
If you want to use it without plugin, read the Freestanding instructions. We provide some helper functions, such as NewConfigFromViewEvent and such.
27+
28+
## Plugin:
29+
1130
To open an single file, you can use `explorer.OpenFileOp`.
1231

1332
That will open native File Dialog/File Picker. Once the file is selected by the end-user,
1433
one `explorer.OpenFileEvent` will be sent to the given `Tag`.
1534

1635
```go
17-
explorer.OpenFileOp{
36+
gioexplorer.OpenFileOp{
1837
Tag: yourTag,
1938
Mimetype: []mimetype.MimeType{
2039
{Extension: "png", Type: "image", Subtype: "png"},
@@ -30,22 +49,22 @@ explorer.OpenFileOp{
3049

3150
Operations must be added with `.Add(gtx.Ops)` method. The operation will be executed at the end of the frame.
3251

33-
- `explorer.OpenFileOp`:
52+
- `gioexplorer.OpenFileOp`:
3453
- Opens the native file dialog to open/import a single file.
35-
- `explorer.SaveFileOp`:
54+
- `gioexplorer.SaveFileOp`:
3655
- Open the native file dialog to save/export a single file.
3756

3857
## Events:
3958

4059
Events are response sent using the `Tag` and should be handled with `gtx.Events()`.
4160

42-
- `explorer.OpenFileEvent`:
61+
- `gioexplorer.OpenFileEvent`:
4362
- Sent to `Tag` when the user chooses the file to be read/open. That event contains one io.ReadCloser.
44-
- `explorer.SaveFileEvent`:
63+
- `gioexplorer.SaveFileEvent`:
4564
- Sent to `Tag` when the user chooses the file to save/replace. That event contains one io.WriteCloser.
46-
- `explorer.ErrorEvent`:
65+
- `gioexplorer.ErrorEvent`:
4766
- Sent to `Tag` when some error occurs.
48-
- `explorer.CancelEvent`:
67+
- `gioexplorer.CancelEvent`:
4968
- Sent to `Tag` when the user closes the file-dialog or not select one valid file.
5069

5170
## Features

explorer/config.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
//go:build !android && !darwin && !ios && !windows && !(js && wasm)
2+
3+
package explorer
4+
5+
// Config is the configuration for a Explorer.
6+
//
7+
// Each OS contains their own settings and options,
8+
// check each config_* file for more details.
9+
type Config struct{}

explorer/config_android.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package explorer
2+
3+
// Config is the configuration for a Explorer.
4+
type Config struct {
5+
// VM is the Java VM.
6+
VM uintptr
7+
8+
View uintptr
9+
10+
// Context is the Android Context.
11+
Context uintptr
12+
13+
// RunOnMain is a function that runs on the main UI thread.
14+
RunOnMain func(f func())
15+
}

explorer/config_ios.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package explorer
2+
3+
// Config is the configuration for a Explorer.
4+
type Config struct {
5+
// View is a CFTypeRef for the UIViewController for the window.
6+
View uintptr
7+
8+
// RunOnMain is a function that runs on the main UI thread.
9+
RunOnMain func(f func())
10+
11+
// PxPerDp represents how many pixels per each dp.
12+
PxPerDp float32
13+
}

explorer/config_js.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
package explorer
2+
3+
// Config is the configuration for a Explorer.
4+
type Config struct{}

explorer/config_macos.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
//go:build darwin && !ios
2+
3+
package explorer
4+
5+
// Config is the configuration for a Explorer.
6+
type Config struct {
7+
// View is a CFTypeRef for the NSView for the window.
8+
View uintptr
9+
10+
// Layer is a CFTypeRef of the CALayer of View.
11+
Layer uintptr
12+
13+
// RunOnMain is a function that runs on the main UI thread.
14+
RunOnMain func(f func())
15+
}

explorer/config_unsupported.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
//go:build !android && !darwin && !ios && !windows && !(js && wasm)
2+
3+
package explorer
4+
5+
// Config is the configuration for a Explorer.
6+
type Config struct{}

explorer/config_windows.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package explorer
2+
3+
// Config is the configuration for a Explorer.
4+
type Config struct {
5+
// HWND is the handle to the window.
6+
HWND uintptr
7+
8+
// RunOnMain is a function that runs on the main UI thread.
9+
RunOnMain func(f func())
10+
}

explorer/demo/go.mod

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
module demo
2+
3+
go 1.19
4+
5+
replace github.com/gioui-plugins/gio-plugins => ../../
6+
7+
require (
8+
gioui.org v0.0.0-20230425023356-bba91263b077
9+
github.com/gioui-plugins/gio-plugins v0.0.0-00010101000000-000000000000
10+
golang.org/x/image v0.7.0
11+
)
12+
13+
require (
14+
gioui.org/cpu v0.0.0-20220412190645-f1e9e8c3b1f7 // indirect
15+
gioui.org/shader v1.0.6 // indirect
16+
git.wow.st/gmp/jni v0.0.0-20210610011705-34026c7e22d0 // indirect
17+
github.com/go-text/typesetting v0.0.0-20230413204129-b4f0492bf7ae // indirect
18+
golang.org/x/exp v0.0.0-20221012211006-4de253d81b95 // indirect
19+
golang.org/x/exp/shiny v0.0.0-20220921164117-439092de6870 // indirect
20+
golang.org/x/sys v0.5.0 // indirect
21+
golang.org/x/text v0.9.0 // indirect
22+
)

0 commit comments

Comments
 (0)