Skip to content

Commit a90f680

Browse files
TEXT: optimizing display of small texts by using title instead of rendering
1 parent 635f363 commit a90f680

File tree

1 file changed

+29
-14
lines changed

1 file changed

+29
-14
lines changed

Sources/MyStreamDeckPlugin.m

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -365,21 +365,36 @@ - (void)keyUpForAction:(NSString *)action withContext:(id)context withPayload:(N
365365
[_connectionManager setTitle:secureTitle withContext:context withTarget:kESDSDKTarget_HardwareAndSoftware];
366366
}
367367
else {
368-
// In case the button was used for a secure entry before, we must make sure we clear the title
369-
[_connectionManager setTitle:@"" withContext:context withTarget:kESDSDKTarget_HardwareAndSoftware];
368+
NSString * textToDisplay = _tileText[ keyFromCoord(payload[@"coordinates"]) ];
370369

371-
// Defining everything as image (background + text)
372-
NSString *backgroundWithText64 = CreateBase64EncodedString(ComposeImage(@"postit-empty@2x.png", _tileText[ keyFromCoord(payload[@"coordinates"]) ], thisColor));
373-
374-
[_connectionManager setImage:backgroundWithText64 withContext:context withTarget:kESDSDKTarget_HardwareAndSoftware];
375-
376-
// THE FOLLOWING WOULD HAVE BEEN A LOT SIMPLER IF ONLY THE SDK SUPPORTED TITLE WRAPPING...
377-
378-
// Changing the background for something simpler to display text over
379-
//[_connectionManager setImage:_base64PostitEmpty withContext:context withTarget:kESDSDKTarget_HardwareAndSoftware];
380-
381-
// Adding the text to the tile
382-
//[_connectionManager setTitle:_tileText[ keyFromCoord(payload[@"coordinates"]) ] withContext:context withTarget:kESDSDKTarget_HardwareAndSoftware];
370+
if (textToDisplay.length <= LINE_LENGTH) {
371+
// In this situation, we could render the text but it will look very small and the space mostly
372+
// empty, so it is safer to display it as a title (with the title text being set small enough)
373+
[_connectionManager setImage:_base64PostitEmpty withContext:context withTarget:kESDSDKTarget_HardwareAndSoftware];
374+
375+
[_connectionManager setTitle:textToDisplay withContext:context withTarget:kESDSDKTarget_HardwareAndSoftware];
376+
// When the SDK will allow, we should also set this as centered in the display and with
377+
// a font size between 8 and 10...
378+
379+
}
380+
else {
381+
// In case the button was used for a secure entry before, we must make sure we clear the title
382+
[_connectionManager setTitle:@"" withContext:context withTarget:kESDSDKTarget_HardwareAndSoftware];
383+
384+
// Defining everything as image (background + text)
385+
NSString *backgroundWithText64 = CreateBase64EncodedString(
386+
ComposeImage(@"postit-empty@2x.png", textToDisplay, thisColor));
387+
388+
[_connectionManager setImage:backgroundWithText64 withContext:context withTarget:kESDSDKTarget_HardwareAndSoftware];
389+
390+
// THE FOLLOWING WOULD HAVE BEEN A LOT SIMPLER IF ONLY THE SDK SUPPORTED TITLE WRAPPING...
391+
392+
// Changing the background for something simpler to display text over
393+
//[_connectionManager setImage:_base64PostitEmpty withContext:context withTarget:kESDSDKTarget_HardwareAndSoftware];
394+
395+
// Adding the text to the tile
396+
//[_connectionManager setTitle:_tileText[ keyFromCoord(payload[@"coordinates"]) ] withContext:context withTarget:kESDSDKTarget_HardwareAndSoftware];
397+
}
383398
}
384399
}
385400
else {

0 commit comments

Comments
 (0)