pub struct UiPanel3D {
pub ui: Ui,
pub texture: Texture,
pub size: Vec2,
pub interactive: bool,
/* private fields */
}Expand description
Retained UI shown on a quad in the world (Rust’s Ui on a surface):
a computer screen, a shop terminal, a sign with buttons. Build ui like
Ctx::ui_retained; its widgets are laid out in texture’s pixels.
The panel is the quad size meters wide and high in its entity’s XY
plane, centered on it, facing +Z (what mesh makes). The
mouse uses the nearest panel the camera ray through it hits, unless the
screen’s own UI has it; the panel clicked last also gets the keyboard.
Ctx::create_ui_panel makes the texture, material and mesh at once.
Game::new("t", 1, 1).run_headless(0, |ctx| {
// A 1.2 x 0.8 m terminal, 600 x 400 pixels.
let (mut panel, model) = ctx.create_ui_panel(600, 400, vec2(1.2, 0.8));
let buy = panel.ui.add(UiWidget::Button, Default::default());
panel.ui.set_text(buy, "Buy");
ctx.world.spawn((Transform3D::at(vec3(0.0, 1.5, -2.0)), model, panel));
});Fields§
§ui: UiIts widgets, events, focus and screens.
texture: TextureWhat it’s drawn into each frame: a render target
(Ctx::create_render_target) whose size is the panel’s in pixels.
size: Vec2Its size in the world, in meters.
interactive: boolWhether the mouse and keyboard can use it. Default true.
Implementations§
Source§impl UiPanel3D
impl UiPanel3D
Sourcepub fn new(texture: Texture, size: Vec2) -> Self
pub fn new(texture: Texture, size: Vec2) -> Self
A panel drawn into texture (a render target), size meters in the
world. Show texture on mesh with a material.
Game::new("t", 1, 1).run_headless(0, |ctx| {
let screen = ctx.create_render_target(512, 256);
let panel = UiPanel3D::new(screen, vec2(1.0, 0.5));
assert!(panel.interactive && panel.pointer().is_none());
});Sourcepub fn mesh(&self) -> MeshData
pub fn mesh(&self) -> MeshData
The quad it’s shown on: size in the XY plane, centered, facing +Z,
with the texture’s top-left corner at the top left.
let panel = UiPanel3D::new(screen, vec2(2.0, 1.0));
let quad = panel.mesh();
assert_eq!(quad.positions[0], vec3(-1.0, 0.5, 0.0));
assert_eq!(quad.uvs[0], Vec2::ZERO);Trait Implementations§
Auto Trait Implementations§
impl Forget for UiPanel3D
impl Freeze for UiPanel3D
impl RefUnwindSafe for UiPanel3D
impl Send for UiPanel3D
impl Sync for UiPanel3D
impl Unpin for UiPanel3D
impl UnsafeUnpin for UiPanel3D
impl UnwindSafe for UiPanel3D
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
impl<T> Component for T
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be
downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further
downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSend for T
impl<T> DowncastSend for T
Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
impl<S, T> Duplex<S> for Twhere
T: FromSample<S> + ToSample<S>,
Source§impl<S> FromSample<S> for S
impl<S> FromSample<S> for S
fn from_sample_(s: S) -> S
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<F, T> IntoSample<T> for Fwhere
T: FromSample<F>,
impl<F, T> IntoSample<T> for Fwhere
T: FromSample<F>,
fn into_sample(self) -> T
impl<T> MaybeSync for T
impl<T> MaybeSync for T
Source§impl<T> Pointable for T
impl<T> Pointable for T
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.