Skip to content

Propagate disabled and hidden state to native widgets - #634

Open
metif12 wants to merge 2 commits into
vlang:masterfrom
metif12:native-disabled
Open

metif12 wants to merge 2 commits into
vlang:masterfrom
metif12:native-disabled

Conversation

@metif12

@metif12 metif12 commented Nov 21, 2026

Copy link
Copy Markdown
Member

Problem

Native widgets mode never received the V model's disabled/hidden flags:

  • no native create/update API on any platform carried either flag;
  • native_button_set_enabled (macOS) and Win32 EnableWindow / ShowWindow / IsWindowVisible were declared but never called;
  • a disabled button still fired on_click through native_button_clicked;
  • draw-time state sync only flowed native → V, so a disabled/hidden control looked and behaved enabled.

Change

  • Add NativeWidgets.set_enabled() / set_visible() on all three backends and a shared native_widgets.sync_state() helper.
    • Windows: EnableWindow + ShowWindow (sw_show / sw_hide, both already declared).
    • macOS: setEnabled: and setHidden: via the existing macos_objc_msg_void_bool helper.
    • Default: no-op, as before.
  • Call sync_state() from every native widget's init(), from its native draw path, and from set_visible() (hidden widgets are filtered out of drawing_children, so draw alone cannot hide them).
  • Guard native_button_clicked() with hidden || disabled.

ListItem.disabled is per-item and cannot be expressed in native list controls; it stays on the custom rendering path.

Notes

Add a disabled field and param to Dropdown, Switch, Radio, Slider, TextBox, Picture and Menu/MenuItem, and guard every input handler so disabled widgets cannot be clicked, focused, dragged or typed into. Dim their drawing with a shared dim_color helper.

CheckBox.disabled was declared but never read; it now blocks both mouse and keyboard toggling. ListBox disabled items are no longer selectable via single-select clicks or arrow keys, draggable, or hover-highlighted. Focus navigation now skips disabled widgets via Focusable.is_disabled(), and set_focus/force_focus no longer steal focus for them.

Document the new params in docs.md.
Native widgets mode never received the V model's disabled/hidden flags. Add set_enabled/set_visible to the Windows, macOS and default backends plus a shared NativeWidgets.sync_state helper, and call it from each widget's native init, native draw path and set_visible(). A disabled native button no longer fires on_click.

Windows uses EnableWindow/ShowWindow; macOS sends setEnabled:/setHidden: to the control; the default backend is a no-op as before. Per-item ListBox.disabled is not representable in native list controls and is left to the custom rendering path.
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.

1 participant