Skip to main content

WidgetPath

Struct WidgetPath 

Source
pub struct WidgetPath { /* private fields */ }
Expand description

GtkWidgetPath is a boxed type that represents a widget hierarchy from the topmost widget, typically a toplevel, to any child. This widget path abstraction is used in StyleContext on behalf of the real widget in order to query style information.

If you are using GTK+ widgets, you probably will not need to use this API directly, as there is WidgetExt::path(), and the style context returned by WidgetExt::style_context() will be automatically updated on widget hierarchy changes.

The widget path generation is generally simple:

§Defining a button within a window

⚠️ The following code is in C ⚠️

{
  GtkWidgetPath *path;

  path = gtk_widget_path_new ();
  gtk_widget_path_append_type (path, GTK_TYPE_WINDOW);
  gtk_widget_path_append_type (path, GTK_TYPE_BUTTON);
}

Although more complex information, such as widget names, or different classes (property that may be used by other widget types) and intermediate regions may be included:

§Defining the first tab widget in a notebook

⚠️ The following code is in C ⚠️

{
  GtkWidgetPath *path;
  guint pos;

  path = gtk_widget_path_new ();

  pos = gtk_widget_path_append_type (path, GTK_TYPE_NOTEBOOK);
  gtk_widget_path_iter_add_region (path, pos, "tab", GTK_REGION_EVEN | GTK_REGION_FIRST);

  pos = gtk_widget_path_append_type (path, GTK_TYPE_LABEL);
  gtk_widget_path_iter_set_name (path, pos, "first tab label");
}

All this information will be used to match the style information that applies to the described widget.

Implementations§

Source§

impl WidgetPath

Source

pub fn as_ptr(&self) -> *mut GtkWidgetPath

Return the inner pointer to the underlying C value.

Source

pub unsafe fn from_glib_ptr_borrow<'a>( ptr: *const *const GtkWidgetPath, ) -> &'a Self

Borrows the underlying C value.

Source§

impl WidgetPath

Source

pub fn new() -> WidgetPath

Returns an empty widget path.

§Returns

A newly created, empty, WidgetPath

Source

pub fn append_for_widget(&self, widget: &impl IsA<Widget>) -> i32

Appends the data from widget to the widget hierarchy represented by self. This function is a shortcut for adding information from widget to the given self. This includes setting the name or adding the style classes from widget.

§widget

the widget to append to the widget path

§Returns

the position where the data was inserted

Source

pub fn append_type(&self, type_: Type) -> i32

Appends a widget type to the widget hierarchy represented by self.

§type_

widget type to append

§Returns

the position where the element was inserted

Source

pub fn append_with_siblings( &self, siblings: &WidgetPath, sibling_index: u32, ) -> i32

Appends a widget type with all its siblings to the widget hierarchy represented by self. Using this function instead of append_type() will allow the CSS theming to use sibling matches in selectors and apply :nth-child() pseudo classes. In turn, it requires a lot more care in widget implementations as widgets need to make sure to call WidgetExt::reset_style() on all involved widgets when the siblings path changes.

§siblings

a widget path describing a list of siblings. This path may not contain any siblings itself and it must not be modified afterwards.

§sibling_index

index into siblings for where the added element is positioned.

§Returns

the position where the element was inserted.

Source

pub fn copy(&self) -> Option<WidgetPath>

Source

pub fn object_type(&self) -> Type

Returns the topmost object type, that is, the object type this path is representing.

§Returns

The object type

Source

pub fn has_parent(&self, type_: Type) -> bool

Returns true if any of the parents of the widget represented in self is of type type_, or any subtype of it.

§type_

widget type to check in parents

§Returns

true if any parent is of type type_

Source

pub fn is_type(&self, type_: Type) -> bool

Returns true if the widget type represented by this path is type_, or a subtype of it.

§type_

widget type to match

§Returns

true if the widget represented by self is of type type_

Source

pub fn iter_add_class(&self, pos: i32, name: &str)

Adds the class name to the widget at position pos in the hierarchy defined in self. See StyleContextExt::add_class().

§pos

position to modify, -1 for the path head

§name

a class name

Source

pub fn iter_clear_classes(&self, pos: i32)

Removes all classes from the widget at position pos in the hierarchy defined in self.

§pos

position to modify, -1 for the path head

Source

pub fn iter_get_name(&self, pos: i32) -> Option<GString>

