Add getLineY Layout helper function
This commit is contained in:
parent
0e33848d68
commit
765fb3f4c9
|
|
@ -223,6 +223,16 @@ void gfx_drawRect(point_t start, uint16_t width, uint16_t height, color_t color,
|
|||
*/
|
||||
void gfx_drawCircle(point_t start, uint16_t r, color_t color);
|
||||
|
||||
/**
|
||||
* Calculates printing position to fit a number of text lines on the screen space.
|
||||
* @param cur: current line number over total (1-based)
|
||||
* @param tot: number of lines to fit in screen
|
||||
* @param startY: starting Y coordinate to leave space for top bar
|
||||
* @param endY: ending Y coordinate to leave space for bottom bar
|
||||
* @return Y coordinates for text printing
|
||||
*/
|
||||
uint16_t gfx_getLineY(uint8_t cur, uint8_t tot, uint16_t startY, uint16_t endY);
|
||||
|
||||
/**
|
||||
* Prints text on the screen.
|
||||
* @param start: text line start point, in pixel coordinates.
|
||||
|
|
|
|||
|
|
@ -385,6 +385,13 @@ static inline uint16_t get_reset_x(textAlign_t alignment, uint16_t line_size,
|
|||
return 0;
|
||||
}
|
||||
|
||||
uint16_t gfx_getLineY(uint8_t cur, uint8_t tot, uint16_t startY, uint16_t endY)
|
||||
{
|
||||
// e.g. to print 2 lines we need 3 padding spaces
|
||||
uint16_t step = (endY - startY) / (tot + 1);
|
||||
return startY + (step * cur);
|
||||
}
|
||||
|
||||
point_t gfx_print(point_t start, fontSize_t size, textAlign_t alignment,
|
||||
color_t color, const char *fmt, ... )
|
||||
{
|
||||
|
|
|
|||
|
|
@ -0,0 +1,53 @@
|
|||
/***************************************************************************
|
||||
* Copyright (C) 2020 by Federico Izzo IU2NUO, Niccolò Izzo IU2KIN and *
|
||||
* Silvano Seva IU2KWO *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License as published by *
|
||||
* the Free Software Foundation; either version 3 of the License, or *
|
||||
* (at your option) any later version. *
|
||||
* *
|
||||
* This program is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* along with this program; if not, see <http://www.gnu.org/licenses/> *
|
||||
***************************************************************************/
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <interfaces/graphics.h>
|
||||
#include <interfaces/platform.h>
|
||||
#include <interfaces/delays.h>
|
||||
#include "ui.h"
|
||||
|
||||
|
||||
int main(void)
|
||||
{
|
||||
platform_init();
|
||||
// Init the graphic stack
|
||||
gfx_init();
|
||||
gfx_clearScreen();
|
||||
gfx_render();
|
||||
platform_setBacklightLevel(255);
|
||||
|
||||
while(1)
|
||||
{
|
||||
for(int tot=1; tot<=10; tot++)
|
||||
{
|
||||
gfx_clearScreen();
|
||||
for(int cur=1; cur<=tot; cur++)
|
||||
{
|
||||
uint16_t y = gfx_getLineY(cur, tot, 0, SCREEN_HEIGHT);
|
||||
point_t pos = {0, y};
|
||||
gfx_print(pos, FONT_SIZE_8PT, TEXT_ALIGN_CENTER,
|
||||
color_white, "Line %2d of %2d", cur, tot);
|
||||
}
|
||||
gfx_render();
|
||||
// Sleep for 1 second
|
||||
sleepFor(1u, 0u);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue