# TextHighlighter

Version: 0.5.0
Framework commit: d503df2befa756e681fcdc6250e9552dc7388bea
Canonical URL: /docs/0.5.0/api/ferroui-controls/documents/struct-texthighlighter/

**struct** · [`ferroui-controls`](/docs/0.5.0/api/ferroui-controls/) · v0.5.0

```rust
struct TextHighlighter
```

Paints foreground and background over its ranges without editing text.

A null brush uses the view's TextControlHighlighterForeground or
TextControlHighlighterBackground theme resource. As in WinUI, only solid
color brushes are accepted. Mutable brushes and range changes invalidate all
observing collections; observers never retain this object.

[View source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Controls/documents/text_highlighter.rs#L24)

## Members

- [`TYPE`](#assoc_const-type)
- [`to_ref`](#function-to_ref)
- [`foreground_property`](#function-foreground_property)
- [`background_property`](#function-background_property)
- [`construct`](#function-construct)
- [`new`](#function-new)
- [`ranges`](#function-ranges)
- [`foreground`](#function-foreground)
- [`background`](#function-background)
- [`set_foreground`](#function-set_foreground)
- [`set_background`](#function-set_background)
- [`try_set_foreground`](#function-try_set_foreground)
- [`try_set_background`](#function-try_set_background)
- [`add_child`](#function-add_child)
- [`as_add_child`](#function-as_add_child)
- [`invalidated`](#function-invalidated)

<a id="assoc_const-type"></a>

### TYPE

```rust
const TYPE: &'static $crate::TypeInfo
```

The runtime type of this class.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Controls/documents/text_highlighter.rs#L32)

<a id="function-to_ref"></a>

### to_ref

```rust
fn to_ref(self: &Self) -> $crate::Ref<TextHighlighter>
```

Returns a strong reference to this object.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Controls/documents/text_highlighter.rs#L32)

<a id="function-foreground_property"></a>

### foreground_property

```rust
fn foreground_property() -> &'static StyledProperty<Option<Rc<dyn IBrush>>>
```



[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Controls/documents/text_highlighter.rs#L65)

<a id="function-background_property"></a>

### background_property

```rust
fn background_property() -> &'static StyledProperty<Option<Rc<dyn IBrush>>>
```



[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Controls/documents/text_highlighter.rs#L65)

<a id="function-construct"></a>

### construct

```rust
fn construct() -> Self
```



[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Controls/documents/text_highlighter.rs#L83)

<a id="function-new"></a>

### new

```rust
fn new() -> Ref<Self>
```



[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Controls/documents/text_highlighter.rs#L92)

<a id="function-ranges"></a>

### ranges

```rust
fn ranges(self: &Self) -> TextRangeCollection
```



[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Controls/documents/text_highlighter.rs#L96)

<a id="function-foreground"></a>

### foreground

```rust
fn foreground(self: &Self) -> Option<Rc<dyn IBrush>>
```



[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Controls/documents/text_highlighter.rs#L99)

<a id="function-background"></a>

### background

```rust
fn background(self: &Self) -> Option<Rc<dyn IBrush>>
```



[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Controls/documents/text_highlighter.rs#L102)

<a id="function-set_foreground"></a>

### set_foreground

```rust
fn set_foreground(self: &Self, value: Option<Rc<dyn IBrush>>) -> Result<(), TextHighlightError>
```

Sets a solid brush, returning a validation error without changing the
previous value when supplied a different brush kind.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Controls/documents/text_highlighter.rs#L108)

<a id="function-set_background"></a>

### set_background

```rust
fn set_background(self: &Self, value: Option<Rc<dyn IBrush>>) -> Result<(), TextHighlightError>
```



[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Controls/documents/text_highlighter.rs#L111)

<a id="function-try_set_foreground"></a>

### try_set_foreground

```rust
fn try_set_foreground(self: &Self, value: Option<Rc<dyn IBrush>>) -> Result<(), TextHighlightError>
```



[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Controls/documents/text_highlighter.rs#L114)

<a id="function-try_set_background"></a>

### try_set_background

```rust
fn try_set_background(self: &Self, value: Option<Rc<dyn IBrush>>) -> Result<(), TextHighlightError>
```



[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Controls/documents/text_highlighter.rs#L124)

<a id="function-add_child"></a>

### add_child

```rust
fn add_child(self: &Self, range: TextHighlightRange)
```



[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Controls/documents/text_highlighter.rs#L135)

<a id="function-as_add_child"></a>

### as_add_child

```rust
fn as_add_child(this: Ref<Self>) -> Rc<dyn IAddChild<TextHighlightRange>>
```



[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Controls/documents/text_highlighter.rs#L138)

<a id="function-invalidated"></a>

### invalidated

```rust
fn invalidated(self: &Self, handler: impl Fn() -> () + 'static) -> Subscription
```

Dropping the returned guard removes the handler; `Subscription::detach` keeps it for the
life of the highlighter.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Controls/documents/text_highlighter.rs#L144)

## Trait implementations

- `Send`
- `Sync`
- `Freeze`
- `UnsafeUnpin`
- `Unpin`
- `UnwindSafe`
- `RefUnwindSafe`
- `Borrow<T>`
- `BorrowMut<T>`
- `Into<U>`
- `From<T>`
- `TryInto<U>`
- `TryFrom<U>`
- [`Receiver`](/docs/0.5.0/api/ferroui-system/task/oneshot/struct-receiver/)
- `Any`
- [`FerroObjectImplExt`](/docs/0.5.0/api/ferroui-base/trait-ferroobjectimplext/)
- [`ClassDefaults`](/docs/0.5.0/api/ferroui-base/trait-classdefaults/)
- `ErasedDestructor`
- `IntoEither`
- `Deref`
- [`Upcast<T>`](/docs/0.5.0/api/ferroui-base/trait-upcast/)
- [`Upcast<TextHighlighter>`](/docs/0.5.0/api/ferroui-base/trait-upcast/)
- [`StaticType`](/docs/0.5.0/api/ferroui-base/trait-statictype/)
- [`ObjectType`](/docs/0.5.0/api/ferroui-base/trait-objecttype/)
- [`Subclassable<T>`](/docs/0.5.0/api/ferroui-base/trait-subclassable/)
- [`DefaultConstructible`](/docs/0.5.0/api/ferroui-base/trait-defaultconstructible/)
- [`FerroObjectImpl`](/docs/0.5.0/api/ferroui-base/trait-ferroobjectimpl/)

## Availability

Extracted for `aarch64-apple-darwin`. Cargo features are listed in the [crate index](/docs/0.5.0/api/).
