简体   繁体   English

如何重绘ncurses菜单

[英]How to redraw an ncurses menu

I am working on an ncurses-based tool that has 4 tiled windows with a command bar at the bottom of the screen. 我正在使用基于ncurses的工具,该工具具有4个平铺的窗口,并且在屏幕底部具有命令栏。 The windows form a 2x2 grid like this: 窗口形成一个2x2的网格,如下所示:

+----+----------------+
| 1  |  2             |
+----+----------------+
| 3  |  4             |
|    |                |
|    |                |
|    |                |
+----+----------------+

The top left is fixed in size, so when the app is resized, 2 changes in width, 3 changes in height, and 4 changes in both directions. 左上角的大小是固定的,因此,在调整应用大小时,宽度会发生2个变化,高度会发生3个变化,两个方向都发生4个变化。

I had the redrawing code working fine until I started putting menus (using menu.h) in window 4. Now, if i resize the window too small, part of the menu will get cut off, but when you make the window bigger again, it does not repaint what was removed. 在开始在窗口4中放置菜单(使用menu.h)之前,我的重绘代码工作正常。现在,如果我将窗口的尺寸调整得太小,则菜单的一部分将被切断,但是当您再次增大窗口的尺寸时,它不会重绘已删除的内容。 Doing a post_menu() in the redraw code does not repaint it. 在重绘代码中执行post_menu()不会重绘它。

What is the proper way to repaint a menu? 重新绘制菜单的正确方法是什么? Do I have to dispose of it and recreate it from scratch every time? 我是否必须处理它并每次从头开始重新创建它? I do have logic in my code that only repaints if necessary (data changed, window resized, etc), so it would not be creating a new menu every cycle for no reason, but this still seems a bit heavy handed. 我的代码中确实有逻辑,仅在必要时才重新绘制(更改数据,调整窗口大小等),因此不会无缘无故地在每个周期创建一个新菜单,但这似乎有点繁琐。 There has to be a simple way to just redraw the menu you have already created. 必须有一种简单的方法来重新绘制您已经创建的菜单。 What is it? 它是什么?

Recreating the structure is the simplest way. 重新创建结构是最简单的方法。

The form and menu libraries use an abstraction of the keys you type. 表单和菜单库使用您键入的键的抽象。 That abstraction does not include a resize feature. 该抽象不包括调整大小功能。

You could run wresize for each of the windows in the menu, eg, these lines from menu.h 可以为菜单中的每个窗口运行wresize ,例如,来自menu.h这些行

  WINDOW        *win;                   /* Window containing menu          */
  WINDOW        *sub;                   /* Subwindow for menu display      */
  WINDOW        *userwin;               /* User's window                   */
  WINDOW        *usersub;               /* User's subwindow                */

but making that work requires some study of the library. 但是进行这项工作需要对图书馆进行一些研究。 There's an example which resizes a form in ncurses-examples (named cardfile ), but no analogous example for menus . 有一个示例可以在ncurses-examples (命名为cardfile )中调整表单的大小,但是没有menus的类似示例。

Further reading: 进一步阅读:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM