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

A 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 GResource.

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

§resource_name

The name of the resource 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,

This should be called at class initialization time to specify actions to be added for all instances of this class.

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 the @index_-th action that has been installed for @self during class initialization.

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, false if @index_ is out of range

§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)

For use in language bindings, this will override the default BuilderScope to be used when parsing GtkBuilder XML from this class’s template data.

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

§scope

The 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 read according to @format_string.

The arguments and format string must be provided in the same way as with g_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 or None for no 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 g_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 or None for no 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 g_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 or None for no 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 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 the 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 GtkWidgetClass.activate_signal field with the given @signal_id.

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

The @signal_id must have been registered with g_signal_new() or g_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 GtkWidgetClass.activate_signal field with the signal id for the given @signal_name.

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

The @signal_name of @widget_type must have been registered with g_signal_new() or g_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 AccessibleRole used by the @self

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

Object Safety§

This trait is not object safe.

Implementors§