NeoMutt  2022-04-29-249-gaae397
Teaching an old dog new tricks
DOXYGEN
reflow.c
Go to the documentation of this file.
1
29#include "config.h"
30#include <stddef.h>
31#include "mutt/lib.h"
32#include "reflow.h"
33#include "mutt_window.h"
34
39static void window_reflow_horiz(struct MuttWindow *win)
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}
123
128static void window_reflow_vert(struct MuttWindow *win)
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}
212
220void window_reflow(struct MuttWindow *win)
221{
222 if (!win)
223 return;
226 else
228}
#define MIN(a, b)
Definition: memory.h:31
Convenience wrapper for the library headers.
Window management.
@ MUTT_WIN_ORIENT_VERTICAL
Window uses all available vertical space.
Definition: mutt_window.h:38
@ 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
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
void window_reflow(struct MuttWindow *win)
Reflow Windows.
Definition: reflow.c:220
Window management.
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
enum MuttWindowOrientation orient
Which direction the Window will expand.
Definition: mutt_window.h:130
short req_rows
Number of rows required.
Definition: mutt_window.h:125
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