parent
7269faf651
commit
9060a4179d
12 changed files with 437 additions and 167 deletions
@ -0,0 +1,54 @@ |
||||
#ifndef HEADER_HeaderLayout |
||||
#define HEADER_HeaderLayout |
||||
/*
|
||||
htop - HeaderLayout.h |
||||
(C) 2021 htop dev team |
||||
Released under the GNU GPLv2, see the COPYING file |
||||
in the source distribution for its full text. |
||||
*/ |
||||
|
||||
#include <assert.h> |
||||
#include <stddef.h> |
||||
#include <stdint.h> |
||||
|
||||
#include "Macros.h" |
||||
|
||||
|
||||
typedef enum HeaderLayout_ { |
||||
HF_TWO_50_50, |
||||
HF_TWO_33_67, |
||||
HF_TWO_67_33, |
||||
HF_THREE_33_34_33, |
||||
HF_THREE_25_25_50, |
||||
HF_THREE_25_50_25, |
||||
HF_THREE_50_25_25, |
||||
HF_THREE_40_20_40, |
||||
HF_FOUR_25_25_25_25, |
||||
LAST_HEADER_LAYOUT |
||||
} HeaderLayout; |
||||
|
||||
static const struct { |
||||
uint8_t columns; |
||||
const uint8_t widths[4]; |
||||
const char* description; |
||||
} HeaderLayout_layouts[LAST_HEADER_LAYOUT] = { |
||||
[HF_TWO_50_50] = { 2, { 50, 50, 0, 0 }, "2 columns - 50/50 (default)", }, |
||||
[HF_TWO_33_67] = { 2, { 33, 67, 0, 0 }, "2 columns - 33/67", }, |
||||
[HF_TWO_67_33] = { 2, { 67, 33, 0, 0 }, "2 columns - 67/33", }, |
||||
[HF_THREE_33_34_33] = { 3, { 33, 34, 33, 0 }, "3 columns - 33/34/33", }, |
||||
[HF_THREE_25_25_50] = { 3, { 25, 25, 50, 0 }, "3 columns - 25/25/50", }, |
||||
[HF_THREE_25_50_25] = { 3, { 25, 50, 25, 0 }, "3 columns - 25/50/25", }, |
||||
[HF_THREE_50_25_25] = { 3, { 50, 25, 25, 0 }, "3 columns - 50/25/25", }, |
||||
[HF_THREE_40_20_40] = { 3, { 40, 20, 40, 0 }, "3 columns - 40/20/40", }, |
||||
[HF_FOUR_25_25_25_25] = { 4, { 25, 25, 25, 25 }, "4 columns - 25/25/25/25", }, |
||||
}; |
||||
|
||||
static inline size_t HeaderLayout_getColumns(HeaderLayout hLayout) { |
||||
/* assert the layout is initialized */ |
||||
assert(0 <= hLayout); |
||||
assert(hLayout < LAST_HEADER_LAYOUT); |
||||
assert(HeaderLayout_layouts[hLayout].description[0]); |
||||
return HeaderLayout_layouts[hLayout].columns; |
||||
} |
||||
|
||||
#endif /* HEADER_HeaderLayout */ |
||||
@ -0,0 +1,87 @@ |
||||
/*
|
||||
htop - HeaderOptionsPanel.c |
||||
(C) 2021 htop dev team |
||||
Released under the GNU GPLv2, see the COPYING file |
||||
in the source distribution for its full text. |
||||
*/ |
||||
|
||||
#include "HeaderOptionsPanel.h" |
||||
|
||||
#include <stdbool.h> |
||||
#include <stdlib.h> |
||||
|
||||
#include "CRT.h" |
||||
#include "FunctionBar.h" |
||||
#include "Header.h" |
||||
#include "Object.h" |
||||
#include "OptionItem.h" |
||||
#include "ProvideCurses.h" |
||||
#include "RichString.h" |
||||
#include "Vector.h" |
||||
|
||||
|
||||
static const char* const HeaderOptionsFunctions[] = {" ", " ", " ", " ", " ", " ", " ", " ", " ", "Done ", NULL}; |
||||
|
||||
static void HeaderOptionsPanel_delete(Object* object) { |
||||
Panel* super = (Panel*) object; |
||||
HeaderOptionsPanel* this = (HeaderOptionsPanel*) object; |
||||
Panel_done(super); |
||||
free(this); |
||||
} |
||||
|
||||
static HandlerResult HeaderOptionsPanel_eventHandler(Panel* super, int ch) { |
||||
HeaderOptionsPanel* this = (HeaderOptionsPanel*) super; |
||||
|
||||
HandlerResult result = IGNORED; |
||||
int mark; |
||||
|
||||
switch(ch) { |
||||
case 0x0a: |
||||
case 0x0d: |
||||
case KEY_ENTER: |
||||
case KEY_MOUSE: |
||||
case KEY_RECLICK: |
||||
case ' ': |
||||
mark = Panel_getSelectedIndex(super); |
||||
assert(mark >= 0); |
||||
assert(mark < LAST_HEADER_LAYOUT); |
||||
|
||||
for (int i = 0; i < LAST_HEADER_LAYOUT; i++) |
||||
CheckItem_set((CheckItem*)Panel_get(super, i), false); |
||||
CheckItem_set((CheckItem*)Panel_get(super, mark), true); |
||||
|
||||
Header_setLayout(this->scr->header, mark); |
||||
this->settings->changed = true; |
||||
|
||||
ScreenManager_resize(this->scr); |
||||
|
||||
result = HANDLED; |
||||
} |
||||
|
||||
return result; |
||||
} |
||||
|
||||
const PanelClass HeaderOptionsPanel_class = { |
||||
.super = { |
||||
.extends = Class(Panel), |
||||
.delete = HeaderOptionsPanel_delete |
||||
}, |
||||
.eventHandler = HeaderOptionsPanel_eventHandler |
||||
}; |
||||
|
||||
HeaderOptionsPanel* HeaderOptionsPanel_new(Settings* settings, ScreenManager* scr) { |
||||
HeaderOptionsPanel* this = AllocThis(HeaderOptionsPanel); |
||||
Panel* super = (Panel*) this; |
||||
FunctionBar* fuBar = FunctionBar_new(HeaderOptionsFunctions, NULL, NULL); |
||||
Panel_init(super, 1, 1, 1, 1, Class(CheckItem), true, fuBar); |
||||
|
||||
this->scr = scr; |
||||
this->settings = settings; |
||||
|
||||
Panel_setHeader(super, "Header Layout"); |
||||
for (int i = 0; i < LAST_HEADER_LAYOUT; i++) { |
||||
Panel_add(super, (Object*) CheckItem_newByVal(HeaderLayout_layouts[i].description, false)); |
||||
} |
||||
CheckItem_set((CheckItem*)Panel_get(super, settings->hLayout), true); |
||||
return this; |
||||
} |
||||
@ -0,0 +1,26 @@ |
||||
#ifndef HEADER_HeaderOptionsPanel |
||||
#define HEADER_HeaderOptionsPanel |
||||
/*
|
||||
htop - ColorsPanel.h |
||||
(C) 2021 htop dev team |
||||
Released under the GNU GPLv2, see the COPYING file |
||||
in the source distribution for its full text. |
||||
*/ |
||||
|
||||
#include "Panel.h" |
||||
#include "ScreenManager.h" |
||||
#include "Settings.h" |
||||
|
||||
|
||||
typedef struct HeaderOptionsPanel_ { |
||||
Panel super; |
||||
|
||||
ScreenManager* scr; |
||||
Settings* settings; |
||||
} HeaderOptionsPanel; |
||||
|
||||
extern const PanelClass HeaderOptionsPanel_class; |
||||
|
||||
HeaderOptionsPanel* HeaderOptionsPanel_new(Settings* settings, ScreenManager* scr); |
||||
|
||||
#endif /* HEADER_HeaderOptionsPanel */ |
||||
Loading…
Reference in new issue