Returns the name corresponding to the widget found at the position pos in the widget hierarchy defined by self

§pos

position to get the widget name for, -1 for the path head

§Returns

The widget name, or None if none was set.

Source

pub fn iter_get_object_name(&self, pos: i32) -> Option<GString>

Returns the object name that is at position pos in the widget hierarchy defined in self.

§pos

position to get the object name for, -1 for the path head

§Returns

the name or None

Source

pub fn iter_get_object_type(&self, pos: i32) -> Type

Returns the object GType that is at position pos in the widget hierarchy defined in self.

§pos

position to get the object type for, -1 for the path head

§Returns

a widget type

Source

pub fn iter_get_sibling_index(&self, pos: i32) -> u32

Returns the index into the list of siblings for the element at pos as returned by iter_get_siblings(). If that function would return None because the element at pos has no siblings, this function will return 0.

§pos

position to get the sibling index for, -1 for the path head

§Returns

0 or the index into the list of siblings for the element at pos.

Source

pub fn iter_get_siblings(&self, pos: i32) -> Option<WidgetPath>

Returns the list of siblings for the element at pos. If the element was not added with siblings, None is returned.

§pos

position to get the siblings for, -1 for the path head

§Returns

None or the list of siblings for the element at pos.

Source

pub fn iter_get_state(&self, pos: i32) -> StateFlags

Returns the state flags corresponding to the widget found at the position pos in the widget hierarchy defined by self

§pos

position to get the state for, -1 for the path head

§Returns

The state flags

Source

pub fn iter_has_class(&self, pos: i32, name: &str) -> bool

Returns true if the widget at position pos has the class name defined, false otherwise.

§pos

position to query, -1 for the path head

§name

class name

§Returns

true if the class name is defined for the widget at pos

Source

pub fn iter_has_name(&self, pos: i32, name: &str) -> bool

Returns true if the widget at position pos has the name name, false otherwise.

§pos

position to query, -1 for the path head

§name

a widget name

§Returns

true if the widget at pos has this name

Source

pub fn iter_has_qclass(&self, pos: i32, qname: Quark) -> bool

See iter_has_class(). This is a version that operates with GQuarks.

§pos

position to query, -1 for the path head

§qname

class name as a GQuark

§Returns

true if the widget at pos has the class defined.

Source

pub fn iter_has_qname(&self, pos: i32, qname: Quark) -> bool

See iter_has_name(). This is a version that operates on GQuarks.

§pos

position to query, -1 for the path head

§qname

widget name as a GQuark

§Returns

true if the widget at pos has this name

Source

pub fn iter_list_classes(&self, pos: i32) -> Vec<GString>

Returns a list with all the class names defined for the widget at position pos in the hierarchy defined in self.

§pos

position to query, -1 for the path head

§Returns

The list of classes, This is a list of strings, the GSList contents are owned by GTK+, but you should use g_slist_free() to free the list itself.

Source

pub fn iter_remove_class(&self, pos: i32, name: &str)

Removes the class name from the widget at position pos in the hierarchy defined in self.

§pos

position to modify, -1 for the path head

§name

class name

Source

pub fn iter_set_name(&self, pos: i32, name: &str)

Sets the widget name for the widget found at position pos in the widget hierarchy defined by self.

§pos

position to modify, -1 for the path head

§name

widget name

Source

pub fn iter_set_object_name(&self, pos: i32, name: Option<&str>)

Sets the object name for a given position in the widget hierarchy defined by self.

When set, the object name overrides the object type when matching CSS.

§pos

position to modify, -1 for the path head

§name

object name to set or None to unset

Source

pub fn iter_set_object_type(&self, pos: i32, type_: Type)

Sets the object type for a given position in the widget hierarchy defined by self.

§pos

position to modify, -1 for the path head

§type_

object type to set

Source

pub fn iter_set_state(&self, pos: i32, state: StateFlags)

Sets the widget name for the widget found at position pos in the widget hierarchy defined by self.

If you want to update just a single state flag, you need to do this manually, as this function updates all state flags.

§Setting a flag

⚠️ The following code is in C ⚠️

gtk_widget_path_iter_set_state (path, pos, gtk_widget_path_iter_get_state (path, pos) | flag);
§Unsetting a flag

⚠️ The following code is in C ⚠️

