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

Insert a temporary grid window and measure it #13

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
25 changes: 22 additions & 3 deletions glk/osglkban.c
Expand Up @@ -590,6 +590,25 @@ void os_banner_orphan(void *banner_handle)
os_banner_delete(banner_handle);
}

void osglk_window_get_size(void *banner_handle) {
osbanid_t banner = banner_handle;
if (!banner || !banner->valid || !banner->win) {
return;
}

// Measuring a true grid window or non tab aligned buffer window is easy
if (banner->type == wintype_TextGrid || !banner->status) {
glk_window_get_size(banner->win, &(banner->cwidth), &(banner->cheight));
return;
}

// But for a tab aligned window we'll make a temp grid window to measure the width
glk_window_get_size(banner->win, NULL, &(banner->cheight));
winid_t tempwin = glk_window_open(banner->win, winmethod_Below | winmethod_Fixed, 0, wintype_TextGrid, 0);
glk_window_get_size(tempwin, &(banner->cwidth), NULL);
glk_window_close(tempwin, NULL);
}

int os_banner_getinfo(void *banner_handle, os_banner_info_t *info)
{
osbanid_t banner = banner_handle;
Expand All @@ -612,7 +631,7 @@ int os_banner_getinfo(void *banner_handle, os_banner_info_t *info)

info->style = gstyletab ? OS_BANNER_STYLE_TAB_ALIGN : 0;

glk_window_get_size(banner->win, &(banner->cwidth), &(banner->cheight));
osglk_window_get_size(banner);

info->rows = banner->cheight;
info->columns = banner->cwidth;
Expand All @@ -631,7 +650,7 @@ int os_banner_get_charwidth(void *banner_handle)
if (!banner || !banner->valid || !banner->win)
return 0;

glk_window_get_size(banner->win, &(banner->cwidth), &(banner->cheight));
osglk_window_get_size(banner);

return banner->cwidth;
}
Expand All @@ -642,7 +661,7 @@ int os_banner_get_charheight(void *banner_handle)
if (!banner || !banner->valid || !banner->win)
return 0;

glk_window_get_size(banner->win, &(banner->cwidth), &(banner->cheight));
osglk_window_get_size(banner);

return banner->cheight;
}
Expand Down