/* These functions must be implemented by any appliation that wishes
to use this module */
void onupdate(void);
+void onlayout(void);
void onscroll(double percent);
void onmouseleft(WinRegion id, size_t count, size_t row, size_t col);
void onmousemiddle(WinRegion id, size_t count, size_t row, size_t col);
bool pending = x11_events_await(200 /* ms */);
if (update_focus() || pending) {
x11_events_take();
- x11_flip();
+ if (x11_running())
+ x11_flip();
}
x11_flush();
}
size_t fwidth = x11_font_width(Font);
/* layout and draw the three text regions */
- onupdate(); // Let the user program update the status and such
+ onupdate(); // Let the user program update the status and other content
layout(width, height);
- onupdate(); // Let the user program update the status and such
+ onlayout(); // Let the user program update the scroll bar
for (int i = 0; i < SCROLL; i++) {
View* view = win_view(i);
void onupdate(void) {
}
+void onlayout(void) {
+}
+
#ifndef TEST
int main(int argc, char** argv) {
win_window("term");
strncat(status, path, remlen);
win_settext(STATUS, status_bytes);
win_view(STATUS)->selection = (Sel){0,0,0};
-
+}
+
+void onlayout(void) {
/* calculate and update scroll region */
View* view = win_view(EDIT);
size_t bend = buf_end(win_buf(EDIT));
win_settext(EDIT, "");
View* view = win_view(EDIT);
view->selection = (Sel){0,0,0};
-
- score();
Sel selection = (Sel){0,0,0};
+
+ score();
unsigned off = (ChoiceIdx >= view->nrows ? ChoiceIdx-view->nrows+1 : 0);
for (int i = 0; (i < vec_size(&Choices)) && (i < view->nrows); i++) {
unsigned beg = view->selection.end;
Choice* choice = (Choice*)vec_at(&Choices, i+off);
- for (char* str = choice->string; *str; str++)
+ for (char* str = choice->string; str && *str; str++)
view_insert(view, false, *str);
view_insert(view, false, '\n');
if (ChoiceIdx == i+off) {
}
}
view->selection = selection;
-
+}
+
+void onlayout(void) {
/* update scroll bar */
+ View* view = win_view(EDIT);
+ unsigned off = (ChoiceIdx >= view->nrows ? ChoiceIdx-view->nrows+1 : 0);
double visible = (double)(win_view(EDIT)->nrows);
double choices = (double)vec_size(&Choices);
double current = (double)off;