Default controls keep their hotkey AND the enter key
This commit is contained in:
@@ -160,7 +160,6 @@ cDialog::cDialog(const DialogDefn& file, cDialog* p) : parent(p) {
|
|||||||
|
|
||||||
extern fs::path progDir;
|
extern fs::path progDir;
|
||||||
void cDialog::loadFromFile(const DialogDefn& file){
|
void cDialog::loadFromFile(const DialogDefn& file){
|
||||||
static const cKey enterKey = {true, key_enter};
|
|
||||||
bg = defaultBackground;
|
bg = defaultBackground;
|
||||||
fname = file.id;
|
fname = file.id;
|
||||||
try{
|
try{
|
||||||
@@ -328,7 +327,7 @@ void cDialog::loadFromFile(const DialogDefn& file){
|
|||||||
|
|
||||||
// Set the default button.
|
// Set the default button.
|
||||||
if(hasControl(defaultButton))
|
if(hasControl(defaultButton))
|
||||||
getControl(defaultButton).attachKey(enterKey);
|
getControl(defaultButton).setDefault(true);
|
||||||
|
|
||||||
// Sort by tab order
|
// Sort by tab order
|
||||||
// First, fill any gaps that might have been left, using ones that had no specific tab order
|
// First, fill any gaps that might have been left, using ones that had no specific tab order
|
||||||
@@ -886,8 +885,11 @@ bool cDialog::addLabelFor(std::string key, std::string label, eLabelPos where, s
|
|||||||
|
|
||||||
void cDialog::process_keystroke(cKey keyHit){
|
void cDialog::process_keystroke(cKey keyHit){
|
||||||
ctrlIter iter = controls.begin();
|
ctrlIter iter = controls.begin();
|
||||||
|
bool enterKeyHit = keyHit.spec && keyHit.k == key_enter;
|
||||||
while(iter != controls.end()){
|
while(iter != controls.end()){
|
||||||
if(iter->second->isVisible() && iter->second->isClickable() && iter->second->getAttachedKey() == keyHit){
|
if(iter->second->isVisible() && iter->second->isClickable()
|
||||||
|
&& iter->second->getAttachedKey() == keyHit || (iter->second->isDefault() && enterKeyHit)){
|
||||||
|
|
||||||
iter->second->setActive(true);
|
iter->second->setActive(true);
|
||||||
draw();
|
draw();
|
||||||
iter->second->playClickSound();
|
iter->second->playClickSound();
|
||||||
|
|||||||
@@ -165,6 +165,8 @@ public:
|
|||||||
/// Retrieve the control's current keyboard shortcut as a human-readable string.
|
/// Retrieve the control's current keyboard shortcut as a human-readable string.
|
||||||
/// @return the currently-assigned keyboard shortcut, or an empty string if none is assigned.
|
/// @return the currently-assigned keyboard shortcut, or an empty string if none is assigned.
|
||||||
std::string getAttachedKeyDescription() const;
|
std::string getAttachedKeyDescription() const;
|
||||||
|
inline void setDefault(bool value) { isDefaultControl = value; }
|
||||||
|
inline bool isDefault() { return isDefaultControl; }
|
||||||
/// Attach an event handler to this control.
|
/// Attach an event handler to this control.
|
||||||
/// @tparam t The type of event to attach.
|
/// @tparam t The type of event to attach.
|
||||||
/// @param handler The event handler function or functor. Its signature depends on the event type.
|
/// @param handler The event handler function or functor. Its signature depends on the event type.
|
||||||
@@ -443,6 +445,9 @@ protected:
|
|||||||
eFrameStyle frameStyle;
|
eFrameStyle frameStyle;
|
||||||
/// The control's attached key.
|
/// The control's attached key.
|
||||||
cKey key;
|
cKey key;
|
||||||
|
/// Whether the control is the default control of its dialog.
|
||||||
|
bool isDefaultControl = false;
|
||||||
|
|
||||||
/// Draw a frame around the control.
|
/// Draw a frame around the control.
|
||||||
/// @param amt How much to offset the frame from the control's bounding rect.
|
/// @param amt How much to offset the frame from the control's bounding rect.
|
||||||
/// @param med_or_lt true to use a darker colour for the frame.
|
/// @param med_or_lt true to use a darker colour for the frame.
|
||||||
|
|||||||
Reference in New Issue
Block a user