emilk / emilk/egui

Add `ui.sanity_check` hook-in

Open
#7,537 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

dev-experience
Dominant language
Rust
Stars
30.6k
Forks
2.1k
Avg merge
1d 9h
Merged PRs (30d)
72

Description

When investigating an issue with a tooltip that was too wide, I added this to Ui temporarily, and started calling it from random places:

    #[inline]
    #[track_caller]
    fn sanity_check(ui: &egui::Ui) {
        if cfg!(debug_assertions)
            && ui.layer_id().order == egui::Order::Tooltip
            && ui.spacing().tooltip_width + 100.0 < ui.max_rect().width()
        {
            panic!("DEBUG ASSERT: Huge tooltip: {}", ui.max_rect().size());
        }
    }

We should allow users to install such a sanity-checks as callback, and then call ui.santity_check(); in misc places in egui (e.g. after adding a widget, or when closing a scope).

The default sanity check could check for NaN:s etc, and then call the user-provided ones.

Should only be enabled in debug builds.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by examining the Ui type and the proposed ui.santity_check() call sites, such as after adding a widget or closing a scope. The issue is done when users can install sanity-check callbacks, a default check handles NaN values, callbacks run only in debug builds, and the behavior is covered in the relevant UI paths.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
frontend
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.