1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-12-26 16:18:22 +00:00

fix(core/rust/ui): add cargo flag for Component::bounds() support

Rarely used debugging feature.

[no changelog]
This commit is contained in:
Martin Milata 2023-03-21 23:32:43 +01:00
parent afe965687f
commit e60ed788f2
33 changed files with 49 additions and 3 deletions

View File

@ -15,6 +15,7 @@ protobuf = ["micropython"]
ui = []
dma2d = []
ui_debug = []
ui_bounds = []
bootloader = []
buttons = []
touch = []

View File

@ -54,6 +54,7 @@ pub trait Component {
/// the `Child` wrapper.
fn paint(&mut self);
#[cfg(feature = "ui_bounds")]
/// Report current paint bounds of this component. Used for debugging.
fn bounds(&self, _sink: &mut dyn FnMut(Rect)) {}
}
@ -146,6 +147,7 @@ where
}
}
#[cfg(feature = "ui_bounds")]
fn bounds(&self, sink: &mut dyn FnMut(Rect)) {
self.component.bounds(sink)
}
@ -199,6 +201,7 @@ where
self.1.paint();
}
#[cfg(feature = "ui_bounds")]
fn bounds(&self, sink: &mut dyn FnMut(Rect)) {
self.0.bounds(sink);
self.1.bounds(sink);
@ -249,6 +252,7 @@ where
self.2.paint();
}
#[cfg(feature = "ui_bounds")]
fn bounds(&self, sink: &mut dyn FnMut(Rect)) {
self.0.bounds(sink);
self.1.bounds(sink);
@ -301,6 +305,7 @@ where
}
}
#[cfg(feature = "ui_bounds")]
fn bounds(&self, sink: &mut dyn FnMut(Rect)) {
if let Some(ref c) = self {
c.bounds(sink)

View File

@ -39,6 +39,7 @@ where
self.inner.paint()
}
#[cfg(feature = "ui_bounds")]
fn bounds(&self, sink: &mut dyn FnMut(Rect)) {
self.inner.bounds(sink);
}

View File

@ -48,6 +48,7 @@ impl Component for Image {
self.draw(self.area.center(), CENTER);
}
#[cfg(feature = "ui_bounds")]
fn bounds(&self, sink: &mut dyn FnMut(Rect)) {
sink(Rect::from_center_and_size(
self.area.center(),
@ -123,6 +124,7 @@ impl Component for BlendedImage {
self.paint_image();
}
#[cfg(feature = "ui_bounds")]
fn bounds(&self, sink: &mut dyn FnMut(Rect)) {
sink(Rect::from_top_left_and_size(
self.bg_top_left,

View File

@ -80,6 +80,7 @@ where
self.layout.render_text(self.text.as_ref());
}
#[cfg(feature = "ui_bounds")]
fn bounds(&self, sink: &mut dyn FnMut(Rect)) {
sink(self.layout.bounds)
}

View File

@ -31,6 +31,7 @@ where
self.inner.paint()
}
#[cfg(feature = "ui_bounds")]
fn bounds(&self, sink: &mut dyn FnMut(Rect)) {
self.inner.bounds(sink);
}

View File

@ -93,6 +93,7 @@ where
}
}
#[cfg(feature = "ui_bounds")]
fn bounds(&self, sink: &mut dyn FnMut(Rect)) {
sink(self.pad.area);
self.inner.bounds(sink);

View File

@ -39,6 +39,7 @@ where
(self.func)(self.area);
}
#[cfg(feature = "ui_bounds")]
fn bounds(&self, sink: &mut dyn FnMut(Rect)) {
sink(self.area)
}

View File

@ -141,6 +141,7 @@ impl Component for Qr {
Self::draw(&qr, area, self.border, scale);
}
#[cfg(feature = "ui_bounds")]
fn bounds(&self, sink: &mut dyn FnMut(Rect)) {
sink(self.area)
}

View File

@ -138,6 +138,7 @@ where
self.layout_content(&mut TextRenderer);
}
#[cfg(feature = "ui_bounds")]
fn bounds(&self, sink: &mut dyn FnMut(Rect)) {
sink(self.layout.bounds)
}

View File

@ -201,6 +201,7 @@ where
)
}
#[cfg(feature = "ui_bounds")]
fn bounds(&self, sink: &mut dyn FnMut(Rect)) {
sink(self.area);
for layout in &self.visible {
@ -595,6 +596,7 @@ where
}
}
#[cfg(feature = "ui_bounds")]
fn bounds(&self, sink: &mut dyn FnMut(Rect)) {
sink(self.area);
self.paragraphs.bounds(sink);

View File

@ -64,7 +64,7 @@ pub trait ObjComponent: MaybeTrace {
fn obj_place(&mut self, bounds: Rect) -> Rect;
fn obj_event(&mut self, ctx: &mut EventCtx, event: Event) -> Result<Obj, Error>;
fn obj_paint(&mut self) -> bool;
fn obj_bounds(&self, sink: &mut dyn FnMut(Rect));
fn obj_bounds(&self, _sink: &mut dyn FnMut(Rect)) {}
fn obj_skip_paint(&mut self) {}
}
@ -90,6 +90,7 @@ where
will_paint
}
#[cfg(feature = "ui_bounds")]
fn obj_bounds(&self, sink: &mut dyn FnMut(Rect)) {
self.bounds(sink)
}
@ -509,7 +510,7 @@ extern "C" fn ui_layout_trace(_this: Obj, _callback: Obj) -> Obj {
Obj::const_none()
}
#[cfg(feature = "ui_debug")]
#[cfg(feature = "ui_bounds")]
extern "C" fn ui_layout_bounds(this: Obj) -> Obj {
let block = || {
let this: Gc<LayoutObj> = this.try_into()?;
@ -519,7 +520,7 @@ extern "C" fn ui_layout_bounds(this: Obj) -> Obj {
unsafe { util::try_or_raise(block) }
}
#[cfg(not(feature = "ui_debug"))]
#[cfg(not(feature = "ui_bounds"))]
extern "C" fn ui_layout_bounds(_this: Obj) -> Obj {
Obj::const_none()
}

View File

@ -188,6 +188,7 @@ impl<'a> Component for Confirm<'a> {
}
}
#[cfg(feature = "ui_bounds")]
fn bounds(&self, sink: &mut dyn FnMut(Rect)) {
self.left.bounds(sink);
self.right.bounds(sink);

View File

@ -94,6 +94,7 @@ impl<'a> Component for Intro<'a> {
self.menu.paint();
}
#[cfg(feature = "ui_bounds")]
fn bounds(&self, sink: &mut dyn FnMut(Rect)) {
self.menu.bounds(sink);
}

View File

@ -98,6 +98,7 @@ impl Component for Menu {
self.reset.paint();
}
#[cfg(feature = "ui_bounds")]
fn bounds(&self, sink: &mut dyn FnMut(Rect)) {
self.close.bounds(sink);
self.reboot.bounds(sink);

View File

@ -181,6 +181,7 @@ where
}
}
#[cfg(feature = "ui_bounds")]
fn bounds(&self, sink: &mut dyn FnMut(Rect)) {
match self.current_page {
0 => self.qr_code.bounds(sink),

View File

@ -314,6 +314,7 @@ where
self.paint_content(style);
}
#[cfg(feature = "ui_bounds")]
fn bounds(&self, sink: &mut dyn FnMut(Rect)) {
sink(self.area);
}

View File

@ -71,6 +71,7 @@ where
self.controls.paint();
}
#[cfg(feature = "ui_bounds")]
fn bounds(&self, sink: &mut dyn FnMut(Rect)) {
self.content.bounds(sink);
self.controls.bounds(sink);
@ -192,6 +193,7 @@ where
self.controls.paint();
}
#[cfg(feature = "ui_bounds")]
fn bounds(&self, sink: &mut dyn FnMut(Rect)) {
self.image.bounds(sink);
self.paragraphs.bounds(sink);

View File

@ -191,6 +191,7 @@ where
}
}
#[cfg(feature = "ui_bounds")]
fn bounds(&self, sink: &mut dyn FnMut(Rect)) {
self.icon.bounds(sink);
self.app_name.bounds(sink);

View File

@ -152,6 +152,7 @@ where
self.content.paint();
}
#[cfg(feature = "ui_bounds")]
fn bounds(&self, sink: &mut dyn FnMut(Rect)) {
self.title.bounds(sink);
self.button.bounds(sink);
@ -242,6 +243,7 @@ where
self.content.paint();
}
#[cfg(feature = "ui_bounds")]
fn bounds(&self, sink: &mut dyn FnMut(Rect)) {
sink(self.area);
self.content.bounds(sink);

View File

@ -91,6 +91,7 @@ where
self.buttons.paint();
}
#[cfg(feature = "ui_bounds")]
fn bounds(&self, sink: &mut dyn FnMut(Rect)) {
sink(self.pad.area);
if self.loader.is_animating() {
@ -171,6 +172,7 @@ impl Component for CancelHold {
self.hold.paint();
}
#[cfg(feature = "ui_bounds")]
fn bounds(&self, sink: &mut dyn FnMut(Rect)) {
self.cancel.bounds(sink);
self.hold.bounds(sink);

View File

@ -212,6 +212,7 @@ where
}
}
#[cfg(feature = "ui_bounds")]
fn bounds(&self, sink: &mut dyn FnMut(Rect)) {
self.loader.bounds(sink);
sink(self.pad.area);

View File

@ -124,6 +124,7 @@ where
}
}
#[cfg(feature = "ui_bounds")]
fn bounds(&self, sink: &mut dyn FnMut(Rect)) {
sink(self.pad.area);
self.scrollbar.bounds(sink);

View File

@ -144,6 +144,7 @@ impl Component for Bip39Input {
}
}
#[cfg(feature = "ui_bounds")]
fn bounds(&self, sink: &mut dyn FnMut(Rect)) {
self.button.bounds(sink);
}

