gtk4::subclass::widget

Trait WidgetClassExt

Source
pub unsafe trait WidgetClassExt: ClassStruct {
Show 24 methods // Provided methods fn set_template_bytes(&mut self, template: &Bytes) { ... } fn set_template(&mut self, template: &[u8]) { ... } fn set_template_static(&mut self, template: &'static [u8]) { ... } fn set_template_from_resource(&mut self, resource_name: &str) { ... } fn install_action_async<Fut, F>( &mut self, action_name: &str, parameter_type: Option<&VariantTy>, activate: F, ) where F: Fn(<<Self as ClassStruct>::Type as ObjectSubclass>::Type, String, Option<Variant>) -> Fut + 'static + Clone, Fut: Future<Output = ()> { ... } fn install_action<F>( &mut self, action_name: &str, parameter_type: Option<&VariantTy>, activate: F, ) where F: Fn(&<<Self as ClassStruct>::Type as ObjectSubclass>::Type, &str, Option<&Variant>) + 'static { ... } fn query_action(&self) -> WidgetActionIter { ... } fn set_template_scope<S: IsA<BuilderScope>>(&mut self, scope: &S) { ... } fn add_binding<F: Fn(&<<Self as ClassStruct>::Type as ObjectSubclass>::Type) -> Propagation + 'static>( &mut self, keyval: Key, mods: ModifierType, callback: F, ) { ... } fn add_binding_action( &mut self, keyval: Key, mods: ModifierType, action_name: &str, ) { ... } fn add_binding_signal( &mut self, keyval: Key, mods: ModifierType, signal_name: &str, ) { ... } fn add_shortcut(&mut self, shortcut: &Shortcut) { ... } fn install_property_action( &mut self, action_name: &str, property_name: &str, ) { ... } fn activate_signal(&self) -> Option<SignalId> { ... } fn set_activate_signal(&mut self, signal_id: SignalId) { ... } fn set_activate_signal_from_name(&mut self, signal_name: &str) { ... } fn set_layout_manager_type<T: IsA<LayoutManager>>(&mut self) { ... } fn layout_manager_type(&self) -> Type { ... } fn set_css_name(&mut self, name: &str) { ... } fn css_name(&self) -> GString { ... } fn set_accessible_role(&mut self, role: AccessibleRole) { ... } fn accessible_role(&self) -> AccessibleRole { ... } unsafe fn bind_template_child_with_offset<T>( &mut self, name: &str, internal: bool, offset: FieldOffset<Self::Type, TemplateChild<T>>, ) where T: ObjectType + FromGlibPtrNone<*mut <T as ObjectType>::GlibType> { ... } fn rust_template_scope(&mut self) -> BuilderRustScope { ... }
}

Provided Methods§

Source

fn set_template_bytes(&mut self, template: &Bytes)

Source

fn set_template(&mut self, template: &[u8])

This should be called at class initialization time to specify the Builder XML to be used to extend a widget.

For convenience, set_template_from_resource() is also provided.

Note that any class that installs templates must call Gtk::Widget::init_template() in the widget’s instance initializer.

§template_bytes

GBytes holding the Builder XML

Source

