mirror of
https://github.com/MeowLynxSea/ceditor.git
synced 2025-07-09 10:54:37 +00:00
为组件增加了focusStatus属性,增加了FocusManager类
This commit is contained in:
parent
c95bb4eb3d
commit
96e743fc26
@ -4,7 +4,7 @@
|
|||||||
class BaseComponent {
|
class BaseComponent {
|
||||||
protected:
|
protected:
|
||||||
int top, left, width, height;
|
int top, left, width, height;
|
||||||
bool focused;
|
bool focusStatus;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
BaseComponent(int top, int left, int width, int height) : top(top), left(left), width(width), height(height) {};
|
BaseComponent(int top, int left, int width, int height) : top(top), left(left), width(width), height(height) {};
|
||||||
@ -36,8 +36,12 @@ public:
|
|||||||
return height;
|
return height;
|
||||||
}
|
}
|
||||||
|
|
||||||
void setFocused(bool focused) {
|
void setFocus(bool focused) {
|
||||||
this->focused = focused;
|
this->focusStatus = focused;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool isFocused() {
|
||||||
|
return focusStatus;
|
||||||
}
|
}
|
||||||
|
|
||||||
void setPosition(int top, int left) {
|
void setPosition(int top, int left) {
|
||||||
|
@ -88,6 +88,16 @@ public:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void erase(size_t index) override {
|
||||||
|
if (index >= m_size) {
|
||||||
|
throw std::out_of_range("Index out of range");
|
||||||
|
}
|
||||||
|
for (size_t i = index; i < m_size - 1; ++i) {
|
||||||
|
m_data[i] = std::move(m_data[i + 1]);
|
||||||
|
}
|
||||||
|
--m_size;
|
||||||
|
}
|
||||||
|
|
||||||
T& top() override {
|
T& top() override {
|
||||||
return back();
|
return back();
|
||||||
}
|
}
|
||||||
|
47
utils/FocusManager.h
Normal file
47
utils/FocusManager.h
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
#ifndef FOCUSMANAGER_H
|
||||||
|
#define FOCUSMANAGER_H
|
||||||
|
|
||||||
|
|
||||||
|
#include "../mystl/my_vector.h"
|
||||||
|
#include "../components/BaseComponent.h"
|
||||||
|
|
||||||
|
class FocusManager {
|
||||||
|
private:
|
||||||
|
MyVector<BaseComponent*> components;
|
||||||
|
|
||||||
|
public:
|
||||||
|
FocusManager();
|
||||||
|
~FocusManager() {
|
||||||
|
components.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
void addComponent(BaseComponent* component) {
|
||||||
|
components.push_back(component);
|
||||||
|
}
|
||||||
|
|
||||||
|
void removeComponent(BaseComponent* component) {
|
||||||
|
for(int i = 0; i < components.size(); i++) {
|
||||||
|
if(components[i] == component) {
|
||||||
|
components.erase(i);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void setFocus(BaseComponent* component) {
|
||||||
|
if(component->isFocused()) return;
|
||||||
|
for(int i = 0; i < components.size(); i++) {
|
||||||
|
components[i]->setFocus(false);
|
||||||
|
}
|
||||||
|
component->setFocus(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
BaseComponent* getFocusedComponent() {
|
||||||
|
for(int i = 0; i < components.size(); i++) {
|
||||||
|
if(components[i]->isFocused()) return components[i];
|
||||||
|
}
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
@ -1,4 +0,0 @@
|
|||||||
#ifndef INPUTMANAGER_H
|
|
||||||
#define INPUTMANAGER_H
|
|
||||||
|
|
||||||
#endif
|
|
Loading…
Reference in New Issue
Block a user