-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This will assist with diagnosing mysterious misalignment and margins.
- Loading branch information
Showing
6 changed files
with
113 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
use all_is_cubes::math::GridAab; | ||
use alloc::sync::Arc; | ||
|
||
use all_is_cubes::block::{self, text, Block, Resolution::R64}; | ||
use all_is_cubes::space::{CubeTransaction, SpaceTransaction}; | ||
use all_is_cubes::util::{ConciseDebug, Refmt}; | ||
|
||
use crate::vui::widgets::WidgetTheme; | ||
use crate::vui::{self, Layoutable as _}; | ||
|
||
/// Widget that uses another widget's [`Layoutable`] parameters, but instead of displaying that | ||
/// widget, displays a bounding box of the area it's granted, and data as text. | ||
#[derive(Debug)] | ||
#[doc(hidden)] // experimental | ||
pub struct LayoutDebugFrame { | ||
theme: WidgetTheme, | ||
widget: Arc<dyn vui::Widget>, | ||
} | ||
|
||
impl LayoutDebugFrame { | ||
pub fn new(theme: WidgetTheme, widget: Arc<dyn vui::Widget>) -> Arc<Self> { | ||
Arc::new(Self { theme, widget }) | ||
} | ||
} | ||
|
||
impl vui::Layoutable for LayoutDebugFrame { | ||
fn requirements(&self) -> vui::LayoutRequest { | ||
self.widget.requirements() | ||
} | ||
} | ||
|
||
impl vui::Widget for LayoutDebugFrame { | ||
fn controller(self: Arc<Self>, grant: &vui::LayoutGrant) -> Box<dyn vui::WidgetController> { | ||
let box_style = &self.theme.layout_debug_box_style; | ||
let bounds = grant.bounds; | ||
|
||
let mut info_text = text::Text::new( | ||
all_is_cubes::arcstr::format!( | ||
"Req {:?}\nGrant {:?}\nGrav {:?}", | ||
self.requirements().refmt(&ConciseDebug), | ||
grant.bounds, | ||
grant.gravity.to_array(), | ||
), | ||
text::Font::System16, | ||
text::Positioning { | ||
x: text::PositioningX::Left, | ||
line_y: text::PositioningY::BodyMiddle, | ||
z: text::PositioningZ::Front, | ||
}, | ||
); | ||
info_text.set_layout_bounds(R64, GridAab::for_block(R64)); | ||
|
||
super::OneshotController::new(SpaceTransaction::filling(bounds, |cube| { | ||
// not bothering to skip outside text bounds. | ||
let text_block = Block::from_primitive(block::Primitive::Text { | ||
text: info_text.clone(), | ||
offset: cube.lower_bounds() - bounds.lower_bounds(), | ||
}); | ||
let block: Block = if let Some(box_block) = box_style.cube_at(bounds, cube).cloned() { | ||
block::Composite::new(text_block, block::CompositeOperator::Over) | ||
.compose_or_replace(box_block) | ||
} else { | ||
text_block | ||
}; | ||
CubeTransaction::replacing(None, Some(block)) | ||
})) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.