Skip to content
Snippets Groups Projects
Commit 912a7c12 authored by Joakim Hunskaar's avatar Joakim Hunskaar
Browse files

unsigned w and h, options are not initialized if empty in dropdownlist and...

unsigned w and h, options are not initialized if empty in dropdownlist and marked some functions as const
parent e28c79c7
No related branches found
No related tags found
1 merge request!7Dropdownlist is now more similar to the other widgets
......@@ -12,8 +12,8 @@ namespace TDT4102 {
protected:
void update(nk_context* context) override;
public:
explicit DropdownList(TDT4102::Point location, int width, int height, std::vector<std::string> &options);
std::string getValue();
void setOptions(std::vector<std::string>& updatedOptionsList);
explicit DropdownList(TDT4102::Point location, unsigned int width, unsigned int height, std::vector<std::string> &initialOptions);
std::string getValue() const;
void setOptions(std::vector<std::string> &updatedOptionsList);
};
}
\ No newline at end of file
......@@ -17,7 +17,7 @@ namespace TDT4102 {
void update(nk_context* context) override;
public:
explicit TextInput(TDT4102::Point location, unsigned int width, unsigned int height, std::string initialText = "");
std::string getText();
std::string getText() const;
void setText(std::string text);
};
}
\ No newline at end of file
#include "widgets/DropdownList.h"
#include <stdexcept>
TDT4102::DropdownList::DropdownList(TDT4102::Point location, int width, int height, std::vector<std::string> &options)
: TDT4102::Widget(location, width, height), options{options} {
TDT4102::DropdownList::DropdownList(TDT4102::Point location, unsigned int width, unsigned int height, std::vector<std::string> &initialOptions)
: TDT4102::Widget(location, width, height) {
if(options.size() == 0) {
throw std::runtime_error("The list of options must contain at least one option to choose from!");
}
options = initialOptions;
}
std::string TDT4102::DropdownList::getValue() {
std::string TDT4102::DropdownList::getValue() const {
return options.at(selectedIndex);
}
......@@ -26,6 +28,6 @@ void TDT4102::DropdownList::update(nk_context *context) {
}
}
void TDT4102::DropdownList::setOptions(std::vector<std::string>& updatedOptionsList) {
void TDT4102::DropdownList::setOptions(std::vector<std::string> &updatedOptionsList) {
options = updatedOptionsList;
}
\ No newline at end of file
......@@ -20,7 +20,7 @@ TDT4102::TextInput::TextInput(TDT4102::Point location, unsigned int width, unsig
previousContents.resize(internal::TEXT_INPUT_CHARACTER_LIMIT);
}
std::string TDT4102::TextInput::getText() {
std::string TDT4102::TextInput::getText() const {
// The editing string contains a large number of zeroes at the end
// This chops those off
return std::string(contents.data());
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment