gpt4 book ai didi

c - 调整终端大小后 box() 如何采用最大宽度

转载 作者:太空宇宙 更新时间:2023-11-04 03:09:31 24 4
gpt4 key购买 nike

我不知道重新执行函数 box() 是如何自动采用最大宽度的,这里是测试代码:

getmaxyx(stdscr,y,x);
WINDOW *titleWin = update_title_win(NULL,2,x,0,0);
while((ch = getch()) != 27) {
if(ch == KEY_RESIZE) {
update_title_win(titleWin);
}
}

update_title_win() 代码:

WINDOW* update_title_win(WINDOW *win, int height, int width, int y, int x)
{
if(!win)
win = newwin(height,width,y,x);
box(win,0,0);
refresh();
wrefresh(win);
return win;
}

最佳答案

getch 返回 KEY_RESIZE 时,ncurses 库使用 resizeterm 进行调整。如果(终端/屏幕)缩小,该函数将减小窗口的大小,但屏幕尺寸增加时的行为不太明显。

resizeterm 的手册页没有提到这个,而是一个comment在源代码中解释了行为:

/*
* If we're increasing size, recursively search for windows that have no
* parent, increase those to fit, then increase the contained window, etc.
*/

newwin 创建的窗口没有 parent (不像用 subwin 制作的东西)。由于 titleWin 以屏幕的全宽开始,随着屏幕宽度的变化,ncurses 将尝试保持标题窗口全宽。

关于c - 调整终端大小后 box() 如何采用最大宽度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57975281/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com