Skip to content

Commit

Permalink
ui: Remove ButtonIcon::Text. The about button now has an icon.
Browse files Browse the repository at this point in the history
This removes one of the direct uses of `embedded_graphics`.
See <#528>.
  • Loading branch information
kpreid committed Sep 22, 2024
1 parent 601910d commit af2835d
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 68 deletions.
46 changes: 17 additions & 29 deletions all-is-cubes-ui/src/vui/blocks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use core::fmt;

use exhaust::Exhaust;

use all_is_cubes::drawing::embedded_graphics::mono_font::iso_8859_1 as font;
use all_is_cubes::include_image;
use all_is_cubes::linking::{BlockModule, BlockProvider};
use all_is_cubes::universe::UniverseTransaction;
Expand Down Expand Up @@ -72,90 +71,79 @@ impl UiBlocks {
txn,
"Back",
ButtonIcon::Icon(include_image!("icons/button-back.png")),
)?
.build(),
)?,

UiBlocks::AboutButtonLabel => {
make_button_label_block(txn, "About", ButtonIcon::Text(&font::FONT_10X20, "?"))?
.build()
}
UiBlocks::AboutButtonLabel => make_button_label_block(
txn,
"About",
ButtonIcon::Icon(include_image!("icons/button-help.png")),
)?,

UiBlocks::PauseButtonLabel => make_button_label_block(
txn,
"Pause",
ButtonIcon::Icon(include_image!("icons/button-pause.png")),
)?
.build(),
)?,

UiBlocks::SaveButtonLabel => make_button_label_block(
txn,
"Save",
ButtonIcon::Icon(include_image!("icons/button-save.png")),
)?
.build(),
)?,

UiBlocks::OptionsButtonLabel => make_button_label_block(
txn,
"Options",
ButtonIcon::Icon(include_image!("icons/button-options.png")),
)?
.build(),
)?,

UiBlocks::MouselookButtonLabel => make_button_label_block(
txn,
"Mouselook",
ButtonIcon::Icon(include_image!("icons/button-mouselook.png")),
)?
.build(),
)?,

UiBlocks::FullscreenButtonLabel => make_button_label_block(
txn,
"Fullscreen",
ButtonIcon::Icon(include_image!("icons/button-fullscreen.png")),
)?
.build(),
)?,

UiBlocks::AntialiasButtonLabel => make_button_label_block(
txn,
"Antialiasing",
ButtonIcon::Icon(include_image!("icons/button-antialias.png")),
)?
.build(),
)?,

UiBlocks::DebugInfoTextButtonLabel => make_button_label_block(
txn,
"Debug: Info Text",
ButtonIcon::Icon(include_image!("icons/button-debug-info-text.png")),
)?
.build(),
)?,

UiBlocks::DebugChunkBoxesButtonLabel => make_button_label_block(
txn,
"Debug: Chunk Boxes",
ButtonIcon::Icon(include_image!("icons/button-debug-chunk-boxes.png")),
)?
.build(),
)?,

UiBlocks::DebugBehaviorsButtonLabel => make_button_label_block(
txn,
"Debug: Behaviors",
ButtonIcon::Icon(include_image!("icons/button-debug-behaviors.png")),
)?
.build(),
)?,

UiBlocks::DebugCollisionBoxesButtonLabel => make_button_label_block(
txn,
"Debug: Collision Boxes",
ButtonIcon::Icon(include_image!("icons/button-debug-collision-boxes.png")),
)?
.build(),
)?,

UiBlocks::DebugLightRaysButtonLabel => make_button_label_block(
txn,
"Debug: Light Rays at Cursor",
ButtonIcon::Icon(include_image!("icons/button-debug-light-rays.png")),
)?
.build(),
)?,
})
})
.await
Expand Down
Binary file added all-is-cubes-ui/src/vui/icons/button-help.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
64 changes: 25 additions & 39 deletions all-is-cubes-ui/src/vui/widgets/button.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,16 @@ use exhaust::Exhaust;
use all_is_cubes::arcstr::ArcStr;
use all_is_cubes::behavior::BehaviorSetTransaction;
use all_is_cubes::block::{
self,
builder::BlockBuilderVoxels,
Block, BlockBuilder,
self, Block, BlockBuilder,
Resolution::{self, *},
};
use all_is_cubes::color_block;
use all_is_cubes::content::load_image::{default_srgb, DecodedPng, PngAdapter};
use all_is_cubes::content::palette;
use all_is_cubes::drawing::embedded_graphics::{
image::Image as EgImage,
mono_font::{MonoFont, MonoTextStyle},
prelude::{Dimensions, PixelColor, Point, Size},
primitives::{Primitive, PrimitiveStyleBuilder, Rectangle, RoundedRectangle, StrokeAlignment},
text::{Alignment, Baseline, Text, TextStyleBuilder},
Drawable,
};
use all_is_cubes::drawing::{DrawingPlane, VoxelBrush};
Expand Down Expand Up @@ -490,7 +486,6 @@ pub(crate) fn draw_target_for_button_label<C: PixelColor>(

pub(crate) enum ButtonIcon<'a> {
Icon(&'a DecodedPng),
Text(&'a MonoFont<'a>, &'a str),
}

/// TODO: document, refine, and make public
Expand All @@ -499,41 +494,32 @@ pub(crate) fn make_button_label_block(
txn: &mut UniverseTransaction,
name: &str,
icon: ButtonIcon<'_>,
) -> Result<BlockBuilder<BlockBuilderVoxels, ()>, InGenError> {
let mut space = Space::builder(GridAab::from_lower_size(
[0, 0, 0],
[theme::RESOLUTION.into(), theme::RESOLUTION.into(), 1],
))
.physics(SpacePhysics::DEFAULT_FOR_BLOCK)
.build();
let mut draw_target = draw_target_for_button_label(&mut space);

match icon {
) -> Result<Block, InGenError> {
Ok(match icon {
ButtonIcon::Icon(icon) => {
let id = &PngAdapter::adapt(icon, &default_srgb);
EgImage::new(&id, -id.bounding_box().center() - Point::new(1, 1))
.draw(&mut draw_target)?;
}
ButtonIcon::Text(font, text) => {
Text::with_text_style(
text,
Point::new(-1, -1),
MonoTextStyle::new(
font,
&VoxelBrush::single(color_block!(palette::BUTTON_LABEL)),
),
TextStyleBuilder::new()
.baseline(Baseline::Middle)
.alignment(Alignment::Center)
.build(),
)
.draw(&mut draw_target)?;
let mut space = Space::builder(GridAab::from_lower_size(
[0, 0, 0],
[theme::RESOLUTION.into(), theme::RESOLUTION.into(), 1],
))
.physics(SpacePhysics::DEFAULT_FOR_BLOCK)
.build();

// TODO: replace this with space_from_image()
{
let mut draw_target = draw_target_for_button_label(&mut space);

let id = &PngAdapter::adapt(icon, &default_srgb);
EgImage::new(&id, -id.bounding_box().center() - Point::new(1, 1))
.draw(&mut draw_target)?;
}

let space = txn.insert_anonymous(space);
Block::builder()
.display_name(name.to_owned())
.voxels_handle(theme::RESOLUTION, space)
.build()
}
}
let space = txn.insert_anonymous(space);
Ok(Block::builder()
.display_name(name.to_owned())
.voxels_handle(theme::RESOLUTION, space))
})
}

/// Common constants for button shapes.
Expand Down
Binary file modified test-renderers/expected/ui/session_initial_state-all.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test-renderers/expected/ui/session_page_pause-all.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit af2835d

Please sign in to comment.