View File

@ -163,6 +163,7 @@ where
}
}
#[cfg(feature = "ui_bounds")]
fn bounds(&self, sink: &mut dyn FnMut(Rect)) {
self.prompt.bounds(sink);
self.input.bounds(sink);

View File

@ -264,6 +264,7 @@ impl Component for PassphraseKeyboard {
}
}
#[cfg(feature = "ui_bounds")]
fn bounds(&self, sink: &mut dyn FnMut(Rect)) {
self.input.bounds(sink);
self.scrollbar.bounds(sink);
@ -367,6 +368,7 @@ impl Component for Input {
}
}
#[cfg(feature = "ui_bounds")]
fn bounds(&self, sink: &mut dyn FnMut(Rect)) {
sink(self.area)
}

View File

@ -270,6 +270,7 @@ where
}
}
#[cfg(feature = "ui_bounds")]
fn bounds(&self, sink: &mut dyn FnMut(Rect)) {
self.major_prompt.bounds(sink);
self.minor_prompt.bounds(sink);
@ -454,6 +455,7 @@ impl Component for PinDots {
}
}
#[cfg(feature = "ui_bounds")]
fn bounds(&self, sink: &mut dyn FnMut(Rect)) {
sink(self.area);
sink(self.area.inset(HEADER_PADDING));

View File

@ -178,6 +178,7 @@ impl Component for Slip39Input {
}
}
#[cfg(feature = "ui_bounds")]
fn bounds(&self, sink: &mut dyn FnMut(Rect)) {
self.button.bounds(sink);
}

