// Package gtk was automatically generated by github.com/bnema/puregotk DO NOT EDIT package gtk import ( "structs" "unsafe" "github.com/ebitengine/purego" "github.com/bnema/puregotk/pkg/core" "github.com/bnema/puregotk/v4/glib" "github.com/bnema/puregotk/v4/gobject" "github.com/bnema/puregotk/v4/gobject/types" ) type ToggleButtonClass struct { _ structs.HostLayout ParentClass ButtonClass xToggled uintptr Padding [8]uintptr } func (x *ToggleButtonClass) GoPointer() uintptr { return uintptr(unsafe.Pointer(x)) } // OverrideToggled sets the "toggled" callback function. func (x *ToggleButtonClass) OverrideToggled(cb func(*ToggleButton)) { if cb == nil { x.xToggled = 0 } else { x.xToggled = purego.NewCallback(func(ToggleButtonVarp uintptr) { cb(ToggleButtonNewFromInternalPtr(ToggleButtonVarp)) }) } } // GetToggled gets the "toggled" callback function. func (x *ToggleButtonClass) GetToggled() func(*ToggleButton) { if x.xToggled == 0 { return nil } var rawCallback func(ToggleButtonVarp uintptr) purego.RegisterFunc(&rawCallback, x.xToggled) return func(ToggleButtonVar *ToggleButton) { rawCallback(ToggleButtonVar.GoPointer()) } } // Shows a button which remains “pressed-in” when clicked. // // <picture> // // <source srcset="toggle-button-dark.png" media="(prefers-color-scheme: dark)"> // <img alt="Example GtkToggleButtons" src="toggle-button.png"> // // </picture> // // Clicking again will cause the toggle button to return to its normal state. // // A toggle button is created by calling either [ctor@Gtk.ToggleButton.new] or // [ctor@Gtk.ToggleButton.new_with_label]. If using the former, it is advisable // to pack a widget, (such as a `GtkLabel` and/or a `GtkImage`), into the toggle // button’s container. (See [class@Gtk.Button] for more information). // // The state of a `GtkToggleButton` can be set specifically using // [method@Gtk.ToggleButton.set_active], and retrieved using // [method@Gtk.ToggleButton.get_active]. // // ## Grouping // // Toggle buttons can be grouped together, to form mutually exclusive // groups - only one of the buttons can be toggled at a time, and toggling // another one will switch the currently toggled one off. // // To add a `GtkToggleButton` to a group, use [method@Gtk.ToggleButton.set_group]. // // ## CSS nodes // // `GtkToggleButton` has a single CSS node with name button. To differentiate // it from a plain `GtkButton`, it gets the `.toggle` style class. // // ## Accessibility // // `GtkToggleButton` uses the [enum@Gtk.AccessibleRole.toggle_button] role. // // ## Creating two `GtkToggleButton` widgets. // // ```c // static void // output_state (GtkToggleButton *source, // // gpointer user_data) // // { // g_print ("Toggle button "%s" is active: %s", // gtk_button_get_label (GTK_BUTTON (source)), // gtk_toggle_button_get_active (source) ? "Yes" : "No"); // } // // static void // make_toggles (void) // // { // GtkWidget *window, *toggle1, *toggle2; // GtkWidget *box; // const char *text; // // window = gtk_window_new (); // box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 12); // // text = "Hi, I’m toggle button one"; // toggle1 = gtk_toggle_button_new_with_label (text); // // g_signal_connect (toggle1, "toggled", // G_CALLBACK (output_state), // NULL); // gtk_box_append (GTK_BOX (box), toggle1); // // text = "Hi, I’m toggle button two"; // toggle2 = gtk_toggle_button_new_with_label (text); // g_signal_connect (toggle2, "toggled", // G_CALLBACK (output_state), // NULL); // gtk_box_append (GTK_BOX (box), toggle2); // // gtk_window_set_child (GTK_WINDOW (window), box); // gtk_window_present (GTK_WINDOW (window)); // } // // ``` type ToggleButton struct { Button } var xToggleButtonGLibType func() types.GType func ToggleButtonGLibType() types.GType { return xToggleButtonGLibType() } func ToggleButtonNewFromInternalPtr(ptr uintptr) *ToggleButton { cls := &ToggleButton{} cls.Ptr = ptr return cls } var xNewToggleButton func() uintptr // Creates a new toggle button. // // A widget should be packed into the button, as in [ctor@Gtk.Button.new]. func NewToggleButton() *ToggleButton { var cls *ToggleButton cret := xNewToggleButton() if cret == 0 { return nil } gobject.IncreaseRef(cret) cls = &ToggleButton{} cls.Ptr = cret return cls } var xNewToggleButtonWithLabel func(string) uintptr // Creates a new toggle button with a text label. func NewToggleButtonWithLabel(LabelVar string) *ToggleButton { var cls *ToggleButton cret := xNewToggleButtonWithLabel(LabelVar) if cret == 0 { return nil } gobject.IncreaseRef(cret) cls = &ToggleButton{} cls.Ptr = cret return cls } var xNewToggleButtonWithMnemonic func(string) uintptr // Creates a new `GtkToggleButton` containing a label. // // The label will be created using [ctor@Gtk.Label.new_with_mnemonic], // so underscores in @label indicate the mnemonic for the button. func NewToggleButtonWithMnemonic(LabelVar string) *ToggleButton { var cls *ToggleButton cret := xNewToggleButtonWithMnemonic(LabelVar) if cret == 0 { return nil } gobject.IncreaseRef(cret) cls = &ToggleButton{} cls.Ptr = cret return cls } var xToggleButtonGetActive func(uintptr) bool // Queries a `GtkToggleButton` and returns its current state. // // Returns %TRUE if the toggle button is pressed in and %FALSE // if it is raised. func (x *ToggleButton) GetActive() bool { cret := xToggleButtonGetActive(x.GoPointer()) return cret } var xToggleButtonSetActive func(uintptr, bool) // Sets the status of the toggle button. // // Set to %TRUE if you want the `GtkToggleButton` to be “pressed in”, // and %FALSE to raise it. // // If the status of the button changes, this action causes the // [signal@Gtk.ToggleButton::toggled] signal to be emitted. func (x *ToggleButton) SetActive(IsActiveVar bool) { xToggleButtonSetActive(x.GoPointer(), IsActiveVar) } var xToggleButtonSetGroup func(uintptr, uintptr) // Adds @self to the group of @group. // // In a group of multiple toggle buttons, only one button can be active // at a time. // // Setting up groups in a cycle leads to undefined behavior. // // Note that the same effect can be achieved via the [iface@Gtk.Actionable] // API, by using the same action with parameter type and state type 's' // for all buttons in the group, and giving each button its own target // value. func (x *ToggleButton) SetGroup(GroupVar *ToggleButton) { xToggleButtonSetGroup(x.GoPointer(), GroupVar.GoPointer()) } var xToggleButtonToggled func(uintptr) // Emits the ::toggled signal on the `GtkToggleButton`. func (x *ToggleButton) Toggled() { xToggleButtonToggled(x.GoPointer()) } func (c *ToggleButton) GoPointer() uintptr { if c == nil { return 0 } return c.Ptr } func (c *ToggleButton) SetGoPointer(ptr uintptr) { c.Ptr = ptr } // SetPropertyActive sets the "active" property. // If the toggle button should be pressed in. func (x *ToggleButton) SetPropertyActive(value bool) { var v gobject.Value v.Init(gobject.TypeBooleanVal) v.SetBoolean(value) x.SetProperty("active", &v) } // GetPropertyActive gets the "active" property. // If the toggle button should be pressed in. func (x *ToggleButton) GetPropertyActive() bool { var v gobject.Value x.GetProperty("active", &v) return v.GetBoolean() } // Emitted whenever the `GtkToggleButton`'s state is changed. func (x *ToggleButton) ConnectToggled(cb *func(ToggleButton)) uint { cbPtr := uintptr(unsafe.Pointer(cb)) if cbRefPtr, ok := glib.GetCallback(cbPtr); ok { handlerID := gobject.SignalConnect(x.GoPointer(), "toggled", cbRefPtr) glib.SaveHandlerMapping(handlerID, cbPtr) return handlerID } fcb := func(clsPtr uintptr) { fa := ToggleButton{} fa.Ptr = clsPtr cbFn := *cb cbFn(fa) } cbRefPtr := purego.NewCallback(fcb) glib.SaveCallbackWithClosure(cbPtr, cbRefPtr, cb) handlerID := gobject.SignalConnect(x.GoPointer(), "toggled", cbRefPtr) glib.SaveHandlerMapping(handlerID, cbPtr) return handlerID } // Requests the user's screen reader to announce the given message. // // This kind of notification is useful for messages that // either have only a visual representation or that are not // exposed visually at all, e.g. a notification about a // successful operation. // // Also, by using this API, you can ensure that the message // does not interrupts the user's current screen reader output. func (x *ToggleButton) Announce(MessageVar string, PriorityVar AccessibleAnnouncementPriority) { XGtkAccessibleAnnounce(x.GoPointer(), MessageVar, PriorityVar) } // Retrieves the accessible parent for an accessible object. // // This function returns `NULL` for top level widgets. func (x *ToggleButton) GetAccessibleParent() *AccessibleBase { var cls *AccessibleBase cret := XGtkAccessibleGetAccessibleParent(x.GoPointer()) if cret == 0 { return nil } cls = &AccessibleBase{} cls.Ptr = cret return cls } // Retrieves the accessible role of an accessible object. func (x *ToggleButton) GetAccessibleRole() AccessibleRole { cret := XGtkAccessibleGetAccessibleRole(x.GoPointer()) return cret } // Retrieves the implementation for the given accessible object. func (x *ToggleButton) GetAtContext() *ATContext { var cls *ATContext cret := XGtkAccessibleGetAtContext(x.GoPointer()) if cret == 0 { return nil } cls = &ATContext{} cls.Ptr = cret return cls } // Queries the coordinates and dimensions of this accessible // // This functionality can be overridden by `GtkAccessible` // implementations, e.g. to get the bounds from an ignored // child widget. func (x *ToggleButton) GetBounds(XVar *int, YVar *int, WidthVar *int, HeightVar *int) bool { cret := XGtkAccessibleGetBounds(x.GoPointer(), XVar, YVar, WidthVar, HeightVar) return cret } // Retrieves the first accessible child of an accessible object. func (x *ToggleButton) GetFirstAccessibleChild() *AccessibleBase { var cls *AccessibleBase cret := XGtkAccessibleGetFirstAccessibleChild(x.GoPointer()) if cret == 0 { return nil } cls = &AccessibleBase{} cls.Ptr = cret return cls } // Retrieves the next accessible sibling of an accessible object func (x *ToggleButton) GetNextAccessibleSibling() *AccessibleBase { var cls *AccessibleBase cret := XGtkAccessibleGetNextAccessibleSibling(x.GoPointer()) if cret == 0 { return nil } cls = &AccessibleBase{} cls.Ptr = cret return cls } // Queries a platform state, such as focus. // // This functionality can be overridden by `GtkAccessible` // implementations, e.g. to get platform state from an ignored // child widget, as is the case for `GtkText` wrappers. func (x *ToggleButton) GetPlatformState(StateVar AccessiblePlatformState) bool { cret := XGtkAccessibleGetPlatformState(x.GoPointer(), StateVar) return cret } // Resets the accessible property to its default value. func (x *ToggleButton) ResetProperty(PropertyVar AccessibleProperty) { XGtkAccessibleResetProperty(x.GoPointer(), PropertyVar) } // Resets the accessible relation to its default value. func (x *ToggleButton) ResetRelation(RelationVar AccessibleRelation) { XGtkAccessibleResetRelation(x.GoPointer(), RelationVar) } // Resets the accessible state to its default value. func (x *ToggleButton) ResetState(StateVar AccessibleState) { XGtkAccessibleResetState(x.GoPointer(), StateVar) } // Sets the parent and sibling of an accessible object. // // This function is meant to be used by accessible implementations that are // not part of the widget hierarchy, and but act as a logical bridge between // widgets. For instance, if a widget creates an object that holds metadata // for each child, and you want that object to implement the `GtkAccessible` // interface, you will use this function to ensure that the parent of each // child widget is the metadata object, and the parent of each metadata // object is the container widget. func (x *ToggleButton) SetAccessibleParent(ParentVar Accessible, NextSiblingVar Accessible) { XGtkAccessibleSetAccessibleParent(x.GoPointer(), ParentVar.GoPointer(), NextSiblingVar.GoPointer()) } // Updates the next accessible sibling. // // That might be useful when a new child of a custom accessible // is created, and it needs to be linked to a previous child. func (x *ToggleButton) UpdateNextAccessibleSibling(NewSiblingVar Accessible) { XGtkAccessibleUpdateNextAccessibleSibling(x.GoPointer(), NewSiblingVar.GoPointer()) } // Informs ATs that the platform state has changed. // // This function should be used by `GtkAccessible` implementations that // have a platform state but are not widgets. Widgets handle platform // states automatically. func (x *ToggleButton) UpdatePlatformState(StateVar AccessiblePlatformState) { XGtkAccessibleUpdatePlatformState(x.GoPointer(), StateVar) } // Updates a list of accessible properties. // // See the [enum@Gtk.AccessibleProperty] documentation for the // value types of accessible properties. // // This function should be called by `GtkWidget` types whenever // an accessible property change must be communicated to assistive // technologies. // // Example: // ```c // value = gtk_adjustment_get_value (adjustment); // gtk_accessible_update_property (GTK_ACCESSIBLE (spin_button), // // GTK_ACCESSIBLE_PROPERTY_VALUE_NOW, value, // -1); // // ``` func (x *ToggleButton) UpdateProperty(FirstPropertyVar AccessibleProperty, varArgs ...interface{}) { XGtkAccessibleUpdateProperty(x.GoPointer(), FirstPropertyVar, varArgs...) } // Updates an array of accessible properties. // // This function should be called by `GtkWidget` types whenever an accessible // property change must be communicated to assistive technologies. // // This function is meant to be used by language bindings. func (x *ToggleButton) UpdatePropertyValue(NPropertiesVar int, PropertiesVar []AccessibleProperty, ValuesVar []gobject.Value) { XGtkAccessibleUpdatePropertyValue(x.GoPointer(), NPropertiesVar, PropertiesVar, ValuesVar) } // Updates a list of accessible relations. // // This function should be called by `GtkWidget` types whenever an accessible // relation change must be communicated to assistive technologies. // // If the [enum@Gtk.AccessibleRelation] requires a list of references, // you should pass each reference individually, followed by `NULL`, e.g. // // ```c // gtk_accessible_update_relation (accessible, // // GTK_ACCESSIBLE_RELATION_CONTROLS, // ref1, NULL, // GTK_ACCESSIBLE_RELATION_LABELLED_BY, // ref1, ref2, ref3, NULL, // -1); // // ``` func (x *ToggleButton) UpdateRelation(FirstRelationVar AccessibleRelation, varArgs ...interface{}) { XGtkAccessibleUpdateRelation(x.GoPointer(), FirstRelationVar, varArgs...) } // Updates an array of accessible relations. // // This function should be called by `GtkWidget` types whenever an accessible // relation change must be communicated to assistive technologies. // // This function is meant to be used by language bindings. func (x *ToggleButton) UpdateRelationValue(NRelationsVar int, RelationsVar []AccessibleRelation, ValuesVar []gobject.Value) { XGtkAccessibleUpdateRelationValue(x.GoPointer(), NRelationsVar, RelationsVar, ValuesVar) } // Updates a list of accessible states. // // See the [enum@Gtk.AccessibleState] documentation for the // value types of accessible states. // // This function should be called by `GtkWidget` types whenever // an accessible state change must be communicated to assistive // technologies. // // Example: // // ```c // value = GTK_ACCESSIBLE_TRISTATE_MIXED; // gtk_accessible_update_state (GTK_ACCESSIBLE (check_button), // // GTK_ACCESSIBLE_STATE_CHECKED, value, // -1); // // ``` func (x *ToggleButton) UpdateState(FirstStateVar AccessibleState, varArgs ...interface{}) { XGtkAccessibleUpdateState(x.GoPointer(), FirstStateVar, varArgs...) } // Updates an array of accessible states. // // This function should be called by `GtkWidget` types whenever an accessible // state change must be communicated to assistive technologies. // // This function is meant to be used by language bindings. func (x *ToggleButton) UpdateStateValue(NStatesVar int, StatesVar []AccessibleState, ValuesVar []gobject.Value) { XGtkAccessibleUpdateStateValue(x.GoPointer(), NStatesVar, StatesVar, ValuesVar) } // Gets the action name for @actionable. func (x *ToggleButton) GetActionName() string { cret := XGtkActionableGetActionName(x.GoPointer()) return cret } // Gets the current target value of @actionable. func (x *ToggleButton) GetActionTargetValue() *glib.Variant { cret := XGtkActionableGetActionTargetValue(x.GoPointer()) return cret } // Specifies the name of the action with which this widget should be // associated. // // If @action_name is %NULL then the widget will be unassociated from // any previous action. // // Usually this function is used when the widget is located (or will be // located) within the hierarchy of a `GtkApplicationWindow`. // // Names are of the form “win.save” or “app.quit” for actions on the // containing [class@ApplicationWindow] or its associated [class@Application], // respectively. This is the same form used for actions in the [class@Gio.Menu] // associated with the window. func (x *ToggleButton) SetActionName(ActionNameVar *string) { ActionNameVarPtr := core.GStrdupNullable(ActionNameVar) defer core.GFreeNullable(ActionNameVarPtr) XGtkActionableSetActionName(x.GoPointer(), ActionNameVarPtr) } // Sets the target of an actionable widget. // // This is a convenience function that calls [ctor@GLib.Variant.new] for // @format_string and uses the result to call // [method@Gtk.Actionable.set_action_target_value]. // // If you are setting a string-valued target and want to set // the action name at the same time, you can use // [method@Gtk.Actionable.set_detailed_action_name]. func (x *ToggleButton) SetActionTarget(FormatStringVar string, varArgs ...interface{}) { XGtkActionableSetActionTarget(x.GoPointer(), FormatStringVar, varArgs...) } // Sets the target value of an actionable widget. // // If @target_value is %NULL then the target value is unset. // // The target value has two purposes. First, it is used as the parameter // to activation of the action associated with the `GtkActionable` widget. // Second, it is used to determine if the widget should be rendered as // “active” — the widget is active if the state is equal to the given target. // // Consider the example of associating a set of buttons with a [iface@Gio.Action] // with string state in a typical “radio button” situation. Each button // will be associated with the same action, but with a different target // value for that action. Clicking on a particular button will activate // the action with the target of that button, which will typically cause // the action’s state to change to that value. Since the action’s state // is now equal to the target value of the button, the button will now // be rendered as active (and the other buttons, with different targets, // rendered inactive). func (x *ToggleButton) SetActionTargetValue(TargetValueVar *glib.Variant) { XGtkActionableSetActionTargetValue(x.GoPointer(), TargetValueVar) } // Sets the action-name and associated string target value of an // actionable widget. // // @detailed_action_name is a string in the format accepted by // [func@Gio.Action.parse_detailed_name]. func (x *ToggleButton) SetDetailedActionName(DetailedActionNameVar string) { XGtkActionableSetDetailedActionName(x.GoPointer(), DetailedActionNameVar) } // Gets the ID of the @buildable object. // // `GtkBuilder` sets the name based on the ID attribute // of the `<object>` tag used to construct the @buildable. func (x *ToggleButton) GetBuildableId() string { cret := XGtkBuildableGetBuildableId(x.GoPointer()) return cret } func init() { core.SetPackageName("GTK", "gtk4") core.SetSharedLibraries("GTK", []string{"libgtk-4.so.1"}) var libs []uintptr for _, libPath := range core.GetPaths("GTK") { lib, err := purego.Dlopen(libPath, purego.RTLD_NOW|purego.RTLD_GLOBAL) if err != nil { panic(err) } libs = append(libs, lib) } core.PuregoSafeRegister(&xToggleButtonGLibType, libs, "gtk_toggle_button_get_type") core.PuregoSafeRegister(&xNewToggleButton, libs, "gtk_toggle_button_new") core.PuregoSafeRegister(&xNewToggleButtonWithLabel, libs, "gtk_toggle_button_new_with_label") core.PuregoSafeRegister(&xNewToggleButtonWithMnemonic, libs, "gtk_toggle_button_new_with_mnemonic") core.PuregoSafeRegister(&xToggleButtonGetActive, libs, "gtk_toggle_button_get_active") core.PuregoSafeRegister(&xToggleButtonSetActive, libs, "gtk_toggle_button_set_active") core.PuregoSafeRegister(&xToggleButtonSetGroup, libs, "gtk_toggle_button_set_group") core.PuregoSafeRegister(&xToggleButtonToggled, libs, "gtk_toggle_button_toggled") }