Skip to content

Commit

Permalink
Add property hook for Box.orient field
Browse files Browse the repository at this point in the history
  • Loading branch information
can-lehmann committed Nov 30, 2023
1 parent e2bf7df commit f9b3835
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 5 deletions.
2 changes: 2 additions & 0 deletions owlkettle/bindings/gtk.nim
Original file line number Diff line number Diff line change
Expand Up @@ -627,6 +627,8 @@ proc gtk_widget_set_margin_start*(widget: GtkWidget, margin: cint)
proc gtk_widget_set_margin_end*(widget: GtkWidget, margin: cint)
proc gtk_widget_set_hexpand*(widget: GtkWidget, expand: cbool)
proc gtk_widget_set_vexpand*(widget: GtkWidget, expand: cbool)
proc gtk_widget_set_hexpand_set*(widget: GtkWidget, isSet: cbool)
proc gtk_widget_set_vexpand_set*(widget: GtkWidget, isSet: cbool)
proc gtk_widget_set_halign*(widget: GtkWidget, align: GtkAlign)
proc gtk_widget_set_valign*(widget: GtkWidget, align: GtkAlign)
proc gtk_widget_add_controller*(widget: GtkWidget, cont: GtkEventController)
Expand Down
4 changes: 2 additions & 2 deletions owlkettle/common.nim
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@ template customPragmas*() =
template crossVersionDestructor*(name: untyped, typ: typedesc, body: untyped) =
## Defines a =destroy to work for both nim 2 and nim 1.6.X
when NimMajor >= 2:
proc `=destroy`(name: typ) =
proc `=destroy`*(name: typ) =
body
else:
proc `=destroy`(name: var typ) =
proc `=destroy`*(name: var typ) =
body
24 changes: 21 additions & 3 deletions owlkettle/widgets.nim
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,19 @@ renderable Box of BaseWidget:
widget.valSpacing.cint
)

hooks orient:
property:
gtk_orientable_set_orientation(state.internalWidget, state.orient.toGtk())
for child in state.children:
let childWidget = child.widget.unwrapInternalWidget()
case state.orient:
of OrientX:
gtk_widget_set_vexpand_set(childWidget, cbool(ord(false)))
gtk_widget_set_hexpand(childWidget, child.expand.ord.cbool)
of OrientY:
gtk_widget_set_hexpand_set(childWidget, cbool(ord(false)))
gtk_widget_set_vexpand(childWidget, child.expand.ord.cbool)

hooks spacing:
property:
gtk_box_set_spacing(state.internalWidget, state.spacing.cint)
Expand Down Expand Up @@ -2263,6 +2276,11 @@ crossVersionDestructor(buffer, TextBufferObj):

g_object_unref(pointer(buffer.gtk))

proc `=sink`*(dest: var TextBufferObj; source: TextBufferObj) =
`=destroy`(dest)
wasMoved(dest)
dest.gtk = source.gtk

proc `=copy`*(dest: var TextBufferObj, source: TextBufferObj) =
let areSameObject = pointer(source.gtk) == pointer(dest.gtk)
if areSameObject:
Expand All @@ -2272,12 +2290,12 @@ proc `=copy`*(dest: var TextBufferObj, source: TextBufferObj) =
wasMoved(dest)
if not isNil(source.gtk):
g_object_ref(pointer(source.gtk))

dest.gtk = source.gtk

proc newTextBuffer*(): TextBuffer =
result = TextBuffer(gtk: gtk_text_buffer_new(nil.GtkTextTagTable))

{.push hint[Name]: off.}
proc g_value_new(value: UnderlineKind): GValue =
discard g_value_init(result.addr, G_TYPE_INT)
Expand Down Expand Up @@ -3805,7 +3823,7 @@ proc `=sink`(dest: var MediaStreamObj; source: MediaStreamObj) =
`=destroy`(dest)
wasMoved(dest)
dest.gtk = source.gtk

proc `=copy`*(dest: var MediaStreamObj, source: MediaStreamObj) =
let areSameObject = pointer(source.gtk) == pointer(dest.gtk)
if areSameObject:
Expand Down

0 comments on commit f9b3835

Please sign in to comment.