github go-gui-org/go-gui v0.97.0

one hour ago

Added

  • DrawCanvasCfg.OnAnyClick takes a press of any mouse button (#1290).
    Since v0.81.0 (#844) a canvas's OnClick runs on a left press only. A canvas
    that is its own input surface lost every right and middle press. go-term's
    grid is such a canvas: right-click menus in terminal apps (ttt) did not open,
    and middle-click paste did not work. OnAnyClick runs on every button and
    replaces OnClick when both are set, as ContainerCfg.OnAnyClick does.
    OnClick stays left-only.

  • ButtonCfg.Loading shows a busy spinner (#1264). A button that starts
    slow work (log in, save, upload) sets Loading: true while the work runs. The
    button draws a spinner in the label color in place of its content. The content
    is still laid out, so the button keeps its width. Before, an app put an
    SvgSpinner in Content, and the button changed width when the spinner
    appeared. While loading, OnClick does not fire and no click sound plays.
    Unlike Disabled, the button keeps its normal colors and stays focusable, so
    focus does not move while the work runs. The a11y state gets
    AccessStateBusy. The spinner animates only while Loading is true. The
    showcase Button page has a demo. See docs/specs/button-loading.md.

  • Window.KeepAwake keeps the display on (#1172, #1287). A video player
    calls release := w.KeepAwake("Playing a video") when playback starts and
    release() when it stops. Each call is its own request, so two players never
    end each other's: the display may sleep only once every request is released.
    The OS gets one request for the whole app, held while some window with a
    request is on screen. A minimized or hidden window, or an app in the
    background, lets the display sleep, and closing a window ends its requests.
    Both calls are safe from any goroutine. Windows keeps the display and the
    system awake (powercfg /requests shows the reason), macOS holds an
    NSProcessInfo activity (pmset -g assertions), iOS turns off the idle timer
    and the web takes a Screen Wake Lock (HTTPS or localhost only). On Wayland
    every window carries an idle inhibitor (the idle-inhibit protocol), so it also
    works on sway, Hyprland and other compositors without a ScreenSaver service.
    X11, and a compositor without the protocol (weston, GNOME before 45), ask the
    desktop's org.freedesktop.ScreenSaver service over D-Bus. On Android the
    app's host polls the new PendingKeepAwake and sets FLAG_KEEP_SCREEN_ON
    (see examples/android_demo). DebugWindowDegraded reports a refused
    request. A custom backend implements the new NativePlatform.SetKeepAwake.
    The new examples/keep_awake shows it. See docs/specs/keep-awake.md.

  • GOGUI_RENDERER=soft draws a Linux window on the CPU, without GL (#1265).
    On a machine without a GPU, EGL falls back to Mesa's llvmpipe, which measured
    two to four times the CPU of go-gui's own software renderer while animating
    and about twice the memory. With GOGUI_RENDERER=soft the X11 backend opens
    no EGL display: each frame is drawn by gui/backend/soft and uploaded through
    MIT-SHM (core PutImage on a server that cannot map the shared memory, such
    as a remote display), paced to the monitor's refresh rate. On native Wayland
    the frame is written into a wl_shm buffer the compositor maps and committed,
    paced by frame callbacks, with no EGL or libwayland-egl loaded. Events,
    input methods, the clipboard and DPI handling are the same code as with GL.
    The frame is redrawn in full on each change, so this is aimed at 1× displays,
    and a custom shader draws its children but not its shader fill. gl keeps GL
    (for no value, see the auto-pick entry under Changed), and on Linux the no-GPU
    error now names the variable. The new soft.Renderer is the live counterpart
    of soft.RenderToImage. It draws one pass into one reused buffer: the soft
    glyph backend now uploads new glyphs in the middle of a frame, so a cold glyph
    atlas needs no warm-up pass. soft.RenderToImage of an already-rendered
    window at a new scale now moves its text system to the new density instead of
    freeing it under the window's cached text layouts. See
    docs/specs/live-software-renderer.md.

  • Texture caches are bounded by bytes, and WindowCfg.MaxTextureBytes sets
    the cap (#1239).
    Before, each window kept up to 128 decoded images on the
    GPU (256 on web), whatever their size. With large photos that is gigabytes,
    and on iOS and Android the OS kills the app. Now each window also caps the
    bytes it keeps: 256 MiB on desktop and web, 128 MiB on iOS and Android, or the
    value of MaxTextureBytes. When a new image takes the window over the cap,
    the images not drawn for two frames are deleted, oldest first. Images on
    screen are never deleted: if they alone need more than the cap, the window
    goes over it rather than uploading them again every frame. On web the
    random-batch eviction of loaded images is replaced by the same rule. See
    docs/specs/texture-byte-budget.md.

  • Window.TestStep moves a test window's clock and runs one frame (#1262).
    Before, animation time in a test came from a goroutine on the wall clock. A
    test that needed a tween to end, a caret to blink or a tooltip to show had to
    sleep, and the result changed with machine load. Now w.TestStep(dt) switches
    the window to a manual clock on its first call and stops the animation
    goroutine. Each call adds dt to the clock, ticks every animation once and
    runs one frame. Tweens, springs, keyframes, Animate delays, the caret blink,
    tooltip delays, double-click timing and SVG animations all read that clock.
    w.Now() follows it too, and a time-travel pin still wins over it. The switch
    is one-way and is for headless tests only.

  • Soak harness for long sessions (#1262). The new tools/soak package acts
    as a user on a headless window for a simulated time. It clicks, types accented
    text, emoji and Arabic, presses keys, scrolls, resizes and switches the theme.
    It reports allocations per frame (mean and p99) and the growth of the live
    heap. A second mode sends fully random raw events to find panics.
    examples/showcase/soak_test.go runs it: 5 s on every PR, and nightly 60
    simulated minutes (about 90 s of wall time) with hard gates on allocations and
    heap growth. See tools/soak/README.md.

  • A form checks its fields by itself (#1257). Before, the app reported every
    edit and blur by calling FormOnFieldEvent from each widget's callbacks. The
    call from OnBlur did nothing: Input runs OnBlur after the frame, without a
    layout, so the form was never found. No field was validated when the user left
    it. Now the form compares each frame with the last one. An edit while the
    field's widget has focus is a change, and focus leaving the widget is a blur.
    The app still registers each field every frame with FormRegisterFieldByID,
    and gives the field's widget the field's ID. The new
    FormFieldAdapterCfg.WidgetID names the widget when its ID differs. After an
    edit, the form also re-runs the sync validators of the fields it has already
    checked, so a rule such as "confirm matches password" follows an edit of the
    password. A field set to FormValidateOnSubmit is left alone until submit. A
    value the app sets itself while the widget has no focus is validated on
    submit, not before.

  • An app learns when nobody sees its window (#1170). The new
    EventVisibilityChanged reaches Window.OnEvent when the window stops being
    shown or is shown again: it is minimized, the app called Hide, or the app
    went to the background on Android, iOS or the web. The new Window.IsOccluded
    reports the OS side, IsVisible still reports the app's own Hide, and the
    window is shown when IsVisible() && !IsOccluded(). A media player uses this
    to stop decoding and pause audio. There is one event per change on every
    platform, also where the OS reports a Hide as an occlusion. Android apps
    must add VisibilityChanged to their Go bridge and call it from onStart /
    onStop (see examples/android_demo); without it nothing is reported there.
    Windows and X11 report minimize only, not a covered window. The new
    examples/visibility shows it. See docs/specs/window-visibility-event.md.

Changed

  • BREAKING: NativePlatform requires SetKeepAwake (#1172). A custom
    backend that implements NativePlatform must add
    SetKeepAwake(on bool, app, reason string) error, or it no longer compiles.
    gui calls it only when the app starts or stops keeping the display on. A
    backend that cannot keep the display on returns an error wrapping
    errors.ErrUnsupported, which DebugWindowDegraded reports; returning nil
    instead keeps the old behavior silently. The backends in this repository all
    implement it.

  • Linux X11 picks the CPU renderer by itself when GL would run on the CPU
    anyway (#1265).
    With GOGUI_RENDERER unset, the X11 backend now probes GL
    once at start. When GL_RENDERER names a software rasterizer (llvmpipe,
    softpipe, lavapipe, SwiftShader), or EGL cannot open a display, the window is
    drawn by gui/backend/soft instead, with one log line that says why. On
    llvmpipe that measured about a third of the CPU and half the memory. Before,
    no value meant GL, and a machine without a GPU context failed with
    ErrNoGPUContext; now GOGUI_RENDERER=gl gives that error and skips the
    probe. With no value, the error comes only when EGL opens but the window's own
    GL context fails (the probe kept GL), or when neither renderer can run. A
    machine with a hardware GPU keeps GL, at the cost of one extra context create
    and destroy at start. The native Wayland backend makes the same check on its
    own connection, because a Wayland desktop can hand clients llvmpipe on a
    machine whose GPU works under X11 (Cinnamon does): there the CPU renderer
    measured about a third of llvmpipe's CPU on the benchmark (64 % against 200
    %). An EGL failure on Wayland still falls back to X11. Values other than gl
    and soft keep GL and log a warning. An app that needs custom shaders on a
    machine without a GPU sets GOGUI_RENDERER=gl.

  • A native Wayland frame allocates 7 times instead of 19 (#1265). Every
    libwayland call through purego allocated its argument list on the heap; the
    Wayland bindings now pass arguments from a reused array, so requests, flushes
    and an idle dispatch allocate nothing. What is left comes from purego's
    callback path while events are dispatched (reported upstream as
    ebitengine/purego#567). This applies to GL windows and CPU-rendered ones
    alike. A CPU-rendered frame no longer leaves frame-sized garbage either: on
    X11 the upload goes through MIT-SHM, or through one reused request buffer when
    the server cannot map shared memory, where before each frame left a whole
    frame of request buffers (4 MB at 1280×800) for the garbage collector; on
    Wayland the present itself allocates nothing.

  • The CPU renderer draws gradients, scaled images and SVG meshes without
    allocating (#1282).
    A gradient or image fill went through x/image/vector's
    generic loop, which boxes a color on every pixel it reads and writes: a
    full-window gradient made about 154 000 allocations per frame. Those fills now
    rasterize their coverage into a reused mask and blend it in a typed loop that
    uses the same 16-bit arithmetic, and SVG mesh triangles and coverage masks no
    longer allocate either. In every pixel-golden case, a steady-state
    soft.Renderer frame now makes 0 allocations, and a test pins that.
    soft.RenderToImage no longer allocates per pixel. A 320×240 linear gradient
    takes 7.1 ms instead of 10.2 ms. Fully covered pixels are byte-identical. An
    antialiased edge pixel may differ by one level, because the mask keeps 8 bits
    of coverage where the generic loop read 16.

  • A full state map evicts state that is not in use, not the oldest state
    (#1263).
    Before, a full StateMap namespace, or the scroll, overflow and
    hover maps, removed the oldest inserted key when a new key arrived. A widget
    on screen that reads its state every frame could lose it, for example the rows
    of a list where paging adds new row IDs. Now Get, GetOr and Set stamp
    each entry with the view pass. A full map removes the oldest entry that was
    not used in the current pass. Only when every entry was used in this pass does
    the oldest inserted go. Off-screen state, such as a hidden tab, stays until
    the map is full, as before. Capacities do not change, eviction stays about as
    fast as before, and Keys and Range keep insertion order. A map built with
    NewBoundedMap alone still removes the oldest inserted key.

  • Android, iOS and web stop animating while the app is hidden (#1170). These
    platforms draw no frames in the background, so nothing ran the callbacks that
    running animations kept queuing. Until now go-gui cancelled a spinner two
    seconds after its last frame, and it restarted from the beginning on return.
    Now the animation loop stops while the app is hidden and goes on at the right
    phase when it returns. Animation callbacks (OnValue, Animate) do not run
    while hidden on these platforms. The desktop is unchanged: a minimized window
    still runs them on time.

  • iOS keeps drawing under Control Center (#1170). The display link paused
    whenever the scene became inactive, which also happens under Control Center,
    the notification pull-down and a system alert. It now pauses only when the app
    enters the background.

  • Window.Hide does nothing on web, iOS, Android and native Wayland
    (#1170).
    No window can be hidden there, but Hide still turned IsVisible
    false while the user kept seeing the app. Now IsVisible stays true, no
    EventVisibilityChanged is sent, and DebugWindowDegraded reports the call.
    A custom backend that cannot hide a window gets the same by adding
    CanHideWindow() bool to its platform, returning false.

  • BREAKING: gui.DispatchWindowOccluded must be called on the UI thread
    (#1170).
    It now runs the app's event handler. Before, it only set flags and
    was safe on any goroutine. Every backend in go-gui already calls it on the UI
    thread, so apps are not affected. Migration, for a custom backend that calls
    it from another goroutine: move the call to the UI thread, for example with
    w.QueueCommand(func(w *gui.Window) { gui.DispatchWindowOccluded(w, hidden) })
    where a frame still runs, or from the platform's own main-thread callback.

  • Enter submits a form (#1257). Enter in a single-line Input inside a Form
    now requests submit, as in an HTML form. Before, Enter did nothing there, and
    NoSubmitOnEnter turned off a feature that did not exist. An app that wired
    Enter itself, with an OnEnter that calls FormRequestSubmit, still submits
    once. Migration, for an app whose Enter in a form must not submit: set
    FormCfg.NoSubmitOnEnter, or call ctx.Consume() in that Input's OnEnter.
    An OnEnter that does something else without consuming the key now also
    submits. go-gui's own fields that use Enter for something else consume it: the
    command palette, the data grid's jump-to-row box and the color picker's
    fields.

  • BREAKING: FormCfg.ID is required (#1257). A form without an ID used to
    get a generated one (#881). No app could register a field with that ID or
    submit the form, so such a form never worked. Now it shows its content and
    nothing else, and DebugMissingIDs reports it. Migration: give the Form an
    ID, and pass the same ID to FormRegisterFieldByID and FormRequestSubmit.

  • FormOnFieldEvent is deprecated (#1257). The form now detects edits and
    blur itself, so the call can go. An app that keeps calling it needs no change.
    Each call does what it did before, with one exception: a blur report for a
    field whose widget the form finds does nothing, because the form runs that
    blur itself when focus leaves the widget. Before, a report sent while the
    widget still had focus, such as from a commit on Enter, validated the field
    there and then. Two things improve without a change. When a field's widget
    carries the field's ID, the form now also validates the field on blur, which
    the call from OnBlur never did. After each change, the form re-checks fields
    it has already checked, so a stale cross-field error clears. The call also
    finds the form from a part of a composite widget now, such as a color field.
    Before, that part's own ID started with form:, was taken for the form's, and
    the call did nothing.

  • Button, tab, Select and menu labels sit higher, so lowercase text looks
    centred.
    Before, a control label put the cap height on the vertical centre.
    Most label text is lowercase, and lowercase is shorter than caps, so it sat
    lower. On a showcase button, "Open Command Palette" had its caps centred to
    the pixel and its lowercase 2.5 device pixels low. Now labels centre halfway
    between the cap height and the x-height. That moves a lowercase label up by
    about 0.044 of the font size (0.6 px at size 14), and an all-caps label sits
    only that much high. The value comes from the font and its size, not from the
    label text, so labels in a row keep one baseline. Input fields that hold
    digits or hex values keep their own centring.

Fixed

  • Window.Close takes effect at once on an idle window (#1273). Close
    only set a flag, and the backend reads that flag when its event loop runs. An
    idle loop sleeps until the next OS message, so a Close from a tray menu, a
    timer or another goroutine waited for the next mouse move, and never happened
    on a hidden window. Close now wakes the loop. The system-tray example's
    "Quit" also ended nothing: it sent a quit request, which ran the window's
    hide-on-close hook, and the app stayed alive with no window and no tray. It
    now removes the tray and calls Close on every window. The example's close
    button also did nothing where the window could not go to the tray: on a
    desktop without a tray, and on native Wayland, where a window cannot be
    hidden. There it now closes the window.

  • A click in a Windows tray menu fires the item that was clicked (#1273).
    The menu's item IDs were one lower than the tray code expected. A click fired
    the action of the item above it, the first item fired nothing, and an item
    after a separator, such as "Quit" in the system-tray example, fired nothing
    either. The menu is now built from the same list the click is looked up in.

  • The tray tooltip shows on Windows (#1274). SystemTrayCfg.Tooltip was
    sent to the shell but never shown: the tray uses the newer icon protocol, and
    with it Windows hides the standard tooltip unless it is asked for. The tray
    now asks for it.

  • Window.Hide before the backend starts keeps the window off the screen
    (#1270).
    An app that called w.Hide() before backend.Run, to start with
    no window showing, still got its window on screen, while IsVisible reported
    false. Windows, X11 and macOS now create such a window without showing it, and
    Show brings it up. A tray app can start hidden this way. A Hide in
    OnInit works as before: the window is on screen by then and is taken away
    again. On native Wayland a window cannot be hidden yet, so it still shows.

  • A minimized window under GNOME on X11 counts as hidden (#1170). GNOME's
    window manager keeps a minimized window mapped and marks it in
    _NET_WM_STATE. go-gui only watched for the unmap that other window managers
    send (#954), so under GNOME a minimized window kept asking for animation
    frames, and Window.IsOccluded would have stayed false. Both now count.

  • OnSubmit and OnReset may call SetFocus and SetView (#1257). The
    form called them from its layout pass, which holds the frame lock. An
    OnSubmit that moved focus or switched to the next page therefore panicked.
    Both callbacks now run after the frame, outside the lock, as Input's blur
    callbacks already do. ctx.Layout is nil in them, as before.

  • A form with an async validator can submit (#1257). Every submit started
    the async validators again, and by default a submit is refused while one runs.
    So OnSubmit never ran for a form with an async validator, unless the form
    set AllowPendingSubmit. The showcase form was one of them. Now an async
    validator runs again only when its field's value changes; a blur or a submit
    with the same value reuses its result. A submit that only waits for a running
    check goes ahead when the check passes, or is rejected when it reports an
    issue. It sounds once, when the wait ends.

  • An edit stops a running async check (#1257). In the default mode an edit
    does not validate, so it also did not stop a check of the old value. That
    check's result then landed on the new value, for example "taken" for a name
    the user had already changed. Now any change of a field's value stops its
    running check and drops the result. A submit that waited for that check starts
    over, so it checks what it will send. A reset stops the check too.

  • A submit right after leaving a field sends the committed value (#1257). A
    click on a submit button moves focus out of the field, and the field commits
    its text one frame later, for example NumericInput clamping -5 to 0. The
    submit used the text from before the commit: OnSubmit got -5 while the
    field showed 0. Now a submit made as focus leaves a field waits one frame
    for the committed value.

  • A form warning no longer blocks submit (#1236). Before, go-gui ignored
    FormIssue.Kind. An issue tagged FormIssueWarning therefore counted like an
    error. FormSummaryState.Valid was false, InvalidCount counted the field,
    and submit was blocked unless the form set AllowInvalidSubmit. Now only an
    error makes a field invalid. Warnings still appear in
    FormSummaryState.Issues and FormFieldState.Errors, so an app can still
    show them. An issue that does not set Kind is an error, as before, so
    existing validators keep working.

  • Keyboard focus stays inside a modal dialog, and a Menubar behind it no
    longer opens its menu (#1242).
    A DialogCustom dialog without FocusID
    focused an ID its custom body never carries. Each frame, focus then moved to
    the first tab stop of the window behind the dialog. An Input there showed
    focus, and a Menubar there selected its first item and opened its menu while
    the dialog was up. Focus also changed twice per frame, which cleared input
    selections every time. The same move happened for one frame with a correct
    FocusID, when the focused widget in the dialog was turned off through its
    container. Now a dialog whose FocusID names nothing focuses its first tab
    stop, or no widget when it has none, and a focused widget that goes away under
    a dialog hands focus to another tab stop in the dialog. A FocusID on the
    turned-away face of a FlipPanel also counts as naming nothing: the panel
    takes focus off that face, and the dialog used to put it back every other
    frame. DialogCfg.FocusID now has a doc comment that says how to set it for
    DialogCustom.

  • Markdown task-list checkboxes have room around the check (#1254). A GFM
    task item (- [ ], - [x]) drew its box at 0.8 of the text size, smaller
    than the text beside it, and its check at 1.1 of the box, so the mark touched
    the border. The box is now the body text size, with the toggle style's inner
    padding, and the check is sized for the icon font so its ink is about half the
    box wide. At the default 14px body text the box grows from 11.2px to 14px, and
    the check sits at least 2.5px clear of the border on every side.

What's Changed

Other changes

  • fix(gui): keep keyboard focus inside a modal dialog (#1242) by @ollex in #1255
  • fix(gui): give Markdown task-list checkboxes room around the check (#1254) by @mike-ward in #1256
  • fix(gui): a form warning no longer blocks submit (#1236) by @ollex in #1258
  • feat(gui)!: the form works out field events itself (#1257) by @ollex in #1260
  • docs(claude): no PR is pushed while its docs disagree with it by @ollex in #1259
  • fix(gui): centre control labels between cap and x-height by @mike-ward in #1261
  • fix(gui): StateMap keeps state used this frame when full (#1263) by @mike-ward in #1266
  • feat(gui): Window.TestStep and tools/soak headless soak harness (#1262) by @mike-ward in #1267
  • feat(gui): tell an app when nobody sees its window (#1170) by @ollex in #1269
  • test(gl): Wayland fullscreen tests pass on any screen size (#1268) by @ollex in #1271
  • fix(backend): Hide before the backend starts keeps the window off screen (#1270) by @ollex in #1272
  • fix(gui): tray "Quit" ends the app, Windows tray menu and tooltip (#1273, #1274) by @ollex in #1275
  • feat(gui/backend): bound texture caches by bytes (#1239) by @mike-ward in #1276
  • test: make prepush pass from a pre-push hook in a worktree by @mike-ward in #1277
  • feat(gui/backend/gl): GOGUI_RENDERER=soft presents X11 windows on the CPU (#1265) by @mike-ward in #1278
  • feat(gui/backend/gl): auto-pick the CPU renderer on a software rasterizer (#1265) by @mike-ward in #1279
  • feat(gui/backend/gl): CPU renderer on native Wayland through wl_shm (#1265) by @mike-ward in #1280
  • perf(gui/backend): no frame-sized garbage on the soft present path (#1265) by @mike-ward in #1283
  • perf(gui/backend/soft): gradients, scaled images and blends without allocating (#1282) by @mike-ward in #1285
  • feat(gui): Window.KeepAwake keeps the display on (#1172) by @ollex in #1286
  • feat(gui): ButtonCfg.Loading shows a busy spinner (#1264) by @mike-ward in #1288
  • Wayland: keep the display awake through idle-inhibit, with D-Bus as the fallback by @ollex in #1289
  • feat(gui): DrawCanvasCfg.OnAnyClick takes a press of any mouse button by @mike-ward in #1290
  • changelog: add v0.97.0 by @mike-ward in #1291

Full Changelog: v0.96.0...v0.97.0

Don't miss a new go-gui release

NewReleases is sending notifications on new releases.