Optimize parameter passing to avoid unnecessary copying
This commit is contained in:
@@ -1,12 +1,14 @@
|
||||
#include "Button.hpp"
|
||||
|
||||
#include <utility>
|
||||
|
||||
#include "Label.hpp"
|
||||
#include "../../core/DrawContext.hpp"
|
||||
#include "../../core/Batch2D.hpp"
|
||||
|
||||
using namespace gui;
|
||||
|
||||
Button::Button(std::shared_ptr<UINode> content, glm::vec4 padding)
|
||||
Button::Button(const std::shared_ptr<UINode>& content, glm::vec4 padding)
|
||||
: Panel(glm::vec2(), padding, 0) {
|
||||
glm::vec4 margin = getMargin();
|
||||
setSize(content->getSize()+
|
||||
@@ -20,9 +22,9 @@ Button::Button(std::shared_ptr<UINode> content, glm::vec4 padding)
|
||||
}
|
||||
|
||||
Button::Button(
|
||||
std::wstring text,
|
||||
const std::wstring& text,
|
||||
glm::vec4 padding,
|
||||
onaction action,
|
||||
const onaction& action,
|
||||
glm::vec2 size
|
||||
) : Panel(size, padding, 0)
|
||||
{
|
||||
@@ -63,7 +65,7 @@ std::wstring Button::getText() const {
|
||||
|
||||
Button* Button::textSupplier(wstringsupplier supplier) {
|
||||
if (label) {
|
||||
label->textSupplier(supplier);
|
||||
label->textSupplier(std::move(supplier));
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -10,12 +10,12 @@ namespace gui {
|
||||
protected:
|
||||
std::shared_ptr<Label> label = nullptr;
|
||||
public:
|
||||
Button(std::shared_ptr<UINode> content,
|
||||
Button(const std::shared_ptr<UINode>& content,
|
||||
glm::vec4 padding=glm::vec4(2.0f));
|
||||
|
||||
Button(std::wstring text,
|
||||
Button(const std::wstring& text,
|
||||
glm::vec4 padding,
|
||||
onaction action,
|
||||
const onaction& action,
|
||||
glm::vec2 size=glm::vec2(-1));
|
||||
|
||||
virtual void drawBackground(const DrawContext* pctx, Assets* assets) override;
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
#include "CheckBox.hpp"
|
||||
|
||||
#include <utility>
|
||||
|
||||
#include "../../core/DrawContext.hpp"
|
||||
#include "../../core/Batch2D.hpp"
|
||||
#include "Label.hpp"
|
||||
@@ -30,11 +32,11 @@ void CheckBox::mouseRelease(GUI*, int, int) {
|
||||
}
|
||||
|
||||
void CheckBox::setSupplier(boolsupplier supplier) {
|
||||
this->supplier = supplier;
|
||||
this->supplier = std::move(supplier);
|
||||
}
|
||||
|
||||
void CheckBox::setConsumer(boolconsumer consumer) {
|
||||
this->consumer = consumer;
|
||||
this->consumer = std::move(consumer);
|
||||
}
|
||||
|
||||
CheckBox* CheckBox::setChecked(bool flag) {
|
||||
@@ -42,7 +44,7 @@ CheckBox* CheckBox::setChecked(bool flag) {
|
||||
return this;
|
||||
}
|
||||
|
||||
FullCheckBox::FullCheckBox(std::wstring text, glm::vec2 size, bool checked)
|
||||
FullCheckBox::FullCheckBox(const std::wstring& text, glm::vec2 size, bool checked)
|
||||
: Panel(size),
|
||||
checkbox(std::make_shared<CheckBox>(checked)){
|
||||
setColor(glm::vec4(0.0f));
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
#ifndef GRAPHICS_UI_ELEMENTS_CHECKBOX_HPP_
|
||||
#define GRAPHICS_UI_ELEMENTS_CHECKBOX_HPP_
|
||||
|
||||
#include <utility>
|
||||
|
||||
#include "Panel.hpp"
|
||||
|
||||
namespace gui {
|
||||
@@ -33,14 +35,14 @@ namespace gui {
|
||||
protected:
|
||||
std::shared_ptr<CheckBox> checkbox;
|
||||
public:
|
||||
FullCheckBox(std::wstring text, glm::vec2 size, bool checked=false);
|
||||
FullCheckBox(const std::wstring& text, glm::vec2 size, bool checked=false);
|
||||
|
||||
virtual void setSupplier(boolsupplier supplier) {
|
||||
checkbox->setSupplier(supplier);
|
||||
checkbox->setSupplier(std::move(supplier));
|
||||
}
|
||||
|
||||
virtual void setConsumer(boolconsumer consumer) {
|
||||
checkbox->setConsumer(consumer);
|
||||
checkbox->setConsumer(std::move(consumer));
|
||||
}
|
||||
|
||||
virtual void setChecked(bool flag) {
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include "../../core/Batch2D.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
#include <utility>
|
||||
|
||||
using namespace gui;
|
||||
|
||||
@@ -31,7 +32,7 @@ std::shared_ptr<UINode> Container::getAt(glm::vec2 pos, std::shared_ptr<UINode>
|
||||
}
|
||||
|
||||
void Container::act(float delta) {
|
||||
for (auto node : nodes) {
|
||||
for (const auto& node : nodes) {
|
||||
if (node->isVisible()) {
|
||||
node->act(delta);
|
||||
}
|
||||
@@ -86,7 +87,7 @@ void Container::draw(const DrawContext* pctx, Assets* assets) {
|
||||
{
|
||||
DrawContext ctx = pctx->sub();
|
||||
ctx.setScissors(glm::vec4(pos.x, pos.y, size.x, size.y));
|
||||
for (auto node : nodes) {
|
||||
for (const auto& node : nodes) {
|
||||
if (node->isVisible())
|
||||
node->draw(pctx, assets);
|
||||
}
|
||||
@@ -105,22 +106,22 @@ void Container::drawBackground(const DrawContext* pctx, Assets*) {
|
||||
batch->rect(pos.x, pos.y, size.x, size.y);
|
||||
}
|
||||
|
||||
void Container::add(std::shared_ptr<UINode> node) {
|
||||
void Container::add(const std::shared_ptr<UINode> &node) {
|
||||
nodes.push_back(node);
|
||||
node->setParent(this);
|
||||
node->reposition();
|
||||
refresh();
|
||||
}
|
||||
|
||||
void Container::add(std::shared_ptr<UINode> node, glm::vec2 pos) {
|
||||
void Container::add(const std::shared_ptr<UINode>& node, glm::vec2 pos) {
|
||||
node->setPos(pos);
|
||||
add(node);
|
||||
}
|
||||
|
||||
void Container::remove(std::shared_ptr<UINode> selected) {
|
||||
void Container::remove(const std::shared_ptr<UINode>& selected) {
|
||||
selected->setParent(nullptr);
|
||||
nodes.erase(std::remove_if(nodes.begin(), nodes.end(),
|
||||
[selected](const std::shared_ptr<UINode> node) {
|
||||
[selected](const std::shared_ptr<UINode>& node) {
|
||||
return node == selected;
|
||||
}
|
||||
), nodes.end());
|
||||
@@ -136,7 +137,7 @@ void Container::remove(const std::string& id) {
|
||||
}
|
||||
|
||||
void Container::clear() {
|
||||
for (auto node : nodes) {
|
||||
for (const auto& node : nodes) {
|
||||
node->setParent(nullptr);
|
||||
}
|
||||
nodes.clear();
|
||||
@@ -144,7 +145,7 @@ void Container::clear() {
|
||||
}
|
||||
|
||||
void Container::listenInterval(float interval, ontimeout callback, int repeat) {
|
||||
intervalEvents.push_back({callback, interval, 0.0f, repeat});
|
||||
intervalEvents.push_back({std::move(callback), interval, 0.0f, repeat});
|
||||
}
|
||||
|
||||
void Container::setSize(glm::vec2 size) {
|
||||
|
||||
@@ -22,10 +22,10 @@ namespace gui {
|
||||
virtual void drawBackground(const DrawContext* pctx, Assets* assets);
|
||||
virtual void draw(const DrawContext* pctx, Assets* assets) override;
|
||||
virtual std::shared_ptr<UINode> getAt(glm::vec2 pos, std::shared_ptr<UINode> self) override;
|
||||
virtual void add(std::shared_ptr<UINode> node);
|
||||
virtual void add(std::shared_ptr<UINode> node, glm::vec2 pos);
|
||||
virtual void add(const std::shared_ptr<UINode> &node);
|
||||
virtual void add(const std::shared_ptr<UINode> &node, glm::vec2 pos);
|
||||
virtual void clear();
|
||||
virtual void remove(std::shared_ptr<UINode> node);
|
||||
virtual void remove(const std::shared_ptr<UINode>& node);
|
||||
virtual void remove(const std::string& id);
|
||||
virtual void scrolled(int value) override;
|
||||
virtual void setScrollable(bool flag);
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
#include "Image.hpp"
|
||||
|
||||
#include <utility>
|
||||
|
||||
#include "../../core/DrawContext.hpp"
|
||||
#include "../../core/Batch2D.hpp"
|
||||
#include "../../core/Texture.hpp"
|
||||
@@ -8,7 +10,7 @@
|
||||
|
||||
using namespace gui;
|
||||
|
||||
Image::Image(std::string texture, glm::vec2 size) : UINode(size), texture(texture) {
|
||||
Image::Image(std::string texture, glm::vec2 size) : UINode(size), texture(std::move(texture)) {
|
||||
setInteractive(false);
|
||||
}
|
||||
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
#include "../GUI.hpp"
|
||||
|
||||
#include <glm/glm.hpp>
|
||||
#include <utility>
|
||||
|
||||
using namespace gui;
|
||||
|
||||
@@ -40,9 +41,9 @@ SlotLayout::SlotLayout(
|
||||
position(position),
|
||||
background(background),
|
||||
itemSource(itemSource),
|
||||
updateFunc(updateFunc),
|
||||
shareFunc(shareFunc),
|
||||
rightClick(rightClick) {}
|
||||
updateFunc(std::move(updateFunc)),
|
||||
shareFunc(std::move(shareFunc)),
|
||||
rightClick(std::move(rightClick)) {}
|
||||
|
||||
InventoryBuilder::InventoryBuilder() {
|
||||
view = std::make_shared<InventoryView>();
|
||||
@@ -53,7 +54,7 @@ void InventoryBuilder::addGrid(
|
||||
glm::vec2 pos,
|
||||
int padding,
|
||||
bool addpanel,
|
||||
SlotLayout slotLayout
|
||||
const SlotLayout& slotLayout
|
||||
) {
|
||||
const int slotSize = InventoryView::SLOT_SIZE;
|
||||
const int interval = InventoryView::SLOT_INTERVAL;
|
||||
@@ -95,7 +96,7 @@ void InventoryBuilder::addGrid(
|
||||
}
|
||||
}
|
||||
|
||||
void InventoryBuilder::add(SlotLayout layout) {
|
||||
void InventoryBuilder::add(const SlotLayout& layout) {
|
||||
view->add(view->addSlot(layout), layout.position);
|
||||
}
|
||||
|
||||
@@ -106,7 +107,7 @@ std::shared_ptr<InventoryView> InventoryBuilder::build() {
|
||||
SlotView::SlotView(
|
||||
SlotLayout layout
|
||||
) : UINode(glm::vec2(InventoryView::SLOT_SIZE)),
|
||||
layout(layout)
|
||||
layout(std::move(layout))
|
||||
{
|
||||
setColor(glm::vec4(0, 0, 0, 0.2f));
|
||||
setTooltipDelay(0.05f);
|
||||
@@ -309,7 +310,7 @@ InventoryView::InventoryView() : Container(glm::vec2()) {
|
||||
InventoryView::~InventoryView() {}
|
||||
|
||||
|
||||
std::shared_ptr<SlotView> InventoryView::addSlot(SlotLayout layout) {
|
||||
std::shared_ptr<SlotView> InventoryView::addSlot(const SlotLayout& layout) {
|
||||
uint width = InventoryView::SLOT_SIZE + layout.padding;
|
||||
uint height = InventoryView::SLOT_SIZE + layout.padding;
|
||||
|
||||
@@ -341,7 +342,7 @@ size_t InventoryView::getSlotsCount() const {
|
||||
}
|
||||
|
||||
void InventoryView::bind(
|
||||
std::shared_ptr<Inventory> inventory,
|
||||
const std::shared_ptr<Inventory>& inventory,
|
||||
const Content* content
|
||||
) {
|
||||
this->inventory = inventory;
|
||||
|
||||
@@ -96,13 +96,13 @@ namespace gui {
|
||||
void setSelected(int index);
|
||||
|
||||
void bind(
|
||||
std::shared_ptr<Inventory> inventory,
|
||||
const std::shared_ptr<Inventory>& inventory,
|
||||
const Content* content
|
||||
);
|
||||
|
||||
void unbind();
|
||||
|
||||
std::shared_ptr<SlotView> addSlot(SlotLayout layout);
|
||||
std::shared_ptr<SlotView> addSlot(const SlotLayout& layout);
|
||||
|
||||
std::shared_ptr<Inventory> getInventory() const;
|
||||
|
||||
@@ -130,10 +130,10 @@ namespace gui {
|
||||
glm::vec2 pos,
|
||||
int padding,
|
||||
bool addpanel,
|
||||
SlotLayout slotLayout
|
||||
const SlotLayout& slotLayout
|
||||
);
|
||||
|
||||
void add(SlotLayout slotLayout);
|
||||
void add(const SlotLayout& slotLayout);
|
||||
std::shared_ptr<InventoryView> build();
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
#include "Label.hpp"
|
||||
|
||||
#include <utility>
|
||||
#include "../../core/DrawContext.hpp"
|
||||
#include "../../core/Batch2D.hpp"
|
||||
#include "../../core/Font.hpp"
|
||||
@@ -45,20 +47,20 @@ void LabelCache::update(const std::wstring& text, bool multiline, bool wrap) {
|
||||
}
|
||||
}
|
||||
|
||||
Label::Label(std::string text, std::string fontName)
|
||||
Label::Label(const std::string& text, std::string fontName)
|
||||
: UINode(glm::vec2(text.length() * 8, 15)),
|
||||
text(util::str2wstr_utf8(text)),
|
||||
fontName(fontName)
|
||||
fontName(std::move(fontName))
|
||||
{
|
||||
setInteractive(false);
|
||||
cache.update(this->text, multiline, textWrap);
|
||||
}
|
||||
|
||||
|
||||
Label::Label(std::wstring text, std::string fontName)
|
||||
Label::Label(const std::wstring& text, std::string fontName)
|
||||
: UINode(glm::vec2(text.length() * 8, 15)),
|
||||
text(text),
|
||||
fontName(fontName)
|
||||
fontName(std::move(fontName))
|
||||
{
|
||||
setInteractive(false);
|
||||
cache.update(this->text, multiline, textWrap);
|
||||
@@ -76,7 +78,7 @@ glm::vec2 Label::calcSize() {
|
||||
);
|
||||
}
|
||||
|
||||
void Label::setText(std::wstring text) {
|
||||
void Label::setText(const std::wstring& text) {
|
||||
if (text == this->text && !cache.resetFlag) {
|
||||
return;
|
||||
}
|
||||
@@ -93,7 +95,7 @@ const std::wstring& Label::getText() const {
|
||||
}
|
||||
|
||||
void Label::setFontName(std::string name) {
|
||||
this->fontName = name;
|
||||
this->fontName = std::move(name);
|
||||
}
|
||||
|
||||
const std::string& Label::getFontName() const {
|
||||
@@ -207,7 +209,7 @@ void Label::draw(const DrawContext* pctx, Assets* assets) {
|
||||
}
|
||||
|
||||
void Label::textSupplier(wstringsupplier supplier) {
|
||||
this->supplier = supplier;
|
||||
this->supplier = std::move(supplier);
|
||||
}
|
||||
|
||||
void Label::setAutoResize(bool flag) {
|
||||
|
||||
@@ -53,10 +53,10 @@ namespace gui {
|
||||
/// @brief Auto resize label to fit text
|
||||
bool autoresize = false;
|
||||
public:
|
||||
Label(std::string text, std::string fontName="normal");
|
||||
Label(std::wstring text, std::string fontName="normal");
|
||||
Label(const std::string& text, std::string fontName="normal");
|
||||
Label(const std::wstring& text, std::string fontName="normal");
|
||||
|
||||
virtual void setText(std::wstring text);
|
||||
virtual void setText(const std::wstring& text);
|
||||
const std::wstring& getText() const;
|
||||
|
||||
virtual void setFontName(std::string name);
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include "Menu.hpp"
|
||||
|
||||
#include <stdexcept>
|
||||
#include <utility>
|
||||
|
||||
using namespace gui;
|
||||
|
||||
@@ -12,11 +13,11 @@ bool Menu::has(const std::string& name) {
|
||||
pageSuppliers.find(name) != pageSuppliers.end();
|
||||
}
|
||||
|
||||
void Menu::addPage(std::string name, std::shared_ptr<UINode> panel) {
|
||||
void Menu::addPage(const std::string& name, const std::shared_ptr<UINode> &panel) {
|
||||
pages[name] = Page{name, panel};
|
||||
}
|
||||
|
||||
void Menu::addSupplier(std::string name, supplier<std::shared_ptr<UINode>> pageSupplier) {
|
||||
void Menu::addSupplier(const std::string &name, const supplier<std::shared_ptr<UINode>> &pageSupplier) {
|
||||
pageSuppliers[name] = pageSupplier;
|
||||
}
|
||||
|
||||
@@ -38,7 +39,7 @@ std::shared_ptr<UINode> Menu::fetchPage(const std::string& name) {
|
||||
}
|
||||
}
|
||||
|
||||
void Menu::setPage(std::string name, bool history) {
|
||||
void Menu::setPage(const std::string &name, bool history) {
|
||||
Page page {name, fetchPage(name)};
|
||||
if (page.panel == nullptr) {
|
||||
throw std::runtime_error("no page found");
|
||||
@@ -53,7 +54,7 @@ void Menu::setPage(Page page, bool history) {
|
||||
pageStack.push(current);
|
||||
}
|
||||
}
|
||||
current = page;
|
||||
current = std::move(page);
|
||||
Container::add(current.panel);
|
||||
setSize(current.panel->getSize());
|
||||
}
|
||||
@@ -73,7 +74,7 @@ void Menu::back() {
|
||||
}
|
||||
|
||||
void Menu::setPageLoader(page_loader_func loader) {
|
||||
pagesLoader = loader;
|
||||
pagesLoader = std::move(loader);
|
||||
}
|
||||
|
||||
Page& Menu::getCurrent() {
|
||||
|
||||
@@ -30,15 +30,15 @@ namespace gui {
|
||||
/// @brief Set current page to specified one.
|
||||
/// @param name page or page supplier name
|
||||
/// @param history previous page will not be saved in history if false
|
||||
void setPage(std::string name, bool history=true);
|
||||
void setPage(const std::string &name, bool history=true);
|
||||
void setPage(Page page, bool history=true);
|
||||
void addPage(std::string name, std::shared_ptr<UINode> panel);
|
||||
void addPage(const std::string& name, const std::shared_ptr<UINode> &panel);
|
||||
std::shared_ptr<UINode> fetchPage(const std::string& name);
|
||||
|
||||
/// @brief Add page supplier used if page is not found
|
||||
/// @param name page name
|
||||
/// @param pageSupplier page supplier function
|
||||
void addSupplier(std::string name, supplier<std::shared_ptr<UINode>> pageSupplier);
|
||||
void addSupplier(const std::string &name, const supplier<std::shared_ptr<UINode>> &pageSupplier);
|
||||
|
||||
/// @brief Page loader is called if accessed page is not found
|
||||
void setPageLoader(page_loader_func loader);
|
||||
|
||||
@@ -46,7 +46,7 @@ void Panel::fullRefresh() {
|
||||
Container::fullRefresh();
|
||||
}
|
||||
|
||||
void Panel::add(std::shared_ptr<UINode> node) {
|
||||
void Panel::add(const std::shared_ptr<UINode> &node) {
|
||||
node->setResizing(true);
|
||||
Container::add(node);
|
||||
fullRefresh();
|
||||
|
||||
@@ -24,7 +24,7 @@ namespace gui {
|
||||
virtual void setOrientation(Orientation orientation);
|
||||
Orientation getOrientation() const;
|
||||
|
||||
virtual void add(std::shared_ptr<UINode> node) override;
|
||||
virtual void add(const std::shared_ptr<UINode> &node) override;
|
||||
|
||||
virtual void refresh() override;
|
||||
virtual void fullRefresh() override;
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
#include "TextBox.hpp"
|
||||
|
||||
#include <utility>
|
||||
|
||||
#include "Label.hpp"
|
||||
#include "../../core/DrawContext.hpp"
|
||||
#include "../../core/Batch2D.hpp"
|
||||
@@ -14,7 +16,7 @@ using namespace gui;
|
||||
TextBox::TextBox(std::wstring placeholder, glm::vec4 padding)
|
||||
: Panel(glm::vec2(200,32), padding, 0),
|
||||
input(L""),
|
||||
placeholder(placeholder)
|
||||
placeholder(std::move(placeholder))
|
||||
{
|
||||
setOnUpPressed(nullptr);
|
||||
setOnDownPressed(nullptr);
|
||||
@@ -556,7 +558,7 @@ std::shared_ptr<UINode> TextBox::getAt(glm::vec2 pos, std::shared_ptr<UINode> se
|
||||
return UINode::getAt(pos, self);
|
||||
}
|
||||
|
||||
void TextBox::setOnUpPressed(runnable callback) {
|
||||
void TextBox::setOnUpPressed(const runnable &callback) {
|
||||
if (callback == nullptr) {
|
||||
onUpPressed = [this]() {
|
||||
bool shiftPressed = Events::pressed(keycode::LEFT_SHIFT);
|
||||
@@ -568,7 +570,7 @@ void TextBox::setOnUpPressed(runnable callback) {
|
||||
}
|
||||
}
|
||||
|
||||
void TextBox::setOnDownPressed(runnable callback) {
|
||||
void TextBox::setOnDownPressed(const runnable &callback) {
|
||||
if (callback == nullptr) {
|
||||
onDownPressed = [this]() {
|
||||
bool shiftPressed = Events::pressed(keycode::LEFT_SHIFT);
|
||||
@@ -581,15 +583,15 @@ void TextBox::setOnDownPressed(runnable callback) {
|
||||
}
|
||||
|
||||
void TextBox::setTextSupplier(wstringsupplier supplier) {
|
||||
this->supplier = supplier;
|
||||
this->supplier = std::move(supplier);
|
||||
}
|
||||
|
||||
void TextBox::setTextConsumer(wstringconsumer consumer) {
|
||||
this->consumer = consumer;
|
||||
this->consumer = std::move(consumer);
|
||||
}
|
||||
|
||||
void TextBox::setTextValidator(wstringchecker validator) {
|
||||
this->validator = validator;
|
||||
this->validator = std::move(validator);
|
||||
}
|
||||
|
||||
void TextBox::setFocusedColor(glm::vec4 color) {
|
||||
@@ -614,7 +616,7 @@ std::wstring TextBox::getText() const {
|
||||
return input;
|
||||
}
|
||||
|
||||
void TextBox::setText(const std::wstring value) {
|
||||
void TextBox::setText(const std::wstring& value) {
|
||||
this->input = value;
|
||||
input.erase(std::remove(input.begin(), input.end(), '\r'), input.end());
|
||||
}
|
||||
|
||||
@@ -98,7 +98,7 @@ namespace gui {
|
||||
virtual std::wstring getText() const;
|
||||
|
||||
/// @brief Set TextBox content text
|
||||
virtual void setText(std::wstring value);
|
||||
virtual void setText(const std::wstring &value);
|
||||
|
||||
/// @brief Get text placeholder
|
||||
virtual std::wstring getPlaceholder() const;
|
||||
@@ -169,8 +169,8 @@ namespace gui {
|
||||
virtual void typed(unsigned int codepoint) override;
|
||||
virtual void keyPressed(keycode key) override;
|
||||
virtual std::shared_ptr<UINode> getAt(glm::vec2 pos, std::shared_ptr<UINode> self) override;
|
||||
virtual void setOnUpPressed(runnable callback);
|
||||
virtual void setOnDownPressed(runnable callback);
|
||||
virtual void setOnUpPressed(const runnable &callback);
|
||||
virtual void setOnDownPressed(const runnable &callback);
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
#include "TrackBar.hpp"
|
||||
|
||||
#include <utility>
|
||||
|
||||
#include "../../core/DrawContext.hpp"
|
||||
#include "../../core/Batch2D.hpp"
|
||||
#include "../../../assets/Assets.hpp"
|
||||
@@ -41,11 +43,11 @@ void TrackBar::draw(const DrawContext* pctx, Assets*) {
|
||||
}
|
||||
|
||||
void TrackBar::setSupplier(doublesupplier supplier) {
|
||||
this->supplier = supplier;
|
||||
this->supplier = std::move(supplier);
|
||||
}
|
||||
|
||||
void TrackBar::setConsumer(doubleconsumer consumer) {
|
||||
this->consumer = consumer;
|
||||
this->consumer = std::move(consumer);
|
||||
}
|
||||
|
||||
void TrackBar::mouseMove(GUI*, int x, int) {
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
#include "UINode.hpp"
|
||||
|
||||
#include <utility>
|
||||
|
||||
#include "Container.hpp"
|
||||
#include "../../core/Batch2D.hpp"
|
||||
|
||||
@@ -62,12 +64,12 @@ UINode* UINode::getParent() const {
|
||||
return parent;
|
||||
}
|
||||
|
||||
UINode* UINode::listenAction(onaction action) {
|
||||
UINode* UINode::listenAction(const onaction& action) {
|
||||
actions.listen(action);
|
||||
return this;
|
||||
}
|
||||
|
||||
UINode* UINode::listenDoubleClick(onaction action) {
|
||||
UINode* UINode::listenDoubleClick(const onaction& action) {
|
||||
doubleClickCallbacks.listen(action);
|
||||
return this;
|
||||
}
|
||||
@@ -113,7 +115,7 @@ std::shared_ptr<UINode> UINode::getAt(glm::vec2 point, std::shared_ptr<UINode> s
|
||||
if (!isInteractive() || !enabled) {
|
||||
return nullptr;
|
||||
}
|
||||
return isInside(point) ? self : nullptr;
|
||||
return isInside(point) ? std::move(self) : nullptr;
|
||||
}
|
||||
|
||||
bool UINode::isInteractive() const {
|
||||
@@ -241,8 +243,8 @@ int UINode::getZIndex() const {
|
||||
}
|
||||
|
||||
void UINode::moveInto(
|
||||
std::shared_ptr<UINode> node,
|
||||
std::shared_ptr<Container> dest
|
||||
const std::shared_ptr<UINode>& node,
|
||||
const std::shared_ptr<Container>& dest
|
||||
) {
|
||||
auto parent = node->getParent();
|
||||
if (auto container = dynamic_cast<Container*>(parent)) {
|
||||
@@ -259,7 +261,7 @@ vec2supplier UINode::getPositionFunc() const {
|
||||
}
|
||||
|
||||
void UINode::setPositionFunc(vec2supplier func) {
|
||||
positionfunc = func;
|
||||
positionfunc = std::move(func);
|
||||
}
|
||||
|
||||
vec2supplier UINode::getSizeFunc() const {
|
||||
@@ -267,7 +269,7 @@ vec2supplier UINode::getSizeFunc() const {
|
||||
}
|
||||
|
||||
void UINode::setSizeFunc(vec2supplier func) {
|
||||
sizefunc = func;
|
||||
sizefunc = std::move(func);
|
||||
}
|
||||
|
||||
void UINode::setId(const std::string& id) {
|
||||
@@ -345,7 +347,7 @@ bool UINode::isSubnodeOf(const UINode* node) {
|
||||
}
|
||||
|
||||
void UINode::getIndices(
|
||||
const std::shared_ptr<UINode> node,
|
||||
const std::shared_ptr<UINode>& node,
|
||||
std::unordered_map<std::string, std::shared_ptr<UINode>>& map
|
||||
) {
|
||||
const std::string& id = node->getId();
|
||||
@@ -354,20 +356,20 @@ void UINode::getIndices(
|
||||
}
|
||||
auto container = std::dynamic_pointer_cast<gui::Container>(node);
|
||||
if (container) {
|
||||
for (auto subnode : container->getNodes()) {
|
||||
for (const auto& subnode : container->getNodes()) {
|
||||
getIndices(subnode, map);
|
||||
}
|
||||
}
|
||||
}
|
||||
std::shared_ptr<UINode> UINode::find(
|
||||
const std::shared_ptr<UINode> node,
|
||||
const std::shared_ptr<UINode>& node,
|
||||
const std::string& id
|
||||
) {
|
||||
if (node->getId() == id) {
|
||||
return node;
|
||||
}
|
||||
if (auto container = std::dynamic_pointer_cast<Container>(node)) {
|
||||
for (auto subnode : container->getNodes()) {
|
||||
for (const auto& subnode : container->getNodes()) {
|
||||
if (auto found = UINode::find(subnode, id)) {
|
||||
return found;
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ namespace gui {
|
||||
class ActionsSet {
|
||||
std::unique_ptr<std::vector<onaction>> callbacks;
|
||||
public:
|
||||
void listen(onaction callback) {
|
||||
void listen(const onaction& callback) {
|
||||
if (callbacks == nullptr) {
|
||||
callbacks = std::make_unique<std::vector<onaction>>();
|
||||
}
|
||||
@@ -162,8 +162,8 @@ namespace gui {
|
||||
/// @brief Get element z-index
|
||||
int getZIndex() const;
|
||||
|
||||
virtual UINode* listenAction(onaction action);
|
||||
virtual UINode* listenDoubleClick(onaction action);
|
||||
virtual UINode* listenAction(const onaction &action);
|
||||
virtual UINode* listenDoubleClick(const onaction &action);
|
||||
|
||||
virtual void onFocus(GUI*) {focused = true;}
|
||||
virtual void doubleClick(GUI*, int x, int y);
|
||||
@@ -227,8 +227,8 @@ namespace gui {
|
||||
}
|
||||
};
|
||||
static void moveInto(
|
||||
std::shared_ptr<UINode> node,
|
||||
std::shared_ptr<Container> dest
|
||||
const std::shared_ptr<UINode>& node,
|
||||
const std::shared_ptr<Container>& dest
|
||||
);
|
||||
|
||||
virtual vec2supplier getPositionFunc() const;
|
||||
@@ -249,12 +249,12 @@ namespace gui {
|
||||
|
||||
/// @brief collect all nodes having id
|
||||
static void getIndices(
|
||||
const std::shared_ptr<UINode> node,
|
||||
const std::shared_ptr<UINode>& node,
|
||||
std::unordered_map<std::string, std::shared_ptr<UINode>>& map
|
||||
);
|
||||
|
||||
static std::shared_ptr<UINode> find(
|
||||
const std::shared_ptr<UINode> node,
|
||||
const std::shared_ptr<UINode>& node,
|
||||
const std::string& id
|
||||
);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user