View File

@ -57,6 +57,7 @@ impl Component for SelectWordCount {
}
}
#[cfg(feature = "ui_bounds")]
fn bounds(&self, sink: &mut dyn FnMut(Rect)) {
for btn in self.button.iter() {
btn.bounds(sink)

View File

@ -118,6 +118,7 @@ where
self.confirm_button.paint();
}
#[cfg(feature = "ui_bounds")]
fn bounds(&self, sink: &mut dyn FnMut(Rect)) {
sink(self.area);
self.input.bounds(sink);
@ -226,6 +227,7 @@ impl Component for NumberInput {
self.inc.paint();
}
#[cfg(feature = "ui_bounds")]
fn bounds(&self, sink: &mut dyn FnMut(Rect)) {
self.dec.bounds(sink);
self.inc.bounds(sink);

View File

@ -279,6 +279,7 @@ where
}
}
#[cfg(feature = "ui_bounds")]
fn bounds(&self, sink: &mut dyn FnMut(Rect)) {
sink(self.pad.area);
self.scrollbar.bounds(sink);
@ -458,6 +459,7 @@ where
}
}
#[cfg(feature = "ui_bounds")]
fn bounds(&self, sink: &mut dyn FnMut(Rect)) {
self.loader.bounds(sink);
self.inner.bounds(sink);

View File

@ -119,6 +119,7 @@ where
self.description.paint();
}
#[cfg(feature = "ui_bounds")]
fn bounds(&self, sink: &mut dyn FnMut(Rect)) {
sink(Self::AREA);
self.title.bounds(sink);

View File

@ -120,6 +120,7 @@ impl Component for ScrollBar {
bounds
}
#[cfg(feature = "ui_bounds")]
fn bounds(&self, sink: &mut dyn FnMut(Rect)) {
sink(self.area);
}