Struct pango::AttrList

source ·
pub struct AttrList { /* private fields */ }
Expand description

A AttrList represents a list of attributes that apply to a section of text.

The attributes in a AttrList are, in general, allowed to overlap in an arbitrary fashion. However, if the attributes are manipulated only through change(), the overlap between properties will meet stricter criteria.

Since the AttrList structure is stored as a linear list, it is not suitable for storing attributes for large amounts of text. In general, you should not use a single AttrList for more than one paragraph of text.

Implementations§

source§

impl AttrList

source

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

Return the inner pointer to the underlying C value.

source

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

Borrows the underlying C value.

source§

impl AttrList

source

pub fn new() -> AttrList

Create a new empty attribute list with a reference count of one.

Returns

the newly allocated AttrList, which should be freed with Pango::AttrList::unref()

source

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

source

pub fn filter<P: FnMut(&Attribute) -> bool>(&self, func: P) -> Option<AttrList>

Given a AttrList and callback function, removes any elements of @self for which @func returns true and inserts them into a new list.

func

callback function; returns true if an attribute should be filtered out

Returns

the new AttrList or None if no attributes of the given types were found

source

pub fn attributes(&self) -> Vec<Attribute>

Available on crate feature v1_44 only.

Gets a list of all attributes in @self.

Returns

a list of all attributes in @self. To free this value, call Pango::Attribute::destroy() on each value and g_slist_free() on the list.

source

pub fn iterator(&self) -> AttrIterator<'_>

Create a iterator initialized to the beginning of the list.

@self must not be modified until this iterator is freed.

Returns

the newly allocated AttrIterator, which should be freed with Pango::AttrIterator::destroy()

source

pub fn splice(&self, other: &AttrList, pos: i32, len: i32)

This function opens up a hole in @self, fills it in with attributes from the left, and then merges @other on top of the hole.

This operation is equivalent to stretching every attribute that applies at position @pos in @self by an amount @len, and then calling change() with a copy of each attribute in @other in sequence (offset in position by @pos, and limited in length to @len).

This operation proves useful for, for instance, inserting a pre-edit string in the middle of an edit buffer.

For backwards compatibility, the function behaves differently when @len is 0. In this case, the attributes from @other are not imited to @len, and are just overlayed on top of @self.

This mode is useful for merging two lists of attributes together.

other

another AttrList

pos

the position in @self at which to insert @other

len

the length of the spliced segment. (Note that this must be specified since the attributes in @other may only be present at some subsection of this range)

source

pub fn to_str(&self) -> GString

Available on crate feature v1_50 only.

Serializes a AttrList to a string.

In the resulting string, serialized attributes are separated by newlines or commas. Individual attributes are serialized to a string of the form

START END TYPE VALUE

Where START and END are the indices (with -1 being accepted in place of MAXUINT), TYPE is the nickname of the attribute value type, e.g. weight or stretch, and the value is serialized according to its type:

  • enum values as nick or numeric value
  • boolean values as true or false
  • integers and floats as numbers
  • strings as string, optionally quoted
  • font features as quoted string
  • PangoLanguage as string
  • PangoFontDescription as serialized by FontDescription::to_str(), quoted
  • PangoColor as serialized by Color::to_str()

Examples:

0 10 foreground red, 5 15 weight bold, 0 200 font-desc "Sans 10"
0 -1 weight 700
0 100 family Times

To parse the returned value, use from_string().

Note that shape attributes can not be serialized.

Returns

a newly allocated string

source

pub fn update(&self, pos: i32, remove: i32, add: i32)

Available on crate feature v1_44 only.

Update indices of attributes in @self for a change in the text they refer to.

The change that this function applies is removing @remove bytes at position @pos and inserting @add bytes instead.

Attributes that fall entirely in the (@pos, @pos + @remove) range are removed.

Attributes that start or end inside the (@pos, @pos + @remove) range are shortened to reflect the removal.

Attributes start and end positions are updated if they are behind @pos + @remove.

pos

the position of the change

remove

the number of removed bytes

add

the number of added bytes

source

pub fn from_string(text: &str) -> Result<AttrList, BoolError>

Available on crate feature v1_50 only.

Deserializes a AttrList from a string.

This is the counterpart to to_str(). See that functions for details about the format.

text

a string

Returns

a new AttrList

source§

impl AttrList

source

pub fn change(&self, attr: impl Into<Attribute>)

Insert the given attribute into the AttrList.

It will replace any attributes of the same type on that segment and be merged with any adjoining attributes that are identical.

This function is slower than insert() for creating an attribute list in order (potentially much slower for large lists). However, insert() is not suitable for continually changing a set of attributes since it never removes or combines existing attributes.

attr

the attribute to insert

source

pub fn insert(&self, attr: impl Into<Attribute>)

Insert the given attribute into the AttrList.

It will be inserted after all other attributes with a matching @start_index.

attr

the attribute to insert

source

pub fn insert_before(&self, attr: impl Into<Attribute>)

Insert the given attribute into the AttrList.

It will be inserted before all other attributes with a matching @start_index.

attr

the attribute to insert

Trait Implementations§

source§

impl Clone for AttrList

source§

fn clone(&self) -> Self

Returns a copy of the value. Read more
1.0.0 · source§

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

Performs copy-assignment from source. Read more
source§

impl Debug for AttrList

source§

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

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

impl Default for AttrList

source§

fn default() -> Self

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

impl Display for AttrList

Available on crate feature v1_50 only.
source§

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

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

impl From<AttrList> for Value

source§

fn from(s: AttrList) -> Self

Converts to this type from the input type.
source§

impl FromStr for AttrList

Available on crate feature v1_50 only.
§

type Err = BoolError

The associated error which can be returned from parsing.
source§

fn from_str(s: &str) -> Result<Self, Self::Err>

Parses a string s to return a value of this type. Read more
source§

impl HasParamSpec for AttrList

§

type ParamSpec = ParamSpecBoxed

§

type SetValue = AttrList

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

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

source§

fn param_spec_builder() -> Self::BuilderFn

source§

impl PartialEq for AttrList

Available on crate feature v1_46 only.
source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl StaticType for AttrList

source§

fn static_type() -> Type

Returns the type identifier of Self.
source§

impl Eq for AttrList

Available on crate feature v1_46 only.

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

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

source§

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

source§

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

source§

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

source§

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

source§

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

source§

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

source§

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

source§

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

source§

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

source§

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

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,

§

type Value = T

source§

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

§

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,

§

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§

default 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>,

§

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>,

§

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.
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,