fn set_template_static(&mut self, template: &'static [u8])

Source

fn set_template_from_resource(&mut self, resource_name: &str)

A convenience function that calls set_template() with the contents of a resource.

Note that any class that installs templates must call Gtk::Widget::init_template() in the widget’s instance initializer.

§resource_name

resource path to load the template from

Source

fn install_action_async<Fut, F>( &mut self, action_name: &str, parameter_type: Option<&VariantTy>, activate: F, )
where F: Fn(<<Self as ClassStruct>::Type as ObjectSubclass>::Type, String, Option<Variant>) -> Fut + 'static + Clone, Fut: Future<Output = ()>,

Source

fn install_action<F>( &mut self, action_name: &str, parameter_type: Option<&VariantTy>, activate: F, )
where F: Fn(&<<Self as ClassStruct>::Type as ObjectSubclass>::Type, &str, Option<&Variant>) + 'static,

Adds an action for all instances of a widget class.

This function should be called at class initialization time.

Actions installed by this function are stateless. The only state they have is whether they are enabled or not (which can be changed with WidgetExt::action_set_enabled()).

§action_name

a prefixed action name, such as “clipboard.paste”

§parameter_type

the parameter type

§activate

callback to use when the action is activated

Source

fn query_action(&self) -> WidgetActionIter

Returns details about an action that has been installed for @self.

See install_action() for details on how to install actions.

Note that this function will also return actions defined by parent classes. You can identify those by looking at @owner.

§index_

position of the action to query

§Returns

true if the action was found

§owner

return location for the type where the action was defined

§action_name

return location for the action name

§parameter_type

return location for the parameter type

§property_name

return location for the property name

Source

fn set_template_scope<S: IsA<BuilderScope>>(&mut self, scope: &S)

Overrides the default scope to be used when parsing the class template.

This function is intended for language bindings.

Note that this must be called from a composite widget classes class initializer after calling set_template().

§scope

BuilderScope to use when loading the class template

Source

fn add_binding<F: Fn(&<<Self as ClassStruct>::Type as ObjectSubclass>::Type) -> Propagation + 'static>( &mut self, keyval: Key, mods: ModifierType, callback: F, )

Creates a new shortcut for @self that calls the given @callback with arguments according to @format_string.

The arguments and format string must be provided in the same way as with GLib::Variant::new().

This function is a convenience wrapper around add_shortcut() and must be called during class initialization. It does not provide for user data, if you need that, you will have to use add_shortcut() with a custom shortcut.

§keyval

key value of binding to install

§mods

key modifier of binding to install

§callback

the callback to call upon activation

§format_string

GVariant format string for arguments

Source

fn add_binding_action( &mut self, keyval: Key, mods: ModifierType, action_name: &str, )

Creates a new shortcut for @self that activates the given @action_name with arguments read according to @format_string.

The arguments and format string must be provided in the same way as with GLib::Variant::new().

This function is a convenience wrapper around add_shortcut() and must be called during class initialization.

§keyval

key value of binding to install

§mods

key modifier of binding to install

§action_name

the action to activate

§format_string

GVariant format string for arguments

Source

fn add_binding_signal( &mut self, keyval: Key, mods: ModifierType, signal_name: &str, )

Creates a new shortcut for @self that emits the given action @signal with arguments read according to @format_string.

The arguments and format string must be provided in the same way as with GLib::Variant::new().

This function is a convenience wrapper around add_shortcut() and must be called during class initialization.

§keyval

key value of binding to install

§mods

key modifier of binding to install

§signal

the signal to execute

§format_string

GVariant format string for arguments

Source

fn add_shortcut(&mut self, shortcut: &Shortcut)

Installs a shortcut in @self.

Every instance created for @self or its subclasses will inherit this shortcut and trigger it.

Shortcuts added this way will be triggered in the [enum@Gtk.PropagationPhase.bubble] phase, which means they may also trigger if child widgets have focus.

This function must only be used in class initialization functions otherwise it is not guaranteed that the shortcut will be installed.

§shortcut

the shortcut to add

Source

fn install_property_action(&mut self, action_name: &str, property_name: &str)

Installs an action called @action_name on @self and binds its state to the value of the @property_name property.

This function will perform a few sanity checks on the property selected via @property_name. Namely, the property must exist, must be readable, writable and must not be construct-only. There are also restrictions on the type of the given property, it must be boolean, int, unsigned int, double or string. If any of these conditions are not met, a critical warning will be printed and no action will be added.

The state type of the action matches the property type.

If the property is boolean, the action will have no parameter and toggle the property value. Otherwise, the action will have a parameter of the same type as the property.

§action_name

name of the action

§property_name

name of a property in instances of @self or any parent class

Source

fn activate_signal(&self) -> Option<SignalId>

Retrieves the signal id for the activation signal.

The activation signal is set using set_activate_signal().

§Returns

a signal id, or 0 if the widget class does not specify an activation signal

Source

fn set_activate_signal(&mut self, signal_id: SignalId)

Sets the activation signal for a widget class.

The signal will be emitted when calling WidgetExt::activate().

The @signal_id must have been registered with [function.GObject.signal_new] or signal_newv() before calling this function.

§signal_id

the id for the activate signal

Source

fn set_activate_signal_from_name(&mut self, signal_name: &str)

Sets the activation signal for a widget class.

The signal id will by looked up by @signal_name.

The signal will be emitted when calling WidgetExt::activate().

The @signal_name must have been registered with [function.GObject.signal_new] or signal_newv() before calling this function.

§signal_name

the name of the activate signal of @widget_type

Source

fn set_layout_manager_type<T: IsA<LayoutManager>>(&mut self)

Sets the type to be used for creating layout managers for widgets of @self.

The given @type_ must be a subtype of LayoutManager.

This function should only be called from class init functions of widgets.

§type_

the object type that implements the LayoutManager for @self

Source

fn layout_manager_type(&self) -> Type

Retrieves the type of the LayoutManager used by widgets of class @self.

See also: set_layout_manager_type().

§Returns

type of a LayoutManager subclass, or G_TYPE_INVALID

Source

fn set_css_name(&mut self, name: &str)

Sets the name to be used for CSS matching of widgets.

If this function is not called for a given class, the name set on the parent class is used. By default, Widget uses the name “widget”.

§name

name to use

Source

fn css_name(&self) -> GString

Gets the name used by this class for matching in CSS code.

See set_css_name() for details.

§Returns

the CSS name of the given class

Source

fn set_accessible_role(&mut self, role: AccessibleRole)

Sets the accessible role used by the given widget class.

Different accessible roles have different states, and are rendered differently by assistive technologies.

§accessible_role

the accessible role to use

Source

fn accessible_role(&self) -> AccessibleRole

Retrieves the accessible role used by the given widget class.

Different accessible roles have different states, and are rendered differently by assistive technologies.

See also: AccessibleExt::accessible_role().

§Returns

the accessible role for the widget class

Source

unsafe fn bind_template_child_with_offset<T>( &mut self, name: &str, internal: bool, offset: FieldOffset<Self::Type, TemplateChild<T>>, )

Source

fn rust_template_scope(&mut self) -> BuilderRustScope

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§