Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Reduce ROM by define some helper functions in pages/ #625

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/gui/gui.c
Original file line number Diff line number Diff line change
Expand Up @@ -831,6 +831,17 @@ void GUI_SelectionNotify(void (*notify_cb)(guiObject_t *obj))
select_notify = notify_cb;
}

guiObject_t *GUI_CreateLabel(guiLabel_t *obj, u16 x, u16 y,
const char *(*cb)(guiObject_t *, const void *),
const struct LabelDesc *desc,
const void *data) {
return GUI_CreateLabelBox(obj, x, y, 0, 0, desc, cb, NULL, data);
}

guiObject_t *GUI_CreateImage(guiImage_t *obj, u16 x, u16 y, u16 w, u16 h, const char *file) {
return GUI_CreateImageOffset(obj, x, y, w, h, 0, 0, file, NULL, NULL);
}

const char* _GUI_Localize(struct guiObject *obj, const void* str)
{
(void)obj;
Expand Down
7 changes: 5 additions & 2 deletions src/gui/gui.h
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,10 @@ guiObject_t *GUI_CreateDialog(guiDialog_t *,u16 x, u16 y, u16 width, u16 height,
const char *(*string_cb)(guiObject_t *obj, void *data),
void (*CallBack)(u8 state, void *data),
enum DialogType dgType, void *data);
#define GUI_CreateLabel(obj, x, y, cb, desc, data) GUI_CreateLabelBox(obj, x, y, 0, 0, &desc, cb, NULL, data)
guiObject_t *GUI_CreateLabel(guiLabel_t *, u16 x, u16 y,
const char *(*strCallback)(guiObject_t *, const void *),
const struct LabelDesc *desc,
const void *data);
guiObject_t *GUI_CreateLabelBox(guiLabel_t *,u16 x, u16 y, u16 width, u16 height, const struct LabelDesc *desc,
const char *(*strCallback)(guiObject_t *, const void *),
void (*pressCallback)(guiObject_t *obj, s8 press_type, const void *data),
Expand All @@ -345,7 +348,7 @@ void GUI_DrawLabelHelper(u16 obj_x, u16 obj_y, u16 obj_width, u16 obj_height,
const char *str, const struct LabelDesc *desc, u8 is_selected);
void GUI_SetLabelDesc(guiLabel_t *obj, struct LabelDesc *desc);

#define GUI_CreateImage(obj, x, y, w,h, file) GUI_CreateImageOffset(obj, x, y, w, h, 0, 0, file, NULL, NULL)
guiObject_t *GUI_CreateImage(guiImage_t *obj, u16 x, u16 y, u16 w, u16 h, const char *file);
guiObject_t *GUI_CreateImageOffset(guiImage_t *, u16 x, u16 y, u16 width, u16 height, u16 x_off, u16 y_off, const char *file,
void (*CallBack)(guiObject_t *obj, s8 press_type, const void *data), const void *cb_data);

Expand Down
4 changes: 2 additions & 2 deletions src/pages/128x64x1/main_layout.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,9 @@ void PAGE_LayoutEditInit(int page)
rect.outline_color = 0x0000;
GUI_CreateRect(&gui->editelem, 41, 1, 9, 5, &rect);
gui->editelem.CallBack = move_cb;
GUI_CreateLabel(&gui->xlbl, 0, 1, NULL, micro, "X:");
GUI_CreateLabel(&gui->xlbl, 0, 1, NULL, &micro, "X:");
GUI_CreateLabelBox(&gui->x, 8, 1, 13, 6, &micro, pos_cb, NULL, (void *) 0L);
GUI_CreateLabel(&gui->ylbl, 22, 1, NULL, micro, "Y:");
GUI_CreateLabel(&gui->ylbl, 22, 1, NULL, &micro, "Y:");
GUI_CreateLabelBox(&gui->y, 30, 1, 10, 6, &micro, pos_cb, NULL, (void *) 1L);
//gui->y must be the last element!
GUI_SelectionNotify(notify_cb);
Expand Down
4 changes: 2 additions & 2 deletions src/pages/320x240x16/main_layout.c
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,10 @@ void PAGE_MainLayoutInit(int page)
GUI_CreateIcon(&gui->editelem, 64, 0, &icons[ICON_LAYOUT_CFG], cfg_cb, NULL);
GUI_SetHidden((guiObject_t *)&gui->editelem, 1);
//GUI_CreateTextSelect(&gui->newelem, 36, 12, TEXTSELECT_96, newelem_press_cb, newelem_cb, NULL);
GUI_CreateLabel(&gui->xlbl, 80+18, 9, NULL, TITLE_FONT, "X");
GUI_CreateLabel(&gui->xlbl, 80+18, 9, NULL, &TITLE_FONT, "X");
GUI_CreateTextSelect(&gui->x, 88+18, 8, TEXTSELECT_64, NULL, xpos_cb, NULL);
GUI_SetSelectable((guiObject_t *)&gui->x, 0);
GUI_CreateLabel(&gui->ylbl, 164+16, 9, NULL, TITLE_FONT, "Y");
GUI_CreateLabel(&gui->ylbl, 164+16, 9, NULL, &TITLE_FONT, "Y");
GUI_CreateTextSelect(&gui->y, 172+16, 8, TEXTSELECT_64, NULL, ypos_cb, NULL);
GUI_SetSelectable((guiObject_t *)&gui->y, 0);

Expand Down
10 changes: 5 additions & 5 deletions src/pages/320x240x16/rtc_config.c
Original file line number Diff line number Diff line change
Expand Up @@ -216,31 +216,31 @@ const char *rtc_select_format_cb(guiObject_t *obj, int dir, void *data)

void _show_page()
{
GUI_CreateLabel(&gui->datelbl, XL(128), 40, rtc_text_cb, DEFAULT_FONT, (void *)DATELABEL);
GUI_CreateLabel(&gui->timelbl, XR(128), 40, rtc_text_cb, DEFAULT_FONT, (void *)TIMELABEL);
GUI_CreateLabel(&gui->datelbl, XL(128), 40, rtc_text_cb, &DEFAULT_FONT, (void *)DATELABEL);
GUI_CreateLabel(&gui->timelbl, XR(128), 40, rtc_text_cb, &DEFAULT_FONT, (void *)TIMELABEL);
GUI_CreateTextSelect(&gui->dateformat, XL(128), 56, TEXTSELECT_128, NULL, rtc_select_format_cb, (void *)ACTDATE);
GUI_CreateTextSelect(&gui->timeformat, XR(128), 56, TEXTSELECT_128, NULL, rtc_select_format_cb, (void *)ACTTIME);

RTC_GetDateFormattedOrder((Transmitter.rtcflags & DATEFMT) >> 4, &order[0], &order[1], &order[2]); // initial ordering

for (long i=0; i<6; i++) {
GUI_CreateLabel(&gui->label[i], X(i/3, 32) + ((i%3 == 2) ? 67 : 0) - ((i%3 == 0) ? 67 : 0), 84, rtc_text_cb, DEFAULT_FONT, (void *)i);
GUI_CreateLabel(&gui->label[i], X(i/3, 32) + ((i%3 == 2) ? 67 : 0) - ((i%3 == 0) ? 67 : 0), 84, rtc_text_cb, &DEFAULT_FONT, (void *)i);
GUI_CreateTextSelect(&gui->select[i], X(i/3, 32) + ((i%3 == 2) ? 67 : 0) - ((i%3 == 0) ? 67 : 0), 100, TEXTSELECT_VERT_64, NULL, rtc_val_cb, (void *)i);
}

const int DATEBOXWIDTH = 180;
u16 w, h;
LCD_SetFont(DEFAULT_FONT.font);
LCD_GetStringDimensions((u8 *)rtc_text_cb(NULL, (void *)SETLABEL), &w, &h);
GUI_CreateLabel(&gui->newlbl, XM(w), 168 - h / 2 , rtc_text_cb, DEFAULT_FONT, (void *)SETLABEL);
GUI_CreateLabel(&gui->newlbl, XM(w), 168 - h / 2 , rtc_text_cb, &DEFAULT_FONT, (void *)SETLABEL);
GUI_CreateLabelBox(&gui->newdate, XL(DATEBOXWIDTH), 150, DATEBOXWIDTH, 32, &BIGBOX_FONT, rtc_text_cb, NULL, (void *)NEWDATE);
GUI_CreateLabelBox(&gui->newtime, XR(DATEBOXWIDTH), 150, DATEBOXWIDTH, 32, &BIGBOX_FONT, rtc_text_cb, NULL, (void *)NEWTIME);

GUI_CreateButton(&gui->setdate, XL(96), 184, BUTTON_96, rtc_text_cb, rtc_set_cb, (void *)DATEBUTTON);
GUI_CreateButton(&gui->settime, XR(96), 184, BUTTON_96, rtc_text_cb, rtc_set_cb, (void *)TIMEBUTTON);

LCD_GetStringDimensions((u8 *)rtc_text_cb(NULL, (void *)RESULTLABEL), &w, &h);
GUI_CreateLabel(&gui->actlbl, XM(w), 243 - h / 2 , rtc_text_cb, DEFAULT_FONT, (void *)RESULTLABEL);
GUI_CreateLabel(&gui->actlbl, XM(w), 243 - h / 2 , rtc_text_cb, &DEFAULT_FONT, (void *)RESULTLABEL);
GUI_CreateLabelBox(&gui->actdate, XL(DATEBOXWIDTH), 225, DATEBOXWIDTH, 32, &BIGBOX_FONT, rtc_text_cb, NULL, (void *)ACTDATE);
GUI_CreateLabelBox(&gui->acttime, XR(DATEBOXWIDTH), 225, DATEBOXWIDTH, 32, &BIGBOX_FONT, rtc_text_cb, NULL, (void *)ACTTIME);
}
Expand Down
12 changes: 6 additions & 6 deletions src/pages/320x240x16/set_timer_page.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,26 +83,26 @@ static void _show_settimer_page(u8 index)
};

// actual value
firstObj = GUI_CreateLabel(&guiset->oldlbl, XLEFT, YOLD, GUI_Localize, DEFAULT_FONT, _tr_noop("actual value"));
firstObj = GUI_CreateLabel(&guiset->oldlbl, XLEFT, YOLD, GUI_Localize, &DEFAULT_FONT, _tr_noop("actual value"));
GUI_CreateLabelBox(&guiset->oldvalue, XLEFT, YOLD + 16, 128, 30, &BIGBOX_FONT, timer_value_str_cb, NULL, (void *)OLD_TIMER);

// value to add or set
GUI_CreateLabel(&guiset->addlbl, XLEFT, YNEW, GUI_Localize, DEFAULT_FONT, _tr_noop("value to add or set"));
GUI_CreateLabel(&guiset->addlbl, XLEFT, YNEW, GUI_Localize, &DEFAULT_FONT, _tr_noop("value to add or set"));
GUI_CreateLabelBox(&guiset->addvalue, XLEFT, YNEW + 16, 128, 30, &BIGBOX_FONT, timer_value_str_cb, NULL, (void *)ADD_TIMER);

// select boxes
GUI_CreateLabel(&guiset->hourlbl, XUNIT, YUNIT + 1, GUI_Localize, DEFAULT_FONT, _tr_noop("Hour"));
GUI_CreateLabel(&guiset->hourlbl, XUNIT, YUNIT + 1, GUI_Localize, &DEFAULT_FONT, _tr_noop("Hour"));
GUI_CreateTextSelect(&guiset->hoursel, XVAL, YUNIT, TEXTSELECT_64, NULL, _timer_new_str_cb, (void *)TIMER_HOURS);
GUI_CreateLabel(&guiset->minutelbl, XUNIT, YUNIT + YDIFF + 1, GUI_Localize, DEFAULT_FONT, _tr_noop("Minute"));
GUI_CreateLabel(&guiset->minutelbl, XUNIT, YUNIT + YDIFF + 1, GUI_Localize, &DEFAULT_FONT, _tr_noop("Minute"));
GUI_CreateTextSelect(&guiset->minutesel, XVAL, YUNIT + YDIFF, TEXTSELECT_64, NULL, _timer_new_str_cb, (void *)TIMER_MINUTES);
GUI_CreateLabel(&guiset->secondlbl, XUNIT, YUNIT + YDIFF + YDIFF + 1, GUI_Localize, DEFAULT_FONT, _tr_noop("Second"));
GUI_CreateLabel(&guiset->secondlbl, XUNIT, YUNIT + YDIFF + YDIFF + 1, GUI_Localize, &DEFAULT_FONT, _tr_noop("Second"));
GUI_CreateTextSelect(&guiset->secondsel, XVAL, YUNIT + YDIFF + YDIFF, TEXTSELECT_64, NULL, _timer_new_str_cb, (void *)TIMER_SECONDS);

// add / set buttons
GUI_CreateButton(&guiset->addbtn, XADD, YBTN, BUTTON_64x16, timer_value_str_cb, add_set_button_cb, (void *)ADD_BUTTON);
GUI_CreateButton(&guiset->setbtn, XSET, YBTN, BUTTON_64x16, timer_value_str_cb, add_set_button_cb, (void *)SET_BUTTON);

// resulting value
GUI_CreateLabel(&guiset->newlbl, XLEFT, YRES, GUI_Localize, DEFAULT_FONT, _tr_noop("resulting value"));
GUI_CreateLabel(&guiset->newlbl, XLEFT, YRES, GUI_Localize, &DEFAULT_FONT, _tr_noop("resulting value"));
GUI_CreateLabelBox(&guiset->newvalue, XLEFT, YRES + 16, 128, 30, &BIGBOX_FONT, timer_value_str_cb, NULL, (void *)NEW_TIMER);
}
4 changes: 2 additions & 2 deletions src/pages/320x240x16/trim_page.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ static int row_cb(int absrow, int relrow, int y, void *data)
struct Trim *trim = MIXER_GetAllTrims();
GUI_CreateButton(&gui->src[relrow], PCOL1, y, BUTTON_64x16,
trimsource_name_cb, edit_trim_cb, (void *)((long)absrow));
GUI_CreateLabel(&gui->neg[relrow], PCOL2 + 6, y, negtrim_str, DEFAULT_FONT, (void *)(long)absrow);
GUI_CreateLabel(&gui->pos[relrow], PCOL3 + 6, y, NULL, DEFAULT_FONT, (void *)INPUT_ButtonName(trim[absrow].pos));
GUI_CreateLabel(&gui->neg[relrow], PCOL2 + 6, y, negtrim_str, &DEFAULT_FONT, (void *)absrow);
GUI_CreateLabel(&gui->pos[relrow], PCOL3 + 6, y, NULL, &DEFAULT_FONT, (void *)INPUT_ButtonName(trim[absrow].pos));
GUI_CreateTextSelect(&gui->step[relrow], PCOL4 + 6, y, TEXTSELECT_96, NULL,
set_trimstep_cb, (void *)(long)(absrow + 0x000)); //0x000: Use Model.trims
return 2;
Expand Down
4 changes: 2 additions & 2 deletions src/pages/text/main_layout.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,9 @@ void PAGE_LayoutEditInit(int page)
rect.outline_color = 0x0000;
GUI_CreateRect(&gui->editelem, 41, 1, 9, 5, &rect);
gui->editelem.CallBack = move_cb;
GUI_CreateLabel(&gui->xlbl, 0, 1, NULL, micro, "X:");
GUI_CreateLabel(&gui->xlbl, 0, 1, NULL, &micro, "X:");
GUI_CreateLabelBox(&gui->x, 8, 1, 13, 6, &micro, pos_cb, NULL, (void *) 0L);
GUI_CreateLabel(&gui->ylbl, 22, 1, NULL, micro, "Y:");
GUI_CreateLabel(&gui->ylbl, 22, 1, NULL, &micro, "Y:");
GUI_CreateLabelBox(&gui->y, 30, 1, 9, 6, &micro, pos_cb, NULL, (void *) 1L);
//gui->y must be the last element!
GUI_SelectionNotify(notify_cb);
Expand Down