pub struct ImageNode {
pub color: Color,
pub image: Handle<Image>,
pub texture_atlas: Option<TextureAtlas>,
pub flip_x: bool,
pub flip_y: bool,
pub rect: Option<Rect>,
pub image_mode: NodeImageMode,
}
Expand description
A UI Node that renders an image.
Fields§
§color: Color
The tint color used to draw the image.
This is multiplied by the color of each pixel in the image. The field value defaults to solid white, which will pass the image through unmodified.
image: Handle<Image>
Handle to the texture.
This defaults to a TRANSPARENT_IMAGE_HANDLE
, which points to a fully transparent 1x1 texture.
texture_atlas: Option<TextureAtlas>
The (optional) texture atlas used to render the image.
flip_x: bool
Whether the image should be flipped along its x-axis.
flip_y: bool
Whether the image should be flipped along its y-axis.
rect: Option<Rect>
An optional rectangle representing the region of the image to render, instead of rendering
the full image. This is an easy one-off alternative to using a TextureAtlas
.
When used with a TextureAtlas
, the rect
is offset by the atlas’s minimal (top-left) corner position.
image_mode: NodeImageMode
Controls how the image is altered to fit within the layout and how the layout algorithm determines the space to allocate for the image.
Implementations§
Source§impl ImageNode
impl ImageNode
Sourcepub fn new(texture: Handle<Image>) -> ImageNode
pub fn new(texture: Handle<Image>) -> ImageNode
Create a new ImageNode
with the given texture.
Examples found in repository?
82 pub fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
83 commands.spawn((Camera2d, DespawnOnExit(super::Scene::Image)));
84 commands.spawn((
85 ImageNode::new(asset_server.load("branding/bevy_logo_dark.png")),
86 DespawnOnExit(super::Scene::Image),
87 ));
88 }
89}
90
91mod text {
92 use bevy::{color::palettes::css::*, prelude::*};
93
94 pub fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
95 commands.spawn((Camera2d, DespawnOnExit(super::Scene::Text)));
96 commands.spawn((
97 Text::new("Hello World."),
98 TextFont {
99 font: asset_server.load("fonts/FiraSans-Bold.ttf"),
100 font_size: 200.,
101 ..default()
102 },
103 DespawnOnExit(super::Scene::Text),
104 ));
105
106 commands.spawn((
107 Node {
108 left: px(100.),
109 top: px(250.),
110 ..Default::default()
111 },
112 Text::new("white "),
113 TextFont {
114 font: asset_server.load("fonts/FiraSans-Bold.ttf"),
115 ..default()
116 },
117 DespawnOnExit(super::Scene::Text),
118 children![
119 (TextSpan::new("red "), TextColor(RED.into()),),
120 (TextSpan::new("green "), TextColor(GREEN.into()),),
121 (TextSpan::new("blue "), TextColor(BLUE.into()),),
122 (
123 TextSpan::new("black"),
124 TextColor(Color::BLACK),
125 TextFont {
126 font: asset_server.load("fonts/FiraSans-Bold.ttf"),
127 ..default()
128 },
129 TextBackgroundColor(Color::WHITE)
130 ),
131 ],
132 ));
133
134 commands.spawn((
135 Node {
136 left: px(100.),
137 top: px(300.),
138 ..Default::default()
139 },
140 Text::new(""),
141 TextFont {
142 font: asset_server.load("fonts/FiraSans-Bold.ttf"),
143 ..default()
144 },
145 DespawnOnExit(super::Scene::Text),
146 children![
147 (
148 TextSpan::new("white "),
149 TextFont {
150 font: asset_server.load("fonts/FiraSans-Bold.ttf"),
151 ..default()
152 }
153 ),
154 (TextSpan::new("red "), TextColor(RED.into()),),
155 (TextSpan::new("green "), TextColor(GREEN.into()),),
156 (TextSpan::new("blue "), TextColor(BLUE.into()),),
157 (
158 TextSpan::new("black"),
159 TextColor(Color::BLACK),
160 TextFont {
161 font: asset_server.load("fonts/FiraSans-Bold.ttf"),
162 ..default()
163 },
164 TextBackgroundColor(Color::WHITE)
165 ),
166 ],
167 ));
168
169 commands.spawn((
170 Node {
171 left: px(100.),
172 top: px(350.),
173 ..Default::default()
174 },
175 Text::new(""),
176 TextFont {
177 font: asset_server.load("fonts/FiraSans-Bold.ttf"),
178 ..default()
179 },
180 DespawnOnExit(super::Scene::Text),
181 children![
182 (TextSpan::new(""), TextColor(YELLOW.into()),),
183 TextSpan::new(""),
184 (
185 TextSpan::new("white "),
186 TextFont {
187 font: asset_server.load("fonts/FiraSans-Bold.ttf"),
188 ..default()
189 }
190 ),
191 TextSpan::new(""),
192 (TextSpan::new("red "), TextColor(RED.into()),),
193 TextSpan::new(""),
194 TextSpan::new(""),
195 (TextSpan::new("green "), TextColor(GREEN.into()),),
196 (TextSpan::new(""), TextColor(YELLOW.into()),),
197 (TextSpan::new("blue "), TextColor(BLUE.into()),),
198 TextSpan::new(""),
199 (TextSpan::new(""), TextColor(YELLOW.into()),),
200 (
201 TextSpan::new("black"),
202 TextColor(Color::BLACK),
203 TextFont {
204 font: asset_server.load("fonts/FiraSans-Bold.ttf"),
205 ..default()
206 },
207 TextBackgroundColor(Color::WHITE)
208 ),
209 TextSpan::new(""),
210 ],
211 ));
212 }
213}
214
215mod grid {
216 use bevy::{color::palettes::css::*, prelude::*};
217
218 pub fn setup(mut commands: Commands) {
219 commands.spawn((Camera2d, DespawnOnExit(super::Scene::Grid)));
220 // Top-level grid (app frame)
221 commands.spawn((
222 Node {
223 display: Display::Grid,
224 width: percent(100),
225 height: percent(100),
226 grid_template_columns: vec![GridTrack::min_content(), GridTrack::flex(1.0)],
227 grid_template_rows: vec![
228 GridTrack::auto(),
229 GridTrack::flex(1.0),
230 GridTrack::px(40.),
231 ],
232 ..default()
233 },
234 BackgroundColor(Color::WHITE),
235 DespawnOnExit(super::Scene::Grid),
236 children![
237 // Header
238 (
239 Node {
240 display: Display::Grid,
241 grid_column: GridPlacement::span(2),
242 padding: UiRect::all(px(40)),
243 ..default()
244 },
245 BackgroundColor(RED.into()),
246 ),
247 // Main content grid (auto placed in row 2, column 1)
248 (
249 Node {
250 height: percent(100),
251 aspect_ratio: Some(1.0),
252 display: Display::Grid,
253 grid_template_columns: RepeatedGridTrack::flex(3, 1.0),
254 grid_template_rows: RepeatedGridTrack::flex(2, 1.0),
255 row_gap: px(12),
256 column_gap: px(12),
257 ..default()
258 },
259 BackgroundColor(Color::srgb(0.25, 0.25, 0.25)),
260 children![
261 (Node::default(), BackgroundColor(ORANGE.into())),
262 (Node::default(), BackgroundColor(BISQUE.into())),
263 (Node::default(), BackgroundColor(BLUE.into())),
264 (Node::default(), BackgroundColor(CRIMSON.into())),
265 (Node::default(), BackgroundColor(AQUA.into())),
266 ]
267 ),
268 // Right side bar (auto placed in row 2, column 2)
269 (Node::DEFAULT, BackgroundColor(BLACK.into())),
270 ],
271 ));
272 }
273}
274
275mod borders {
276 use bevy::{color::palettes::css::*, prelude::*};
277
278 pub fn setup(mut commands: Commands) {
279 commands.spawn((Camera2d, DespawnOnExit(super::Scene::Borders)));
280 let root = commands
281 .spawn((
282 Node {
283 flex_wrap: FlexWrap::Wrap,
284 ..default()
285 },
286 DespawnOnExit(super::Scene::Borders),
287 ))
288 .id();
289
290 // all the different combinations of border edges
291 let borders = [
292 UiRect::default(),
293 UiRect::all(px(20)),
294 UiRect::left(px(20)),
295 UiRect::vertical(px(20)),
296 UiRect {
297 left: px(40),
298 top: px(20),
299 ..Default::default()
300 },
301 UiRect {
302 right: px(20),
303 bottom: px(30),
304 ..Default::default()
305 },
306 UiRect {
307 right: px(20),
308 top: px(40),
309 bottom: px(20),
310 ..Default::default()
311 },
312 UiRect {
313 left: px(20),
314 top: px(20),
315 bottom: px(20),
316 ..Default::default()
317 },
318 UiRect {
319 left: px(20),
320 right: px(20),
321 bottom: px(40),
322 ..Default::default()
323 },
324 ];
325
326 let non_zero = |x, y| x != px(0) && y != px(0);
327 let border_size = |x, y| if non_zero(x, y) { f32::MAX } else { 0. };
328
329 for border in borders {
330 for rounded in [true, false] {
331 let border_node = commands
332 .spawn((
333 Node {
334 width: px(100),
335 height: px(100),
336 border,
337 margin: UiRect::all(px(30)),
338 align_items: AlignItems::Center,
339 justify_content: JustifyContent::Center,
340 ..default()
341 },
342 BackgroundColor(MAROON.into()),
343 BorderColor::all(RED),
344 Outline {
345 width: px(10),
346 offset: px(10),
347 color: Color::WHITE,
348 },
349 ))
350 .id();
351
352 if rounded {
353 let border_radius = BorderRadius::px(
354 border_size(border.left, border.top),
355 border_size(border.right, border.top),
356 border_size(border.right, border.bottom),
357 border_size(border.left, border.bottom),
358 );
359 commands.entity(border_node).insert(border_radius);
360 }
361
362 commands.entity(root).add_child(border_node);
363 }
364 }
365 }
366}
367
368mod box_shadow {
369 use bevy::{color::palettes::css::*, prelude::*};
370
371 pub fn setup(mut commands: Commands) {
372 commands.spawn((Camera2d, DespawnOnExit(super::Scene::BoxShadow)));
373
374 commands
375 .spawn((
376 Node {
377 width: percent(100),
378 height: percent(100),
379 padding: UiRect::all(px(30)),
380 column_gap: px(200),
381 flex_wrap: FlexWrap::Wrap,
382 ..default()
383 },
384 BackgroundColor(GREEN.into()),
385 DespawnOnExit(super::Scene::BoxShadow),
386 ))
387 .with_children(|commands| {
388 let example_nodes = [
389 (
390 Vec2::splat(100.),
391 Vec2::ZERO,
392 10.,
393 0.,
394 BorderRadius::bottom_right(px(10)),
395 ),
396 (Vec2::new(200., 50.), Vec2::ZERO, 10., 0., BorderRadius::MAX),
397 (
398 Vec2::new(100., 50.),
399 Vec2::ZERO,
400 10.,
401 10.,
402 BorderRadius::ZERO,
403 ),
404 (
405 Vec2::splat(100.),
406 Vec2::splat(20.),
407 10.,
408 10.,
409 BorderRadius::bottom_right(px(10)),
410 ),
411 (
412 Vec2::splat(100.),
413 Vec2::splat(50.),
414 0.,
415 10.,
416 BorderRadius::ZERO,
417 ),
418 (
419 Vec2::new(50., 100.),
420 Vec2::splat(10.),
421 0.,
422 10.,
423 BorderRadius::MAX,
424 ),
425 ];
426
427 for (size, offset, spread, blur, border_radius) in example_nodes {
428 commands.spawn((
429 Node {
430 width: px(size.x),
431 height: px(size.y),
432 border: UiRect::all(px(2)),
433 ..default()
434 },
435 BorderColor::all(WHITE),
436 border_radius,
437 BackgroundColor(BLUE.into()),
438 BoxShadow::new(
439 Color::BLACK.with_alpha(0.9),
440 percent(offset.x),
441 percent(offset.y),
442 percent(spread),
443 px(blur),
444 ),
445 ));
446 }
447 });
448 }
449}
450
451mod text_wrap {
452 use bevy::prelude::*;
453
454 pub fn setup(mut commands: Commands) {
455 commands.spawn((Camera2d, DespawnOnExit(super::Scene::TextWrap)));
456
457 let root = commands
458 .spawn((
459 Node {
460 flex_direction: FlexDirection::Column,
461 width: px(200),
462 height: percent(100),
463 overflow: Overflow::clip_x(),
464 ..default()
465 },
466 BackgroundColor(Color::BLACK),
467 DespawnOnExit(super::Scene::TextWrap),
468 ))
469 .id();
470
471 for linebreak in [
472 LineBreak::AnyCharacter,
473 LineBreak::WordBoundary,
474 LineBreak::WordOrCharacter,
475 LineBreak::NoWrap,
476 ] {
477 let messages = [
478 "Lorem ipsum dolor sit amet, consectetur adipiscing elit.".to_string(),
479 "pneumonoultramicroscopicsilicovolcanoconiosis".to_string(),
480 ];
481
482 for (j, message) in messages.into_iter().enumerate() {
483 commands.entity(root).with_child((
484 Text(message.clone()),
485 TextLayout::new(Justify::Left, linebreak),
486 BackgroundColor(Color::srgb(0.8 - j as f32 * 0.3, 0., 0.)),
487 ));
488 }
489 }
490 }
491}
492
493mod overflow {
494 use bevy::{color::palettes::css::*, prelude::*};
495
496 pub fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
497 commands.spawn((Camera2d, DespawnOnExit(super::Scene::Overflow)));
498 let image = asset_server.load("branding/icon.png");
499
500 commands
501 .spawn((
502 Node {
503 width: percent(100),
504 height: percent(100),
505 align_items: AlignItems::Center,
506 justify_content: JustifyContent::SpaceAround,
507 ..Default::default()
508 },
509 BackgroundColor(BLUE.into()),
510 DespawnOnExit(super::Scene::Overflow),
511 ))
512 .with_children(|parent| {
513 for overflow in [
514 Overflow::visible(),
515 Overflow::clip_x(),
516 Overflow::clip_y(),
517 Overflow::clip(),
518 ] {
519 parent
520 .spawn((
521 Node {
522 width: px(100),
523 height: px(100),
524 padding: UiRect {
525 left: px(25),
526 top: px(25),
527 ..Default::default()
528 },
529 border: UiRect::all(px(5)),
530 overflow,
531 ..default()
532 },
533 BorderColor::all(RED),
534 BackgroundColor(Color::WHITE),
535 ))
536 .with_children(|parent| {
537 parent.spawn((
538 ImageNode::new(image.clone()),
539 Node {
540 min_width: px(100),
541 min_height: px(100),
542 ..default()
543 },
544 Interaction::default(),
545 Outline {
546 width: px(2),
547 offset: px(2),
548 color: Color::NONE,
549 },
550 ));
551 });
552 }
553 });
554 }
More examples
135fn spawn_image(
136 parent: &mut ChildSpawnerCommands,
137 asset_server: &Res<AssetServer>,
138 update_transform: impl UpdateTransform + Component,
139) {
140 spawn_container(parent, update_transform, |parent| {
141 parent.spawn((
142 ImageNode::new(asset_server.load("branding/bevy_logo_dark_big.png")),
143 Node {
144 height: px(100),
145 position_type: PositionType::Absolute,
146 top: px(-50),
147 left: px(-200),
148 ..default()
149 },
150 ));
151 });
152}
38fn atlas_render_system(
39 mut commands: Commands,
40 mut state: ResMut<State>,
41 font_atlas_sets: Res<FontAtlasSets>,
42 images: Res<Assets<Image>>,
43) {
44 if let Some(set) = font_atlas_sets.get(&state.handle)
45 && let Some((_size, font_atlases)) = set.iter().next()
46 {
47 let x_offset = state.atlas_count as f32;
48 if state.atlas_count == font_atlases.len() as u32 {
49 return;
50 }
51 let font_atlas = &font_atlases[state.atlas_count as usize];
52 let image = images.get(&font_atlas.texture).unwrap();
53 state.atlas_count += 1;
54 commands.spawn((
55 ImageNode::new(font_atlas.texture.clone()),
56 Node {
57 position_type: PositionType::Absolute,
58 top: Val::ZERO,
59 left: px(image.width() as f32 * x_offset),
60 ..default()
61 },
62 ));
63 }
64}
70 fn splash_setup(mut commands: Commands, asset_server: Res<AssetServer>) {
71 let icon = asset_server.load("branding/icon.png");
72 // Display the logo
73 commands.spawn((
74 // This entity will be despawned when exiting the state
75 DespawnOnExit(GameState::Splash),
76 Node {
77 align_items: AlignItems::Center,
78 justify_content: JustifyContent::Center,
79 width: percent(100),
80 height: percent(100),
81 ..default()
82 },
83 OnSplashScreen,
84 children![(
85 ImageNode::new(icon),
86 Node {
87 // This will set the logo to be 200px wide, and auto adjust its height
88 width: px(200),
89 ..default()
90 },
91 )],
92 ));
93 // Insert the timer as a resource
94 commands.insert_resource(SplashTimer(Timer::from_seconds(1.0, TimerMode::Once)));
95 }
96
97 // Tick the timer, and change state when finished
98 fn countdown(
99 mut game_state: ResMut<NextState<GameState>>,
100 time: Res<Time>,
101 mut timer: ResMut<SplashTimer>,
102 ) {
103 if timer.tick(time.delta()).is_finished() {
104 game_state.set(GameState::Menu);
105 }
106 }
107}
108
109mod game {
110 use bevy::{
111 color::palettes::basic::{BLUE, LIME},
112 prelude::*,
113 };
114
115 use super::{DisplayQuality, GameState, Volume, TEXT_COLOR};
116
117 // This plugin will contain the game. In this case, it's just be a screen that will
118 // display the current settings for 5 seconds before returning to the menu
119 pub fn game_plugin(app: &mut App) {
120 app.add_systems(OnEnter(GameState::Game), game_setup)
121 .add_systems(Update, game.run_if(in_state(GameState::Game)));
122 }
123
124 // Tag component used to tag entities added on the game screen
125 #[derive(Component)]
126 struct OnGameScreen;
127
128 #[derive(Resource, Deref, DerefMut)]
129 struct GameTimer(Timer);
130
131 fn game_setup(
132 mut commands: Commands,
133 display_quality: Res<DisplayQuality>,
134 volume: Res<Volume>,
135 ) {
136 commands.spawn((
137 DespawnOnExit(GameState::Game),
138 Node {
139 width: percent(100),
140 height: percent(100),
141 // center children
142 align_items: AlignItems::Center,
143 justify_content: JustifyContent::Center,
144 ..default()
145 },
146 OnGameScreen,
147 children![(
148 Node {
149 // This will display its children in a column, from top to bottom
150 flex_direction: FlexDirection::Column,
151 // `align_items` will align children on the cross axis. Here the main axis is
152 // vertical (column), so the cross axis is horizontal. This will center the
153 // children
154 align_items: AlignItems::Center,
155 ..default()
156 },
157 BackgroundColor(Color::BLACK),
158 children![
159 (
160 Text::new("Will be back to the menu shortly..."),
161 TextFont {
162 font_size: 67.0,
163 ..default()
164 },
165 TextColor(TEXT_COLOR),
166 Node {
167 margin: UiRect::all(px(50)),
168 ..default()
169 },
170 ),
171 (
172 Text::default(),
173 Node {
174 margin: UiRect::all(px(50)),
175 ..default()
176 },
177 children![
178 (
179 TextSpan(format!("quality: {:?}", *display_quality)),
180 TextFont {
181 font_size: 50.0,
182 ..default()
183 },
184 TextColor(BLUE.into()),
185 ),
186 (
187 TextSpan::new(" - "),
188 TextFont {
189 font_size: 50.0,
190 ..default()
191 },
192 TextColor(TEXT_COLOR),
193 ),
194 (
195 TextSpan(format!("volume: {:?}", *volume)),
196 TextFont {
197 font_size: 50.0,
198 ..default()
199 },
200 TextColor(LIME.into()),
201 ),
202 ]
203 ),
204 ]
205 )],
206 ));
207 // Spawn a 5 seconds timer to trigger going back to the menu
208 commands.insert_resource(GameTimer(Timer::from_seconds(5.0, TimerMode::Once)));
209 }
210
211 // Tick the timer, and change state when finished
212 fn game(
213 time: Res<Time>,
214 mut game_state: ResMut<NextState<GameState>>,
215 mut timer: ResMut<GameTimer>,
216 ) {
217 if timer.tick(time.delta()).is_finished() {
218 game_state.set(GameState::Menu);
219 }
220 }
221}
222
223mod menu {
224 use bevy::{
225 app::AppExit,
226 color::palettes::css::CRIMSON,
227 ecs::spawn::{SpawnIter, SpawnWith},
228 prelude::*,
229 };
230
231 use super::{DisplayQuality, GameState, Volume, TEXT_COLOR};
232
233 // This plugin manages the menu, with 5 different screens:
234 // - a main menu with "New Game", "Settings", "Quit"
235 // - a settings menu with two submenus and a back button
236 // - two settings screen with a setting that can be set and a back button
237 pub fn menu_plugin(app: &mut App) {
238 app
239 // At start, the menu is not enabled. This will be changed in `menu_setup` when
240 // entering the `GameState::Menu` state.
241 // Current screen in the menu is handled by an independent state from `GameState`
242 .init_state::<MenuState>()
243 .add_systems(OnEnter(GameState::Menu), menu_setup)
244 // Systems to handle the main menu screen
245 .add_systems(OnEnter(MenuState::Main), main_menu_setup)
246 // Systems to handle the settings menu screen
247 .add_systems(OnEnter(MenuState::Settings), settings_menu_setup)
248 // Systems to handle the display settings screen
249 .add_systems(
250 OnEnter(MenuState::SettingsDisplay),
251 display_settings_menu_setup,
252 )
253 .add_systems(
254 Update,
255 (setting_button::<DisplayQuality>.run_if(in_state(MenuState::SettingsDisplay)),),
256 )
257 // Systems to handle the sound settings screen
258 .add_systems(OnEnter(MenuState::SettingsSound), sound_settings_menu_setup)
259 .add_systems(
260 Update,
261 setting_button::<Volume>.run_if(in_state(MenuState::SettingsSound)),
262 )
263 // Common systems to all screens that handles buttons behavior
264 .add_systems(
265 Update,
266 (menu_action, button_system).run_if(in_state(GameState::Menu)),
267 );
268 }
269
270 // State used for the current menu screen
271 #[derive(Clone, Copy, Default, Eq, PartialEq, Debug, Hash, States)]
272 enum MenuState {
273 Main,
274 Settings,
275 SettingsDisplay,
276 SettingsSound,
277 #[default]
278 Disabled,
279 }
280
281 // Tag component used to tag entities added on the main menu screen
282 #[derive(Component)]
283 struct OnMainMenuScreen;
284
285 // Tag component used to tag entities added on the settings menu screen
286 #[derive(Component)]
287 struct OnSettingsMenuScreen;
288
289 // Tag component used to tag entities added on the display settings menu screen
290 #[derive(Component)]
291 struct OnDisplaySettingsMenuScreen;
292
293 // Tag component used to tag entities added on the sound settings menu screen
294 #[derive(Component)]
295 struct OnSoundSettingsMenuScreen;
296
297 const NORMAL_BUTTON: Color = Color::srgb(0.15, 0.15, 0.15);
298 const HOVERED_BUTTON: Color = Color::srgb(0.25, 0.25, 0.25);
299 const HOVERED_PRESSED_BUTTON: Color = Color::srgb(0.25, 0.65, 0.25);
300 const PRESSED_BUTTON: Color = Color::srgb(0.35, 0.75, 0.35);
301
302 // Tag component used to mark which setting is currently selected
303 #[derive(Component)]
304 struct SelectedOption;
305
306 // All actions that can be triggered from a button click
307 #[derive(Component)]
308 enum MenuButtonAction {
309 Play,
310 Settings,
311 SettingsDisplay,
312 SettingsSound,
313 BackToMainMenu,
314 BackToSettings,
315 Quit,
316 }
317
318 // This system handles changing all buttons color based on mouse interaction
319 fn button_system(
320 mut interaction_query: Query<
321 (&Interaction, &mut BackgroundColor, Option<&SelectedOption>),
322 (Changed<Interaction>, With<Button>),
323 >,
324 ) {
325 for (interaction, mut background_color, selected) in &mut interaction_query {
326 *background_color = match (*interaction, selected) {
327 (Interaction::Pressed, _) | (Interaction::None, Some(_)) => PRESSED_BUTTON.into(),
328 (Interaction::Hovered, Some(_)) => HOVERED_PRESSED_BUTTON.into(),
329 (Interaction::Hovered, None) => HOVERED_BUTTON.into(),
330 (Interaction::None, None) => NORMAL_BUTTON.into(),
331 }
332 }
333 }
334
335 // This system updates the settings when a new value for a setting is selected, and marks
336 // the button as the one currently selected
337 fn setting_button<T: Resource + Component + PartialEq + Copy>(
338 interaction_query: Query<(&Interaction, &T, Entity), (Changed<Interaction>, With<Button>)>,
339 selected_query: Single<(Entity, &mut BackgroundColor), With<SelectedOption>>,
340 mut commands: Commands,
341 mut setting: ResMut<T>,
342 ) {
343 let (previous_button, mut previous_button_color) = selected_query.into_inner();
344 for (interaction, button_setting, entity) in &interaction_query {
345 if *interaction == Interaction::Pressed && *setting != *button_setting {
346 *previous_button_color = NORMAL_BUTTON.into();
347 commands.entity(previous_button).remove::<SelectedOption>();
348 commands.entity(entity).insert(SelectedOption);
349 *setting = *button_setting;
350 }
351 }
352 }
353
354 fn menu_setup(mut menu_state: ResMut<NextState<MenuState>>) {
355 menu_state.set(MenuState::Main);
356 }
357
358 fn main_menu_setup(mut commands: Commands, asset_server: Res<AssetServer>) {
359 // Common style for all buttons on the screen
360 let button_node = Node {
361 width: px(300),
362 height: px(65),
363 margin: UiRect::all(px(20)),
364 justify_content: JustifyContent::Center,
365 align_items: AlignItems::Center,
366 ..default()
367 };
368 let button_icon_node = Node {
369 width: px(30),
370 // This takes the icons out of the flexbox flow, to be positioned exactly
371 position_type: PositionType::Absolute,
372 // The icon will be close to the left border of the button
373 left: px(10),
374 ..default()
375 };
376 let button_text_font = TextFont {
377 font_size: 33.0,
378 ..default()
379 };
380
381 let right_icon = asset_server.load("textures/Game Icons/right.png");
382 let wrench_icon = asset_server.load("textures/Game Icons/wrench.png");
383 let exit_icon = asset_server.load("textures/Game Icons/exitRight.png");
384
385 commands.spawn((
386 DespawnOnExit(MenuState::Main),
387 Node {
388 width: percent(100),
389 height: percent(100),
390 align_items: AlignItems::Center,
391 justify_content: JustifyContent::Center,
392 ..default()
393 },
394 OnMainMenuScreen,
395 children![(
396 Node {
397 flex_direction: FlexDirection::Column,
398 align_items: AlignItems::Center,
399 ..default()
400 },
401 BackgroundColor(CRIMSON.into()),
402 children![
403 // Display the game name
404 (
405 Text::new("Bevy Game Menu UI"),
406 TextFont {
407 font_size: 67.0,
408 ..default()
409 },
410 TextColor(TEXT_COLOR),
411 Node {
412 margin: UiRect::all(px(50)),
413 ..default()
414 },
415 ),
416 // Display three buttons for each action available from the main menu:
417 // - new game
418 // - settings
419 // - quit
420 (
421 Button,
422 button_node.clone(),
423 BackgroundColor(NORMAL_BUTTON),
424 MenuButtonAction::Play,
425 children![
426 (ImageNode::new(right_icon), button_icon_node.clone()),
427 (
428 Text::new("New Game"),
429 button_text_font.clone(),
430 TextColor(TEXT_COLOR),
431 ),
432 ]
433 ),
434 (
435 Button,
436 button_node.clone(),
437 BackgroundColor(NORMAL_BUTTON),
438 MenuButtonAction::Settings,
439 children![
440 (ImageNode::new(wrench_icon), button_icon_node.clone()),
441 (
442 Text::new("Settings"),
443 button_text_font.clone(),
444 TextColor(TEXT_COLOR),
445 ),
446 ]
447 ),
448 (
449 Button,
450 button_node,
451 BackgroundColor(NORMAL_BUTTON),
452 MenuButtonAction::Quit,
453 children![
454 (ImageNode::new(exit_icon), button_icon_node),
455 (Text::new("Quit"), button_text_font, TextColor(TEXT_COLOR),),
456 ]
457 ),
458 ]
459 )],
460 ));
461 }
263fn spawn_button(
264 commands: &mut ChildSpawnerCommands,
265 background_color: Color,
266 buttons: f32,
267 column: usize,
268 row: usize,
269 spawn_text: bool,
270 border: UiRect,
271 border_color: BorderColor,
272 image: Option<Handle<Image>>,
273) {
274 let width = vw(90.0 / buttons);
275 let height = vh(90.0 / buttons);
276 let margin = UiRect::axes(width * 0.05, height * 0.05);
277 let mut builder = commands.spawn((
278 Button,
279 Node {
280 width,
281 height,
282 margin,
283 align_items: AlignItems::Center,
284 justify_content: JustifyContent::Center,
285 border,
286 ..default()
287 },
288 BackgroundColor(background_color),
289 border_color,
290 IdleColor(background_color),
291 ));
292
293 if let Some(image) = image {
294 builder.insert(ImageNode::new(image));
295 }
296
297 if spawn_text {
298 builder.with_children(|parent| {
299 // These labels are split to stress test multi-span text
300 parent
301 .spawn((
302 Text(format!("{column}, ")),
303 TextFont {
304 font_size: FONT_SIZE,
305 ..default()
306 },
307 TextColor(Color::srgb(0.5, 0.2, 0.2)),
308 ))
309 .with_child((
310 TextSpan(format!("{row}")),
311 TextFont {
312 font_size: FONT_SIZE,
313 ..default()
314 },
315 TextColor(Color::srgb(0.2, 0.2, 0.5)),
316 ));
317 });
318 }
319}
24fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
25 commands.spawn(Camera2d);
26
27 let text_font = TextFont {
28 font_size: 13.,
29 ..default()
30 };
31
32 commands
33 .spawn((
34 Node {
35 width: percent(50),
36 height: percent(50),
37 position_type: PositionType::Absolute,
38 left: percent(25),
39 top: percent(25),
40 justify_content: JustifyContent::SpaceAround,
41 align_items: AlignItems::Center,
42 ..default()
43 },
44 BackgroundColor(ANTIQUE_WHITE.into()),
45 ))
46 .with_children(|parent| {
47 parent
48 .spawn((
49 Node {
50 width: px(40),
51 height: px(40),
52 ..default()
53 },
54 BackgroundColor(RED.into()),
55 ))
56 .with_children(|parent| {
57 parent.spawn((Text::new("Size!"), text_font, TextColor::BLACK));
58 });
59 parent.spawn((
60 Node {
61 width: percent(15),
62 height: percent(15),
63 ..default()
64 },
65 BackgroundColor(BLUE.into()),
66 ));
67 parent.spawn((
68 ImageNode::new(asset_server.load("branding/icon.png")),
69 Node {
70 width: px(30),
71 height: px(30),
72 ..default()
73 },
74 ));
75 });
76}
Sourcepub fn solid_color(color: Color) -> ImageNode
pub fn solid_color(color: Color) -> ImageNode
Create a solid color ImageNode
.
This is primarily useful for debugging / mocking the extents of your image.
Sourcepub fn from_atlas_image(image: Handle<Image>, atlas: TextureAtlas) -> ImageNode
pub fn from_atlas_image(image: Handle<Image>, atlas: TextureAtlas) -> ImageNode
Create a ImageNode
from an image, with an associated texture atlas
Examples found in repository?
84fn build_ability(
85 food: FoodItem,
86 texture: Handle<Image>,
87 layout: Handle<TextureAtlasLayout>,
88) -> impl Bundle {
89 let FoodItem {
90 name,
91 cooldown,
92 index,
93 } = food;
94 let name = Name::new(name);
95
96 // Every food item is a button with a child node.
97 // The child node's height will be animated to be at 100% at the beginning
98 // of a cooldown, effectively graying out the whole button, and then getting smaller over time.
99 (
100 Node {
101 width: px(80),
102 height: px(80),
103 flex_direction: FlexDirection::ColumnReverse,
104 ..default()
105 },
106 BackgroundColor(tailwind::SLATE_400.into()),
107 Button,
108 ImageNode::from_atlas_image(texture, TextureAtlas { layout, index }),
109 Cooldown(Timer::from_seconds(cooldown, TimerMode::Once)),
110 name,
111 children![(
112 Node {
113 width: percent(100),
114 height: percent(0),
115 ..default()
116 },
117 BackgroundColor(tailwind::SLATE_50.with_alpha(0.5).into()),
118 )],
119 )
120}
More examples
18fn setup(
19 mut commands: Commands,
20 asset_server: Res<AssetServer>,
21 mut texture_atlases: ResMut<Assets<TextureAtlasLayout>>,
22) {
23 // Camera
24 commands.spawn(Camera2d);
25
26 let text_font = TextFont::default();
27
28 let texture_handle = asset_server.load("textures/rpg/chars/gabe/gabe-idle-run.png");
29 let texture_atlas = TextureAtlasLayout::from_grid(UVec2::splat(24), 7, 1, None, None);
30 let texture_atlas_handle = texture_atlases.add(texture_atlas);
31
32 // root node
33 commands
34 .spawn(Node {
35 width: percent(100),
36 height: percent(100),
37 flex_direction: FlexDirection::Column,
38 justify_content: JustifyContent::Center,
39 align_items: AlignItems::Center,
40 row_gap: px(text_font.font_size * 2.),
41 ..default()
42 })
43 .with_children(|parent| {
44 parent.spawn((
45 ImageNode::from_atlas_image(
46 texture_handle,
47 TextureAtlas::from(texture_atlas_handle),
48 ),
49 Node {
50 width: px(256),
51 height: px(256),
52 ..default()
53 },
54 BackgroundColor(ANTIQUE_WHITE.into()),
55 Outline::new(px(8), Val::ZERO, CRIMSON.into()),
56 ));
57 parent
58 .spawn((Text::new("press "), text_font.clone()))
59 .with_child((
60 TextSpan::new("space"),
61 TextColor(YELLOW.into()),
62 text_font.clone(),
63 ))
64 .with_child((TextSpan::new(" to advance frames"), text_font));
65 });
66}
47fn setup(
48 mut commands: Commands,
49 asset_server: Res<AssetServer>,
50 mut texture_atlases: ResMut<Assets<TextureAtlasLayout>>,
51) {
52 let texture_handle = asset_server.load("textures/fantasy_ui_borders/border_sheet.png");
53 let atlas_layout =
54 TextureAtlasLayout::from_grid(UVec2::new(50, 50), 6, 6, Some(UVec2::splat(2)), None);
55 let atlas_layout_handle = texture_atlases.add(atlas_layout);
56
57 let slicer = TextureSlicer {
58 border: BorderRect::all(24.0),
59 center_scale_mode: SliceScaleMode::Stretch,
60 sides_scale_mode: SliceScaleMode::Stretch,
61 max_corner_scale: 1.0,
62 };
63 // ui camera
64 commands.spawn(Camera2d);
65 commands
66 .spawn(Node {
67 width: percent(100),
68 height: percent(100),
69 align_items: AlignItems::Center,
70 justify_content: JustifyContent::Center,
71 ..default()
72 })
73 .with_children(|parent| {
74 for (idx, [w, h]) in [
75 (0, [150.0, 150.0]),
76 (7, [300.0, 150.0]),
77 (13, [150.0, 300.0]),
78 ] {
79 parent
80 .spawn((
81 Button,
82 ImageNode::from_atlas_image(
83 texture_handle.clone(),
84 TextureAtlas {
85 index: idx,
86 layout: atlas_layout_handle.clone(),
87 },
88 )
89 .with_mode(NodeImageMode::Sliced(slicer.clone())),
90 Node {
91 width: px(w),
92 height: px(h),
93 // horizontally center child text
94 justify_content: JustifyContent::Center,
95 // vertically center child text
96 align_items: AlignItems::Center,
97 margin: UiRect::all(px(20)),
98 ..default()
99 },
100 ))
101 .with_children(|parent| {
102 parent.spawn((
103 Text::new("Button"),
104 TextFont {
105 font: asset_server.load("fonts/FiraSans-Bold.ttf"),
106 font_size: 33.0,
107 ..default()
108 },
109 TextColor(Color::srgb(0.9, 0.9, 0.9)),
110 ));
111 });
112 }
113 });
114}
Sourcepub const fn with_color(self, color: Color) -> ImageNode
pub const fn with_color(self, color: Color) -> ImageNode
Set the color tint
Sourcepub const fn with_flip_x(self) -> ImageNode
pub const fn with_flip_x(self) -> ImageNode
Flip the image along its x-axis
Sourcepub const fn with_flip_y(self) -> ImageNode
pub const fn with_flip_y(self) -> ImageNode
Flip the image along its y-axis
pub const fn with_rect(self, rect: Rect) -> ImageNode
Sourcepub const fn with_mode(self, mode: NodeImageMode) -> ImageNode
pub const fn with_mode(self, mode: NodeImageMode) -> ImageNode
Examples found in repository?
47fn setup(
48 mut commands: Commands,
49 asset_server: Res<AssetServer>,
50 mut texture_atlases: ResMut<Assets<TextureAtlasLayout>>,
51) {
52 let texture_handle = asset_server.load("textures/fantasy_ui_borders/border_sheet.png");
53 let atlas_layout =
54 TextureAtlasLayout::from_grid(UVec2::new(50, 50), 6, 6, Some(UVec2::splat(2)), None);
55 let atlas_layout_handle = texture_atlases.add(atlas_layout);
56
57 let slicer = TextureSlicer {
58 border: BorderRect::all(24.0),
59 center_scale_mode: SliceScaleMode::Stretch,
60 sides_scale_mode: SliceScaleMode::Stretch,
61 max_corner_scale: 1.0,
62 };
63 // ui camera
64 commands.spawn(Camera2d);
65 commands
66 .spawn(Node {
67 width: percent(100),
68 height: percent(100),
69 align_items: AlignItems::Center,
70 justify_content: JustifyContent::Center,
71 ..default()
72 })
73 .with_children(|parent| {
74 for (idx, [w, h]) in [
75 (0, [150.0, 150.0]),
76 (7, [300.0, 150.0]),
77 (13, [150.0, 300.0]),
78 ] {
79 parent
80 .spawn((
81 Button,
82 ImageNode::from_atlas_image(
83 texture_handle.clone(),
84 TextureAtlas {
85 index: idx,
86 layout: atlas_layout_handle.clone(),
87 },
88 )
89 .with_mode(NodeImageMode::Sliced(slicer.clone())),
90 Node {
91 width: px(w),
92 height: px(h),
93 // horizontally center child text
94 justify_content: JustifyContent::Center,
95 // vertically center child text
96 align_items: AlignItems::Center,
97 margin: UiRect::all(px(20)),
98 ..default()
99 },
100 ))
101 .with_children(|parent| {
102 parent.spawn((
103 Text::new("Button"),
104 TextFont {
105 font: asset_server.load("fonts/FiraSans-Bold.ttf"),
106 font_size: 33.0,
107 ..default()
108 },
109 TextColor(Color::srgb(0.9, 0.9, 0.9)),
110 ));
111 });
112 }
113 });
114}
More examples
31fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
32 // Camera
33 commands.spawn((Camera2d, IsDefaultUiCamera, BoxShadowSamples(6)));
34
35 // root node
36 commands
37 .spawn(Node {
38 width: percent(100),
39 height: percent(100),
40 justify_content: JustifyContent::SpaceBetween,
41 ..default()
42 })
43 .insert(Pickable::IGNORE)
44 .with_children(|parent| {
45 // left vertical fill (border)
46 parent
47 .spawn((
48 Node {
49 width: px(200),
50 border: UiRect::all(px(2)),
51 ..default()
52 },
53 BackgroundColor(Color::srgb(0.65, 0.65, 0.65)),
54 ))
55 .with_children(|parent| {
56 // left vertical fill (content)
57 parent
58 .spawn((
59 Node {
60 width: percent(100),
61 flex_direction: FlexDirection::Column,
62 padding: UiRect::all(px(5)),
63 row_gap: px(5),
64 ..default()
65 },
66 BackgroundColor(Color::srgb(0.15, 0.15, 0.15)),
67 Visibility::Visible,
68 ))
69 .with_children(|parent| {
70 // text
71 parent.spawn((
72 Text::new("Text Example"),
73 TextFont {
74 font: asset_server.load("fonts/FiraSans-Bold.ttf"),
75 font_size: 25.0,
76 ..default()
77 },
78 // Because this is a distinct label widget and
79 // not button/list item text, this is necessary
80 // for accessibility to treat the text accordingly.
81 Label,
82 ));
83
84 #[cfg(feature = "bevy_ui_debug")]
85 {
86 // Debug overlay text
87 parent.spawn((
88 Text::new("Press Space to toggle debug outlines."),
89 TextFont {
90 font: asset_server.load("fonts/FiraSans-Bold.ttf"),
91 ..default()
92 },
93 Label,
94 ));
95
96 parent.spawn((
97 Text::new("V: toggle UI root's visibility"),
98 TextFont {
99 font: asset_server.load("fonts/FiraSans-Bold.ttf"),
100 font_size: 12.,
101 ..default()
102 },
103 Label,
104 ));
105
106 parent.spawn((
107 Text::new("S: toggle outlines for hidden nodes"),
108 TextFont {
109 font: asset_server.load("fonts/FiraSans-Bold.ttf"),
110 font_size: 12.,
111 ..default()
112 },
113 Label,
114 ));
115 parent.spawn((
116 Text::new("C: toggle outlines for clipped nodes"),
117 TextFont {
118 font: asset_server.load("fonts/FiraSans-Bold.ttf"),
119 font_size: 12.,
120 ..default()
121 },
122 Label,
123 ));
124 }
125 #[cfg(not(feature = "bevy_ui_debug"))]
126 parent.spawn((
127 Text::new("Try enabling feature \"bevy_ui_debug\"."),
128 TextFont {
129 font: asset_server.load("fonts/FiraSans-Bold.ttf"),
130 ..default()
131 },
132 Label,
133 ));
134 });
135 });
136 // right vertical fill
137 parent
138 .spawn(Node {
139 flex_direction: FlexDirection::Column,
140 justify_content: JustifyContent::Center,
141 align_items: AlignItems::Center,
142 width: px(200),
143 ..default()
144 })
145 .with_children(|parent| {
146 // Title
147 parent.spawn((
148 Text::new("Scrolling list"),
149 TextFont {
150 font: asset_server.load("fonts/FiraSans-Bold.ttf"),
151 font_size: 21.,
152 ..default()
153 },
154 Label,
155 ));
156 // Scrolling list
157 parent
158 .spawn((
159 Node {
160 flex_direction: FlexDirection::Column,
161 align_self: AlignSelf::Stretch,
162 height: percent(50),
163 overflow: Overflow::scroll_y(),
164 ..default()
165 },
166 BackgroundColor(Color::srgb(0.10, 0.10, 0.10)),
167 ))
168 .with_children(|parent| {
169 parent
170 .spawn((
171 Node {
172 flex_direction: FlexDirection::Column,
173 ..Default::default()
174 },
175 BackgroundGradient::from(LinearGradient::to_bottom(vec![
176 ColorStop::auto(NAVY),
177 ColorStop::auto(Color::BLACK),
178 ])),
179 Pickable {
180 should_block_lower: false,
181 ..Default::default()
182 },
183 ))
184 .with_children(|parent| {
185 // List items
186 for i in 0..25 {
187 parent
188 .spawn((
189 Text(format!("Item {i}")),
190 TextFont {
191 font: asset_server
192 .load("fonts/FiraSans-Bold.ttf"),
193 ..default()
194 },
195 Label,
196 AccessibilityNode(Accessible::new(Role::ListItem)),
197 ))
198 .insert(Pickable {
199 should_block_lower: false,
200 ..default()
201 });
202 }
203 });
204 });
205 });
206
207 parent
208 .spawn(Node {
209 left: px(210),
210 bottom: px(10),
211 position_type: PositionType::Absolute,
212 ..default()
213 })
214 .with_children(|parent| {
215 parent
216 .spawn((
217 Node {
218 width: px(200),
219 height: px(200),
220 border: UiRect::all(px(20)),
221 flex_direction: FlexDirection::Column,
222 justify_content: JustifyContent::Center,
223 ..default()
224 },
225 BorderColor::all(LIME),
226 BackgroundColor(Color::srgb(0.8, 0.8, 1.)),
227 ))
228 .with_children(|parent| {
229 parent.spawn((
230 ImageNode::new(asset_server.load("branding/bevy_logo_light.png")),
231 // Uses the transform to rotate the logo image by 45 degrees
232 Node {
233 ..Default::default()
234 },
235 UiTransform {
236 rotation: Rot2::radians(0.25 * PI),
237 ..Default::default()
238 },
239 BorderRadius::all(px(10)),
240 Outline {
241 width: px(2),
242 offset: px(4),
243 color: DARK_GRAY.into(),
244 },
245 ));
246 });
247 });
248
249 let shadow_style = ShadowStyle {
250 color: Color::BLACK.with_alpha(0.5),
251 blur_radius: px(2),
252 x_offset: px(10),
253 y_offset: px(10),
254 ..default()
255 };
256
257 // render order test: reddest in the back, whitest in the front (flex center)
258 parent
259 .spawn(Node {
260 width: percent(100),
261 height: percent(100),
262 position_type: PositionType::Absolute,
263 align_items: AlignItems::Center,
264 justify_content: JustifyContent::Center,
265 ..default()
266 })
267 .insert(Pickable::IGNORE)
268 .with_children(|parent| {
269 parent
270 .spawn((
271 Node {
272 width: px(100),
273 height: px(100),
274 ..default()
275 },
276 BackgroundColor(Color::srgb(1.0, 0.0, 0.)),
277 BoxShadow::from(shadow_style),
278 ))
279 .with_children(|parent| {
280 parent.spawn((
281 Node {
282 // Take the size of the parent node.
283 width: percent(100),
284 height: percent(100),
285 position_type: PositionType::Absolute,
286 left: px(20),
287 bottom: px(20),
288 ..default()
289 },
290 BackgroundColor(Color::srgb(1.0, 0.3, 0.3)),
291 BoxShadow::from(shadow_style),
292 ));
293 parent.spawn((
294 Node {
295 width: percent(100),
296 height: percent(100),
297 position_type: PositionType::Absolute,
298 left: px(40),
299 bottom: px(40),
300 ..default()
301 },
302 BackgroundColor(Color::srgb(1.0, 0.5, 0.5)),
303 BoxShadow::from(shadow_style),
304 ));
305 parent.spawn((
306 Node {
307 width: percent(100),
308 height: percent(100),
309 position_type: PositionType::Absolute,
310 left: px(60),
311 bottom: px(60),
312 ..default()
313 },
314 BackgroundColor(Color::srgb(0.0, 0.7, 0.7)),
315 BoxShadow::from(shadow_style),
316 ));
317 // alpha test
318 parent.spawn((
319 Node {
320 width: percent(100),
321 height: percent(100),
322 position_type: PositionType::Absolute,
323 left: px(80),
324 bottom: px(80),
325 ..default()
326 },
327 BackgroundColor(Color::srgba(1.0, 0.9, 0.9, 0.4)),
328 BoxShadow::from(ShadowStyle {
329 color: Color::BLACK.with_alpha(0.3),
330 ..shadow_style
331 }),
332 ));
333 });
334 });
335 // bevy logo (flex center)
336 parent
337 .spawn(Node {
338 width: percent(100),
339 position_type: PositionType::Absolute,
340 justify_content: JustifyContent::Center,
341 align_items: AlignItems::FlexStart,
342 ..default()
343 })
344 .with_children(|parent| {
345 // bevy logo (image)
346 parent
347 .spawn((
348 ImageNode::new(asset_server.load("branding/bevy_logo_dark_big.png"))
349 .with_mode(NodeImageMode::Stretch),
350 Node {
351 width: px(500),
352 height: px(125),
353 margin: UiRect::top(vmin(5)),
354 ..default()
355 },
356 ))
357 .with_children(|parent| {
358 // alt text
359 // This UI node takes up no space in the layout and the `Text` component is used by the accessibility module
360 // and is not rendered.
361 parent.spawn((
362 Node {
363 display: Display::None,
364 ..default()
365 },
366 Text::new("Bevy logo"),
367 ));
368 });
369 });
370
371 // four bevy icons demonstrating image flipping
372 parent
373 .spawn(Node {
374 width: percent(100),
375 height: percent(100),
376 position_type: PositionType::Absolute,
377 justify_content: JustifyContent::Center,
378 align_items: AlignItems::FlexEnd,
379 column_gap: px(10),
380 padding: UiRect::all(px(10)),
381 ..default()
382 })
383 .insert(Pickable::IGNORE)
384 .with_children(|parent| {
385 for (flip_x, flip_y) in
386 [(false, false), (false, true), (true, true), (true, false)]
387 {
388 parent.spawn((
389 ImageNode {
390 image: asset_server.load("branding/icon.png"),
391 flip_x,
392 flip_y,
393 ..default()
394 },
395 Node {
396 // The height will be chosen automatically to preserve the image's aspect ratio
397 width: px(75),
398 ..default()
399 },
400 ));
401 }
402 });
403 });
404}
Trait Implementations§
Source§impl Component for ImageNode
Required Components: Node
, ImageNodeSize
, ContentSize
.
impl Component for ImageNode
Required Components: Node
, ImageNodeSize
, ContentSize
.
A component’s Required Components are inserted whenever it is inserted. Note that this will also insert the required components of the required components, recursively, in depth-first order.
Source§const STORAGE_TYPE: StorageType = bevy_ecs::component::StorageType::Table
const STORAGE_TYPE: StorageType = bevy_ecs::component::StorageType::Table
Source§type Mutability = Mutable
type Mutability = Mutable
Component<Mutability = Mutable>
,
while immutable components will instead have Component<Mutability = Immutable>
. Read moreSource§fn register_required_components(
_requiree: ComponentId,
required_components: &mut RequiredComponentsRegistrator<'_, '_>,
)
fn register_required_components( _requiree: ComponentId, required_components: &mut RequiredComponentsRegistrator<'_, '_>, )
Source§fn clone_behavior() -> ComponentCloneBehavior
fn clone_behavior() -> ComponentCloneBehavior
Source§fn on_add() -> Option<for<'w> fn(DeferredWorld<'w>, HookContext)>
fn on_add() -> Option<for<'w> fn(DeferredWorld<'w>, HookContext)>
Source§fn on_insert() -> Option<for<'w> fn(DeferredWorld<'w>, HookContext)>
fn on_insert() -> Option<for<'w> fn(DeferredWorld<'w>, HookContext)>
Source§fn on_replace() -> Option<for<'w> fn(DeferredWorld<'w>, HookContext)>
fn on_replace() -> Option<for<'w> fn(DeferredWorld<'w>, HookContext)>
Source§fn on_remove() -> Option<for<'w> fn(DeferredWorld<'w>, HookContext)>
fn on_remove() -> Option<for<'w> fn(DeferredWorld<'w>, HookContext)>
Source§fn on_despawn() -> Option<for<'w> fn(DeferredWorld<'w>, HookContext)>
fn on_despawn() -> Option<for<'w> fn(DeferredWorld<'w>, HookContext)>
Source§fn map_entities<E>(_this: &mut Self, _mapper: &mut E)where
E: EntityMapper,
fn map_entities<E>(_this: &mut Self, _mapper: &mut E)where
E: EntityMapper,
EntityMapper
. This is used to remap entities in contexts like scenes and entity cloning.
When deriving Component
, this is populated by annotating fields containing entities with #[entities]
Read moreSource§impl Default for ImageNode
impl Default for ImageNode
Source§fn default() -> ImageNode
fn default() -> ImageNode
A transparent 1x1 image with a solid white tint.
§Warning
This will be invisible by default.
To set this to a visible image, you need to set the texture
field to a valid image handle,
or use Handle<Image>
’s default 1x1 solid white texture (as is done in ImageNode::solid_color
).
Source§impl FromReflect for ImageNode
impl FromReflect for ImageNode
Source§fn from_reflect(reflect: &(dyn PartialReflect + 'static)) -> Option<ImageNode>
fn from_reflect(reflect: &(dyn PartialReflect + 'static)) -> Option<ImageNode>
Self
from a reflected value.Source§fn take_from_reflect(
reflect: Box<dyn PartialReflect>,
) -> Result<Self, Box<dyn PartialReflect>>
fn take_from_reflect( reflect: Box<dyn PartialReflect>, ) -> Result<Self, Box<dyn PartialReflect>>
Self
using,
constructing the value using from_reflect
if that fails. Read moreSource§impl GetOwnership for ImageNode
impl GetOwnership for ImageNode
Source§impl GetTypeRegistration for ImageNode
impl GetTypeRegistration for ImageNode
Source§fn get_type_registration() -> TypeRegistration
fn get_type_registration() -> TypeRegistration
TypeRegistration
for this type.Source§fn register_type_dependencies(registry: &mut TypeRegistry)
fn register_type_dependencies(registry: &mut TypeRegistry)
Source§impl IntoReturn for ImageNode
impl IntoReturn for ImageNode
Source§impl PartialReflect for ImageNode
impl PartialReflect for ImageNode
Source§fn get_represented_type_info(&self) -> Option<&'static TypeInfo>
fn get_represented_type_info(&self) -> Option<&'static TypeInfo>
Source§fn try_apply(
&mut self,
value: &(dyn PartialReflect + 'static),
) -> Result<(), ApplyError>
fn try_apply( &mut self, value: &(dyn PartialReflect + 'static), ) -> Result<(), ApplyError>
Source§fn reflect_kind(&self) -> ReflectKind
fn reflect_kind(&self) -> ReflectKind
Source§fn reflect_ref(&self) -> ReflectRef<'_>
fn reflect_ref(&self) -> ReflectRef<'_>
Source§fn reflect_mut(&mut self) -> ReflectMut<'_>
fn reflect_mut(&mut self) -> ReflectMut<'_>
Source§fn reflect_owned(self: Box<ImageNode>) -> ReflectOwned
fn reflect_owned(self: Box<ImageNode>) -> ReflectOwned
Source§fn try_into_reflect(
self: Box<ImageNode>,
) -> Result<Box<dyn Reflect>, Box<dyn PartialReflect>>
fn try_into_reflect( self: Box<ImageNode>, ) -> Result<Box<dyn Reflect>, Box<dyn PartialReflect>>
Source§fn try_as_reflect(&self) -> Option<&(dyn Reflect + 'static)>
fn try_as_reflect(&self) -> Option<&(dyn Reflect + 'static)>
Source§fn try_as_reflect_mut(&mut self) -> Option<&mut (dyn Reflect + 'static)>
fn try_as_reflect_mut(&mut self) -> Option<&mut (dyn Reflect + 'static)>
Source§fn into_partial_reflect(self: Box<ImageNode>) -> Box<dyn PartialReflect>
fn into_partial_reflect(self: Box<ImageNode>) -> Box<dyn PartialReflect>
Source§fn as_partial_reflect(&self) -> &(dyn PartialReflect + 'static)
fn as_partial_reflect(&self) -> &(dyn PartialReflect + 'static)
Source§fn as_partial_reflect_mut(&mut self) -> &mut (dyn PartialReflect + 'static)
fn as_partial_reflect_mut(&mut self) -> &mut (dyn PartialReflect + 'static)
Source§fn reflect_partial_eq(
&self,
value: &(dyn PartialReflect + 'static),
) -> Option<bool>
fn reflect_partial_eq( &self, value: &(dyn PartialReflect + 'static), ) -> Option<bool>
Source§fn debug(&self, f: &mut Formatter<'_>) -> Result<(), Error>
fn debug(&self, f: &mut Formatter<'_>) -> Result<(), Error>
Source§fn reflect_clone(&self) -> Result<Box<dyn Reflect>, ReflectCloneError>
fn reflect_clone(&self) -> Result<Box<dyn Reflect>, ReflectCloneError>
Self
using reflection. Read moreSource§fn apply(&mut self, value: &(dyn PartialReflect + 'static))
fn apply(&mut self, value: &(dyn PartialReflect + 'static))
Source§fn to_dynamic(&self) -> Box<dyn PartialReflect>
fn to_dynamic(&self) -> Box<dyn PartialReflect>
Source§fn reflect_clone_and_take<T>(&self) -> Result<T, ReflectCloneError>
fn reflect_clone_and_take<T>(&self) -> Result<T, ReflectCloneError>
PartialReflect
, combines reflect_clone
and
take
in a useful fashion, automatically constructing an appropriate
ReflectCloneError
if the downcast fails. Read moreSource§fn reflect_hash(&self) -> Option<u64>
fn reflect_hash(&self) -> Option<u64>
Source§fn is_dynamic(&self) -> bool
fn is_dynamic(&self) -> bool
Source§impl Reflect for ImageNode
impl Reflect for ImageNode
Source§fn into_any(self: Box<ImageNode>) -> Box<dyn Any>
fn into_any(self: Box<ImageNode>) -> Box<dyn Any>
Box<dyn Any>
. Read moreSource§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut dyn Any
. Read moreSource§fn into_reflect(self: Box<ImageNode>) -> Box<dyn Reflect>
fn into_reflect(self: Box<ImageNode>) -> Box<dyn Reflect>
Source§fn as_reflect(&self) -> &(dyn Reflect + 'static)
fn as_reflect(&self) -> &(dyn Reflect + 'static)
Source§fn as_reflect_mut(&mut self) -> &mut (dyn Reflect + 'static)
fn as_reflect_mut(&mut self) -> &mut (dyn Reflect + 'static)
Source§impl Struct for ImageNode
impl Struct for ImageNode
Source§fn field(&self, name: &str) -> Option<&(dyn PartialReflect + 'static)>
fn field(&self, name: &str) -> Option<&(dyn PartialReflect + 'static)>
name
as a &dyn PartialReflect
.Source§fn field_mut(
&mut self,
name: &str,
) -> Option<&mut (dyn PartialReflect + 'static)>
fn field_mut( &mut self, name: &str, ) -> Option<&mut (dyn PartialReflect + 'static)>
name
as a
&mut dyn PartialReflect
.Source§fn field_at(&self, index: usize) -> Option<&(dyn PartialReflect + 'static)>
fn field_at(&self, index: usize) -> Option<&(dyn PartialReflect + 'static)>
index
as a
&dyn PartialReflect
.Source§fn field_at_mut(
&mut self,
index: usize,
) -> Option<&mut (dyn PartialReflect + 'static)>
fn field_at_mut( &mut self, index: usize, ) -> Option<&mut (dyn PartialReflect + 'static)>
index
as a &mut dyn PartialReflect
.Source§fn name_at(&self, index: usize) -> Option<&str>
fn name_at(&self, index: usize) -> Option<&str>
index
.Source§fn iter_fields(&self) -> FieldIter<'_> ⓘ
fn iter_fields(&self) -> FieldIter<'_> ⓘ
Source§fn to_dynamic_struct(&self) -> DynamicStruct
fn to_dynamic_struct(&self) -> DynamicStruct
DynamicStruct
from this struct.Source§fn get_represented_struct_info(&self) -> Option<&'static StructInfo>
fn get_represented_struct_info(&self) -> Option<&'static StructInfo>
None
if TypeInfo
is not available.Source§impl TypePath for ImageNode
impl TypePath for ImageNode
Source§fn type_path() -> &'static str
fn type_path() -> &'static str
Source§fn short_type_path() -> &'static str
fn short_type_path() -> &'static str
Source§fn type_ident() -> Option<&'static str>
fn type_ident() -> Option<&'static str>
Source§fn crate_name() -> Option<&'static str>
fn crate_name() -> Option<&'static str>
Auto Trait Implementations§
impl Freeze for ImageNode
impl !RefUnwindSafe for ImageNode
impl Send for ImageNode
impl Sync for ImageNode
impl Unpin for ImageNode
impl !UnwindSafe for ImageNode
Blanket Implementations§
Source§impl<T, U> AsBindGroupShaderType<U> for T
impl<T, U> AsBindGroupShaderType<U> for T
Source§fn as_bind_group_shader_type(&self, _images: &RenderAssets<GpuImage>) -> U
fn as_bind_group_shader_type(&self, _images: &RenderAssets<GpuImage>) -> U
T
ShaderType
for self
. When used in AsBindGroup
derives, it is safe to assume that all images in self
exist.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
Source§impl<C> Bundle for Cwhere
C: Component,
impl<C> Bundle for Cwhere
C: Component,
fn component_ids( components: &mut ComponentsRegistrator<'_>, ids: &mut impl FnMut(ComponentId), )
Source§fn get_component_ids(
components: &Components,
ids: &mut impl FnMut(Option<ComponentId>),
)
fn get_component_ids( components: &Components, ids: &mut impl FnMut(Option<ComponentId>), )
Source§impl<C> BundleFromComponents for Cwhere
C: Component,
impl<C> BundleFromComponents for Cwhere
C: Component,
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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> 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> DowncastSend for T
impl<T> DowncastSend for T
Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<C> DynamicBundle for Cwhere
C: Component,
impl<C> DynamicBundle for Cwhere
C: Component,
Source§unsafe fn get_components(
ptr: MovingPtr<'_, C>,
func: &mut impl FnMut(StorageType, OwningPtr<'_>),
) -> <C as DynamicBundle>::Effect
unsafe fn get_components( ptr: MovingPtr<'_, C>, func: &mut impl FnMut(StorageType, OwningPtr<'_>), ) -> <C as DynamicBundle>::Effect
Source§unsafe fn apply_effect(
_ptr: MovingPtr<'_, MaybeUninit<C>>,
_entity: &mut EntityWorldMut<'_>,
)
unsafe fn apply_effect( _ptr: MovingPtr<'_, MaybeUninit<C>>, _entity: &mut EntityWorldMut<'_>, )
Source§impl<T> DynamicTypePath for Twhere
T: TypePath,
impl<T> DynamicTypePath for Twhere
T: TypePath,
Source§fn reflect_type_path(&self) -> &str
fn reflect_type_path(&self) -> &str
TypePath::type_path
.Source§fn reflect_short_type_path(&self) -> &str
fn reflect_short_type_path(&self) -> &str
Source§fn reflect_type_ident(&self) -> Option<&str>
fn reflect_type_ident(&self) -> Option<&str>
TypePath::type_ident
.Source§fn reflect_crate_name(&self) -> Option<&str>
fn reflect_crate_name(&self) -> Option<&str>
TypePath::crate_name
.Source§fn reflect_module_path(&self) -> Option<&str>
fn reflect_module_path(&self) -> Option<&str>
Source§impl<T> DynamicTyped for Twhere
T: Typed,
impl<T> DynamicTyped for Twhere
T: Typed,
Source§fn reflect_type_info(&self) -> &'static TypeInfo
fn reflect_type_info(&self) -> &'static TypeInfo
Typed::type_info
.Source§impl<T> FmtForward for T
impl<T> FmtForward for T
Source§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
self
to use its Binary
implementation when Debug
-formatted.Source§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
self
to use its Display
implementation when
Debug
-formatted.Source§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
self
to use its LowerExp
implementation when
Debug
-formatted.Source§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
self
to use its LowerHex
implementation when
Debug
-formatted.Source§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
self
to use its Octal
implementation when Debug
-formatted.Source§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
self
to use its Pointer
implementation when
Debug
-formatted.Source§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
self
to use its UpperExp
implementation when
Debug
-formatted.Source§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
self
to use its UpperHex
implementation when
Debug
-formatted.Source§impl<S> FromSample<S> for S
impl<S> FromSample<S> for S
fn from_sample_(s: S) -> S
Source§impl<T> FromWorld for Twhere
T: Default,
impl<T> FromWorld for Twhere
T: Default,
Source§fn from_world(_world: &mut World) -> T
fn from_world(_world: &mut World) -> T
Creates Self
using default()
.
Source§impl<S> GetField for Swhere
S: Struct,
impl<S> GetField for Swhere
S: Struct,
Source§impl<T> GetPath for T
impl<T> GetPath for T
Source§fn reflect_path<'p>(
&self,
path: impl ReflectPath<'p>,
) -> Result<&(dyn PartialReflect + 'static), ReflectPathError<'p>>
fn reflect_path<'p>( &self, path: impl ReflectPath<'p>, ) -> Result<&(dyn PartialReflect + 'static), ReflectPathError<'p>>
path
. Read moreSource§fn reflect_path_mut<'p>(
&mut self,
path: impl ReflectPath<'p>,
) -> Result<&mut (dyn PartialReflect + 'static), ReflectPathError<'p>>
fn reflect_path_mut<'p>( &mut self, path: impl ReflectPath<'p>, ) -> Result<&mut (dyn PartialReflect + 'static), ReflectPathError<'p>>
path
. Read moreSource§fn path<'p, T>(
&self,
path: impl ReflectPath<'p>,
) -> Result<&T, ReflectPathError<'p>>where
T: Reflect,
fn path<'p, T>(
&self,
path: impl ReflectPath<'p>,
) -> Result<&T, ReflectPathError<'p>>where
T: Reflect,
path
. Read moreSource§fn path_mut<'p, T>(
&mut self,
path: impl ReflectPath<'p>,
) -> Result<&mut T, ReflectPathError<'p>>where
T: Reflect,
fn path_mut<'p, T>(
&mut self,
path: impl ReflectPath<'p>,
) -> Result<&mut T, ReflectPathError<'p>>where
T: Reflect,
path
. Read moreSource§impl<T, W> HasTypeWitness<W> for Twhere
W: MakeTypeWitness<Arg = T>,
T: ?Sized,
impl<T, W> HasTypeWitness<W> for Twhere
W: MakeTypeWitness<Arg = T>,
T: ?Sized,
Source§impl<T> Identity for Twhere
T: ?Sized,
impl<T> Identity for Twhere
T: ?Sized,
Source§impl<T> InitializeFromFunction<T> for T
impl<T> InitializeFromFunction<T> for T
Source§fn initialize_from_function(f: fn() -> T) -> T
fn initialize_from_function(f: fn() -> T) -> T
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<T> IntoResult<T> for T
impl<T> IntoResult<T> for T
Source§fn into_result(self) -> Result<T, RunSystemError>
fn into_result(self) -> Result<T, RunSystemError>
Source§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
Source§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
Source§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
Source§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self
and passes that borrow into the pipe function. Read moreSource§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self
and passes that borrow into the pipe function. Read moreSource§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
Source§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
Source§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self
, then passes self.as_ref()
into the pipe function.Source§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self
, then passes self.as_mut()
into the pipe
function.Source§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self
, then passes self.deref()
into the pipe function.Source§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<R, P> ReadPrimitive<R> for P
impl<R, P> ReadPrimitive<R> for P
Source§fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
ReadEndian::read_from_little_endian()
.Source§impl<Ret> SpawnIfAsync<(), Ret> for Ret
impl<Ret> SpawnIfAsync<(), Ret> for Ret
Source§impl<T, O> SuperFrom<T> for Owhere
O: From<T>,
impl<T, O> SuperFrom<T> for Owhere
O: From<T>,
Source§fn super_from(input: T) -> O
fn super_from(input: T) -> O
Source§impl<T, O, M> SuperInto<O, M> for Twhere
O: SuperFrom<T, M>,
impl<T, O, M> SuperInto<O, M> for Twhere
O: SuperFrom<T, M>,
Source§fn super_into(self) -> O
fn super_into(self) -> O
Source§impl<T> Tap for T
impl<T> Tap for T
Source§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B>
of a value. Read moreSource§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B>
of a value. Read moreSource§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R>
view of a value. Read moreSource§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R>
view of a value. Read moreSource§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target
of a value. Read moreSource§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target
of a value. Read moreSource§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap()
only in debug builds, and is erased in release builds.Source§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut()
only in debug builds, and is erased in release
builds.Source§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow()
only in debug builds, and is erased in release
builds.Source§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut()
only in debug builds, and is erased in release
builds.Source§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref()
only in debug builds, and is erased in release
builds.Source§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut()
only in debug builds, and is erased in release
builds.Source§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref()
only in debug builds, and is erased in release
builds.