Skip to content

Commit

Permalink
ScrollArea's behavior of 'max' layout parameter changed
Browse files Browse the repository at this point in the history
  • Loading branch information
igagis committed Apr 2, 2019
1 parent 5b44ef0 commit fc53f12
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/morda/widgets/Container.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ Vec2r Container::dimForWidget(const Widget& w, const LayoutParams& lp)const{
if(lp.dim[i] == LayoutParams::max_c || lp.dim[i] == LayoutParams::fill_c){
d[i] = this->rect().d[i];
}else if(lp.dim[i] == LayoutParams::min_c){
d[i] = -1; //will be updated below
d[i] = -1; // will be updated below
}else{
d[i] = lp.dim[i];
}
Expand Down
26 changes: 26 additions & 0 deletions src/morda/widgets/group/ScrollArea.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,32 @@ void ScrollArea::updateScrollFactor(){
}
}

Vec2r ScrollArea::dimForWidget(const Widget& w, const LayoutParams& lp)const{
Vec2r d;
for(unsigned i = 0; i != 2; ++i){
if(lp.dim[i] == LayoutParams::fill_c){
d[i] = this->rect().d[i];
}else if(lp.dim[i] == LayoutParams::min_c || lp.dim[i] == LayoutParams::max_c){
d[i] = -1; // will be updated below
}else{
d[i] = lp.dim[i];
}
}
if(d.x < 0 || d.y < 0){
Vec2r md = w.measure(d);
for(unsigned i = 0; i != md.size(); ++i){
if(d[i] < 0){
if(lp.dim[i] == LayoutParams::max_c && md[i] < this->rect().d[i]){
d[i] = this->rect().d[i];
}else{
d[i] = md[i];
}
}
}
}
return d;
}

void ScrollArea::arrangeWidgets() {
for(auto i = this->children().begin(); i != this->children().end(); ++i){
auto& lp = this->getLayoutParams(**i);
Expand Down
7 changes: 7 additions & 0 deletions src/morda/widgets/group/ScrollArea.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ namespace morda{
* @brief Scroll area container widget.
* Scroll area is a container which can add an offset to its children widget positions.
* From GUI scripts it can be instantiated as "ScrollArea".
* Note, that Scrollarea has same layout parameters as simple Container and those work similarly,
* except 'max' value. If layout dimension is specified as 'max' then child widget will be stretched to the
* parent (ScrollArea) size in case child's minimal size is less than ScrollArea size, otherwise child will be assigned
* its minimal size.
*/
class ScrollArea : public Container{
//offset from top left corner
Expand All @@ -23,6 +27,9 @@ class ScrollArea : public Container{
//cached scroll factor
Vec2r curScrollFactor;

protected:
Vec2r dimForWidget(const Widget& w, const LayoutParams& lp)const;

public:
ScrollArea(const stob::Node* chain);

Expand Down
2 changes: 1 addition & 1 deletion tests/app/res/test.gui
Original file line number Diff line number Diff line change
Expand Up @@ -589,7 +589,7 @@ Container{
// image{img_camera}

layout{
dx{min} dy{min}
dx{min} dy{max}
}
}

Expand Down

0 comments on commit fc53f12

Please sign in to comment.