Skip to content
Snippets Groups Projects
Commit 1564517f authored by Joakim Borge Hunskår's avatar Joakim Borge Hunskår
Browse files

Merge branch 'update-dropdownlist' into 'main'

Dropdownlist is now more similar to the other widgets

See merge request !7
parents 7d63eea5 ced45305
No related branches found
No related tags found
1 merge request!7Dropdownlist is now more similar to the other widgets
...@@ -47,11 +47,11 @@ namespace TDT4102::internal { ...@@ -47,11 +47,11 @@ namespace TDT4102::internal {
std::unordered_map<Font, std::unordered_map<unsigned int, nk_font*>> loadedFonts; std::unordered_map<Font, std::unordered_map<unsigned int, nk_font*>> loadedFonts;
std::unordered_map<Font, std::unordered_map<unsigned int, nk_font_atlas*>> loadedAtlases; std::unordered_map<Font, std::unordered_map<unsigned int, nk_font_atlas*>> loadedAtlases;
std::filesystem::path findTTFInDirectory(const std::filesystem::path& directoryToSearch, const std::string& fontFileName); std::filesystem::path findTTFInDirectory(const std::filesystem::path &directoryToSearch, const std::string &fontFileName);
std::filesystem::path findTTFFile(const std::string &filename); std::filesystem::path findTTFFile(const std::string &filename);
void loadFont(nk_context *context, TDT4102::Font face, unsigned int size); void loadFont(nk_context *context, TDT4102::Font face, unsigned int size);
public: public:
void initialise(); void initialize();
void setFont(nk_context* context, TDT4102::Font face, unsigned int size); void setFont(nk_context* context, TDT4102::Font face, unsigned int size);
}; };
} }
...@@ -12,8 +12,8 @@ namespace TDT4102 { ...@@ -12,8 +12,8 @@ namespace TDT4102 {
protected: protected:
void update(nk_context* context) override; void update(nk_context* context) override;
public: public:
explicit DropdownList(TDT4102::Point location, int width, int height, std::vector<std::string> &options); explicit DropdownList(TDT4102::Point location, unsigned int width, unsigned int height, std::vector<std::string> &initialOptions);
std::string getValue(); std::string getSelectedValue() const;
void setOptions(std::vector<std::string>& updatedOptionsList); void setOptions(std::vector<std::string> &updatedOptionsList);
}; };
} }
\ No newline at end of file
...@@ -17,7 +17,7 @@ namespace TDT4102 { ...@@ -17,7 +17,7 @@ namespace TDT4102 {
void update(nk_context* context) override; void update(nk_context* context) override;
public: public:
explicit TextInput(TDT4102::Point location, unsigned int width, unsigned int height, std::string initialText = ""); 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); void setText(std::string text);
}; };
} }
\ No newline at end of file
...@@ -50,7 +50,7 @@ TDT4102::AnimationWindow::AnimationWindow(int x, int y, int width, int height, c ...@@ -50,7 +50,7 @@ TDT4102::AnimationWindow::AnimationWindow(int x, int y, int width, int height, c
std::cout << "Created an SDL renderer with name: " << rendererInfo.name << std::endl; std::cout << "Created an SDL renderer with name: " << rendererInfo.name << std::endl;
context = nk_sdl_init(windowHandle, rendererHandle); context = nk_sdl_init(windowHandle, rendererHandle);
fontCache.initialise(); fontCache.initialize();
fontCache.setFont(context, Font::defaultFont, 18); fontCache.setFont(context, Font::defaultFont, 18);
nk_clear(context); nk_clear(context);
} }
......
...@@ -66,7 +66,7 @@ void TDT4102::internal::FontCache::setFont(nk_context *context, TDT4102::Font fa ...@@ -66,7 +66,7 @@ void TDT4102::internal::FontCache::setFont(nk_context *context, TDT4102::Font fa
} }
void TDT4102::internal::FontCache::initialise() { void TDT4102::internal::FontCache::initialize() {
for(const std::pair<const TDT4102::Font, std::vector<std::string>> &fontFaceAlternatives : TTFFilenames) { for(const std::pair<const TDT4102::Font, std::vector<std::string>> &fontFaceAlternatives : TTFFilenames) {
bool suitableFontFound = false; bool suitableFontFound = false;
for(const std::string& fontFaceFile : fontFaceAlternatives.second) { for(const std::string& fontFaceFile : fontFaceAlternatives.second) {
......
#include "widgets/DropdownList.h" #include "widgets/DropdownList.h"
#include <stdexcept> #include <stdexcept>
TDT4102::DropdownList::DropdownList(TDT4102::Point location, int width, int height, std::vector<std::string> &options) TDT4102::DropdownList::DropdownList(TDT4102::Point location, unsigned int width, unsigned int height, std::vector<std::string> &initialOptions)
: TDT4102::Widget(location, width, height), options{options} { : TDT4102::Widget(location, width, height) {
if(options.size() == 0) { if(initialOptions.size() == 0) {
throw std::runtime_error("The list of options must contain at least one option to choose from!"); 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::getSelectedValue() const {
return options.at(selectedIndex); return options.at(selectedIndex);
} }
...@@ -26,6 +28,6 @@ void TDT4102::DropdownList::update(nk_context *context) { ...@@ -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; options = updatedOptionsList;
} }
\ No newline at end of file
#include "widgets/TextInput.h" #include "widgets/TextInput.h"
void TDT4102::TextInput::update(nk_context *context) { void TDT4102::TextInput::update(nk_context *context) {
nk_edit_string_zero_terminated(context, NK_EDIT_SELECTABLE | NK_EDIT_ALWAYS_INSERT_MODE | NK_EDIT_BOX | NK_EDIT_SIMPLE, contents.data(), internal::TEXT_INPUT_CHARACTER_LIMIT, nk_filter_ascii); nk_edit_string_zero_terminated(context, NK_EDIT_SELECTABLE | NK_EDIT_ALWAYS_INSERT_MODE | NK_EDIT_BOX | NK_EDIT_SIMPLE, const_cast<char*>(contents.data()), internal::TEXT_INPUT_CHARACTER_LIMIT, nk_filter_ascii);
// Detect whether any editing of the string has occurred // Detect whether any editing of the string has occurred
// Nuklear only reports whether the text box has lost focus // Nuklear only reports whether the text box has lost focus
...@@ -20,7 +20,7 @@ TDT4102::TextInput::TextInput(TDT4102::Point location, unsigned int width, unsig ...@@ -20,7 +20,7 @@ TDT4102::TextInput::TextInput(TDT4102::Point location, unsigned int width, unsig
previousContents.resize(internal::TEXT_INPUT_CHARACTER_LIMIT); 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 // The editing string contains a large number of zeroes at the end
// This chops those off // This chops those off
return std::string(contents.data()); 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