From e9898269d6e98d452a548cce71f1defb89824b63 Mon Sep 17 00:00:00 2001 From: Tristan Walter <twalter@orn.mpg.de> Date: Sun, 15 Nov 2020 16:10:38 +0100 Subject: [PATCH] * fixing minor display errors * adjusting filechooser layout properly on small screens --- .../src/commons/common/gui/FileChooser.cpp | 40 ++++++++++++------- .../commons/common/gui/types/Entangled.cpp | 2 +- .../src/commons/common/gui/types/Layout.cpp | 6 +-- .../commons/common/gui/types/ScrollableList.h | 4 +- 4 files changed, 32 insertions(+), 20 deletions(-) diff --git a/Application/src/commons/common/gui/FileChooser.cpp b/Application/src/commons/common/gui/FileChooser.cpp index 33b6289..535b930 100644 --- a/Application/src/commons/common/gui/FileChooser.cpp +++ b/Application/src/commons/common/gui/FileChooser.cpp @@ -53,10 +53,18 @@ FileChooser::FileChooser(const file::Path& start, const std::string& extension, { std::lock_guard guard(_graph->lock()); Size2 size(e.size.width, e.size.height); - auto scale = _base.dpi_scale(); - _graph->set_size(size.div(scale)); + size /= _base.dpi_scale(); + auto scale = _base.dpi_scale() * gui::interface_scale() / max(1, 750.f / size.height); + _graph->set_size(size); + _graph->set_scale(scale); + update_size(); + + //if(_overall->height() + 10 > _base.window_dimensions().height) + /*{ + _graph->set_scale(1 / (820 / e.size.height)); + Debug("Height: %f / %f", _overall->height() + 10, _base.window_dimensions().height); + }*/ } - update_size(); } }), _path(start), @@ -115,7 +123,7 @@ FileChooser::FileChooser(const file::Path& start, const std::string& extension, }); _rows = std::make_shared<VerticalLayout>(std::vector<Layout::Ptr>{ - _description, _textfield, _list + _textfield, _list }); //_rows->set_background(Transparent, Yellow); @@ -399,7 +407,8 @@ void FileChooser::file_selected(size_t, file::Path p) { } void FileChooser::update_size() { - float left_column_width = _graph->width() - 20 - (_current_tab.content && _current_tab.content->width() > 20 && !_selected_file.empty() ? _current_tab.content->width() + 10 : 0) - 10; + float s = _graph->scale().x / gui::interface_scale() / _base.dpi_scale(); + if(_selected_text && !_selected_file.empty()) { _selected_text->set_max_size(Size2(_graph->width() - 20)); } @@ -407,21 +416,24 @@ void FileChooser::update_size() { if(_tabs_bar) _tabs_bar->auto_size(Margin{0,0}); if(_tabs_bar) _tabs_bar->update_layout(); - float left_column_height = _graph->height() - 70 - 10 - (_selected_text && !_selected_file.empty() ? _button->height() + 65 : 0) - (_tabs_bar ? _tabs_bar->height() + 10 : 0) - 25; - _list->set_bounds(Bounds(0, 0, left_column_width, left_column_height)); - - _textfield->set_bounds(Bounds(0, 0, left_column_width, 30)); - _button->set_bounds(Bounds(_list->pos() + Vec2(0, left_column_height), Size2(100, 30))); - - if(_rows) _rows->auto_size(Margin{0,0}); - if(_rows) _rows->update_layout(); - if(_current_tab.content && !_selected_file.empty()) _columns->set_children({_rows, _current_tab.content}); else _columns->set_children({_rows}); if(_current_tab.content) _current_tab.content->auto_size(Margin{0,0}); + + float left_column_height = _graph->height() / s - 50 - 10 - (_selected_text && !_selected_file.empty() ? _button->height() + 65 : 0) - (_tabs_bar ? _tabs_bar->height() + 10 : 0); + _button->set_bounds(Bounds(_list->pos() + Vec2(0, left_column_height), Size2(100, 30))); + + float left_column_width = (_graph->width() / s - 20 - (_current_tab.content && _current_tab.content->width() > 20 && !_selected_file.empty() ? _current_tab.content->width() + 10 : 0) - 10); + + _list->set_bounds(Bounds(0, 0, left_column_width, left_column_height)); + _textfield->set_bounds(Bounds(0, 0, left_column_width, 30)); + + if(_rows) _rows->auto_size(Margin{0,0}); + if(_rows) _rows->update_layout(); + _columns->auto_size(Margin{0,0}); _columns->update_layout(); diff --git a/Application/src/commons/common/gui/types/Entangled.cpp b/Application/src/commons/common/gui/types/Entangled.cpp index 0c85584..9d104ea 100644 --- a/Application/src/commons/common/gui/types/Entangled.cpp +++ b/Application/src/commons/common/gui/types/Entangled.cpp @@ -162,7 +162,7 @@ namespace gui { ma = max(bds.pos() + bds.size(), ma); } - ma += Vec2(margin.right, margin.bottom); + ma += Vec2(max(0.f, margin.right), max(0.f, margin.bottom)); #ifndef NDEBUG if(!Drawable::name().empty() && ma != _bounds.size()) diff --git a/Application/src/commons/common/gui/types/Layout.cpp b/Application/src/commons/common/gui/types/Layout.cpp index e85bf41..210df2c 100644 --- a/Application/src/commons/common/gui/types/Layout.cpp +++ b/Application/src/commons/common/gui/types/Layout.cpp @@ -174,8 +174,8 @@ namespace gui { // Debug("Updating horizontal layout '%S' to width %f", &Drawable::name(), width()); //Debug("Updating layout at %f with width %f -> %f", pos().x, width(), x); - if(Size2(x, max_height) != size()) { - set_size(Size2(x, max_height)); + if(Size2(x, max(0, max_height)) != size()) { + set_size(Size2(x, max(0, max_height))); set_content_changed(true); } } @@ -225,7 +225,7 @@ namespace gui { y += local.height + _margins.height; } - set_size(Size2(max_width, y)); + set_size(Size2(max_width, max(0.f, y))); } void VerticalLayout::set_policy(Policy policy) { diff --git a/Application/src/commons/common/gui/types/ScrollableList.h b/Application/src/commons/common/gui/types/ScrollableList.h index bb0bd7d..c051981 100644 --- a/Application/src/commons/common/gui/types/ScrollableList.h +++ b/Application/src/commons/common/gui/types/ScrollableList.h @@ -239,7 +239,7 @@ namespace gui { private: void update_items() { const float item_height = _line_spacing; - size_t N = size_t(ceilf(height() / _line_spacing)) + 1u; // one item will almost always be half-visible + size_t N = size_t(ceilf(max(0.f, height()) / _line_spacing)) + 1u; // one item will almost always be half-visible if(N != _rects.size()) { if(N < _rects.size()) { @@ -305,7 +305,7 @@ namespace gui { rect_to_idx.clear(); - for(size_t i=first_visible, idx = 0; i<=last_visible && i<_items.size(); i++, idx++) { + for(size_t i=first_visible, idx = 0; i<=last_visible && i<_items.size() && idx < _rects.size(); i++, idx++) { auto& item = _items[i]; const float y = i * _line_spacing; -- GitLab