draw first meeting

This commit is contained in:
stubbfelnewpc
2020-05-14 20:06:50 +02:00
parent 443f999d77
commit 6d818b51ee
5 changed files with 94 additions and 41 deletions

View File

@@ -41,7 +41,7 @@ PositionalProperties StackPanel::draw(const PositionalProperties & positionals)
};
for(auto i = 0; i < itmes.size; i++) {
auto callback = itmes.callbacks[i];
auto & callback = itmes.callbacks[i];
auto last = callback(inner);
inner = move(inner, last);
}

View File

@@ -5,6 +5,7 @@
#include "Color_t.hpp"
#include "PositionalProperties_t.hpp"
#include <functional>
//namespace myink { namespace ui {
class StackPanel;
@@ -13,7 +14,7 @@
typedef size_t LineWidth;
typedef size_t Margin;
typedef size_t Padding;
typedef PositionalProperties(*DrawItemCallBack)(const PositionalProperties &);
using DrawItemCallBack = std::function<PositionalProperties(const PositionalProperties &)>;
typedef struct DrawItemCallBackList_t
{
size_t size;

View File

@@ -5,6 +5,7 @@
//namespace myink { namespace ui {
PositionalProperties Paint_DrawString(UWORD Xstart, UWORD Ystart, const char * pString, sFONT* Font, UWORD Color_Foreground, UWORD Color_Background);
TextBlock::TextBlock(const char * t, const TextBlockStyleProperties & s): text(t), style(s)
{
@@ -17,8 +18,51 @@ TextBlock::~TextBlock()
PositionalProperties TextBlock::draw(const PositionalProperties & p)
{
auto font = style.font;
Paint_DrawString_EN(p.left, p.top, text, &font, style.background_color, style.font_color);
return { p.left, p.top, strlen(text) * font.Width, font.Height};
return Paint_DrawString(p.left, p.top, text, &font, style.background_color, style.font_color);
}
PositionalProperties Paint_DrawString(UWORD Xstart, UWORD Ystart, const char * pString,
sFONT* Font, UWORD Color_Foreground, UWORD Color_Background)
{
UWORD Xpoint = Xstart;
UWORD max_x_pos = Xstart;
UWORD max_y_pos = Ystart + Font->Height;
UWORD Ypoint = Ystart;
while (* pString != '\0') {
//if X direction filled , reposition to(Xstart,Ypoint),Ypoint is Y direction plus the Height of the character
if (*pString == '\n'|| (Xpoint + Font->Width ) > Paint.Width ) {
Xpoint = Xstart;
Ypoint += Font->Height;
if(Ypoint >= max_y_pos) {
max_y_pos = Ypoint + Font->Height;
}
if (*pString == '\n')
{
pString++;
}
}
// If the Y direction is full, reposition to(Xstart, Ystart)
if ((Ypoint + Font->Height ) > Paint.Height ) {
Xpoint = Xstart;
Ypoint = Ystart;
}
Paint_DrawChar(Xpoint, Ypoint, * pString, Font, Color_Background, Color_Foreground);
//The next character of the address
pString ++;
//The next word of the abscissa increases the font of the broadband
Xpoint += Font->Width;
if(Xpoint > max_x_pos) {
max_x_pos = Xpoint;
}
}
return{Xstart, Ystart, max_x_pos - Xstart, (max_y_pos - Ystart)};
}
//}}

View File

@@ -12,7 +12,7 @@
{
Color background_color;
Color font_color;
sFONT & font;
const sFONT & font;
} TextBlockStyleProperties, *TextBlockStylePropertiesPtr;
//}}

View File

@@ -11,6 +11,44 @@
UBYTE *BlackImage;
sFONT * font = &Font8;
PositionalProperties draw_label(const char * title, const char * value, const PositionalProperties & p, const sFONT & f)
{
DrawItemCallBack draw_items[] = {
[&f, &title](const PositionalProperties & p) -> PositionalProperties {
return TextBlock(title, {WHITE, BLACK, f}).draw(p);
},
[&value, &f](const PositionalProperties & p) -> PositionalProperties {
return TextBlock(value, {WHITE, BLACK, f}).draw(p);
},
};
DrawItemCallBackList draw_list = {2, draw_items};
StackPanelStyleProperties style = {WHITE, 0, BLACK, 0, 1};
auto date_stack = StackPanel(style, draw_list, StackPanel::move_right);
return date_stack.draw(p);
}
PositionalProperties draw_meeting(const char * date, const char * subject, const char * location, const PositionalProperties & p, const sFONT & f)
{
DrawItemCallBack meetings_draw_items[] = {
[&date, &f](const PositionalProperties & p) -> PositionalProperties {
return draw_label("date: ", date, p, f);
},
[&subject, &f](const PositionalProperties & p) -> PositionalProperties {
return draw_label("subject: ", subject, p, f);
},
[&location, &f](const PositionalProperties & p) -> PositionalProperties {
return draw_label("location: ", location, p, f);
}
};
DrawItemCallBackList meeting_draw_list = {3, meetings_draw_items};
StackPanelStyleProperties meeting_style = {WHITE, 1, BLACK, 1, 2};
auto meeting_stack = StackPanel(meeting_style, meeting_draw_list, StackPanel::move_down);
return meeting_stack.draw(p);
}
void setup() {
// put your setup code here, to run once:
DEV_Module_Init();
@@ -26,44 +64,14 @@ void setup() {
Paint_NewImage(BlackImage, EPD_7IN5_V2_WIDTH , EPD_7IN5_V2_HEIGHT / 2, 90, WHITE);
Paint_SelectImage(BlackImage);
Paint_Clear(WHITE);
draw_meeting("Monday", "boring meeting\nbooring", "home", {0, 0 , 300, 300}, Font12);
EPD_7IN5_V2_SendHalfImage(0, BlackImage);
EPD_7IN5_V2_SendHalfImage(1, BlackImage);
EPD_7IN5_V2_TurnOnDisplay();
}
void loop() {
// put your main code here, to run repeatedly:
DEV_Delay_ms(2000);
show_time.Sec = show_time.Sec + 1;
Paint_DrawTime(100, 10, &show_time, &Font24, WHITE, BLACK);
DrawItemCallBack itmes[] = {
[](const PositionalProperties & p) -> PositionalProperties {
return TextBlock("Hallo Miri :)", {WHITE, BLACK, *font}).draw(p);
},
[](const PositionalProperties & p) -> PositionalProperties {
return TextBlock("Hallo Welt", {WHITE, BLACK, *font}).draw(p);
}
};
DrawItemCallBackList list = {2, itmes};
StackPanelStyleProperties style = {WHITE, 1, BLACK, 2, 4};
PositionalProperties p = {50, 200 ,200, 50};
auto panel = StackPanel(style, list, StackPanel::move_right);
panel.draw(p);
p.top += 150;
panel.draw(p);
EPD_7IN5_V2_SendHalfImage(0, BlackImage);
font = &Font24;
style.border_line_width = 2;
style.margin = 4;
style.padding = 8;
p.left = 0;
p.top = 400;
StackPanel(style, list, StackPanel::move_down).draw(p);
EPD_7IN5_V2_SendHalfImage(1, BlackImage);
EPD_7IN5_V2_TurnOnDisplay();
EPD_7IN5_V2_Sleep();
}