FIX: button focused state

Change-Id: Ieab02661c8f2e406b5bf5f156d9142efbe76d1cf
This commit is contained in:
chunmao.guo 2022-07-29 15:10:41 +08:00 committed by Lane.Wei
parent 09d5651c39
commit ec59446e44
5 changed files with 19 additions and 4 deletions

View file

@ -26,8 +26,9 @@ Button::Button()
, text_color(*wxBLACK)
{
background_color = StateColor(
std::make_pair(*wxLIGHT_GREY, (int) StateColor::Checked),
std::make_pair(0x00AE42, (int) StateColor::Checked),
std::make_pair(*wxLIGHT_GREY, (int) StateColor::Hovered),
std::make_pair(0x37EE7C, (int) StateColor::Hovered | StateColor::Checked),
std::make_pair(*wxWHITE, (int) StateColor::Normal));
}

View file

@ -27,7 +27,6 @@ END_EVENT_TABLE()
SpinInput::SpinInput()
: state_handler(this)
, border_color(std::make_pair(0xDBDBDB, (int) StateColor::Disabled),
std::make_pair(0x00AE42, (int) StateColor::Focused),
std::make_pair(0x00AE42, (int) StateColor::Hovered),
std::make_pair(0xDBDBDB, (int) StateColor::Normal))
, text_color(std::make_pair(0xACACAC, (int) StateColor::Disabled), std::make_pair(*wxBLACK, (int) StateColor::Normal))

View file

@ -36,6 +36,9 @@ int StateColor::states() const
{
int states = 0;
for (auto s : statesList_) states |= s;
states = (states & 0xffff) | (states >> 16);
if (takeFocusedAsHovered_ && (states & Hovered))
states |= Focused;
return states;
}
@ -45,6 +48,7 @@ wxColour StateColor::defaultColor() {
wxColour StateColor::colorForStates(int states)
{
bool focused = takeFocusedAsHovered_ && (states & Focused);
for (int i = 0; i < statesList_.size(); ++i) {
int s = statesList_[i];
int on = s & 0xffff;
@ -52,6 +56,13 @@ wxColour StateColor::colorForStates(int states)
if ((on & states) == on && (off & ~states) == off) {
return colors_[i];
}
if (focused && (on & Hovered)) {
on |= Focused;
on &= ~Hovered;
if ((on & states) == on && (off & ~states) == off) {
return colors_[i];
}
}
}
return wxColour(0, 0, 0, 0);
}
@ -78,3 +89,5 @@ bool StateColor::setColorForStates(wxColour const &color, int states)
return false;
}
void StateColor::setTakeFocusedAsHovered(bool set) { takeFocusedAsHovered_ = set; }

View file

@ -58,6 +58,8 @@ public:
bool setColorForStates(wxColour const & color, int states);
void setTakeFocusedAsHovered(bool set);
private:
template<typename Color, typename ...Colors>
void fill(std::pair<Color, int> color, std::pair<Colors, int>... colors) {
@ -76,6 +78,7 @@ private:
private:
std::vector<int> statesList_;
std::vector<wxColour> colors_;
bool takeFocusedAsHovered_ = true;
};
#endif // !slic3r_GUI_StateColor_hpp_

View file

@ -26,7 +26,6 @@ END_EVENT_TABLE()
TextInput::TextInput()
: state_handler(this)
, border_color(std::make_pair(0xDBDBDB, (int) StateColor::Disabled),
std::make_pair(0x00AE42, (int) StateColor::Focused),
std::make_pair(0x00AE42, (int) StateColor::Hovered),
std::make_pair(0xDBDBDB, (int) StateColor::Normal))
, text_color(std::make_pair(0xACACAC, (int) StateColor::Disabled),