Click outside popups to dismiss them. Fix focus display of active tabs.

This commit is contained in:
Henrik Rydgard committed 2013-08-20 13:03:42 +02:00
1 parent 40193a7d12
commit 8f0d82ffb7
4 files changed
+40 -10

No files matched your search

+20 -8
View File
@@ -99,24 +99,36 @@ UI::EventReturn UIScreen::OnBack(UI::EventParams &e) {
}
PopupScreen::PopupScreen(std::string title, std::string button1, std::string button2)
: title_(title), button1_(button1), button2_(button2) {}
: title_(title), button1_(button1), button2_(button2), box_(0) {}
void PopupScreen::touch(const TouchInput &touch) {
if (!box_ || (touch.flags & TOUCH_DOWN) == 0 || touch.id != 0) {
UIDialogScreen::touch(touch);
return;
}
if (!box_->GetBounds().Contains(touch.x, touch.y))
screenManager()->finishDialog(this, DR_CANCEL);
UIDialogScreen::touch(touch);
}
void PopupScreen::CreateViews() {
using namespace UI;
root_ = new AnchorLayout(new LayoutParams(FILL_PARENT, FILL_PARENT));
LinearLayout *box = new LinearLayout(ORIENT_VERTICAL,
box_ = new LinearLayout(ORIENT_VERTICAL,
new AnchorLayoutParams(550, FillVertical() ? dp_yres - 30 : WRAP_CONTENT, dp_xres / 2, dp_yres / 2, NONE, NONE, true));
root_->Add(box);
box->SetBG(UI::Drawable(0xFF303030));
box->SetHasDropShadow(true);
root_->Add(box_);
box_->SetBG(UI::Drawable(0xFF303030));
box_->SetHasDropShadow(true);
View *title = new PopupHeader(title_);
box->Add(title);
box_->Add(title);
CreatePopupContents(box);
CreatePopupContents(box_);
if (ShowButtons()) {
// And the two buttons at the bottom.
@@ -135,7 +147,7 @@ void PopupScreen::CreateViews() {
buttonRow->Add(new Button(button1_, new LinearLayoutParams(1.0f)))->OnClick.Handle(this, &PopupScreen::OnOK);
#endif
box->Add(buttonRow);
box_->Add(buttonRow);
}
}
+2
View File
@@ -45,6 +45,7 @@ public:
virtual void CreatePopupContents(UI::ViewGroup *parent) = 0;
virtual void CreateViews();
virtual bool isTransparent() { return true; }
virtual void touch(const TouchInput &touch);
protected:
virtual bool FillVertical() { return false; }
@@ -55,6 +56,7 @@ private:
UI::EventReturn OnOK(UI::EventParams &e);
UI::EventReturn OnCancel(UI::EventParams &e);
UI::ViewGroup *box_;
std::string title_;
std::string button1_;
std::string button2_;
+12 -2
View File
@@ -297,7 +297,18 @@ void Choice::GetContentDimensions(const UIContext &dc, float &w, float &h) const
}
void Choice::Draw(UIContext &dc) {
ClickableItem::Draw(dc);
if (!IsSticky()) {
ClickableItem::Draw(dc);
} else {
Style style = dc.theme->itemStyle;
if (down_) {
style = dc.theme->itemDownStyle;
}
if (HasFocus()) {
style = dc.theme->itemFocusedStyle;
}
dc.FillRect(style.background, bounds_);
}
Style style = dc.theme->itemStyle;
if (!IsEnabled())
@@ -313,7 +324,6 @@ void Choice::Draw(UIContext &dc) {
if (selected_) {
dc.Draw()->DrawImage(dc.theme->checkOn, bounds_.x2() - 40, bounds_.centerY(), 1.0f, style.fgColor, ALIGN_CENTER);
}
// dc.draw->DrawText(dc.theme->uiFontSmaller, text_.c_str(), paddingX, paddingY, 0xFFFFFFFF, ALIGN_TOPLEFT);
}
void InfoItem::Draw(UIContext &dc) {
+6
View File
@@ -502,6 +502,9 @@ public:
virtual void Draw(UIContext &dc);
protected:
// hackery
virtual bool IsSticky() const { return false; }
std::string text_;
std::string smallText_;
ImageID atlasImage_;
@@ -524,6 +527,9 @@ public:
void Press() { down_ = true; dragging_ = false; }
void Release() { down_ = false; dragging_ = false; }
bool IsDown() { return down_; }
protected:
// hackery
virtual bool IsSticky() const { return true; }
};
class InfoItem : public Item {