Struct gtk::WidgetPath
source · [−]#[repr(transparent)]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
sourceimpl WidgetPath
impl WidgetPath
sourcepub fn new() -> WidgetPath
pub fn new() -> WidgetPath
sourcepub fn append_for_widget(&self, widget: &impl IsA<Widget>) -> i32
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
sourcepub fn append_type(&self, type_: Type) -> i32
pub fn append_type(&self, type_: Type) -> i32
sourcepub fn append_with_siblings(
&self,
siblings: &WidgetPath,
sibling_index: u32
) -> i32
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.
pub fn copy(&self) -> Option<WidgetPath>
sourcepub fn object_type(&self) -> Type
pub fn object_type(&self) -> Type
Returns the topmost object type, that is, the object type this path is representing.
Returns
The object type
sourcepub fn has_parent(&self, type_: Type) -> bool
pub fn has_parent(&self, type_: Type) -> bool
sourcepub fn iter_add_class(&self, pos: i32, name: &str)
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
sourcepub fn iter_clear_classes(&self, pos: i32)
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
sourcepub fn iter_get_name(&self, pos: i32) -> Option<GString>
pub fn iter_get_name(&self, pos: i32) -> Option<GString>
sourcepub fn iter_get_object_name(&self, pos: i32) -> Option<GString>
Available on crate feature v3_20
only.
pub fn iter_get_object_name(&self, pos: i32) -> Option<GString>
v3_20
only.sourcepub fn iter_get_object_type(&self, pos: i32) -> Type
pub fn iter_get_object_type(&self, pos: i32) -> Type
sourcepub fn iter_get_sibling_index(&self, pos: i32) -> u32
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
.
sourcepub fn iter_get_siblings(&self, pos: i32) -> Option<WidgetPath>
pub fn iter_get_siblings(&self, pos: i32) -> Option<WidgetPath>
sourcepub fn iter_get_state(&self, pos: i32) -> StateFlags
pub fn iter_get_state(&self, pos: i32) -> StateFlags
sourcepub fn iter_has_class(&self, pos: i32, name: &str) -> bool
pub fn iter_has_class(&self, pos: i32, name: &str) -> bool
sourcepub fn iter_has_name(&self, pos: i32, name: &str) -> bool
pub fn iter_has_name(&self, pos: i32, name: &str) -> bool
sourcepub fn iter_has_qclass(&self, pos: i32, qname: Quark) -> bool
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.
sourcepub fn iter_has_qname(&self, pos: i32, qname: Quark) -> bool
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
sourcepub fn iter_list_classes(&self, pos: i32) -> Vec<GString>
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.
sourcepub fn iter_remove_class(&self, pos: i32, name: &str)
pub fn iter_remove_class(&self, pos: i32, name: &str)
sourcepub fn iter_set_name(&self, pos: i32, name: &str)
pub fn iter_set_name(&self, pos: i32, name: &str)
sourcepub fn iter_set_object_name(&self, pos: i32, name: Option<&str>)
Available on crate feature v3_20
only.
pub fn iter_set_object_name(&self, pos: i32, name: Option<&str>)
v3_20
only.sourcepub fn iter_set_object_type(&self, pos: i32, type_: Type)
pub fn iter_set_object_type(&self, pos: i32, type_: Type)
sourcepub fn iter_set_state(&self, pos: i32, state: StateFlags)
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
sourcepub fn prepend_type(&self, type_: Type)
pub fn prepend_type(&self, type_: Type)
sourcepub fn to_str(&self) -> GString
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
sourceimpl Clone for WidgetPath
impl Clone for WidgetPath
sourceimpl Debug for WidgetPath
impl Debug for WidgetPath
sourceimpl Default for WidgetPath
impl Default for WidgetPath
sourceimpl Display for WidgetPath
impl Display for WidgetPath
sourceimpl Hash for WidgetPath
impl Hash for WidgetPath
sourceimpl Ord for WidgetPath
impl Ord for WidgetPath
sourceimpl PartialEq<WidgetPath> for WidgetPath
impl PartialEq<WidgetPath> for WidgetPath
sourcefn eq(&self, other: &WidgetPath) -> bool
fn eq(&self, other: &WidgetPath) -> bool
This method tests for self
and other
values to be equal, and is used
by ==
. Read more
sourcefn ne(&self, other: &WidgetPath) -> bool
fn ne(&self, other: &WidgetPath) -> bool
This method tests for !=
.
sourceimpl PartialOrd<WidgetPath> for WidgetPath
impl PartialOrd<WidgetPath> for WidgetPath
sourcefn partial_cmp(&self, other: &WidgetPath) -> Option<Ordering>
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 · sourcefn lt(&self, other: &Rhs) -> bool
fn lt(&self, other: &Rhs) -> bool
This method tests less than (for self
and other
) and is used by the <
operator. Read more
1.0.0 · sourcefn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
sourceimpl StaticType for WidgetPath
impl StaticType for WidgetPath
sourcefn static_type() -> Type
fn static_type() -> Type
Returns the type identifier of Self
.
impl Eq for WidgetPath
impl StructuralEq for WidgetPath
impl StructuralPartialEq for WidgetPath
Auto Trait Implementations
impl RefUnwindSafe for WidgetPath
impl !Send for WidgetPath
impl !Sync for WidgetPath
impl Unpin for WidgetPath
impl UnwindSafe for WidgetPath
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> StaticTypeExt for T where
T: StaticType,
impl<T> StaticTypeExt for T where
T: StaticType,
sourcefn ensure_type()
fn ensure_type()
Ensures that the type has been registered with the type system.
sourceimpl<T> ToClosureReturnValue for T where
T: ToValue,
impl<T> ToClosureReturnValue for T where
T: ToValue,
fn to_closure_return_value(&self) -> Option<Value>
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more