Commit Graph

1204 Commits

Author SHA1 Message Date
Elias Naur 05efb9b5f4 example/kitchen: add Switch widget
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-05-05 10:41:10 +02:00
Elias Naur 26da49e145 widget/material: add Switch widget
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-05-05 10:38:31 +02:00
Elias Naur 6b4eb710b3 widget: rename CheckBox to Bool
We're about to introduce the Switch widget that re-uses the same
state type as CheckBox. The Bool name covers both uses.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-05-04 17:13:50 +02:00
Chris Waldon 13941c9f1b io/router: add tests for Enter/Leave pointer events
Signed-off-by: Chris Waldon <christopher.waldon.dev@gmail.com>
2020-05-04 14:41:28 +02:00
Chris Waldon 1c113f19c6 io/router: send pointer Enter/Leave events
This commit introduces a naive system for sending events
when a pointer enters or leaves a pointer hit area.

Signed-off-by: Chris Waldon <christopher.waldon.dev@gmail.com>
2020-05-04 14:41:25 +02:00
Chris Waldon 6501ecf2a0 io/pointer: define new Enter/Leave pointer events
Signed-off-by: Chris Waldon <christopher.waldon.dev@gmail.com>
2020-05-04 14:41:21 +02:00
Elias Naur 52d8a8867d widget,widget/material: export CheckBox.Checked
Similar to the previous change to Enum, expose the current state of
the CheckBox. Rename the Checked method to just Update and get rid
of the SetChecked method.

Fixes gio#100

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-05-03 21:28:33 +02:00
Elias Naur f1e266a9e7 widget,widget/material: export Enum.Value
The Value method both updated the enum value and returned it.

In order to access the current value withoutm, expose the Value
field of the enum and rename the method to Update. As a bonus we
can get rid of the SetValue method as well.

Updates gio#96

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-05-03 21:28:33 +02:00
Elias Naur a1166e6652 example,cmd: bump gio version
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-05-03 21:07:53 +02:00
Elias Naur 8d9612f9aa layout,app,io/system: move Queue from app.Window to FrameEvent
Change gioui.org/commit/0e70fbc1262920a69c60409285795b6bb8701b09
added a note that app.Window.Queue must only be used during the
processing of a FrameEvent. The change was added because a Gio
user took the existence of app.Window.Queue to mean it was always
available.

This change reduces the scope of window Queues by moving it from Window
to FrameEvent, and minimizes the risk of misuse by not offering
Window.Queue at all.

Note that the gioui.org/commit/a937a7653439333b8c6fc30c7a6039b717339766
change moved Window's Frame method (named Update) to FrameEvent for the
same reason.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-05-03 21:04:52 +02:00
Elias Naur 289fe02b90 layout: replace NewContext with a Queue argument to Context.Reset
We're about to reduce the scope of the Window.Queue by moving it
to FrameEvent. As a consequence, Context can no longer rely on a
Queue constant over its lifetime.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-05-03 21:03:40 +02:00
Elias Naur d350f82011 layout: fix typo
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-05-03 17:13:08 +02:00
Elias Naur d474b5b16a example: bump gio version
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-05-03 13:06:55 +02:00
Elias Naur 060cff257f material: make theme constructors stand-alone functions
The multitude of widget methods on Theme is unnecessary coupling in that all
possible widgets either have to be included in package material, or be
different than 3rd party widgets:

	var th *Theme

	// Core widget, calling a method on Theme.
	th.Button(...).Layout(...)

	// 3rd party widget, calling a function taking a Theme.
	datepicker.New(th, ...).Layout(...)

Another reason for the Theme methods was to enable a poor man's
theme replacement, so that you could use the same code for
compatible themes. For example,

	mat.Button(...).Layout(...)

would not need to change if the type of mat changed, as long as
the new type had a compatible method Button.

However, that point misses the fact that the mat variable had to
be declared somewhere, naming the theme package:

	var mat *material.Theme (or, say, *cocoa.Theme)

A better and complete way to replace a theme is to use import renaming.
For example, to replace the material theme with a hypothetical Windows
theme, replace

	import theme "gioui.org/widget/material"

with

	import theme "github.com/somebody/windows

This change moves all Theme widget methods to be standalone functions,
and renames the widget style types accordingly.

For example, instead of the method

	func (t *Theme) Button(...) Button

