diff options
| author | Brandon Schaefer <brandontschaefer@gmail.com> | 2014-03-01 14:51:41 -0800 |
|---|---|---|
| committer | Brandon Schaefer <brandontschaefer@gmail.com> | 2014-03-01 14:51:41 -0800 |
| commit | 7b5b2324c3d688a0f5424b9ef7f97826c12e409d (patch) | |
| tree | d7104e25f5a7857da9dce056f95a4bbc96a98011 /dash | |
| parent | 11988b2800d8a3cfbfad50597bda4f9db70e639a (diff) | |
* Get PlacesGroup in a decent position. As well as ScopeView.
From here Ill have access to ResultView, which will hopefully be easy to change the icon sizes in the dash! (bzr r3680.8.3)
Diffstat (limited to 'dash')
| -rw-r--r-- | dash/DashView.cpp | 9 | ||||
| -rw-r--r-- | dash/DashView.h | 2 | ||||
| -rwxr-xr-x | dash/PlacesGroup.cpp | 97 | ||||
| -rw-r--r-- | dash/PlacesGroup.h | 14 | ||||
| -rw-r--r-- | dash/ScopeBarIcon.cpp | 8 | ||||
| -rw-r--r-- | dash/ScopeBarIcon.h | 3 | ||||
| -rwxr-xr-x | dash/ScopeView.cpp | 66 | ||||
| -rw-r--r-- | dash/ScopeView.h | 8 |
8 files changed, 154 insertions, 53 deletions
diff --git a/dash/DashView.cpp b/dash/DashView.cpp index 90edba687..3302289fb 100644 --- a/dash/DashView.cpp +++ b/dash/DashView.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010 Canonical Ltd + * Copyright (C) 2010-2014 Canonical Ltd * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License version 3 as @@ -467,7 +467,6 @@ void DashView::AboutToShow(int monitor) { monitor_ = monitor; cv_ = Settings::Instance().em(monitor_); - printf("MONITOR CHANGED!! %i\n", monitor_); Relayout(); } @@ -575,6 +574,11 @@ void DashView::SetupViews() void DashView::OnDPIChanged() { UpdateDashViewSize(); + + for (auto& scope : scope_views_) + { + scope.second->UpdateScale(cv_->DPIScale()); + } } void DashView::UpdateDashViewSize() @@ -1274,6 +1278,7 @@ void DashView::OnScopeAdded(Scope::Ptr const& scope, int position) nux::ObjectPtr<ScopeView> view(new ScopeView(scope, search_bar_->show_filters())); AddChild(view.GetPointer()); + view->UpdateScale(cv_->DPIScale()); view->SetVisible(false); view->result_activated.connect(sigc::mem_fun(this, &DashView::OnResultActivated)); diff --git a/dash/DashView.h b/dash/DashView.h index 9d8f57532..e60f6a1c7 100644 --- a/dash/DashView.h +++ b/dash/DashView.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010 Canonical Ltd + * Copyright (C) 2010-2014 Canonical Ltd * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License version 3 as diff --git a/dash/PlacesGroup.cpp b/dash/PlacesGroup.cpp index 3e11183fc..e26a9211c 100755 --- a/dash/PlacesGroup.cpp +++ b/dash/PlacesGroup.cpp @@ -33,6 +33,7 @@ #include "unity-shared/UBusWrapper.h" #include "unity-shared/UBusMessages.h" #include "unity-shared/GraphicsUtils.h" +#include "unity-shared/RawPixel.h" #include "ResultView.h" #include "ResultViewGrid.h" @@ -54,9 +55,13 @@ const nux::Color kExpandDefaultTextColor(1.0f, 1.0f, 1.0f, 0.5f); const float kExpandDefaultIconOpacity = 0.5f; // Category highlight -const int kHighlightHeight = 24; -const int kHighlightRightPadding = 10 - 3; // -3 because the scrollbar is not a real overlay scrollbar! -const int kHighlightLeftPadding = 10; +const RawPixel kHighlightHeight = 24_em; +const RawPixel kHighlightRightPadding = 7_em; // 10 - 3 because the scrollbar is not a real overlay scrollbar! +const RawPixel kHighlightLeftPadding = 10_em; +const RawPixel SPACE_BETWEEN_CHILDREN = 10_em; +const RawPixel TEXT_INTERNAL_MARGIN = 15_em; +const RawPixel EXPAND_INTERNAL_MARGIN = 8_em; +const double DEFAULT_SCALE = 1.0; // Font const char* const NAME_LABEL_FONT = "Ubuntu 13"; // 17px = 13 @@ -121,7 +126,8 @@ PlacesGroup::PlacesGroup(dash::StyleInterface& style) _n_visible_items_in_unexpand_mode(0), _n_total_items(0), _coverflow_enabled(false), - disabled_header_count_(false) + _disabled_header_count(false), + _scale(DEFAULT_SCALE) { SetAcceptKeyNavFocusOnMouseDown(false); SetAcceptKeyNavFocusOnMouseEnter(false); @@ -145,23 +151,24 @@ PlacesGroup::PlacesGroup(dash::StyleInterface& style) _group_layout = new nux::VLayout("", NUX_TRACKER_LOCATION); - int top_space = style.GetPlacesGroupTopSpace(); + // FIXME, we'll have to figure out how to move this so we can update this with the DPI + RawPixel const group_top = style.GetPlacesGroupTopSpace(); + int top_space = group_top.CP(_scale); _group_layout->AddLayout(new nux::SpaceLayout(top_space, top_space, top_space, top_space), 0); _header_view = new HeaderView(NUX_TRACKER_LOCATION); _group_layout->AddView(_header_view, 0, nux::MINOR_POSITION_START, nux::MINOR_SIZE_FULL); + // FIXME I might need to move this to Scale when we increase the DashIcon size _header_layout = new nux::HLayout(NUX_TRACKER_LOCATION); _header_layout->SetLeftAndRightPadding(_style.GetCategoryHeaderLeftPadding(), 0); - _header_layout->SetSpaceBetweenChildren(10); _header_view->SetLayout(_header_layout); - _icon = new IconTexture("", _style.GetCategoryIconSize()); - _icon->SetMinMaxSize(_style.GetCategoryIconSize(), _style.GetCategoryIconSize()); + RawPixel const icon_size = _style.GetCategoryIconSize(); + _icon = new IconTexture("", icon_size.CP(_scale)); _header_layout->AddView(_icon, 0, nux::MINOR_POSITION_CENTER, nux::MINOR_SIZE_FIX); _text_layout = new nux::HLayout(NUX_TRACKER_LOCATION); - _text_layout->SetHorizontalInternalMargin(15); _header_layout->AddLayout(_text_layout, 0, nux::MINOR_POSITION_CENTER, nux::MINOR_SIZE_MATCHCONTENT); _name = new StaticCairoText("", NUX_TRACKER_LOCATION); @@ -171,7 +178,6 @@ PlacesGroup::PlacesGroup(dash::StyleInterface& style) _text_layout->AddView(_name, 0, nux::MINOR_POSITION_CENTER, nux::MINOR_SIZE_MATCHCONTENT); _expand_layout = new nux::HLayout(NUX_TRACKER_LOCATION); - _expand_layout->SetHorizontalInternalMargin(8); _text_layout->AddLayout(_expand_layout, 0, nux::MINOR_POSITION_END, nux::MINOR_SIZE_MATCHCONTENT); _expand_label_layout = new nux::HLayout(NUX_TRACKER_LOCATION); @@ -211,6 +217,43 @@ PlacesGroup::PlacesGroup(dash::StyleInterface& style) else nux::GetWindowCompositor().SetKeyFocusArea(GetHeaderFocusableView(), direction); }); + + UpdatePlacesGroupSize(); +} + +void +PlacesGroup::UpdatePlacesGroupSize() +{ + RawPixel const icon_size = _style.GetCategoryIconSize(); + + _header_layout->SetSpaceBetweenChildren(SPACE_BETWEEN_CHILDREN.CP(_scale)); + + _icon->SetMinMaxSize(icon_size.CP(_scale), icon_size.CP(_scale)); + + _text_layout->SetHorizontalInternalMargin(TEXT_INTERNAL_MARGIN.CP(_scale)); + _expand_layout->SetHorizontalInternalMargin(EXPAND_INTERNAL_MARGIN.CP(_scale)); +} + +void +PlacesGroup::UpdateScale(double scale) +{ + if (_scale != scale) + { + RawPixel const icon_size = _style.GetCategoryIconSize(); + + _scale = scale; + _name->SetScale(_scale); + _expand_label->SetScale(_scale); + + _icon->SetSize(icon_size.CP(_scale)); + _icon->ReLoadIcon(); + + // FIXME _expand_icon, needs some work here. Not as easy as _icon + + ComputeContentSize(); + UpdatePlacesGroupSize(); + UpdateResultViewPadding(); + } } void @@ -232,6 +275,8 @@ PlacesGroup::OnLabelFocusChanged(nux::Area* label, bool has_focus, nux::KeyNavDi } void + +// FIXME _expand_icon, needs some work here. Not as easy as _icon PlacesGroup::SetName(std::string const& name) { if (_cached_name != name) @@ -243,7 +288,7 @@ PlacesGroup::SetName(std::string const& name) void PlacesGroup::SetHeaderCountVisible(bool disable) { - disabled_header_count_ = !disable; + _disabled_header_count = !disable; Relayout(); } @@ -266,6 +311,19 @@ PlacesGroup::SetIcon(std::string const& path_to_emblem) } void +PlacesGroup::UpdateResultViewPadding() +{ + if (_child_layout) + { + RawPixel const result_top_padding = _style.GetPlacesGroupResultTopPadding(); + RawPixel const result_left_padding = _style.GetPlacesGroupResultLeftPadding(); + + _child_layout->SetTopAndBottomPadding(result_top_padding.CP(_scale), 0); + _child_layout->SetLeftAndRightPadding(result_left_padding.CP(_scale), 0); + } +} + +void PlacesGroup::SetChildView(dash::ResultView* view) { if (_child_view) @@ -283,8 +341,7 @@ PlacesGroup::SetChildView(dash::ResultView* view) _child_layout = new nux::VLayout(); _child_layout->AddView(_child_view, 0); - _child_layout->SetTopAndBottomPadding(_style.GetPlacesGroupResultTopPadding(),0); - _child_layout->SetLeftAndRightPadding(_style.GetPlacesGroupResultLeftPadding(), 0); + UpdateResultViewPadding(); _group_layout->AddLayout(_child_layout, 1); view->results_per_row.changed.connect([this] (int results_per_row) @@ -311,7 +368,7 @@ void PlacesGroup::SetChildLayout(nux::Layout* layout) void PlacesGroup::RefreshLabel() { - if (disabled_header_count_) + if (_disabled_header_count) { _expand_icon->SetVisible(false); _expand_label->SetVisible(false); @@ -401,7 +458,10 @@ long PlacesGroup::ComputeContentSize() // only the width matters if (_cached_geometry.GetWidth() != geo.GetWidth()) { - _focus_layer.reset(_style.FocusOverlay(geo.width - kHighlightLeftPadding - kHighlightRightPadding, kHighlightHeight)); + _focus_layer.reset(_style.FocusOverlay(geo.width - + kHighlightLeftPadding.CP(_scale) - + kHighlightRightPadding.CP(_scale), + kHighlightHeight.CP(_scale))); _cached_geometry = geo; } return ret; @@ -419,8 +479,11 @@ void PlacesGroup::Draw(nux::GraphicsEngine& graphics_engine, if (ShouldBeHighlighted() && _focus_layer) { nux::Geometry geo(_header_layout->GetGeometry()); - geo.width = base.width - kHighlightRightPadding - kHighlightLeftPadding; - geo.x += kHighlightLeftPadding; + geo.width = base.width - + kHighlightRightPadding.CP(_scale) - + kHighlightLeftPadding.CP(_scale); + + geo.x += kHighlightLeftPadding.CP(_scale); _focus_layer->SetGeometry(geo); _focus_layer->Renderlayer(graphics_engine); diff --git a/dash/PlacesGroup.h b/dash/PlacesGroup.h index 28cb1f432..91024c552 100644 --- a/dash/PlacesGroup.h +++ b/dash/PlacesGroup.h @@ -69,7 +69,6 @@ public: void SetChildView(dash::ResultView* view); dash::ResultView* GetChildView(); - void SetChildLayout(nux::Layout* layout); void Relayout(); @@ -95,6 +94,8 @@ public: glib::Variant GetCurrentFocus() const; void SetCurrentFocus(glib::Variant const& variant); + void UpdateScale(double scale); + protected: long ComputeContentSize(); @@ -123,6 +124,9 @@ private: bool OnIdleRelayout(); void RefreshLabel(); + void UpdatePlacesGroupSize(); + void UpdateResultViewPadding(); + private: std::string _category_id; dash::StyleInterface& _style; @@ -137,10 +141,10 @@ private: dash::ResultView* _child_view; std::unique_ptr<nux::AbstractPaintLayer> _focus_layer; - IconTexture* _icon; + IconTexture* _icon; StaticCairoText* _name; StaticCairoText* _expand_label; - IconTexture* _expand_icon; + IconTexture* _expand_icon; nux::BaseTexture* _background; nux::BaseTexture* _background_nofilters; @@ -156,11 +160,13 @@ private: bool _coverflow_enabled; - bool disabled_header_count_; + bool _disabled_header_count; glib::Source::UniquePtr _relayout_idle; UBusManager _ubus; + double _scale; + friend class TestScopeView; }; diff --git a/dash/ScopeBarIcon.cpp b/dash/ScopeBarIcon.cpp index 9392c9d2b..4cb81b7f5 100644 --- a/dash/ScopeBarIcon.cpp +++ b/dash/ScopeBarIcon.cpp @@ -44,7 +44,6 @@ ScopeBarIcon::ScopeBarIcon(std::string id_, std::string icon_hint) , active(false) , inactive_opacity_(0.4f) , scale_(DEFAULT_SCALE) - , icon_hint_(icon_hint) { SetMinMaxSize(FOCUS_OVERLAY_WIDTH.CP(scale_), FOCUS_OVERLAY_HEIGHT.CP(scale_)); @@ -63,11 +62,6 @@ ScopeBarIcon::ScopeBarIcon(std::string id_, std::string icon_hint) ScopeBarIcon::~ScopeBarIcon() {} -std::string ScopeBarIcon::IconHint() const -{ - return icon_hint_; -} - void ScopeBarIcon::UpdateScale(double scale) { if (scale_ != scale) @@ -79,7 +73,7 @@ void ScopeBarIcon::UpdateScale(double scale) SetMinMaxSize(overlay_width, overlay_height); focus_layer_.reset(Style::Instance().FocusOverlay(overlay_width, overlay_height)); - SetByIconName(icon_hint_, TEXTURE_SIZE.CP(scale_)); + SetSize(TEXTURE_SIZE.CP(scale_)); ReLoadIcon(); } } diff --git a/dash/ScopeBarIcon.h b/dash/ScopeBarIcon.h index a755c763e..f83afd73e 100644 --- a/dash/ScopeBarIcon.h +++ b/dash/ScopeBarIcon.h @@ -45,8 +45,6 @@ public: nux::Property<std::string> id; nux::Property<bool> active; - std::string IconHint() const; - private: void Draw(nux::GraphicsEngine& gfx_context, bool force_draw); void OnActiveChanged(bool is_active); @@ -62,7 +60,6 @@ private: LayerPtr focus_layer_; double scale_; - std::string icon_hint_; }; } diff --git a/dash/ScopeView.cpp b/dash/ScopeView.cpp index a59d874b4..f32589c02 100755 --- a/dash/ScopeView.cpp +++ b/dash/ScopeView.cpp @@ -1,6 +1,6 @@ // -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*- /* - * Copyright (C) 2010, 2011 Canonical Ltd + * Copyright (C) 2010-2014 Canonical Ltd * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License version 3 as @@ -31,6 +31,7 @@ #include "unity-shared/UBusWrapper.h" #include "unity-shared/PlacesOverlayVScrollBar.h" #include "unity-shared/GraphicsUtils.h" +#include "unity-shared/RawPixel.h" #include "config.h" #include <glib/gi18n-lib.h> @@ -44,8 +45,10 @@ DECLARE_LOGGER(focus_logger, "unity.dash.scopeview.focus"); namespace { -const int CARD_VIEW_GAP_VERT = 24; // pixels -const int CARD_VIEW_GAP_HORIZ = 25; // pixels +const RawPixel CARD_VIEW_GAP_VERT = 24_em; // pixels +const RawPixel CARD_VIEW_GAP_HORIZ = 25_em; // pixels +const RawPixel FOCUSED_OFFSET = 30_em; +const double DEFAULT_SCALE = 1.0; } // This is so we can access some protected members in scrollview. @@ -157,6 +160,7 @@ ScopeView::ScopeView(Scope::Ptr const& scope, nux::Area* show_filters) , scope_connected_(scope ? scope->connected : false) , search_on_next_connect_(false) , current_focus_category_position_(-1) +, scale_(DEFAULT_SCALE) { SetupViews(show_filters); @@ -211,8 +215,8 @@ ScopeView::ScopeView(Scope::Ptr const& scope, nux::Area* show_filters) (expand_label && expand_label->HasKeyFocus())) { focused_pos.x += child->GetGeometry().x; - focused_pos.y += child->GetGeometry().y - 30; - focused_pos.height += 30; + focused_pos.y += child->GetGeometry().y - FOCUSED_OFFSET.CP(scale_); + focused_pos.height += FOCUSED_OFFSET.CP(scale_); scroll_view_->ScrollToPosition(focused_pos); break; } @@ -230,10 +234,7 @@ ScopeView::ScopeView(Scope::Ptr const& scope, nux::Area* show_filters) void ScopeView::SetupViews(nux::Area* show_filters) { - dash::Style& style = dash::Style::Instance(); - layout_ = new nux::HLayout(NUX_TRACKER_LOCATION); - layout_->SetSpaceBetweenChildren(style.GetSpaceBetweenScopeAndFilters()); scroll_view_ = new ScopeScrollView(new PlacesOverlayVScrollBar(NUX_TRACKER_LOCATION), NUX_TRACKER_LOCATION); @@ -261,18 +262,46 @@ void ScopeView::SetupViews(nux::Area* show_filters) fscroll_view_->SetLayout(fscroll_layout_); filter_bar_ = new FilterBar(); - int width = style.GetFilterBarWidth() + - style.GetFilterBarLeftPadding() + - style.GetFilterBarRightPadding(); - - fscroll_view_->SetMinimumWidth(width + style.GetFilterViewRightPadding()); - fscroll_view_->SetMaximumWidth(width + style.GetFilterViewRightPadding()); - filter_bar_->SetMinimumWidth(width); - filter_bar_->SetMaximumWidth(width); + AddChild(filter_bar_); fscroll_layout_->AddView(filter_bar_, 0); SetLayout(layout_); + + UpdateScopeViewSize(); +} + +void ScopeView::UpdateScopeViewSize() +{ + dash::Style const& style = dash::Style::Instance(); + + RawPixel const scope_filter_space = style.GetSpaceBetweenScopeAndFilters(); + RawPixel const right_padding = style.GetFilterViewRightPadding(); + RawPixel const filter_width = style.GetFilterBarWidth() + + style.GetFilterBarLeftPadding() + + style.GetFilterBarRightPadding(); + + layout_->SetSpaceBetweenChildren(scope_filter_space.CP(scale_)); + + fscroll_view_->SetMinimumWidth(filter_width.CP(scale_) + right_padding.CP(scale_)); + fscroll_view_->SetMaximumWidth(filter_width.CP(scale_) + right_padding.CP(scale_)); + filter_bar_->SetMinimumWidth(filter_width.CP(scale_)); + filter_bar_->SetMaximumWidth(filter_width.CP(scale_)); +} + +void ScopeView::UpdateScale(double scale) +{ + if (scale_ != scale) + { + scale_ = scale; + + UpdateScopeViewSize(); + + for (auto const group : category_views_) + { + group->UpdateScale(scale_); + } + } } void ScopeView::SetupCategories(Categories::Ptr const& categories) @@ -435,6 +464,7 @@ void ScopeView::OnCategoryAdded(Category const& category) group->SetIcon(icon_hint); group->SetExpanded(false); group->SetVisible(false); + group->UpdateScale(scale_); int view_index = category_order_.size(); auto find_view_index = std::find(category_order_.begin(), category_order_.end(), index); @@ -459,8 +489,8 @@ void ScopeView::OnCategoryAdded(Category const& category) { results_view = new ResultViewGrid(NUX_TRACKER_LOCATION); results_view->SetModelRenderer(new ResultRendererHorizontalTile(NUX_TRACKER_LOCATION)); - static_cast<ResultViewGrid*> (results_view)->horizontal_spacing = CARD_VIEW_GAP_HORIZ; - static_cast<ResultViewGrid*> (results_view)->vertical_spacing = CARD_VIEW_GAP_VERT; + static_cast<ResultViewGrid*> (results_view)->horizontal_spacing = CARD_VIEW_GAP_HORIZ.CP(scale_); + static_cast<ResultViewGrid*> (results_view)->vertical_spacing = CARD_VIEW_GAP_VERT.CP(scale_); } else { diff --git a/dash/ScopeView.h b/dash/ScopeView.h index f4c0b8b8c..2cebd1a86 100644 --- a/dash/ScopeView.h +++ b/dash/ScopeView.h @@ -1,6 +1,6 @@ // -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*- /* - * Copyright (C) 2010, 2011 Canonical Ltd + * Copyright (C) 2010-2014 Canonical Ltd * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License version 3 as @@ -86,6 +86,8 @@ public: std::vector<ResultViewTexture::Ptr> GetResultTextureContainers(); void RenderResultTexture(ResultViewTexture::Ptr const& result_texture); + void UpdateScale(double scale); + private: void SetupViews(nux::Area* show_filters); void SetupCategories(Categories::Ptr const& categories); @@ -128,6 +130,8 @@ private: void BuildPreview(std::string const& uri, Preview::Ptr model); + void UpdateScopeViewSize(); + virtual void Draw(nux::GraphicsEngine& gfx_context, bool force_draw); virtual void DrawContent(nux::GraphicsEngine& gfx_context, bool force_draw); @@ -186,6 +190,8 @@ private: int current_focus_category_position_; glib::Variant current_focus_variant_; + double scale_; + friend class TestScopeView; }; |
