Extract editor interaction states
This commit is contained in:
@@ -27,6 +27,10 @@ public:
|
||||
return m_openRequested;
|
||||
}
|
||||
|
||||
void Clear() {
|
||||
m_openRequested = false;
|
||||
}
|
||||
|
||||
private:
|
||||
bool m_openRequested = false;
|
||||
};
|
||||
@@ -77,6 +81,76 @@ private:
|
||||
char m_buffer[BufferCapacity] = {};
|
||||
};
|
||||
|
||||
template <typename ItemId, size_t BufferCapacity>
|
||||
class InlineTextEditState {
|
||||
public:
|
||||
void Begin(ItemId itemId, const char* initialValue = "") {
|
||||
m_active = true;
|
||||
m_itemId = itemId;
|
||||
SetValue(initialValue);
|
||||
m_focusRequested = true;
|
||||
}
|
||||
|
||||
bool IsActive() const {
|
||||
return m_active;
|
||||
}
|
||||
|
||||
bool IsEditing(ItemId itemId) const {
|
||||
return m_active && m_itemId == itemId;
|
||||
}
|
||||
|
||||
ItemId Item() const {
|
||||
return m_itemId;
|
||||
}
|
||||
|
||||
bool ConsumeFocusRequest() {
|
||||
if (!m_focusRequested) {
|
||||
return false;
|
||||
}
|
||||
|
||||
m_focusRequested = false;
|
||||
return true;
|
||||
}
|
||||
|
||||
void SetValue(const char* value) {
|
||||
if (value && value[0] != '\0') {
|
||||
strcpy_s(m_buffer, value);
|
||||
return;
|
||||
}
|
||||
|
||||
m_buffer[0] = '\0';
|
||||
}
|
||||
|
||||
bool Empty() const {
|
||||
return m_buffer[0] == '\0';
|
||||
}
|
||||
|
||||
char* Buffer() {
|
||||
return m_buffer;
|
||||
}
|
||||
|
||||
const char* Buffer() const {
|
||||
return m_buffer;
|
||||
}
|
||||
|
||||
constexpr size_t BufferSize() const {
|
||||
return BufferCapacity;
|
||||
}
|
||||
|
||||
void Cancel() {
|
||||
m_active = false;
|
||||
m_itemId = ItemId{};
|
||||
m_buffer[0] = '\0';
|
||||
m_focusRequested = false;
|
||||
}
|
||||
|
||||
private:
|
||||
bool m_active = false;
|
||||
ItemId m_itemId = ItemId{};
|
||||
char m_buffer[BufferCapacity] = {};
|
||||
bool m_focusRequested = false;
|
||||
};
|
||||
|
||||
} // namespace UI
|
||||
} // namespace Editor
|
||||
} // namespace XCEngine
|
||||
|
||||
Reference in New Issue
Block a user