Warning cleanup

This commit is contained in:
casey langen 2021-03-06 14:36:38 -08:00
parent 95420b8359
commit e0fcfcf162
3 changed files with 27 additions and 24 deletions

View File

@ -198,16 +198,16 @@ void DialogOverlay::RecalculateSize() {
/* ensure the overlay doesn't exceed the height of the screen,
or things may get crashy. normally this will be done for us automatically
in Window, but because we're free-floating we need to do it manually here. */
int top = this->GetY();
int bottom = top + this->height + VERTICAL_PADDING;
int screenHeight = Screen::GetHeight();
const int top = this->GetY();
const int bottom = top + this->height + VERTICAL_PADDING;
const int screenHeight = Screen::GetHeight();
if (bottom > screenHeight) {
this->height = screenHeight - top - VERTICAL_PADDING;
}
int left = this->GetX();
int right = left + this->width + HORIZONTAL_PADDING;
int screenWidth = Screen::GetWidth();
const int left = this->GetX();
const int right = left + this->width + HORIZONTAL_PADDING;
const int screenWidth = Screen::GetWidth();
if (right > screenWidth) {
this->width = screenWidth - left - HORIZONTAL_PADDING;
}

View File

@ -45,7 +45,7 @@ inline static bool removeUtf8Char(std::string& value, size_t position) {
/* optimize the normal case, at the end... */
if (position >= value.size()) {
std::string::iterator it = value.end();
std::string::iterator start = value.begin();
const std::string::iterator start = value.begin();
if (it != start) {
utf8::prior(it, start);
value = std::string(value.begin(), it);
@ -53,9 +53,9 @@ inline static bool removeUtf8Char(std::string& value, size_t position) {
}
}
else {
size_t offset = u8offset(value, position - 1);
const size_t offset = u8offset(value, position - 1);
if (offset != std::string::npos) {
size_t end = u8offset(value, position);
const size_t end = u8offset(value, position);
value.erase(offset, end - offset);
return true;
}
@ -90,8 +90,8 @@ void TextInput::OnRedraw() {
werase(c);
std::string trimmed;
int contentWidth = GetContentWidth();
int columns = u8cols(buffer);
const int contentWidth = GetContentWidth();
const size_t columns = u8cols(buffer);
/* if the string is larger than our width, we gotta trim it for
display purposes... */
@ -104,7 +104,7 @@ void TextInput::OnRedraw() {
if (!columns && hintText.size()) {
/* draw the hint if we have one and there's no string yet */
int64_t color = Color(Color::TextDisabled);
const int64_t color = Color(Color::TextDisabled);
wattron(c, color);
wmove(c, 0, 0);
checked_waddstr(c, u8substr(hintText, 0, contentWidth).c_str());
@ -119,7 +119,7 @@ void TextInput::OnRedraw() {
/* if we're in "Line" mode and the string is short, pad the
end with a bunch of underscores */
if (style == StyleLine) {
int remaining = contentWidth - columns;
const int remaining = contentWidth - columns;
if (remaining > 0) {
trimmed += std::string(remaining, '_');
}
@ -131,7 +131,7 @@ void TextInput::OnRedraw() {
}
}
size_t TextInput::Length() {
size_t TextInput::Length() noexcept {
return this->bufferLength;
}
@ -145,7 +145,7 @@ bool TextInput::Write(const std::string& key) {
/* one character at a time. if it's more than one character, we're
dealing with an escape sequence and should not print it unless
the input mode allows for modifiers */
int len = u8len(key);
const int len = narrow_cast<int>(u8len(key));
if (len == 1 || (len > 1 && this->inputMode == InputRaw)) {
if (this->inputMode == InputRaw) {
auto& bl = this->rawBlacklist;
@ -158,7 +158,7 @@ bool TextInput::Write(const std::string& key) {
}
else {
if (truncate) {
int cols = u8cols(this->buffer);
const int cols = narrow_cast<int>(u8cols(this->buffer));
if (cols >= this->GetWidth()) {
return false;
}
@ -179,13 +179,13 @@ bool TextInput::Write(const std::string& key) {
return false;
}
void TextInput::SetTruncate(bool truncate) {
void TextInput::SetTruncate(bool truncate) noexcept {
if (this->truncate != truncate) {
this->truncate = truncate;
}
}
void TextInput::SetEnterEnabled(bool enabled) {
void TextInput::SetEnterEnabled(bool enabled) noexcept {
this->enterEnabled = enabled;
}
@ -239,8 +239,8 @@ bool TextInput::KeyPress(const std::string& key) {
return true;
}
else if (key == "KEY_DC") {
if ((int) this->bufferLength > this->position) {
removeUtf8Char(this->buffer, this->position + 1);
if (narrow_cast<int>(this->bufferLength) > this->position) {
removeUtf8Char(this->buffer, narrow_cast<size_t>(this->position + 1));
this->bufferLength = u8len(buffer);
this->Redraw();
this->TextChanged(this, this->buffer);

View File

@ -60,9 +60,12 @@ namespace cursespp {
/* IInput */
bool Write(const std::string& key) override;
size_t Length() override;
size_t Length() noexcept override;
size_t Position() override;
InputMode GetInputMode() noexcept override { return this->inputMode; }
InputMode GetInputMode() noexcept override {
return this->inputMode;
}
/* IWindow */
bool KeyPress(const std::string& key) override;
@ -73,9 +76,9 @@ namespace cursespp {
/* regular methods we define */
void SetRawKeyBlacklist(const std::vector<std::string>&& blacklist);
void SetTruncate(bool truncate);
void SetTruncate(bool truncate) noexcept;
void SetHint(const std::string& hint);
void SetEnterEnabled(bool enabled);
void SetEnterEnabled(bool enabled) noexcept;
Style GetStyle() noexcept {
return style;