// Code generated by girgen. DO NOT EDIT.

package adw

import (
	"runtime"
	"unsafe"

	"github.com/diamondburned/gotk4/pkg/core/gextras"
	coreglib "github.com/diamondburned/gotk4/pkg/core/glib"
	"github.com/diamondburned/gotk4/pkg/gtk/v4"
)

// #include <stdlib.h>
// #include <adwaita.h>
// #include <glib-object.h>
import "C"

// GType values.
var (
	GTypeLayout = coreglib.Type(C.adw_layout_get_type())
)

func init() {
	coreglib.RegisterGValueMarshalers([]coreglib.TypeMarshaler{
		coreglib.TypeMarshaler{T: GTypeLayout, F: marshalLayout},
	})
}

// LayoutOverrides contains methods that are overridable.
type LayoutOverrides struct {
}

func defaultLayoutOverrides(v *Layout) LayoutOverrides {
	return LayoutOverrides{}
}

// Layout: individual layout in multilayoutview.
type Layout struct {
	_ [0]func() // equal guard
	*coreglib.Object

	gtk.Buildable
}

var (
	_ coreglib.Objector = (*Layout)(nil)
)

func init() {
	coreglib.RegisterClassInfo[*Layout, *LayoutClass, LayoutOverrides](
		GTypeLayout,
		initLayoutClass,
		wrapLayout,
		defaultLayoutOverrides,
	)
}

func initLayoutClass(gclass unsafe.Pointer, overrides LayoutOverrides, classInitFunc func(*LayoutClass)) {
	if classInitFunc != nil {
		class := (*LayoutClass)(gextras.NewStructNative(gclass))
		classInitFunc(class)
	}
}

func wrapLayout(obj *coreglib.Object) *Layout {
	return &Layout{
		Object: obj,
		Buildable: gtk.Buildable{
			Object: obj,
		},
	}
}

func marshalLayout(p uintptr) (interface{}, error) {
	return wrapLayout(coreglib.ValueFromNative(unsafe.Pointer(p)).Object()), nil
}

// NewLayout creates a new AdwLayout that contains content.
//
// The function takes the following parameters:
//
//   - content widget to use.
//
// The function returns the following values:
//
//   - layout: new AdwLayout.
func NewLayout(content gtk.Widgetter) *Layout {
	var _arg1 *C.GtkWidget // out
	var _cret *C.AdwLayout // in

	_arg1 = (*C.GtkWidget)(unsafe.Pointer(coreglib.InternObject(content).Native()))

	_cret = C.adw_layout_new(_arg1)
	runtime.KeepAlive(content)

	var _layout *Layout // out

	_layout = wrapLayout(coreglib.AssumeOwnership(unsafe.Pointer(_cret)))

	return _layout
}

// Content gets the content widget.
//
// The function returns the following values:
//
//   - widget: content.
func (self *Layout) Content() gtk.Widgetter {
	var _arg0 *C.AdwLayout // out
	var _cret *C.GtkWidget // in

	_arg0 = (*C.AdwLayout)(unsafe.Pointer(coreglib.InternObject(self).Native()))

	_cret = C.adw_layout_get_content(_arg0)
	runtime.KeepAlive(self)

	var _widget gtk.Widgetter // out

	{
		objptr := unsafe.Pointer(_cret)
		if objptr == nil {
			panic("object of type gtk.Widgetter is nil")
		}

		object := coreglib.Take(objptr)
		casted := object.WalkCast(func(obj coreglib.Objector) bool {
			_, ok := obj.(gtk.Widgetter)
			return ok
		})
		rv, ok := casted.(gtk.Widgetter)
		if !ok {
			panic("no marshaler for " + object.TypeFromInstance().String() + " matching gtk.Widgetter")
		}
		_widget = rv
	}

	return _widget
}

// Name gets the name of the layout.
//
// The function returns the following values:
//
//   - utf8 (optional): name of the layout.
func (self *Layout) Name() string {
	var _arg0 *C.AdwLayout // out
	var _cret *C.char      // in

	_arg0 = (*C.AdwLayout)(unsafe.Pointer(coreglib.InternObject(self).Native()))

	_cret = C.adw_layout_get_name(_arg0)
	runtime.KeepAlive(self)

	var _utf8 string // out

	if _cret != nil {
		_utf8 = C.GoString((*C.gchar)(unsafe.Pointer(_cret)))
	}

	return _utf8
}

// SetName sets the name of the layout.
//
// The function takes the following parameters:
//
//   - name (optional): layout name.
func (self *Layout) SetName(name string) {
	var _arg0 *C.AdwLayout // out
	var _arg1 *C.char      // out

	_arg0 = (*C.AdwLayout)(unsafe.Pointer(coreglib.InternObject(self).Native()))
	if name != "" {
		_arg1 = (*C.char)(unsafe.Pointer(C.CString(name)))
		defer C.free(unsafe.Pointer(_arg1))
	}

	C.adw_layout_set_name(_arg0, _arg1)
	runtime.KeepAlive(self)
	runtime.KeepAlive(name)
}