gtk_widget_path_iter_set_state (path, pos, gtk_widget_path_iter_get_state (path, pos) & ~flag);
§pos

position to modify, -1 for the path head

§state

state flags

Source

pub fn length(&self) -> i32

Returns the number of Widget GTypes between the represented widget and its topmost container.

§Returns

the number of elements in the path

Source

pub fn prepend_type(&self, type_: Type)

Prepends a widget type to the widget hierachy represented by self.

§type_

widget type to prepend

Source

pub fn to_str(&self) -> GString

Dumps the widget path into a string representation. It tries to match the CSS style as closely as possible (Note that there might be paths that cannot be represented in CSS).

The main use of this code is for debugging purposes, so that you can g_print() the path or dump it in a gdb session.

§Returns

A new string describing self.

Trait Implementations§

Source§

impl Clone for WidgetPath

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for WidgetPath

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for WidgetPath

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Display for WidgetPath

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for WidgetPath

Source§

impl From<WidgetPath> for Value

Source§

fn from(s: WidgetPath) -> Self

Converts to this type from the input type.
Source§

impl HasParamSpec for WidgetPath

Source§

type ParamSpec = ParamSpecBoxed

Source§

type SetValue = WidgetPath

Preferred value to be used as setter for the associated ParamSpec.
Source§

type BuilderFn = fn(&str) -> ParamSpecBoxedBuilder<'_, WidgetPath>

Source§

fn param_spec_builder() -> Self::BuilderFn

Source§

impl Hash for WidgetPath

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl Ord for WidgetPath

Source§

fn cmp(&self, other: &WidgetPath) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 (const: unstable) · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 (const: unstable) · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 (const: unstable) · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl PartialEq for WidgetPath

Source§

fn eq(&self, other: &WidgetPath) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl PartialOrd for WidgetPath

Source§

fn partial_cmp(&self, other: &WidgetPath) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 (const: unstable) · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 (const: unstable) · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 (const: unstable) · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 (const: unstable) · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl StaticType for WidgetPath

Source§

fn static_type() -> Type

Returns the type identifier of Self.
Source§

impl StructuralPartialEq for WidgetPath

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FromGlibContainerAsVec<<T as GlibPtrDefault>::GlibType, *const GList> for T

Source§

unsafe fn from_glib_none_num_as_vec(ptr: *const GList, num: usize) -> Vec<T>

Source§

unsafe fn from_glib_container_num_as_vec(_: *const GList, _: usize) -> Vec<T>

Source§

unsafe fn from_glib_full_num_as_vec(_: *const GList, _: usize) -> Vec<T>

Source§

impl<T> FromGlibContainerAsVec<<T as GlibPtrDefault>::GlibType, *const GPtrArray> for T

Source§

unsafe fn from_glib_none_num_as_vec(ptr: *const GPtrArray, num: usize) -> Vec<T>

Source§

unsafe fn from_glib_container_num_as_vec( _: *const GPtrArray, _: usize, ) -> Vec<T>

Source§

unsafe fn from_glib_full_num_as_vec(_: *const GPtrArray, _: usize) -> Vec<T>

Source§

impl<T> FromGlibContainerAsVec<<T as GlibPtrDefault>::GlibType, *const GSList> for T

Source§

unsafe fn from_glib_none_num_as_vec(ptr: *const GSList, num: usize) -> Vec<T>

Source§

unsafe fn from_glib_container_num_as_vec(_: *const GSList, _: usize) -> Vec<T>

Source§

unsafe fn from_glib_full_num_as_vec(_: *const GSList, _: usize) -> Vec<T>

Source§

impl<T> FromGlibContainerAsVec<<T as GlibPtrDefault>::GlibType, *mut GList> for T

Source§

unsafe fn from_glib_none_num_as_vec(ptr: *mut GList, num: usize) -> Vec<T>

Source§

unsafe fn from_glib_container_num_as_vec(ptr: *mut GList, num: usize) -> Vec<T>

Source§

unsafe fn from_glib_full_num_as_vec(ptr: *mut GList, num: usize) -> Vec<T>

Source§

impl<T> FromGlibContainerAsVec<<T as GlibPtrDefault>::GlibType, *mut GPtrArray> for T

Source§

unsafe fn from_glib_none_num_as_vec(ptr: *mut GPtrArray, num: usize) -> Vec<T>

Source§

