All controls store their name/keyO

This commit is contained in:
2025-02-27 00:16:17 -06:00
committed by Celtic Minstrel
parent f5f157c2ea
commit a01c9d6e2a
5 changed files with 6 additions and 5 deletions

View File

@@ -245,6 +245,7 @@ void cDialog::loadFromFile(const DialogDefn& file){
} }
} }
prevCtrl = *inserted; prevCtrl = *inserted;
prevCtrl.second->setName(prevCtrl.first);
// Needed to correctly resolve relative positioning // Needed to correctly resolve relative positioning
inserted->second->recalcRect(); inserted->second->recalcRect();
} }
@@ -464,6 +465,7 @@ bool cDialog::add(cControl* what, rectangle ctrl_frame, std::string key){
if(controls.find(key) != controls.end()) return false; if(controls.find(key) != controls.end()) return false;
what->setBounds(ctrl_frame); what->setBounds(ctrl_frame);
controls.insert(std::make_pair(key,what)); controls.insert(std::make_pair(key,what));
what->setName(key);
return true; return true;
} }

View File

@@ -59,6 +59,7 @@ bool cContainer::parseChildControl(ticpp::Element& elem, std::map<std::string,cC
} }
} }
prevCtrl = *inserted; prevCtrl = *inserted;
prevCtrl.second->setName(prevCtrl.first);
return true; return true;
} }

View File

@@ -149,6 +149,7 @@ protected:
/// @throw xMissingAttr if a required attribute is missing /// @throw xMissingAttr if a required attribute is missing
/// @throw xMissingElem if a required attribute is either missing or present in insufficient quantity /// @throw xMissingElem if a required attribute is either missing or present in insufficient quantity
virtual void validatePostParse(ticpp::Element& who, std::string fname, const std::set<std::string>& attrs, const std::multiset<std::string>& nodes); virtual void validatePostParse(ticpp::Element& who, std::string fname, const std::set<std::string>& attrs, const std::multiset<std::string>& nodes);
std::string name;
public: public:
/// Attach a keyboard shortcut to a control. Pressing the keyboard shortcut is equivalent to clicking the control. /// Attach a keyboard shortcut to a control. Pressing the keyboard shortcut is equivalent to clicking the control.
/// @param key The desired keyboard shortcut. /// @param key The desired keyboard shortcut.
@@ -181,6 +182,8 @@ public:
if(old_handler.empty()) return nullptr; if(old_handler.empty()) return nullptr;
return boost::any_cast<typename event_fcn<t>::type>(old_handler); return boost::any_cast<typename event_fcn<t>::type>(old_handler);
} }
inline std::string getName() { return name; }
inline void setName(std::string value) { name = value; }
/// Attach a click handler to this control. /// Attach a click handler to this control.
/// @param f The click handler to attach. /// @param f The click handler to attach.
/// @throw xHandlerNotSupported if this control does not support click handlers. Most controls do support click handlers. /// @throw xHandlerNotSupported if this control does not support click handlers. Most controls do support click handlers.

View File

@@ -41,10 +41,6 @@ bool cScrollbar::isScrollable() const {
return true; return true;
} }
void cScrollbar::setName(std::string name) {
this->name = name;
}
void cScrollbar::setPosition(long newPos, bool record) { void cScrollbar::setPosition(long newPos, bool record) {
if(record && recording){ if(record && recording){
std::map<std::string,std::string> info; std::map<std::string,std::string> info;

View File

@@ -105,7 +105,6 @@ public:
/// Get the scrollbar style. /// Get the scrollbar style.
/// @return The style /// @return The style
eScrollStyle getStyle() const; eScrollStyle getStyle() const;
void setName(std::string name);
/// Set the scrollbar thumb's current position. /// Set the scrollbar thumb's current position.
/// @param to The new position. /// @param to The new position.
void setPosition(long to, bool record = false); void setPosition(long to, bool record = false);