mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-12-23 06:48:16 +00:00
fix(core/rust/ui): respect DISABLE_ANIMATION
[no changelog]
This commit is contained in:
parent
75cee540a4
commit
1b4dff6275
@ -16,6 +16,7 @@ static void _librust_qstrs(void) {
|
||||
MP_QSTR_CONFIRMED;
|
||||
MP_QSTR_CANCELLED;
|
||||
MP_QSTR_INFO;
|
||||
MP_QSTR_disable_animation;
|
||||
MP_QSTR_confirm_action;
|
||||
MP_QSTR_confirm_blob;
|
||||
MP_QSTR_confirm_properties;
|
||||
|
@ -89,6 +89,10 @@ where
|
||||
self
|
||||
}
|
||||
|
||||
pub fn inner(&self) -> &T {
|
||||
&self.source
|
||||
}
|
||||
|
||||
pub fn inner_mut(&mut self) -> &mut T {
|
||||
&mut self.source
|
||||
}
|
||||
|
@ -6,10 +6,14 @@ use crate::{
|
||||
iter::{Iter, IterBuf},
|
||||
list::List,
|
||||
obj::Obj,
|
||||
util::try_or_raise,
|
||||
},
|
||||
ui::component::text::{
|
||||
paragraphs::{Paragraph, ParagraphSource, ParagraphStrType},
|
||||
TextStyle,
|
||||
ui::{
|
||||
component::text::{
|
||||
paragraphs::{Paragraph, ParagraphSource, ParagraphStrType},
|
||||
TextStyle,
|
||||
},
|
||||
util::set_animation_disabled,
|
||||
},
|
||||
};
|
||||
use cstr_core::cstr;
|
||||
@ -228,3 +232,11 @@ impl ParagraphStrType for StrBuffer {
|
||||
self.offset(chars)
|
||||
}
|
||||
}
|
||||
|
||||
pub extern "C" fn upy_disable_animation(disable: Obj) -> Obj {
|
||||
let block = || {
|
||||
set_animation_disabled(disable.try_into()?);
|
||||
Ok(Obj::const_none())
|
||||
};
|
||||
unsafe { try_or_raise(block) }
|
||||
}
|
||||
|
@ -13,6 +13,7 @@ use crate::{
|
||||
layout::{
|
||||
obj::{ComponentMsgObj, LayoutObj},
|
||||
result::{CANCELLED, CONFIRMED},
|
||||
util::upy_disable_animation,
|
||||
},
|
||||
},
|
||||
};
|
||||
@ -116,6 +117,10 @@ pub static mp_module_trezorui2: Module = obj_module! {
|
||||
/// CANCELLED: object
|
||||
Qstr::MP_QSTR_CANCELLED => CANCELLED.as_obj(),
|
||||
|
||||
/// def disable_animation(disable: bool) -> None:
|
||||
/// """Disable animations, debug builds only."""
|
||||
Qstr::MP_QSTR_disable_animation => obj_fn_1!(upy_disable_animation).as_obj(),
|
||||
|
||||
/// def confirm_action(
|
||||
/// *,
|
||||
/// title: str,
|
||||
|
@ -13,6 +13,7 @@ use crate::{
|
||||
layout::{
|
||||
obj::{ComponentMsgObj, LayoutObj},
|
||||
result::{CANCELLED, CONFIRMED},
|
||||
util::upy_disable_animation,
|
||||
},
|
||||
},
|
||||
};
|
||||
@ -116,6 +117,10 @@ pub static mp_module_trezorui2: Module = obj_module! {
|
||||
/// CANCELLED: object
|
||||
Qstr::MP_QSTR_CANCELLED => CANCELLED.as_obj(),
|
||||
|
||||
/// def disable_animation(disable: bool) -> None:
|
||||
/// """Disable animations, debug builds only."""
|
||||
Qstr::MP_QSTR_disable_animation => obj_fn_1!(upy_disable_animation).as_obj(),
|
||||
|
||||
/// def confirm_action(
|
||||
/// *,
|
||||
/// title: str,
|
||||
|
@ -3,6 +3,7 @@ use crate::{
|
||||
ui::{
|
||||
component::{Child, Component, ComponentExt, Event, EventCtx, FixedHeightBar, Pad},
|
||||
geometry::{Grid, Insets, Rect},
|
||||
util::animation_disabled,
|
||||
},
|
||||
};
|
||||
|
||||
@ -220,7 +221,7 @@ where
|
||||
loader.start_shrinking(ctx, now);
|
||||
}
|
||||
Some(ButtonMsg::Clicked) => {
|
||||
if loader.is_completely_grown(now) {
|
||||
if loader.is_completely_grown(now) || animation_disabled() {
|
||||
return true;
|
||||
} else {
|
||||
loader.start_shrinking(ctx, now);
|
||||
|
@ -6,6 +6,7 @@ use crate::{
|
||||
display::{self, Color},
|
||||
geometry::{Offset, Rect},
|
||||
model_tt::constant,
|
||||
util::animation_disabled,
|
||||
},
|
||||
};
|
||||
|
||||
@ -131,7 +132,9 @@ impl Component for Loader {
|
||||
if let Event::Timer(EventCtx::ANIM_FRAME_TIMER) = event {
|
||||
if self.is_animating() {
|
||||
// We have something to paint, so request to be painted in the next pass.
|
||||
ctx.request_paint();
|
||||
if !animation_disabled() {
|
||||
ctx.request_paint();
|
||||
}
|
||||
|
||||
if self.is_completely_grown(now) {
|
||||
return Some(LoaderMsg::GrownCompletely);
|
||||
|
@ -32,7 +32,9 @@ use crate::{
|
||||
layout::{
|
||||
obj::{ComponentMsgObj, LayoutObj},
|
||||
result::{CANCELLED, CONFIRMED, INFO},
|
||||
util::{iter_into_array, iter_into_objs, ConfirmBlob, PropsList},
|
||||
util::{
|
||||
iter_into_array, iter_into_objs, upy_disable_animation, ConfirmBlob, PropsList,
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
@ -1175,6 +1177,10 @@ pub static mp_module_trezorui2: Module = obj_module! {
|
||||
/// INFO: object
|
||||
Qstr::MP_QSTR_INFO => INFO.as_obj(),
|
||||
|
||||
/// def disable_animation(disable: bool) -> None:
|
||||
/// """Disable animations, debug builds only."""
|
||||
Qstr::MP_QSTR_disable_animation => obj_fn_1!(upy_disable_animation).as_obj(),
|
||||
|
||||
/// def confirm_action(
|
||||
/// *,
|
||||
/// title: str,
|
||||
|
@ -31,6 +31,30 @@ pub fn u32_to_str(num: u32, buffer: &mut [u8]) -> Option<&str> {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "ui_debug")]
|
||||
static mut DISABLE_ANIMATION: bool = false;
|
||||
|
||||
#[cfg(feature = "ui_debug")]
|
||||
pub fn animation_disabled() -> bool {
|
||||
// SAFETY: single-threaded access
|
||||
unsafe { DISABLE_ANIMATION }
|
||||
}
|
||||
|
||||
#[cfg(feature = "ui_debug")]
|
||||
pub fn set_animation_disabled(disabled: bool) {
|
||||
// SAFETY: single-threaded access
|
||||
unsafe {
|
||||
DISABLE_ANIMATION = disabled;
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "ui_debug"))]
|
||||
pub fn animation_disabled() -> bool {
|
||||
false
|
||||
}
|
||||
#[cfg(not(feature = "ui_debug"))]
|
||||
pub fn set_animation_disabled(_disabled: bool) {}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
@ -3,6 +3,11 @@ CONFIRMED: object
|
||||
CANCELLED: object
|
||||
|
||||
|
||||
# rust/src/ui/model_t1/layout.rs
|
||||
def disable_animation(disable: bool) -> None:
|
||||
"""Disable animations, debug builds only."""
|
||||
|
||||
|
||||
# rust/src/ui/model_t1/layout.rs
|
||||
def confirm_action(
|
||||
*,
|
||||
@ -29,6 +34,11 @@ CONFIRMED: object
|
||||
CANCELLED: object
|
||||
|
||||
|
||||
# rust/src/ui/model_tr/layout.rs
|
||||
def disable_animation(disable: bool) -> None:
|
||||
"""Disable animations, debug builds only."""
|
||||
|
||||
|
||||
# rust/src/ui/model_tr/layout.rs
|
||||
def confirm_action(
|
||||
*,
|
||||
@ -56,6 +66,11 @@ CANCELLED: object
|
||||
INFO: object
|
||||
|
||||
|
||||
# rust/src/ui/model_tt/layout.rs
|
||||
def disable_animation(disable: bool) -> None:
|
||||
"""Disable animations, debug builds only."""
|
||||
|
||||
|
||||
# rust/src/ui/model_tt/layout.rs
|
||||
def confirm_action(
|
||||
*,
|
||||
|
@ -2,6 +2,7 @@ from typing import TYPE_CHECKING, Sequence
|
||||
|
||||
from trezor import io, log, loop, ui, wire, workflow
|
||||
from trezor.enums import ButtonRequestType
|
||||
from trezor.utils import DISABLE_ANIMATION
|
||||
|
||||
import trezorui2
|
||||
|
||||
@ -14,6 +15,10 @@ if TYPE_CHECKING:
|
||||
ExceptionType = BaseException | Type[BaseException]
|
||||
|
||||
|
||||
if __debug__:
|
||||
trezorui2.disable_animation(bool(DISABLE_ANIMATION))
|
||||
|
||||
|
||||
class _RustLayout(ui.Layout):
|
||||
# pylint: disable=super-init-not-called
|
||||
def __init__(self, layout: Any):
|
||||
|
@ -24,6 +24,12 @@ CANCELLED = trezorui2.CANCELLED
|
||||
INFO = trezorui2.INFO
|
||||
|
||||
|
||||
if __debug__:
|
||||
from trezor.utils import DISABLE_ANIMATION
|
||||
|
||||
trezorui2.disable_animation(bool(DISABLE_ANIMATION))
|
||||
|
||||
|
||||
class _RustLayout(ui.Layout):
|
||||
# pylint: disable=super-init-not-called
|
||||
def __init__(self, layout: Any, is_backup: bool = False):
|
||||
|
Loading…
Reference in New Issue
Block a user