unsafe fn from_glib_container_num_as_vec( ptr: *mut GPtrArray, num: usize, ) -> Vec<T>

Source§

unsafe fn from_glib_full_num_as_vec(ptr: *mut GPtrArray, num: usize) -> Vec<T>

Source§

impl<T> FromGlibContainerAsVec<<T as GlibPtrDefault>::GlibType, *mut GSList> for T

Source§

unsafe fn from_glib_none_num_as_vec(ptr: *mut GSList, num: usize) -> Vec<T>

Source§

unsafe fn from_glib_container_num_as_vec(ptr: *mut GSList, num: usize) -> Vec<T>

Source§

unsafe fn from_glib_full_num_as_vec(ptr: *mut GSList, num: usize) -> Vec<T>

Source§

impl<T> FromGlibPtrArrayContainerAsVec<<T as GlibPtrDefault>::GlibType, *const GList> for T

Source§

unsafe fn from_glib_none_as_vec(ptr: *const GList) -> Vec<T>

Source§

unsafe fn from_glib_container_as_vec(_: *const GList) -> Vec<T>

Source§

unsafe fn from_glib_full_as_vec(_: *const GList) -> Vec<T>

Source§

impl<T> FromGlibPtrArrayContainerAsVec<<T as GlibPtrDefault>::GlibType, *const GPtrArray> for T

Source§

unsafe fn from_glib_none_as_vec(ptr: *const GPtrArray) -> Vec<T>

Source§

unsafe fn from_glib_container_as_vec(_: *const GPtrArray) -> Vec<T>

Source§

unsafe fn from_glib_full_as_vec(_: *const GPtrArray) -> Vec<T>

Source§

impl<T> FromGlibPtrArrayContainerAsVec<<T as GlibPtrDefault>::GlibType, *const GSList> for T

Source§

unsafe fn from_glib_none_as_vec(ptr: *const GSList) -> Vec<T>

Source§

unsafe fn from_glib_container_as_vec(_: *const GSList) -> Vec<T>

Source§

unsafe fn from_glib_full_as_vec(_: *const GSList) -> Vec<T>

Source§

impl<T> FromGlibPtrArrayContainerAsVec<<T as GlibPtrDefault>::GlibType, *mut GList> for T

Source§

unsafe fn from_glib_none_as_vec(ptr: *mut GList) -> Vec<T>

Source§

unsafe fn from_glib_container_as_vec(ptr: *mut GList) -> Vec<T>

Source§

unsafe fn from_glib_full_as_vec(ptr: *mut GList) -> Vec<T>

Source§

impl<T> FromGlibPtrArrayContainerAsVec<<T as GlibPtrDefault>::GlibType, *mut GPtrArray> for T

Source§

unsafe fn from_glib_none_as_vec(ptr: *mut GPtrArray) -> Vec<T>

Source§

unsafe fn from_glib_container_as_vec(ptr: *mut GPtrArray) -> Vec<T>

Source§

unsafe fn from_glib_full_as_vec(ptr: *mut GPtrArray) -> Vec<T>

Source§

impl<T> FromGlibPtrArrayContainerAsVec<<T as GlibPtrDefault>::GlibType, *mut GSList> for T

Source§

unsafe fn from_glib_none_as_vec(ptr: *mut GSList) -> Vec<T>

Source§

unsafe fn from_glib_container_as_vec(ptr: *mut GSList) -> Vec<T>

Source§

unsafe fn from_glib_full_as_vec(ptr: *mut GSList) -> Vec<T>

Source§

impl<'a, T, C, E> FromValueOptional<'a> for T
where T: FromValue<'a, Checker = C>, C: ValueTypeChecker<Error = ValueTypeMismatchOrNoneError<E>>, E: Error + Send + 'static,

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoClosureReturnValue for T
where T: Into<Value>,

Source§

impl<T> Property for T
where T: HasParamSpec,

Source§

type Value = T

Source§

impl<T> PropertyGet for T
where T: HasParamSpec,

Source§

type Value = T

Source§

fn get<R, F>(&self, f: F) -> R
where F: Fn(&<T as PropertyGet>::Value) -> R,

Source§

impl<T> StaticTypeExt for T
where T: StaticType,

Source§

fn ensure_type()

Ensures that the type has been registered with the type system.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T> TransparentType for T

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T> TryFromClosureReturnValue for T
where T: for<'a> FromValue<'a> + StaticType + 'static,

Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.