add the ability to have text padding depending on item selection

This commit is contained in:
speedie 2023-04-30 23:45:58 +02:00
parent 5b642b66b9
commit 4f1a6d5349
6 changed files with 35 additions and 4 deletions

View file

@ -6,6 +6,9 @@
!! Fonts
spmenu.font: Noto Sans Mono 8
spmenu.textpadding: 0
spmenu.normitempadding: 0
spmenu.selitempadding: 0
spmenu.priitempadding: 0
!! Colors
spmenu.col_itemnormfg: #bbbbbb

View file

@ -30,7 +30,10 @@ spmenu = {
/* Text */
text = ( { font = "Noto Sans Mono 8"; // Font to use for all text (text)
padding = 0; // Horizontal padding around the text (px)
padding = 0; // Horizontal padding around the text globally (px)
normitempadding = 0; // Horizontal padding around the normal item text (px)
selitempadding = 0; // Horizontal padding around the selected item text (px)
priitempadding = 0; // Horizontal padding around the high priority item text (px)
leftarrow = "<"; // Left arrow text (text)
rightarrow = ">"; // Right arrow text (text)
password = "*"; // Password character (text)

View file

@ -133,6 +133,9 @@ conf_init(void)
strcpy(font, strdup(dest));
config_setting_lookup_int(conf, "padding", &textpadding); // spmenu.text.padding
config_setting_lookup_int(conf, "normitempadding", &normitempadding); // spmenu.text.normitempadding
config_setting_lookup_int(conf, "selitempadding", &selitempadding); // spmenu.text.selitempadding
config_setting_lookup_int(conf, "priitempadding", &priitempadding); // spmenu.text.priitempadding
if (config_setting_lookup_string(conf, "leftarrow", &dest)) // spmenu.text.leftarrow
leftarrow = strdup(dest);

View file

@ -50,18 +50,34 @@ drawitemtext(struct item *item, int x, int y, int w)
int bgfg = 0; // both
int ignore = 0; // ignore colors
int skiphighlight = 0; // skip highlighting
int selitem = 0;
int priitem = 0;
// memcpy the correct scheme
if (item == sel) {
memcpy(scm, scheme[SchemeItemSel], sizeof(scm));
selitem = 1;
if (item->hp)
if (item->hp) {
memcpy(scm, scheme[SchemeItemSelPri], sizeof(scm));
priitem = 1;
}
} else {
memcpy(scm, scheme[SchemeItemNorm], sizeof(scm));
if (item->hp)
if (item->hp) {
memcpy(scm, scheme[SchemeItemNormPri], sizeof(scm));
priitem = 1;
}
}
// apply extra padding
if ((selitem && !priitem) && lines) {
leftpadding += selitempadding;
} else if (priitem && lines) {
leftpadding += priitempadding;
} else if (lines) {
leftpadding += normitempadding;
}
// don't color

View file

@ -104,6 +104,9 @@ ResourcePref resources[] = {
{ "menumarginv", INTEGER, &menumarginv },
{ "menumarginh", INTEGER, &menumarginh },
{ "textpadding", INTEGER, &textpadding },
{ "normitempadding", INTEGER, &normitempadding },
{ "selitempadding", INTEGER, &selitempadding },
{ "priitempadding", INTEGER, &priitempadding },
{ "indentitems", INTEGER, &indentitems },
{ "accuratewidth", INTEGER, &accuratewidth },
{ "alpha", INTEGER, &alpha },

View file

@ -58,7 +58,10 @@ static int borderwidth = 0; /* Width of the border */
/* Font options */
static char font[] = "Noto Sans Mono 8"; /* Font to draw text and Pango markup with. */
static int textpadding = 0; /* Text padding (lrpad) */
static int textpadding = 0; /* Global text padding */
static int normitempadding = 0; /* Text padding for normal items */
static int selitempadding = 0; /* Text padding for the selected item */
static int priitempadding = 0; /* Text padding for the high priority items */
/* Text options */
static char *leftarrow = "<"; /* Left arrow, used to indicate you can move to the left */