NeoMutt  2024-03-23-23-gec7045
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
reflow.c File Reference

Window reflowing. More...

#include "config.h"
#include <stddef.h>
#include "mutt/lib.h"
#include "reflow.h"
#include "mutt_window.h"
+ Include dependency graph for reflow.c:

Go to the source code of this file.

Functions

static void window_reflow_horiz (struct MuttWindow *win)
 Reflow Windows using all the available horizontal space.
 
static void window_reflow_vert (struct MuttWindow *win)
 Reflow Windows using all the available vertical space.
 
void window_reflow (struct MuttWindow *win)
 Reflow Windows.
 

Detailed Description

Window reflowing.

Authors
  • Richard Russon

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

Definition in file reflow.c.

Function Documentation

◆ window_reflow_horiz()

static void window_reflow_horiz ( struct MuttWindow win)
static

Reflow Windows using all the available horizontal space.

Parameters
winWindow

Definition at line 39 of file reflow.c.

40{
41 if (!win)
42 return;
43
44 int max_count = 0;
45 int space = win->state.cols;
46
47 // Pass one - minimal allocation
48 struct MuttWindow *np = NULL;
49 TAILQ_FOREACH(np, &win->children, entries)
50 {
51 if (!np->state.visible)
52 continue;
53
54 switch (np->size)
55 {
57 {
58 const int avail = MIN(space, np->req_cols);
59 np->state.cols = avail;
60 np->state.rows = win->state.rows;
61 space -= avail;
62 break;
63 }
65 {
66 np->state.cols = 1;
67 np->state.rows = win->state.rows;
68 max_count++;
69 space -= 1;
70 break;
71 }
73 {
74 np->state.rows = win->state.rows;
75 np->state.cols = win->state.cols;
78 window_reflow(np);
79 space -= np->state.cols;
80 break;
81 }
82 }
83 }
84
85 // Pass two - sharing
86 if ((max_count > 0) && (space > 0))
87 {
88 int alloc = (space + max_count - 1) / max_count;
89 TAILQ_FOREACH(np, &win->children, entries)
90 {
91 if (space == 0)
92 break;
93 if (!np->state.visible)
94 continue;
96 continue;
97
98 alloc = MIN(space, alloc);
99 np->state.cols += alloc;
100 space -= alloc;
101 }
102 }
103
104 // Pass three - position and recursion
105 int col = win->state.col_offset;
106 TAILQ_FOREACH(np, &win->children, entries)
107 {
108 if (!np->state.visible)
109 continue;
110
111 np->state.col_offset = col;
112 np->state.row_offset = win->state.row_offset;
113 col += np->state.cols;
114
115 window_reflow(np);
116 }
117
118 if ((space > 0) && (win->size == MUTT_WIN_SIZE_MINIMISE))
119 {
120 win->state.cols -= space;
121 }
122}
#define MIN(a, b)
Definition: memory.h:32
@ MUTT_WIN_SIZE_FIXED
Window has a fixed size.
Definition: mutt_window.h:47
@ MUTT_WIN_SIZE_MINIMISE
Window size depends on its children.
Definition: mutt_window.h:49
@ MUTT_WIN_SIZE_MAXIMISE
Window wants as much space as possible.
Definition: mutt_window.h:48
#define TAILQ_FOREACH(var, head, field)
Definition: queue.h:725
void window_reflow(struct MuttWindow *win)
Reflow Windows.
Definition: reflow.c:220
short req_cols
Number of columns required.
Definition: mutt_window.h:124
struct WindowState state
Current state of the Window.
Definition: mutt_window.h:127
struct MuttWindowList children
Children Windows.
Definition: mutt_window.h:136
enum MuttWindowSize size
Type of Window, e.g. MUTT_WIN_SIZE_FIXED.
Definition: mutt_window.h:131
bool visible
Window is visible.
Definition: mutt_window.h:59
short cols
Number of columns, can be MUTT_WIN_SIZE_UNLIMITED.
Definition: mutt_window.h:60
short row_offset
Absolute on-screen row.
Definition: mutt_window.h:63
short col_offset
Absolute on-screen column.
Definition: mutt_window.h:62
short rows
Number of rows, can be MUTT_WIN_SIZE_UNLIMITED.
Definition: mutt_window.h:61
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ window_reflow_vert()

static void window_reflow_vert ( struct MuttWindow win)
static

Reflow Windows using all the available vertical space.

Parameters
winWindow

Definition at line 128 of file reflow.c.

129{
130 if (!win)
131 return;
132
133 int max_count = 0;
134 int space = win->state.rows;
135
136 // Pass one - minimal allocation
137 struct MuttWindow *np = NULL;
138 TAILQ_FOREACH(np, &win->children, entries)
139 {
140 if (!np->state.visible)
141 continue;
142
143 switch (np->size)
144 {
146 {
147 const int avail = MIN(space, np->req_rows);
148 np->state.rows = avail;
149 np->state.cols = win->state.cols;
150 space -= avail;
151 break;
152 }
154 {
155 np->state.rows = 1;
156 np->state.cols = win->state.cols;
157 max_count++;
158 space -= 1;
159 break;
160 }
162 {
163 np->state.rows = win->state.rows;
164 np->state.cols = win->state.cols;
165 np->state.row_offset = win->state.row_offset;
166 np->state.col_offset = win->state.col_offset;
167 window_reflow(np);
168 space -= np->state.rows;
169 break;
170 }
171 }
172 }
173
174 // Pass two - sharing
175 if ((max_count > 0) && (space > 0))
176 {
177 int alloc = (space + max_count - 1) / max_count;
178 TAILQ_FOREACH(np, &win->children, entries)
179 {
180 if (space == 0)
181 break;
182 if (!np->state.visible)
183 continue;
184 if (np->size != MUTT_WIN_SIZE_MAXIMISE)
185 continue;
186
187 alloc = MIN(space, alloc);
188 np->state.rows += alloc;
189 space -= alloc;
190 }
191 }
192
193 // Pass three - position and recursion
194 int row = win->state.row_offset;
195 TAILQ_FOREACH(np, &win->children, entries)
196 {
197 if (!np->state.visible)
198 continue;
199
200 np->state.row_offset = row;
201 np->state.col_offset = win->state.col_offset;
202 row += np->state.rows;
203
204 window_reflow(np);
205 }
206
207 if ((space > 0) && (win->size == MUTT_WIN_SIZE_MINIMISE))
208 {
209 win->state.rows -= space;
210 }
211}
short req_rows
Number of rows required.
Definition: mutt_window.h:125
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ window_reflow()

void window_reflow ( struct MuttWindow win)

Reflow Windows.

Parameters
winRoot Window

Using the rules coded into the Windows, such as Fixed or Maximise, allocate space to a set of nested Windows.

Definition at line 220 of file reflow.c.

221{
222 if (!win)
223 return;
226 else
228}
@ MUTT_WIN_ORIENT_VERTICAL
Window uses all available vertical space.
Definition: mutt_window.h:38
static void window_reflow_vert(struct MuttWindow *win)
Reflow Windows using all the available vertical space.
Definition: reflow.c:128
static void window_reflow_horiz(struct MuttWindow *win)
Reflow Windows using all the available horizontal space.
Definition: reflow.c:39
enum MuttWindowOrientation orient
Which direction the Window will expand.
Definition: mutt_window.h:130
+ Here is the call graph for this function:
+ Here is the caller graph for this function: