Permalink
Browse files

UI: Make sliders able to show disabled.

For alternate speed, we'll allow separate speeds to be "on" or "off".
  • Loading branch information...
unknownbrackets committed Jun 17, 2018
1 parent e2c217a commit 23ecd2ad62204d42a4a90f593580b9e4a0a005fb
Showing with 30 additions and 5 deletions.
  1. +17 −3 ext/native/ui/ui_screen.cpp
  2. +13 −2 ext/native/ui/ui_screen.h
@@ -516,6 +516,8 @@ EventReturn PopupSliderChoice::HandleClick(EventParams &e) {
restoreFocus_ = HasFocus();
SliderPopupScreen *popupScreen = new SliderPopupScreen(value_, minValue_, maxValue_, ChopTitle(text_), step_, units_);
if (!negativeLabel_.empty())
popupScreen->SetNegativeDisable(negativeLabel_);
popupScreen->OnChange.Handle(this, &PopupSliderChoice::HandleChange);
if (e.v)
popupScreen->SetPopupOrigin(e.v);
@@ -541,9 +543,12 @@ void PopupSliderChoice::Draw(UIContext &dc) {
int paddingX = 12;
dc.SetFontStyle(dc.theme->uiFont);
char temp[32];
// Always good to have space for Unicode.
char temp[256];
if (zeroLabel_.size() && *value_ == 0) {
strcpy(temp, zeroLabel_.c_str());
} else if (negativeLabel_.size() && *value_ < 0) {
strcpy(temp, negativeLabel_.c_str());
} else {
sprintf(temp, fmt_, *value_);
}
@@ -585,7 +590,7 @@ void PopupSliderChoiceFloat::Draw(UIContext &dc) {
int paddingX = 12;
dc.SetFontStyle(dc.theme->uiFont);
char temp[32];
char temp[256];
if (zeroLabel_.size() && *value_ == 0.0f) {
strcpy(temp, zeroLabel_.c_str());
} else {
@@ -611,6 +616,7 @@ EventReturn SliderPopupScreen::OnDecrease(EventParams &params) {
sprintf(temp, "%d", sliderValue_);
edit_->SetText(temp);
changing_ = false;
disabled_ = false;
return EVENT_DONE;
}
@@ -625,6 +631,7 @@ EventReturn SliderPopupScreen::OnIncrease(EventParams &params) {
sprintf(temp, "%d", sliderValue_);
edit_->SetText(temp);
changing_ = false;
disabled_ = false;
return EVENT_DONE;
}
@@ -634,12 +641,14 @@ EventReturn SliderPopupScreen::OnSliderChange(EventParams &params) {
sprintf(temp, "%d", sliderValue_);
edit_->SetText(temp);
changing_ = false;
disabled_ = false;
return EVENT_DONE;
}
EventReturn SliderPopupScreen::OnTextChange(EventParams &params) {
if (!changing_) {
sliderValue_ = atoi(edit_->GetText().c_str());
disabled_ = false;
slider_->Clamp();
}
return EVENT_DONE;
@@ -650,6 +659,8 @@ void SliderPopupScreen::CreatePopupContents(UI::ViewGroup *parent) {
UIContext &dc = *screenManager()->getUIContext();
sliderValue_ = *value_;
if (disabled_ && sliderValue_ < 0)
sliderValue_ = 0;
LinearLayout *vert = parent->Add(new LinearLayout(ORIENT_VERTICAL, new LinearLayoutParams(UI::Margins(10, 10))));
slider_ = new Slider(&sliderValue_, minValue_, maxValue_, new LinearLayoutParams(UI::Margins(10, 10)));
slider_->OnChange.Handle(this, &SliderPopupScreen::OnSliderChange);
@@ -672,6 +683,9 @@ void SliderPopupScreen::CreatePopupContents(UI::ViewGroup *parent) {
if (!units_.empty())
lin->Add(new TextView(units_, new LinearLayoutParams(10.0f)))->SetTextColor(dc.theme->popupStyle.fgColor);
if (!negativeLabel_.empty())
vert->Add(new CheckBox(&disabled_, negativeLabel_));
if (IsFocusMovementEnabled())
UI::SetFocusedView(slider_);
}
@@ -754,7 +768,7 @@ EventReturn SliderFloatPopupScreen::OnTextChange(EventParams &params) {
void SliderPopupScreen::OnCompleted(DialogResult result) {
if (result == DR_OK) {
*value_ = sliderValue_;
*value_ = disabled_ ? -1 : sliderValue_;
EventParams e{};
e.v = nullptr;
e.a = *value_;
@@ -169,9 +169,14 @@ namespace UI {
class SliderPopupScreen : public PopupScreen {
public:
SliderPopupScreen(int *value, int minValue, int maxValue, const std::string &title, int step = 1, const std::string &units = "")
: PopupScreen(title, "OK", "Cancel"), units_(units), value_(value), minValue_(minValue), maxValue_(maxValue), step_(step), changing_(false) {}
: PopupScreen(title, "OK", "Cancel"), units_(units), value_(value), minValue_(minValue), maxValue_(maxValue), step_(step) {}
virtual void CreatePopupContents(ViewGroup *parent) override;
void SetNegativeDisable(const std::string &str) {
negativeLabel_ = str;
disabled_ = *value_ < 0;
}
Event OnChange;
private:
@@ -183,12 +188,14 @@ class SliderPopupScreen : public PopupScreen {
Slider *slider_;
UI::TextEdit *edit_;
std::string units_;
std::string negativeLabel_;
int *value_;
int sliderValue_;
int minValue_;
int maxValue_;
int step_;
bool changing_;
bool changing_ = false;
bool disabled_ = false;
};
class SliderFloatPopupScreen : public PopupScreen {
@@ -325,6 +332,9 @@ class PopupSliderChoice : public Choice {
void SetZeroLabel(const std::string &str) {
zeroLabel_ = str;
}
void SetNegativeDisable(const std::string &str) {
negativeLabel_ = str;
}
Event OnChange;
@@ -338,6 +348,7 @@ class PopupSliderChoice : public Choice {
int step_;
const char *fmt_;
std::string zeroLabel_;
std::string negativeLabel_;
std::string units_;
ScreenManager *screenManager_;
bool restoreFocus_;

0 comments on commit 23ecd2a

Please sign in to comment.