there is now a function

	func Button(t *Theme, ...) ButtonStyle

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-05-03 13:03:04 +02:00
Elias Naur e460e4f4bf widget,widget/material: move Image and Icon to widget package
There is nothing theme-specific about displaying images and icons,
so move the types from the material package to the generic widget
package.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-05-03 12:22:32 +02:00
Elias Naur fa7f9d3ba8 widget/material: report icons dimensions after running Icon.Layout
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-05-02 20:56:33 +02:00
Pierre.Curto 4db3cb2afb gesture: support multiple click actions
Double click or tap actions are common in user interfaces and this
commit adds support for it in the gesture package.
ClickEvent has now a new field NumClicks that contains the number of
successive clicks that occurred within 200ms.

Fixes gio#101

Signed-off-by: Pierre.Curto <pierre.curto@gmail.com>
2020-05-02 19:07:59 +02:00
Fabian Geiselhart b862f4f174 example/kitchen: Use the button passed to iconAndTextButton.Layout
The global iconTextButton variable was used instead of the passed
button.

Signed-off-by: Fabian Geiselhart <me@f4814n.de>
2020-05-01 15:32:27 +02:00
Elias Naur 0e70fbc126 app: add note about the safe use of Window.Queue.
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-04-29 10:22:02 +02:00
Elias Naur 133fa45258 example,cmd: update gio version
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-04-29 10:08:36 +02:00
Elias Naur 4bde9fbcaa app/internal/log: add synchronized logger on Android
By default, the standard library log package outputs to stderr.
However, stderr is redirected through a pipe to the Android logger,
so recent writes may be not have been sent when os.Exit is called.

The log.Fatal family of functions does just that: write to the log
and call os.Exit.

To ensure all messages are sent, register a synchronized logger at
startup.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-04-29 10:03:07 +02:00
Elias Naur 51e4df7707 app/internal/log: fix typo
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-04-29 09:08:11 +02:00
Elias Naur 9218df1db7 example,cmd: update gio version
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-04-28 14:58:49 +02:00
Elias Naur 9842cbd30b gpu/gl: detect float FBO support under Safari's WebGL1 implementation
Safari's WebGL does not advertise support for EXT_color_buffer_half_float,
but does support rendering to float FBOs.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-04-28 14:54:59 +02:00
Elias Naur 1062d4e79d gpu/shaders: avoid first-class arrays
Safari's WebGL1 implementation (rightly) complains that first-class
array types are not supported as function result types. Define and
use a struct type instead.

While we're here, use const variables instead of functions.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-04-28 14:46:33 +01:00
Elias Naur 22f964548b gesture: fix typo
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-04-27 21:29:11 +02:00
Elias Naur 84d4800a16 cmd/gogio: match Android window background with default Gio color
While launching an app on Android, the hard-coded theme is used for
the color. That color is by default black, and results in a jarring
transition to the actual app background.

The default Gio color is white, so use that for the theme background
as well.

This change will break for "dark mode" programs and similar.  A future
improvement would be to reflect the actual app background in the theme.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-04-24 15:59:30 +02:00
Elias Naur cf6e128d48 example,cmd: update gio version
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-04-23 21:15:17 +02:00
Elias Naur 533bf953f9 app/internal/cocoainit: enable multithread support in Cocoa
According to

https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/Multithreading/CreatingThreads/CreatingThreads.html#//apple_ref/doc/uid/20000738-125024

Cocoa is by default not multithread-safe for programs that use the posix
api for creating threads:

"
For multithreaded applications, Cocoa frameworks use locks and other
forms of internal synchronization to ensure they behave correctly. To
prevent these locks from degrading performance in the single-threaded
case, however, Cocoa does not create them until the application spawns
its first new thread using the NSThread class. If you spawn threads
using only POSIX thread routines, Cocoa does not receive the
notifications it needs to know that your application is now
multithreaded. When that happens, operations involving the Cocoa
frameworks may destabilize or crash your application.
"

That includes Go programs.

The fix, as discovered by Steeve Morin, is to create and launch
an empty NSThread.

Add a package that does that, and use it everywhere Cocoa is used.

