Hello,
Please find an initial example below that determines the size of a button based upon the size of characters used. You can use this as a starting point to add, for example, more error checking and optimise it further. We will fine tune it and add an accompanying readme before adding it to our Github examples, but in the meantime please give this one a try.
Best regards, BRT Community
/**
* (C) Copyright, Bridgetek Pte. Ltd.
* ============================================================================
*
* This source code ("the Software") is provided by Bridgetek Pte Ltd
* ("Bridgetek") subject to the licence terms set out
* http://www.ftdichip.com/FTSourceCodeLicenceTerms.htm ("the Licence Terms").
* You must read the Licence Terms before downloading or using the Software.
* By installing or using the Software you agree to the Licence Terms. If you
* do not agree to the Licence Terms then do not download or use the Software.
*
* Without prejudice to the Licence Terms, here is a summary of some of the key
* terms of the Licence Terms (and in the event of any conflict between this
* summary and the Licence Terms then the text of the Licence Terms will
* prevail).
*
* The Software is provided "as is".
* There are no warranties (or similar) in relation to the quality of the
* Software. You use it at your own risk.
* The Software should not be used in, or for, any medical device, system or
* appliance. There are exclusions of Bridgetek liability for certain types of loss
* such as: special loss or damage; incidental loss or damage; indirect or
* consequential loss or damage; loss of income; loss of business; loss of
* profits; loss of revenue; loss of contracts; business interruption; loss of
* the use of money or anticipated savings; loss of information; loss of
* opportunity; loss of goodwill or reputation; and/or loss of, damage to or
* corruption of data.
* There is a monetary cap on Bridgetek's liability.
* The Software may have subsequently been amended by another user and then
* distributed by that other user ("Adapted Software"). If so that user may
* have additional licence terms that apply to those amendments. However, Bridgetek
* has no liability in relation to those amendments.
* ============================================================================
*/
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include "EVE.h"
#include "../include/HAL.h"
#include "MCU.h"
#include "eve_example.h"
void eve_display(void)
{
#define FontNum 28
EVE_GPU_FONT_HEADER StdFont;
uint32_t FontByte;
uint16_t FontIndexCounter;
uint32_t FontTableAddress = 0;
uint32_t StringWidth = 0;
char ButtonText[100];
char letter;
int ButtonTextlength = 0;
uint8_t CharWidth = 0;
// -----------------------------------------------------------------------------------------------------------------------
// Get the character widths from the ROM font
// -----------------------------------------------------------------------------------------------------------------------
FontTableAddress = ((HAL_MemRead32(EVE_ROMFONT_TABLEADDRESS)) + ((FontNum - 16) * FT_GPU_FONT_TABLE_SIZE));
FontIndexCounter = 0;
while(FontIndexCounter < 128)
{
FontByte = HAL_MemRead8(FontTableAddress + FontIndexCounter);
StdFont.FontWidth[FontIndexCounter] = FontByte;
FontIndexCounter ++;
}
FontByte = HAL_MemRead32(FontTableAddress + FontIndexCounter);
StdFont.FontBitmapFormat = FontByte;
FontIndexCounter = FontIndexCounter + 4;
FontByte = HAL_MemRead32(FontTableAddress + FontIndexCounter);
StdFont.FontLineStride = FontByte;
FontIndexCounter = FontIndexCounter + 4;
FontByte = HAL_MemRead32(FontTableAddress + FontIndexCounter);
StdFont.FontWidthInPixels = FontByte;
FontIndexCounter = FontIndexCounter + 4;
FontByte = HAL_MemRead32(FontTableAddress + FontIndexCounter);
StdFont.FontHeightInPixels = FontByte;
FontIndexCounter = FontIndexCounter + 4;
FontByte = HAL_MemRead32(FontTableAddress + FontIndexCounter);
StdFont.PointerToFontGraphicsData = FontByte;
// -----------------------------------------------------------------------------------------------------------------------
// Set the string for the button and determine the length as a sum of the widths of individual characters
// -----------------------------------------------------------------------------------------------------------------------
sprintf(ButtonText, "Hello 12345 abcde"); // Text to go in the button
ButtonTextlength = strlen(ButtonText); // get the length of the string
// For each letter, get the character width and add them up
uint8_t i = 0;
for (i = 0; i < ButtonTextlength; i++)
{
letter = ButtonText[i];
CharWidth = StdFont.FontWidth[letter];
StringWidth += (uint32_t)(CharWidth);
}
// -----------------------------------------------------------------------------------------------------------------------
// Draw the button
// -----------------------------------------------------------------------------------------------------------------------
// Write the text Hello and also calculate what width it is based on the characters
EVE_LIB_BeginCoProList(); // Begin co-processor commands
EVE_CMD_DLSTART(); // New display list
EVE_CLEAR_COLOR_RGB(0, 0, 0); // Clear screen to black
EVE_CLEAR(1,1,1); // Clear
EVE_COLOR_RGB(255,255,255); // White color for text
EVE_CMD_BUTTON(100, 100, (StringWidth + 20), 40, FontNum, 0, ButtonText); // Button
EVE_CMD_NUMBER(100, 200, FontNum, 0, StringWidth); // Print the length of the text
EVE_DISPLAY(); // Finish the display list
EVE_CMD_SWAP(); // Swap to make the list active
EVE_LIB_EndCoProList(); // Finish the list of commands
EVE_LIB_AwaitCoProEmpty(); // And wait until complete
while(1)
{
}
}
void eve_example(void)
{
EVE_Init();
eve_display();
}