Skip to main content

Module ui

Module ui 

Source
Expand description

UI panels laid out in one world and drawn in another. UI panels laid out in one world and drawn in another.

A unlit3d::ui::UiPanel can only be built where its egui::Context runs: the callback is handed a &mut egui::Ui, which belongs to the pass building it, so it cannot be carried to another thread. A UI whose panels belong to one world and whose drawing belongs to another therefore crosses the boundary as data: the panel’s world lays the frame out and tessellates it, and the drawing world uploads and records what comes back.

The handover is one way: the panel world sends a job carrying an unlit3d::ui::ExternalFrame to the world holding the unlit3d::ui::UiSource, which keeps it in a slot and draws it. A settled panel sends nothing, so the frame already there keeps being drawn. What comes back is the target the drawing side draws at, published from the source into a Snapshot the panel world subscribes to, so a frame is laid out at the size and density it will be drawn at.

No frame is laid out before the drawing side has drawn once: until then there is no target, and a frame laid out at a guessed size would be dropped by the source rather than drawn.

The two sides hold separate contexts. Sharing one would have both worlds writing egui’s memory and its font atlas, and egui treats one run_ui call as one whole frame, so two worlds running it against one context would interleave two frames into one. Their texture ids both start at zero, which the drawing side handles by keying textures by origin and id: nothing renumbers them.

Re-exportsΒ§

use core::time::Duration; πŸ”’
use crate::job::Job; πŸ”’
use crate::job::JobSender; πŸ”’
use crate::job::SendError; πŸ”’
use unlit_ecs::World; πŸ”’
use unlit3d::frame::Frame; πŸ”’
use unlit3d::input::InputEvent; πŸ”’
use unlit3d::input::InputEvents; πŸ”’
use unlit3d::relay::SnapshotReader; πŸ”’
use unlit3d::source::Source; πŸ”’
use unlit3d::ui::ExternalFrame; πŸ”’
use unlit3d::ui::UiSource; πŸ”’
use unlit3d::ui::UiTarget; πŸ”’
use unlit3d::ui::egui; πŸ”’
use unlit3d::ui::lay_out; πŸ”’
use unlit3d::ui::raw_input; πŸ”’

StructsΒ§

UiPanelHost
A world’s panel publishing: the context its panels are built in, where its frames are sent and the target it lays out against.

FunctionsΒ§

panel_frame_job
Hand frame to the UI source of the world this job runs in.