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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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.
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>
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>
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>
I've resisted relying on pkg-config in the hope that hard-coded include and
library paths would suffice. However, apart from having to work around some
distro-specific differences, building with hardcoded include paths fails when
building on a buildroot:
x86_64-buildroot-linux-gnu-gcc: ERROR: unsafe header/library path used in cross-compilation: '-I/usr/include/wayland'
(see #91)
Andri mentions a workaround (prefixing paths with "="), but that doesn't seem
to work on the BSDs.
Let's see how pkg-config fares. It's an extra dependency, but it promises to keep
us isolated from the varying paths on Linux distrobutions.
Updates #91
Signed-off-by: Elias Naur <mail@eliasnaur.com>
Add ButtonLayout for adding button behaviour and style to arbitrary content such
as a combined icon-and-text button.
Fixes#43
Signed-off-by: metaclips <utimichael9@gmail.com>
EGL is window system agnostic, but its egl.h header includex X11
headers by default. Use the MESA_EGL_NO_X11_HEADERS define to avoid
it, fixing the "nox11" build for systems without X11 headers installed.
Fixes#91
Signed-off-by: Elias Naur <mail@eliasnaur.com>