| Christian Göttsche | 9060a41 | 2020-12-25 16:42:35 +0100 | [diff] [blame] | 1 | #ifndef HEADER_HeaderLayout |
| 2 | #define HEADER_HeaderLayout |
| 3 | /* |
| 4 | htop - HeaderLayout.h |
| 5 | (C) 2021 htop dev team |
| Daniel Lange | 94ad111 | 2021-09-22 11:33:00 +0200 | [diff] [blame] | 6 | Released under the GNU GPLv2+, see the COPYING file |
| Christian Göttsche | 9060a41 | 2020-12-25 16:42:35 +0100 | [diff] [blame] | 7 | in the source distribution for its full text. |
| 8 | */ |
| 9 | |
| 10 | #include <assert.h> |
| 11 | #include <stddef.h> |
| 12 | #include <stdint.h> |
| 13 | |
| 14 | #include "Macros.h" |
| Christian Göttsche | db076b9 | 2021-08-24 17:40:22 +0200 | [diff] [blame] | 15 | #include "XUtils.h" |
| Christian Göttsche | 9060a41 | 2020-12-25 16:42:35 +0100 | [diff] [blame] | 16 | |
| 17 | |
| 18 | typedef enum HeaderLayout_ { |
| hwangcc23 | 72c5669 | 2022-04-04 23:29:48 +0800 | [diff] [blame] | 19 | HF_INVALID = -1, |
| Peter Dey | 13ca4e2 | 2024-04-16 20:59:25 +0200 | [diff] [blame] | 20 | HF_ONE_100, |
| Christian Göttsche | 9060a41 | 2020-12-25 16:42:35 +0100 | [diff] [blame] | 21 | HF_TWO_50_50, |
| 22 | HF_TWO_33_67, |
| 23 | HF_TWO_67_33, |
| 24 | HF_THREE_33_34_33, |
| 25 | HF_THREE_25_25_50, |
| 26 | HF_THREE_25_50_25, |
| 27 | HF_THREE_50_25_25, |
| Christian Hesse | 8980d7a | 2023-12-22 07:51:28 +0100 | [diff] [blame] | 28 | HF_THREE_40_30_30, |
| 29 | HF_THREE_30_40_30, |
| 30 | HF_THREE_30_30_40, |
| Christian Göttsche | 9060a41 | 2020-12-25 16:42:35 +0100 | [diff] [blame] | 31 | HF_THREE_40_20_40, |
| 32 | HF_FOUR_25_25_25_25, |
| 33 | LAST_HEADER_LAYOUT |
| 34 | } HeaderLayout; |
| 35 | |
| 36 | static const struct { |
| 37 | uint8_t columns; |
| 38 | const uint8_t widths[4]; |
| Christian Göttsche | db076b9 | 2021-08-24 17:40:22 +0200 | [diff] [blame] | 39 | const char* name; |
| Christian Göttsche | 9060a41 | 2020-12-25 16:42:35 +0100 | [diff] [blame] | 40 | const char* description; |
| 41 | } HeaderLayout_layouts[LAST_HEADER_LAYOUT] = { |
| Peter Dey | 13ca4e2 | 2024-04-16 20:59:25 +0200 | [diff] [blame] | 42 | [HF_ONE_100] = { 1, { 100, 0, 0, 0 }, "one_100", "1 column - full width", }, |
| Christian Göttsche | db076b9 | 2021-08-24 17:40:22 +0200 | [diff] [blame] | 43 | [HF_TWO_50_50] = { 2, { 50, 50, 0, 0 }, "two_50_50", "2 columns - 50/50 (default)", }, |
| 44 | [HF_TWO_33_67] = { 2, { 33, 67, 0, 0 }, "two_33_67", "2 columns - 33/67", }, |
| 45 | [HF_TWO_67_33] = { 2, { 67, 33, 0, 0 }, "two_67_33", "2 columns - 67/33", }, |
| 46 | [HF_THREE_33_34_33] = { 3, { 33, 34, 33, 0 }, "three_33_34_33", "3 columns - 33/34/33", }, |
| 47 | [HF_THREE_25_25_50] = { 3, { 25, 25, 50, 0 }, "three_25_25_50", "3 columns - 25/25/50", }, |
| 48 | [HF_THREE_25_50_25] = { 3, { 25, 50, 25, 0 }, "three_25_50_25", "3 columns - 25/50/25", }, |
| 49 | [HF_THREE_50_25_25] = { 3, { 50, 25, 25, 0 }, "three_50_25_25", "3 columns - 50/25/25", }, |
| Christian Hesse | 8980d7a | 2023-12-22 07:51:28 +0100 | [diff] [blame] | 50 | [HF_THREE_40_30_30] = { 3, { 40, 30, 30, 0 }, "three_40_30_30", "3 columns - 40/30/30", }, |
| 51 | [HF_THREE_30_40_30] = { 3, { 30, 40, 30, 0 }, "three_30_40_30", "3 columns - 30/40/30", }, |
| 52 | [HF_THREE_30_30_40] = { 3, { 30, 30, 40, 0 }, "three_30_30_40", "3 columns - 30/30/40", }, |
| Christian Göttsche | db076b9 | 2021-08-24 17:40:22 +0200 | [diff] [blame] | 53 | [HF_THREE_40_20_40] = { 3, { 40, 20, 40, 0 }, "three_40_20_40", "3 columns - 40/20/40", }, |
| 54 | [HF_FOUR_25_25_25_25] = { 4, { 25, 25, 25, 25 }, "four_25_25_25_25", "4 columns - 25/25/25/25", }, |
| Christian Göttsche | 9060a41 | 2020-12-25 16:42:35 +0100 | [diff] [blame] | 55 | }; |
| 56 | |
| 57 | static inline size_t HeaderLayout_getColumns(HeaderLayout hLayout) { |
| 58 | /* assert the layout is initialized */ |
| 59 | assert(0 <= hLayout); |
| 60 | assert(hLayout < LAST_HEADER_LAYOUT); |
| Christian Göttsche | db076b9 | 2021-08-24 17:40:22 +0200 | [diff] [blame] | 61 | assert(HeaderLayout_layouts[hLayout].name[0]); |
| Christian Göttsche | 9060a41 | 2020-12-25 16:42:35 +0100 | [diff] [blame] | 62 | assert(HeaderLayout_layouts[hLayout].description[0]); |
| 63 | return HeaderLayout_layouts[hLayout].columns; |
| 64 | } |
| 65 | |
| Christian Göttsche | db076b9 | 2021-08-24 17:40:22 +0200 | [diff] [blame] | 66 | static inline const char* HeaderLayout_getName(HeaderLayout hLayout) { |
| 67 | /* assert the layout is initialized */ |
| 68 | assert(0 <= hLayout); |
| 69 | assert(hLayout < LAST_HEADER_LAYOUT); |
| 70 | assert(HeaderLayout_layouts[hLayout].name[0]); |
| 71 | assert(HeaderLayout_layouts[hLayout].description[0]); |
| 72 | return HeaderLayout_layouts[hLayout].name; |
| 73 | } |
| 74 | |
| 75 | static inline HeaderLayout HeaderLayout_fromName(const char* name) { |
| 76 | for (size_t i = 0; i < LAST_HEADER_LAYOUT; i++) { |
| 77 | if (String_eq(HeaderLayout_layouts[i].name, name)) |
| 78 | return (HeaderLayout) i; |
| 79 | } |
| 80 | |
| 81 | return LAST_HEADER_LAYOUT; |
| 82 | } |
| 83 | |
| Christian Göttsche | 9060a41 | 2020-12-25 16:42:35 +0100 | [diff] [blame] | 84 | #endif /* HEADER_HeaderLayout */ |