Sigh.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-04-23 21:13:19 +02:00
Fabian Geiselhart 08dfd2943b ui: fix wrong method name in documentation
Signed-off-by: Fabian Geiselhart <me@f4814n.de>
2020-04-23 15:55:51 +02:00
Elias Naur 925f5af930 example/go.mod: update gio version
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-04-23 00:32:59 +02:00
Elias Naur 02d4316c56 gpu: reset to the default framebuffer on reset
The macOS backend doesn't re-create contexts, holding on to the first
created instead. Make sure the GPU leaves the default framebuffer bound,
in case the context is re-used.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-04-23 00:27:04 +02:00
Elias Naur aefc6f3625 app/internal/window: [Android] use correct JNI Call variant for registerFragment
While we're here,

- replace the registerFragment trampoline with a general variadic
CallVoidMethod trampoline.
- Use UTF-16 for passing strings to Java. Java's modified UTF-8 encoding differ
from Go's in corner cases.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-04-20 20:54:50 +02:00
Elias Naur ae77377f7b app: [Android] replace PlatformHandle with JavaVM, AppContext methods
Clearer and fewer types.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-04-20 20:21:39 +02:00
Elias Naur 10f932137c app: fix NewWindow comment
Window options are a list now, not a struct.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-04-20 20:08:01 +02:00
Elias Naur 30b46ded6b internal/window: [Android] remove unused C function
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-04-20 19:11:04 +02:00
Elias Naur 2b1935d657 cmd/gogio: include Android themes in .aar outputs
Not strictly necessary, but makes embedding a Gio Android Activity
easier; adding

	<activity android:name="org.gioui.GioActivity"
		android:theme="@style/Theme.GioApp"
		android:configChanges="orientation|keyboardHidden"
		android:windowSoftInputMode="adjustResize">
		<intent-filter>
			<action android:name="android.intent.action.MAIN" />
			<category android:name="android.intent.category.LAUNCHER" />
		</intent-filter>
	</activity>

should be enough.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-04-18 20:24:42 +02:00
Elias Naur 0cfc914d8b example/tabs: add example for tabbed content
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-04-17 10:50:50 +02:00
Elias Naur b1aed3eae0 Revert "widget/material: propagate ButtonLayout minimum constraints to content"
This reverts commit 52ccc183b5.

Reason for revert:

This doesn't seem like a good idea after all. The reason for the change was to
propagate the minimum constraints to the button content. But in the simplest case,
a label, stretching the button will make the label stretch as well, leaving the label
top-aligned.

We'll revisit this issue if a real use-case comes up.
2020-04-16 19:57:19 +02:00
Elias Naur b8cbc1e99d widget: improve Click description
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-04-16 19:15:10 +02:00
metaclips efce78d414 example/kitchen: add ProgressBar example
Updates the kitchen example codebase showing ProgressBar functionality.

Signed-off-by: metaclips <utimichael9@gmail.com>
2020-04-03 10:49:47 +02:00
metaclips da01fbdea7 widget/material: add ProgressBar
Add progress indicator support to material widget

Signed-off-by: metaclips <utimichael9@gmail.com>
2020-04-02 21:05:13 +02:00
Elias Naur 221ce02328 LICENSE: merge UNLICENSE and LICENSE-MIT
The pleasing of automatic license detectors continues.

No license change, merely a merging of LICENSE-MIT and UNLICENSE and the
license blurp from README.md.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-04-02 10:45:37 +02:00
Elias Naur 0542796463 .builds: add webassembly build test
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-04-01 13:32:18 +02:00
Elias Naur 97538991d2 example/glfw: fix build
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-04-01 13:21:55 +02:00
Elias Naur 1a3bbd5d92 example,cmd: update gio
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-04-01 13:21:55 +02:00
Elias Naur 1ad891ff67 app/internal: fix Android build
pkg-config doesn't exist for Android.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-04-01 13:04:40 +02:00
Elias Naur 27d81b8c7e widget/material: re-center Button label
A previous change propagated the minimum layout constraints to Button's
content, which made Button no longer center its label when stretched.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-03-27 16:40:13 +01:00
Elias Naur 52ccc183b5 widget/material: propagate ButtonLayout minimum constraints to content
The previous change fixed a regression where minimum constraints larger than 0
would not affect the button. This change moves the minimum constraints one
level lower so the content widget will see them as well. The wrapping
layout.Center ensures that any misbehaving widgets still end up centered.

Add a test to lock in the new behaviour and the previous fix.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-03-25 17:52:02 +01:00
metaclips f7a23ad46a widget/material: draw button to max width with ButtonLayout
This patch allows support to draw button to maximum width using ButtonLayout.
2020-03-25 17:41:01 +01:00