Skip to content

Commit

Permalink
ui: use Label widget for graphics options labels
Browse files Browse the repository at this point in the history
  • Loading branch information
kpreid committed Dec 4, 2023
1 parent eb1a1a7 commit 1791e75
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 37 deletions.
39 changes: 5 additions & 34 deletions all-is-cubes-ui/src/ui_content/options.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,11 @@
use alloc::sync::Arc;

use all_is_cubes::block;
use all_is_cubes::camera::{AntialiasingOption, GraphicsOptions};
use all_is_cubes::content::palette;
use all_is_cubes::drawing::embedded_graphics::{mono_font::iso_8859_1 as font, text::TextStyle};
use all_is_cubes::drawing::VoxelBrush;
use all_is_cubes::math::Face6;
use all_is_cubes::space::{SpaceBuilder, SpacePhysics};
use all_is_cubes::universe::{Name, URef};

use crate::apps::ControlMessage;
use crate::ui_content::hud::HudInputs;
use crate::vui::{self, widgets};
use crate::vui::{LayoutTree, UiBlocks, Widget, WidgetTree};
use crate::vui::{widgets, LayoutTree, UiBlocks, Widget, WidgetTree};

#[derive(Clone, Copy, Debug)]
pub(crate) enum OptionsStyle {
Expand Down Expand Up @@ -129,32 +122,10 @@ fn graphics_toggle_button(
OptionsStyle::CompactRow => LayoutTree::leaf(button),
OptionsStyle::LabeledColumn => Arc::new(LayoutTree::Stack {
direction: Face6::PX,
children: vec![LayoutTree::leaf(button), {
// TODO: extract this for general use and reconcile with pages::parts::shrink()
let text: WidgetTree = LayoutTree::leaf(Arc::new(widgets::LargeText {
text: text_label,
font: || &font::FONT_6X10,
brush: VoxelBrush::single(block::Block::from(palette::ALMOST_BLACK)),
text_style: TextStyle::default(),
}));
let space = text
.to_space(
SpaceBuilder::default().physics(SpacePhysics::DEFAULT_FOR_BLOCK),
vui::Gravity::new(vui::Align::Low, vui::Align::Center, vui::Align::Low),
)
.unwrap();
LayoutTree::leaf(Arc::new(widgets::Voxels::new(
space.bounds(),
// TODO: Using a pending ref is working only by accident here.
// The space is never actually inserted, so `Anonym(0)` is never
// rejected as it should be, and only this widget itself is keeping
// the space alive -- but we don't yet have the ability to ask for
// an anonymous pending ref and actually insert it.
URef::new_pending(Name::Anonym(0), space),
block::Resolution::R32,
block::BlockAttributes::default(),
)))
}],
children: vec![
LayoutTree::leaf(button),
LayoutTree::leaf(Arc::new(widgets::Label::new(text_label))),
],
}),
}
}
Expand Down
13 changes: 10 additions & 3 deletions all-is-cubes-ui/src/vui/widgets/text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use alloc::sync::Arc;

use all_is_cubes::arcstr::ArcStr;
use all_is_cubes::block::text::{self, Text as BlockText};
use all_is_cubes::block::Resolution::*;
use all_is_cubes::drawing::embedded_graphics::{
mono_font::{MonoFont, MonoTextStyle},
prelude::{Dimensions, Point},
Expand Down Expand Up @@ -131,7 +132,7 @@ impl Widget for Label {
}

fn text_for_widget(text: ArcStr, font: text::Font, gravity: vui::Gravity) -> text::Text {
text::Text::new(
let mut text = text::Text::new(
text,
font,
text::Positioning {
Expand All @@ -141,13 +142,19 @@ fn text_for_widget(text: ArcStr, font: text::Font, gravity: vui::Gravity) -> tex
vui::Align::High => text::PositioningX::Right,
},
// TODO: need to be able to set the anchor to produce middle-of-block
line_y: text::PositioningY::BodyBottom,
line_y: match gravity.y {
vui::Align::Low => text::PositioningY::BodyBottom,
vui::Align::Center => text::PositioningY::BodyMiddle,
vui::Align::High => text::PositioningY::BodyTop,
},
z: match gravity.z {
vui::Align::Low | vui::Align::Center => text::PositioningZ::Back,
vui::Align::High => text::PositioningZ::Front,
},
},
)
);
text.set_layout_bounds(R32, GridAab::for_block(R32));
text
}

fn draw_text_txn(text: &BlockText, grant: &LayoutGrant) -> SpaceTransaction {
Expand Down

0 comments on commit 1791e75

Please sign in to comment.