@@ -884,7 +884,7 @@ impl FirmwareUI for UIBolt {
884884 title,
885885 TString :: empty ( ) ,
886886 description,
887- button,
887+ ( ! button. is_empty ( ) ) . then_some ( button ) ,
888888 allow_cancel,
889889 time_ms,
890890 icon,
@@ -990,13 +990,17 @@ impl FirmwareUI for UIBolt {
990990 fn show_info (
991991 title : TString < ' static > ,
992992 description : TString < ' static > ,
993- button : TString < ' static > ,
993+ button : Option < ( TString < ' static > , bool ) > ,
994994 time_ms : u32 ,
995995 ) -> Result < Gc < LayoutObj > , Error > {
996- assert ! (
997- !button. is_empty( ) || time_ms > 0 ,
998- "either button or timeout must be set"
999- ) ;
996+ let button_text = match ( button, time_ms) {
997+ // either button or timeout must be set
998+ ( None , 0 ) => return Err ( Error :: NotImplementedError ) ,
999+ ( None , _) => None ,
1000+ // disabled buttons are not supported on Bolt
1001+ ( Some ( ( _, false ) ) , _) => return Err ( Error :: NotImplementedError ) ,
1002+ ( Some ( ( text, true ) ) , _) => Some ( text) ,
1003+ } ;
10001004
10011005 let icon = BlendedImage :: new (
10021006 theme:: IMAGE_BG_CIRCLE ,
@@ -1009,7 +1013,7 @@ impl FirmwareUI for UIBolt {
10091013 title,
10101014 TString :: empty ( ) ,
10111015 description,
1012- button ,
1016+ button_text ,
10131017 false ,
10141018 time_ms,
10151019 icon,
@@ -1247,7 +1251,7 @@ impl FirmwareUI for UIBolt {
12471251 title,
12481252 TString :: empty ( ) ,
12491253 description,
1250- button,
1254+ ( ! button. is_empty ( ) ) . then_some ( button ) ,
12511255 allow_cancel,
12521256 time_ms,
12531257 icon,
@@ -1280,7 +1284,7 @@ impl FirmwareUI for UIBolt {
12801284 title,
12811285 value,
12821286 description,
1283- button,
1287+ ( ! button. is_empty ( ) ) . then_some ( button ) ,
12841288 allow_cancel,
12851289 0 ,
12861290 icon,
@@ -1302,62 +1306,70 @@ fn new_show_modal(
13021306 title : TString < ' static > ,
13031307 value : TString < ' static > ,
13041308 description : TString < ' static > ,
1305- button : TString < ' static > ,
1309+ button : Option < TString < ' static > > ,
13061310 allow_cancel : bool ,
13071311 time_ms : u32 ,
13081312 icon : BlendedImage ,
13091313 button_style : ButtonStyleSheet ,
13101314) -> Result < Gc < LayoutObj > , Error > {
1311- let no_buttons = button. is_empty ( ) ;
1312- let obj = if no_buttons && time_ms == 0 {
1313- // No buttons and no timer, used when we only want to draw the dialog once and
1314- // then throw away the layout object.
1315- LayoutObj :: new (
1316- IconDialog :: new ( icon, title, Empty )
1317- . with_value ( value)
1318- . with_description ( description) ,
1319- ) ?
1320- } else if no_buttons && time_ms > 0 {
1321- // Timeout, no buttons.
1322- LayoutObj :: new (
1323- IconDialog :: new (
1324- icon,
1325- title,
1326- Timeout :: new ( time_ms) . map ( |_| Some ( CancelConfirmMsg :: Confirmed ) ) ,
1327- )
1328- . with_value ( value)
1329- . with_description ( description) ,
1330- ) ?
1331- } else if allow_cancel {
1332- // Two buttons.
1333- LayoutObj :: new (
1334- IconDialog :: new (
1335- icon,
1336- title,
1337- Button :: cancel_confirm (
1338- Button :: with_icon ( theme:: ICON_CANCEL ) ,
1339- Button :: with_text ( button) . styled ( button_style) ,
1340- false ,
1341- ) ,
1342- )
1343- . with_value ( value)
1344- . with_description ( description) ,
1345- ) ?
1346- } else {
1347- // Single button.
1348- LayoutObj :: new (
1349- IconDialog :: new (
1350- icon,
1351- title,
1352- theme:: button_bar ( Button :: with_text ( button) . styled ( button_style) . map ( |msg| {
1353- ( matches ! ( msg, ButtonMsg :: Clicked ) ) . then ( || CancelConfirmMsg :: Confirmed )
1354- } ) ) ,
1355- )
1356- . with_value ( value)
1357- . with_description ( description) ,
1358- ) ?
1315+ let obj = match button {
1316+ None => {
1317+ if time_ms == 0 {
1318+ // No buttons and no timer, used when we only want to draw the dialog once and
1319+ // then throw away the layout object.
1320+ LayoutObj :: new (
1321+ IconDialog :: new ( icon, title, Empty )
1322+ . with_value ( value)
1323+ . with_description ( description) ,
1324+ ) ?
1325+ } else {
1326+ // Timeout, no buttons.
1327+ LayoutObj :: new (
1328+ IconDialog :: new (
1329+ icon,
1330+ title,
1331+ Timeout :: new ( time_ms) . map ( |_| Some ( CancelConfirmMsg :: Confirmed ) ) ,
1332+ )
1333+ . with_value ( value)
1334+ . with_description ( description) ,
1335+ ) ?
1336+ }
1337+ }
1338+ Some ( button) => {
1339+ if allow_cancel {
1340+ // Two buttons.
1341+ LayoutObj :: new (
1342+ IconDialog :: new (
1343+ icon,
1344+ title,
1345+ Button :: cancel_confirm (
1346+ Button :: with_icon ( theme:: ICON_CANCEL ) ,
1347+ Button :: with_text ( button) . styled ( button_style) ,
1348+ false ,
1349+ ) ,
1350+ )
1351+ . with_value ( value)
1352+ . with_description ( description) ,
1353+ ) ?
1354+ } else {
1355+ // Single button.
1356+ LayoutObj :: new (
1357+ IconDialog :: new (
1358+ icon,
1359+ title,
1360+ theme:: button_bar ( Button :: with_text ( button) . styled ( button_style) . map (
1361+ |msg| {
1362+ ( matches ! ( msg, ButtonMsg :: Clicked ) )
1363+ . then ( || CancelConfirmMsg :: Confirmed )
1364+ } ,
1365+ ) ) ,
1366+ )
1367+ . with_value ( value)
1368+ . with_description ( description) ,
1369+ ) ?
1370+ }
1371+ }
13591372 } ;
1360-
13611373 Ok ( obj)
13621374}
13631375
0 commit comments