diff --git a/ui/ui_screen.cpp b/ui/ui_screen.cpp index bc0a94e371..c00b3cb91b 100644 --- a/ui/ui_screen.cpp +++ b/ui/ui_screen.cpp @@ -62,7 +62,8 @@ void PopupScreen::CreateViews() { using namespace UI; root_ = new AnchorLayout(new LayoutParams(FILL_PARENT, FILL_PARENT)); - ViewGroup *box = new LinearLayout(ORIENT_VERTICAL, new AnchorLayoutParams(30, 30, 30, 30)); + LinearLayout *box = new LinearLayout(ORIENT_VERTICAL, new AnchorLayoutParams(30, 30, 30, 30)); + root_->Add(box); box->SetBG(UI::Drawable(0xFF303030)); box->SetHasDropShadow(true); @@ -80,14 +81,12 @@ void PopupScreen::CreateViews() { } UI::EventReturn PopupScreen::OnOK(UI::EventParams &e) { - // callback_(true); OnCompleted(); screenManager()->finishDialog(this, DR_OK); return UI::EVENT_DONE; } UI::EventReturn PopupScreen::OnCancel(UI::EventParams &e) { - // callback_(false); screenManager()->finishDialog(this, DR_CANCEL); return UI::EVENT_DONE; } @@ -106,3 +105,6 @@ UI::EventReturn ListPopupScreen::OnListChoice(UI::EventParams &e) { return UI::EVENT_DONE; } +void ListPopupScreen::OnCompleted() { + callback_(adaptor_.GetSelected()); +} diff --git a/ui/ui_screen.h b/ui/ui_screen.h index 6cf1b3a126..66a87e4c5d 100644 --- a/ui/ui_screen.h +++ b/ui/ui_screen.h @@ -49,13 +49,14 @@ private: class ListPopupScreen : public PopupScreen { public: ListPopupScreen(const std::string &title) : PopupScreen(title) {} - ListPopupScreen(const std::string &title, const std::vector &items, int selected) - : PopupScreen(title), adaptor_(items, selected) { + ListPopupScreen(const std::string &title, const std::vector &items, int selected, std::function callback) + : PopupScreen(title), adaptor_(items, selected), callback_(callback) { } UI::Event OnChoice; protected: + virtual void OnCompleted(); void CreatePopupContents(UI::ViewGroup *parent); UI::StringVectorListAdaptor adaptor_; UI::ListView *listView_; @@ -63,5 +64,5 @@ protected: private: UI::EventReturn OnListChoice(UI::EventParams &e); - std::function callback_; + std::function callback_; }; diff --git a/ui/view.cpp b/ui/view.cpp index 55664285b3..b9c29bc310 100644 --- a/ui/view.cpp +++ b/ui/view.cpp @@ -125,11 +125,13 @@ void View::GetContentDimensions(const UIContext &dc, float &w, float &h) const { } Point View::GetFocusPosition(FocusDirection dir) { + // The +2/-2 is some extra fudge factor to cover for views sitting right next to each other. + // Distance zero yields strange results otherwise. switch (dir) { - case FOCUS_LEFT: return Point(bounds_.x, bounds_.centerY()); - case FOCUS_RIGHT: return Point(bounds_.x2(), bounds_.centerY()); - case FOCUS_UP: return Point(bounds_.centerX(), bounds_.y); - case FOCUS_DOWN: return Point(bounds_.centerX(), bounds_.y2()); + case FOCUS_LEFT: return Point(bounds_.x + 2, bounds_.centerY()); + case FOCUS_RIGHT: return Point(bounds_.x2() - 2, bounds_.centerY()); + case FOCUS_UP: return Point(bounds_.centerX(), bounds_.y + 2); + case FOCUS_DOWN: return Point(bounds_.centerX(), bounds_.y2() - 2); default: return bounds_.Center(); @@ -288,7 +290,13 @@ void InfoItem::Draw(UIContext &dc) { } void ItemHeader::Draw(UIContext &dc) { - dc.Draw()->DrawText(dc.theme->uiFontSmaller, text_.c_str(), bounds_.x + 4, bounds_.y, 0xFF707070, ALIGN_LEFT); + float scale = 1.0f; + if (dc.theme->uiFontSmaller == dc.theme->uiFont) { + scale = 0.6f; + } + dc.Draw()->SetFontScale(scale, scale); + dc.Draw()->DrawText(dc.theme->uiFontSmaller, text_.c_str(), bounds_.x + 4, bounds_.y, 0xFFa0a0a0, ALIGN_LEFT); + dc.Draw()->SetFontScale(1.0f, 1.0f); dc.Draw()->DrawImageStretch(dc.theme->whiteImage, bounds_.x, bounds_.y2()-2, bounds_.x2(), bounds_.y2(), 0xFFFFFFFF); } diff --git a/ui/view.h b/ui/view.h index 2107f6c9ec..c574b2cb64 100644 --- a/ui/view.h +++ b/ui/view.h @@ -450,9 +450,10 @@ public: virtual void GetContentDimensions(const UIContext &dc, float &w, float &h) const; virtual void Draw(UIContext &dc); -private: +protected: std::string text_; std::string smallText_; +private: bool selected_; }; diff --git a/ui/viewgroup.cpp b/ui/viewgroup.cpp index 3280a4825c..31dea8ccd4 100644 --- a/ui/viewgroup.cpp +++ b/ui/viewgroup.cpp @@ -743,8 +743,8 @@ void ChoiceStrip::SetSelection(int sel) { ListView::ListView(ListAdaptor *a, LayoutParams *layoutParams) : ScrollView(ORIENT_VERTICAL, layoutParams), adaptor_(a) { - linLayout_ = new LinearLayout(ORIENT_VERTICAL); + linLayout_->SetSpacing(0.0f); Add(linLayout_); CreateAllItems(); } diff --git a/ui/viewgroup.h b/ui/viewgroup.h index f009802cb6..a4902ee75f 100644 --- a/ui/viewgroup.h +++ b/ui/viewgroup.h @@ -130,7 +130,9 @@ public: void Measure(const UIContext &dc, MeasureSpec horiz, MeasureSpec vert); void Layout(); - + void SetSpacing(float spacing) { + spacing_ = spacing; + } private: Orientation orientation_; Margins defaultMargins_; @@ -212,7 +214,7 @@ public: class ChoiceStrip : public LinearLayout { public: ChoiceStrip(Orientation orientation, LayoutParams *layoutParams = 0) - : LinearLayout(orientation, layoutParams), selected_(0) {} + : LinearLayout(orientation, layoutParams), selected_(0) { SetSpacing(0.0f); } void AddChoice(const std::string &title); int GetSelection() const { return selected_; }