Skip to content

How do I move focus from one widget to another? #49

Answered by can-lehmann
silenc3r asked this question in Q&A
Discussion options

You must be logged in to vote

There currently is no simple built-in method for getting a reference to a GTK Widget anywhere in the widget tree. You can however use hooks to get around this limitation. One idea for solving your specific use case might be building something similar to React's refs. Here is a basic implementation of a Ref widget that extracts the underlying GTK widget of its child.

# License: MIT
# Copyright (c) 2023 Can Joshua Lehmann

import owlkettle/[gtk, widgetutils]

type Cell = ref object
  widget*: GtkWidget

proc focus*(cell: Cell) =
  gtk_widget_grab_focus(cell.widget)

renderable Ref:
  cell: Cell
  child: Widget
  
  hooks:
    beforeBuild:
      state.internalWidget = gtk_box_new(GTK_ORIENTA…

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
1 reply
@can-lehmann
Comment options

Answer selected by silenc3r
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants
Converted from issue

This discussion was converted from issue #48 on March 30, 2023 14:29.