Skip to content

Commit

Permalink
Use status window pad settings to calculate width
Browse files Browse the repository at this point in the history
Reported in pekwm#171. Also fix PADADAPT not working, I think.
  • Loading branch information
pclouds committed Aug 16, 2024
1 parent 8f3e4fe commit bad1d3e
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 17 deletions.
2 changes: 1 addition & 1 deletion doc/themes.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ Theming of the frame.

* _Height (pixels)_, Amount of pixels the titlebar should height.
* _HeightAdapt (boolean)_, If true, Height is adapted to fit the Title font.
* _Pad (pixels t,d,l,r)_, How many pixels are left around a title text.
* _Pad (pixels t,b,l,r)_, How many pixels are left around a title text.
* _PadAdapt (boolean), Set true to adjust vertical padding so that the font gets centered vertically, requires _HeightAdapt_ to be false.
* _Focused (texture)_, Background texture for a focused titlebar.
* _UnFocused (texture)_, Background texture for an unfocused titlebar.
Expand Down
6 changes: 4 additions & 2 deletions src/StatusWindow.cc
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,9 @@ StatusWindow::draw(const std::string &text, bool do_center, Geometry *gm)
Theme::TextDialogData *sd = _theme->getStatusData();
PFont *font = sd->getFont();

width = font->getWidth(text) + 10;
width = font->getWidth(text)
+ sd->getPad(PAD_LEFT)
+ sd->getPad(PAD_RIGHT);
width = width - (width % 10);
height = font->getHeight()
+ sd->getPad(PAD_UP)
Expand All @@ -99,7 +101,7 @@ StatusWindow::draw(const std::string &text, bool do_center, Geometry *gm)
font->setColor(sd->getColor());
X11::clearWindow(_status_wo->getWindow());
font->draw(_status_wo,
(width - font->getWidth(text)) / 2,
sd->getPad(PAD_LEFT),
sd->getPad(PAD_UP),
text.c_str());
}
Expand Down
28 changes: 14 additions & 14 deletions src/tk/Theme.cc
Original file line number Diff line number Diff line change
Expand Up @@ -53,19 +53,19 @@ static void parse_pad(const std::string& str, int *pad)
static void calculate_pad_adapt(const int height_available, PFont* font,
int& pad_up, int& pad_down)
{
if (height_available == 0) {
pad_up = 0;
pad_down = 0;
float height = font->getHeight();
if (height_available < font->getHeight()) {
// Keep user settings if we can't adjust height
return;
}

float pad = height_available - height;
if (font->useAscentDescent()) {
pad_up = pad / (height / font->getAscent());
pad_down = pad / (height / font->getDescent());
} else {
float height = font->getHeight();
float pad = height_available - height;
if (font->useAscentDescent()) {
pad_up = pad / (height / font->getAscent());
pad_down = pad / (height / font->getDescent());
} else {
pad_up = pad / 2;
pad_down = pad / 2;
}
pad_up = pad / 2;
pad_down = pad / 2;
}
}

Expand Down Expand Up @@ -701,7 +701,7 @@ Theme::PMenuData::load(CfgParser::Entry *section)

if (pad_adapt) {
PFont* font = _font[OBJECT_STATE_FOCUSED];
calculate_pad_adapt(font->getHeight(), font,
calculate_pad_adapt(font->getHeight() + _pad[PAD_UP] + _pad[PAD_DOWN], font,
_pad[PAD_UP], _pad[PAD_DOWN]);
}

Expand Down Expand Up @@ -858,7 +858,7 @@ Theme::TextDialogData::load(CfgParser::Entry *section)
check();

if (pad_adapt) {
calculate_pad_adapt(_font->getHeight(), _font,
calculate_pad_adapt(_font->getHeight() + _pad[PAD_UP] + _pad[PAD_DOWN], _font,
_pad[PAD_UP], _pad[PAD_DOWN]);
}

Expand Down

0 comments on commit bad1d3e

Please sign in to comment.