mirror of
https://github.com/clangen/musikcube.git
synced 2024-11-19 20:13:36 +00:00
Added text alignment options to ShortcutsWindow.
This commit is contained in:
parent
7e60827aab
commit
38912b9e63
@ -43,7 +43,8 @@
|
||||
using namespace cursespp;
|
||||
|
||||
ShortcutsWindow::ShortcutsWindow()
|
||||
: Window(nullptr) {
|
||||
: Window(nullptr)
|
||||
, alignment(text::AlignCenter) {
|
||||
this->SetFrameVisible(false);
|
||||
this->UpdateContentColor();
|
||||
}
|
||||
@ -51,6 +52,11 @@ ShortcutsWindow::ShortcutsWindow()
|
||||
ShortcutsWindow::~ShortcutsWindow() {
|
||||
}
|
||||
|
||||
void ShortcutsWindow::SetAlignment(text::TextAlign align) {
|
||||
this->alignment = align;
|
||||
this->Repaint();
|
||||
}
|
||||
|
||||
void ShortcutsWindow::AddShortcut(
|
||||
const std::string& key,
|
||||
const std::string& description,
|
||||
@ -83,6 +89,29 @@ void ShortcutsWindow::UpdateContentColor() {
|
||||
: CURSESPP_SHORTCUT_ROW_NORMAL);
|
||||
}
|
||||
|
||||
size_t ShortcutsWindow::CalculateLeftPadding() {
|
||||
if (this->alignment = text::AlignLeft) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int padding = this->GetContentWidth();
|
||||
|
||||
for (size_t i = 0; i < this->entries.size(); i++) {
|
||||
auto e = this->entries[i];
|
||||
padding -= u8cols(e->key) + u8cols(e->description) + 5;
|
||||
}
|
||||
|
||||
if (padding < 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (this->alignment == text::AlignRight) {
|
||||
return padding;
|
||||
}
|
||||
|
||||
return (padding / 2); /* text::AlignCenter */
|
||||
}
|
||||
|
||||
void ShortcutsWindow::Repaint() {
|
||||
Window::Repaint();
|
||||
|
||||
@ -93,6 +122,9 @@ void ShortcutsWindow::Repaint() {
|
||||
|
||||
WINDOW* c = this->GetContent();
|
||||
|
||||
size_t leftPadding = this->CalculateLeftPadding();
|
||||
wmove(c, 0, leftPadding);
|
||||
|
||||
size_t remaining = this->GetContentWidth();
|
||||
for (size_t i = 0; i < this->entries.size() && remaining > 0; i++) {
|
||||
auto e = this->entries[i];
|
||||
|
@ -34,7 +34,8 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <cursespp/Window.h>
|
||||
#include "Window.h"
|
||||
#include "Text.h"
|
||||
|
||||
namespace cursespp {
|
||||
class ShortcutsWindow :
|
||||
@ -47,6 +48,8 @@ namespace cursespp {
|
||||
ShortcutsWindow();
|
||||
virtual ~ShortcutsWindow();
|
||||
|
||||
void SetAlignment(text::TextAlign alignment);
|
||||
|
||||
void AddShortcut(
|
||||
const std::string& key,
|
||||
const std::string& description,
|
||||
@ -63,6 +66,7 @@ namespace cursespp {
|
||||
|
||||
private:
|
||||
void UpdateContentColor();
|
||||
size_t CalculateLeftPadding();
|
||||
|
||||
struct Entry {
|
||||
Entry(const std::string& key, const std::string& desc, int64 attrs = -1) {
|
||||
@ -80,5 +84,6 @@ namespace cursespp {
|
||||
|
||||
EntryList entries;
|
||||
std::string activeKey;
|
||||
text::TextAlign alignment;
|
||||
};
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user