// Code generated by girgen. DO NOT EDIT.

package adw

import (
	"fmt"
	"runtime"
	"unsafe"

	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 (
	GTypeLengthUnit = coreglib.Type(C.adw_length_unit_get_type())
)

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

// LengthUnit describes length units.
//
// | Unit | Regular Text | Large Text | | ---- | ------------ | ---------- | |
// 1px | 1px | 1px | | 1pt | 1.333333px | 1.666667px | | 1sp | 1px | 1.25px |
//
// New values may be added to this enumeration over time.
type LengthUnit C.gint

const (
	// LengthUnitPx: pixels.
	LengthUnitPx LengthUnit = iota
	// LengthUnitPt: points, changes with text scale factor.
	LengthUnitPt
	// LengthUnitSp: scale independent pixels, changes with text scale factor.
	LengthUnitSp
)

func marshalLengthUnit(p uintptr) (interface{}, error) {
	return LengthUnit(coreglib.ValueFromNative(unsafe.Pointer(p)).Enum()), nil
}

// String returns the name in string for LengthUnit.
func (l LengthUnit) String() string {
	switch l {
	case LengthUnitPx:
		return "Px"
	case LengthUnitPt:
		return "Pt"
	case LengthUnitSp:
		return "Sp"
	default:
		return fmt.Sprintf("LengthUnit(%d)", l)
	}
}

// LengthUnitFromPx converts value from pixels to unit.
//
// The function takes the following parameters:
//
//   - unit: length unit.
//   - value in pixels.
//   - settings (optional) to use, or NULL for default settings.
//
// The function returns the following values:
//
//   - gdouble: length in unit.
func LengthUnitFromPx(unit LengthUnit, value float64, settings *gtk.Settings) float64 {
	var _arg1 C.AdwLengthUnit // out
	var _arg2 C.double        // out
	var _arg3 *C.GtkSettings  // out
	var _cret C.double        // in

	_arg1 = C.AdwLengthUnit(unit)
	_arg2 = C.double(value)
	if settings != nil {
		_arg3 = (*C.GtkSettings)(unsafe.Pointer(coreglib.InternObject(settings).Native()))
	}

	_cret = C.adw_length_unit_from_px(_arg1, _arg2, _arg3)
	runtime.KeepAlive(unit)
	runtime.KeepAlive(value)
	runtime.KeepAlive(settings)

	var _gdouble float64 // out

	_gdouble = float64(_cret)

	return _gdouble
}

// LengthUnitToPx converts value from unit to pixels.
//
// The function takes the following parameters:
//
//   - unit: length unit.
//   - value in unit.
//   - settings (optional) to use, or NULL for default settings.
//
// The function returns the following values:
//
//   - gdouble: length in pixels.
func LengthUnitToPx(unit LengthUnit, value float64, settings *gtk.Settings) float64 {
	var _arg1 C.AdwLengthUnit // out
	var _arg2 C.double        // out
	var _arg3 *C.GtkSettings  // out
	var _cret C.double        // in

	_arg1 = C.AdwLengthUnit(unit)
	_arg2 = C.double(value)
	if settings != nil {
		_arg3 = (*C.GtkSettings)(unsafe.Pointer(coreglib.InternObject(settings).Native()))
	}

	_cret = C.adw_length_unit_to_px(_arg1, _arg2, _arg3)
	runtime.KeepAlive(unit)
	runtime.KeepAlive(value)
	runtime.KeepAlive(settings)

	var _gdouble float64 // out

	_gdouble = float64(_cret)

	return _gdouble
}
