Incular logoIncular
API ReferenceInput & Forms

Hit Testing

HitTestBehavior plus IgnorePointer and AbsorbPointer filters.

HitTestBehavior

use incular::prelude::*;
use incular::widgets::HitTestBehavior;

fn main() {
    let app = Application::new(|_cx| {
        Container::builder()
            .padding(EdgeInsets::all(24.0))
            .alignment(Alignment::CENTER)
            .child(
                GestureDetector::new(Text::new("Opaque hit"))
                    .behavior(HitTestBehavior::Opaque),
            )
            .build()
            .into()
    })
    .expect("valid application");
    incular::run(app).expect("run application");
}

DeferToChild only hits when the child does; Opaque claims the whole bounds; Translucent claims while letting events pass through to widgets behind.

BehaviorHit when child misses?Events pass behind?
DeferToChild (default)NoYes
OpaqueYesNo
TranslucentYesYes

IgnorePointer

Hides the subtree from hit-testing — a painted sibling behind receives the pointer.

use incular::prelude::*;

fn main() {
    let app = Application::new(|_cx| {
        Container::builder()
            .padding(EdgeInsets::all(24.0))
            .alignment(Alignment::CENTER)
            .child(
                Stack::builder()
                    .children(Vec::<Widget>::from([
                        GestureDetector::new(Text::new("Behind"))
                                .on_tap(|| println!("behind tapped")).into(),
                        IgnorePointer::new(Text::new("Ghost"))
                                .ignoring(true).into(),
                    ]))
                    .build(),
            )
            .build()
            .into()
    })
    .expect("valid application");
    incular::run(app).expect("run application");
}

AbsorbPointer

Returns its own retained boundary and never descends to normal child interaction — blocks descendants and siblings behind.

use incular::prelude::*;

fn main() {
    let app = Application::new(|_cx| {
        Container::builder()
            .padding(EdgeInsets::all(24.0))
            .alignment(Alignment::CENTER)
            .child(
                AbsorbPointer::new(Text::new("Blocked"))
                    .absorbing(true),
            )
            .build()
            .into()
    })
    .expect("valid application");
    incular::run(app).expect("run application");
}

Related: GestureDetector, Raw Input.

On this page