Fixed some minor bugs

This commit is contained in:
Markus Gans 2020-08-13 00:34:39 +02:00
parent b54d1c2f38
commit 50fc6fdb63
3 changed files with 15 additions and 12 deletions

View File

@ -108,7 +108,7 @@ FMessageBox& FMessageBox::operator = (const FMessageBox& mbox)
} }
else else
{ {
for (uInt n{0}; n < num_buttons && button[n]; n++) for (std::size_t n{0}; n < num_buttons && n < MAX_BUTTONS; n++)
delete button[n]; delete button[n];
if ( mbox.getParentWidget() ) if ( mbox.getParentWidget() )
@ -138,7 +138,7 @@ void FMessageBox::setHeadline (const FString& headline)
headline_text.setString(headline); headline_text.setString(headline);
setHeight(getHeight() + 2, true); setHeight(getHeight() + 2, true);
for (uInt n{0}; n < num_buttons && button[n]; n++) for (std::size_t n{0}; n < num_buttons && n < MAX_BUTTONS; n++)
button[n]->setY (int(getHeight()) - 4, false); button[n]->setY (int(getHeight()) - 4, false);
const std::size_t column_width = getColumnWidth(headline_text); const std::size_t column_width = getColumnWidth(headline_text);
@ -268,7 +268,7 @@ inline void FMessageBox::allocation()
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline void FMessageBox::deallocation() inline void FMessageBox::deallocation()
{ {
for (uInt n{0}; n < num_buttons && button[n]; n++) for (std::size_t n{0}; n < num_buttons && n < MAX_BUTTONS; n++)
delete button[n]; delete button[n];
} }
@ -388,7 +388,7 @@ void FMessageBox::resizeButtons() const
std::size_t len[3]{}; std::size_t len[3]{};
std::size_t max_size{}; std::size_t max_size{};
for (std::size_t n{0}; n < num_buttons && button[n]; n++) for (std::size_t n{0}; n < num_buttons && n < MAX_BUTTONS; n++)
{ {
len[n] = button[n]->getText().getLength(); len[n] = button[n]->getText().getLength();
@ -410,7 +410,7 @@ void FMessageBox::resizeButtons() const
if ( max_size < 7 ) if ( max_size < 7 )
max_size = 7; max_size = 7;
for (std::size_t n{0}; n < num_buttons && button[n]; n++) for (std::size_t n{0}; n < num_buttons && n < MAX_BUTTONS; n++)
button[n]->setWidth(max_size + 3, false); button[n]->setWidth(max_size + 3, false);
} }
@ -420,7 +420,7 @@ void FMessageBox::adjustButtons()
static constexpr std::size_t gap = 4; static constexpr std::size_t gap = 4;
std::size_t btn_width{0}; std::size_t btn_width{0};
for (std::size_t n{0}; n < num_buttons && button[n]; n++) for (std::size_t n{0}; n < num_buttons && n < MAX_BUTTONS; n++)
{ {
if ( n == num_buttons - 1 ) if ( n == num_buttons - 1 )
btn_width += button[n]->getWidth(); btn_width += button[n]->getWidth();
@ -439,7 +439,7 @@ void FMessageBox::adjustButtons()
const int btn_x = int((getWidth() - btn_width) / 2); const int btn_x = int((getWidth() - btn_width) / 2);
for (std::size_t n{0}; n < num_buttons && button[n]; n++) for (std::size_t n{0}; n < num_buttons && n < MAX_BUTTONS; n++)
{ {
if ( n == 0 ) if ( n == 0 )
button[n]->setX(btn_x); button[n]->setX(btn_x);

View File

@ -137,6 +137,9 @@ class FMessageBox : public FDialog
void cb_processClick (int); void cb_processClick (int);
private: private:
// Constants
static constexpr std::size_t MAX_BUTTONS = 3;
// Methods // Methods
void init(); void init();
void allocation(); void allocation();
@ -151,11 +154,11 @@ class FMessageBox : public FDialog
FString headline_text{}; FString headline_text{};
FString text{}; FString text{};
FStringList text_components{}; FStringList text_components{};
FButton* button[3]{nullptr}; FButton* button[MAX_BUTTONS]{nullptr};
std::size_t max_line_width{0}; std::size_t max_line_width{0};
FColor emphasis_color{getColorTheme()->dialog_emphasis_fg}; FColor emphasis_color{getColorTheme()->dialog_emphasis_fg};
int button_digit[3]{0}; int button_digit[MAX_BUTTONS]{0};
uInt num_buttons{0}; std::size_t num_buttons{0};
std::size_t text_num_lines{0}; std::size_t text_num_lines{0};
bool center_text{false}; bool center_text{false};
}; };

View File

@ -320,7 +320,7 @@ class FWidget : public FVTerm, public FObject
void addCallback (const FString&, Args&&...); void addCallback (const FString&, Args&&...);
template<typename... Args> template<typename... Args>
void delCallback (Args&&...); void delCallback (Args&&...);
void emitCallback (const FString&); void emitCallback (const FString&) const;
void addAccelerator (FKey); void addAccelerator (FKey);
virtual void addAccelerator (FKey, FWidget*); virtual void addAccelerator (FKey, FWidget*);
void delAccelerator (); void delAccelerator ();
@ -997,7 +997,7 @@ inline void FWidget::delCallback (Args&&... args)
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline void FWidget::emitCallback (const FString& emit_signal) inline void FWidget::emitCallback (const FString& emit_signal) const
{ {
callback_impl.emitCallback(emit_signal); callback_impl.emitCallback(emit_signal);
} }