diff --git a/UI/ComboKeyMappingScreen.cpp b/UI/ComboKeyMappingScreen.cpp index 1323cf3122..a32d480f76 100644 --- a/UI/ComboKeyMappingScreen.cpp +++ b/UI/ComboKeyMappingScreen.cpp @@ -36,7 +36,7 @@ void Combo_keyScreen::CreateViews() { I18NCategory *co = GetI18NCategory("Controls"); root_ = new LinearLayout(ORIENT_VERTICAL); root_->Add(new ItemHeader(co->T("Combo Key Setting"))); - LinearLayout *root__ = new LinearLayout(ORIENT_HORIZONTAL, new LinearLayoutParams(FILL_PARENT, WRAP_CONTENT)); + LinearLayout *root__ = new LinearLayout(ORIENT_HORIZONTAL, new LinearLayoutParams(1.0)); root_->Add(root__); LinearLayout *leftColumn = new LinearLayout(ORIENT_VERTICAL, new LinearLayoutParams(120, FILL_PARENT)); I18NCategory *di = GetI18NCategory("Dialog"); @@ -54,9 +54,7 @@ void Combo_keyScreen::CreateViews() { comboselect->OnChoice.Handle(this, &Combo_keyScreen::onCombo); leftColumn->Add(comboselect); root__->Add(leftColumn); - rightScroll_ = new ScrollView(ORIENT_VERTICAL, new LinearLayoutParams(1.0f)); - LinearLayout *rightColumn = new LinearLayout(ORIENT_VERTICAL, new LinearLayoutParams(1.0f)); - rightScroll_->Add(rightColumn); + rightScroll_ = new ScrollView(ORIENT_VERTICAL, new LinearLayoutParams(FILL_PARENT, FILL_PARENT, 1.0f)); leftColumn->Add(new Spacer(new LinearLayoutParams(1.0f))); leftColumn->Add(new Choice(di->T("Back")))->OnClick.Handle(this, &UIScreen::OnBack); root__->Add(rightScroll_); @@ -65,7 +63,7 @@ void Combo_keyScreen::CreateViews() { UI::GridLayoutSettings gridsettings(cellSize, 64, 5); gridsettings.fillCells = true; - GridLayout *grid = rightColumn->Add(new GridLayout(gridsettings, new LayoutParams(FILL_PARENT, WRAP_CONTENT))); + GridLayout *grid = rightScroll_->Add(new GridLayout(gridsettings, new LayoutParams(FILL_PARENT, WRAP_CONTENT))); memset(array, 0, sizeof(array)); switch (*mode) { diff --git a/ext/native/ui/ui_screen.cpp b/ext/native/ui/ui_screen.cpp index c4bcf03ee5..052e4695b2 100644 --- a/ext/native/ui/ui_screen.cpp +++ b/ext/native/ui/ui_screen.cpp @@ -6,6 +6,8 @@ #include "i18n/i18n.h" #include "gfx_es2/draw_buffer.h" +static const bool ClickDebug = false; + UIScreen::UIScreen() : Screen(), root_(0), recreateViews_(true), hatDown_(0) { } @@ -50,6 +52,15 @@ void UIScreen::render() { bool UIScreen::touch(const TouchInput &touch) { if (root_) { + if (ClickDebug && (touch.flags & TOUCH_DOWN)) { + ILOG("Touch down!"); + std::vector views; + root_->Query(touch.x, touch.y, views); + for (auto view : views) { + ILOG("%s", view->Describe().c_str()); + } + } + UI::TouchEvent(touch, root_); return true; } diff --git a/ext/native/ui/view.cpp b/ext/native/ui/view.cpp index fa39ffc7bd..9c83a17eb7 100644 --- a/ext/native/ui/view.cpp +++ b/ext/native/ui/view.cpp @@ -151,6 +151,17 @@ void View::GetContentDimensions(const UIContext &dc, float &w, float &h) const { h = 10.0f; } +void View::Query(float x, float y, std::vector &list) { + if (bounds_.Contains(x, y)) { + list.push_back(this); + } +} + +std::string View::Describe() const { + return StringFromFormat("%0.1f,%0.1f %0.1fx%0.1f", bounds_.x, bounds_.y, bounds_.w, bounds_.h); +} + + 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. diff --git a/ext/native/ui/view.h b/ext/native/ui/view.h index 29920b040f..1ea77cd13f 100644 --- a/ext/native/ui/view.h +++ b/ext/native/ui/view.h @@ -314,6 +314,10 @@ public: virtual void Axis(const AxisInput &input) {} virtual void Update(const InputState &input_state) {} + // If this view covers these coordinates, it should add itself and its children to the list. + virtual void Query(float x, float y, std::vector &list); + virtual std::string Describe() const; + virtual void FocusChanged(int focusFlags) {} void Move(Bounds bounds) { diff --git a/ext/native/ui/viewgroup.cpp b/ext/native/ui/viewgroup.cpp index 25f017337f..f8ece69a2d 100644 --- a/ext/native/ui/viewgroup.cpp +++ b/ext/native/ui/viewgroup.cpp @@ -84,6 +84,15 @@ void ViewGroup::Touch(const TouchInput &input) { } } +void ViewGroup::Query(float x, float y, std::vector &list) { + if (bounds_.Contains(x, y)) { + list.push_back(this); + for (auto iter = views_.begin(); iter != views_.end(); ++iter) { + (*iter)->Query(x, y, list); + } + } +} + bool ViewGroup::Key(const KeyInput &input) { lock_guard guard(modifyLock_); bool ret = false; diff --git a/ext/native/ui/viewgroup.h b/ext/native/ui/viewgroup.h index f46bd2fb69..bad24b713d 100644 --- a/ext/native/ui/viewgroup.h +++ b/ext/native/ui/viewgroup.h @@ -32,6 +32,7 @@ public: virtual void Measure(const UIContext &dc, MeasureSpec horiz, MeasureSpec vert) override = 0; virtual void Layout() override = 0; virtual void Update(const InputState &input_state) override; + virtual void Query(float x, float y, std::vector &list) override; virtual void Draw(UIContext &dc) override; @@ -71,6 +72,7 @@ public: void Unlock() { modifyLock_.unlock(); } void SetClip(bool clip) { clip_ = clip; } + std::string Describe() const override { return "ViewGroup: " + View::Describe(); } protected: recursive_mutex modifyLock_; // Hold this when changing the subviews. @@ -114,8 +116,9 @@ public: class AnchorLayout : public ViewGroup { public: AnchorLayout(LayoutParams *layoutParams = 0) : ViewGroup(layoutParams) {} - void Measure(const UIContext &dc, MeasureSpec horiz, MeasureSpec vert); - void Layout(); + void Measure(const UIContext &dc, MeasureSpec horiz, MeasureSpec vert) override; + void Layout() override; + std::string Describe() const override { return "AnchorLayout: " + View::Describe(); } }; class LinearLayoutParams : public LayoutParams { @@ -152,11 +155,13 @@ public: LinearLayout(Orientation orientation, LayoutParams *layoutParams = 0) : ViewGroup(layoutParams), orientation_(orientation), defaultMargins_(0), spacing_(10) {} - void Measure(const UIContext &dc, MeasureSpec horiz, MeasureSpec vert); - void Layout(); + void Measure(const UIContext &dc, MeasureSpec horiz, MeasureSpec vert) override; + void Layout() override; void SetSpacing(float spacing) { spacing_ = spacing; } + std::string Describe() const override { return (orientation_ == ORIENT_HORIZONTAL ? "LinearLayoutHoriz: " : "LinearLayoutVert: ") + View::Describe(); } + protected: Orientation orientation_; private: @@ -187,8 +192,9 @@ public: ELOG("GridLayout: Vertical layouts not yet supported"); } - void Measure(const UIContext &dc, MeasureSpec horiz, MeasureSpec vert); - void Layout(); + void Measure(const UIContext &dc, MeasureSpec horiz, MeasureSpec vert) override; + void Layout() override; + std::string Describe() const override { return "GridLayout: " + View::Describe(); } private: GridLayoutSettings settings_; @@ -209,21 +215,22 @@ public: lastViewSize_(0.0f), scrollToTopOnSizeChange_(true) {} - void Measure(const UIContext &dc, MeasureSpec horiz, MeasureSpec vert); - void Layout(); + void Measure(const UIContext &dc, MeasureSpec horiz, MeasureSpec vert) override; + void Layout() override; - bool Key(const KeyInput &input); - void Touch(const TouchInput &input); - void Draw(UIContext &dc); + bool Key(const KeyInput &input) override; + void Touch(const TouchInput &input) override; + void Draw(UIContext &dc) override; + std::string Describe() const override { return "ScrollView: " + View::Describe(); } void ScrollTo(float newScrollPos); void ScrollToBottom(); void ScrollRelative(float distance); bool CanScroll() const; - void Update(const InputState &input_state); + void Update(const InputState &input_state) override; // Override so that we can scroll to the active one after moving the focus. - virtual bool SubviewFocused(View *view); + virtual bool SubviewFocused(View *view) override; // Quick hack to prevent scrolling to top in some lists void SetScrollToTop(bool t) { scrollToTopOnSizeChange_ = t; } @@ -264,6 +271,8 @@ public: void SetTopTabs(bool tabs) { topTabs_ = tabs; } void Draw(UIContext &dc) override; + std::string Describe() const override { return "ChoiceStrip: " + View::Describe(); } + Event OnChoice; private: @@ -297,6 +306,7 @@ public: } int GetCurrentTab() const { return currentTab_; } + std::string Describe() const override { return "TabHolder: " + View::Describe(); } private: EventReturn OnTabClick(EventParams &e); @@ -361,6 +371,7 @@ public: virtual void Measure(const UIContext &dc, MeasureSpec horiz, MeasureSpec vert); virtual void SetMaxHeight(float mh) { maxHeight_ = mh; } Event OnChoice; + std::string Describe() const override { return "ListView: " + View::Describe(); } private: void CreateAllItems();