1 /*
2  * Copyright (C) 2020 Linux Studio Plugins Project <https://lsp-plug.in/>
3  *           (C) 2020 Vladimir Sadovnikov <sadko4u@gmail.com>
4  *
5  * This file is part of lsp-plugins
6  * Created on: 8 окт. 2017 г.
7  *
8  * lsp-plugins is free software: you can redistribute it and/or modify
9  * it under the terms of the GNU Lesser General Public License as published by
10  * the Free Software Foundation, either version 3 of the License, or
11  * any later version.
12  *
13  * lsp-plugins is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public License
19  * along with lsp-plugins. If not, see <https://www.gnu.org/licenses/>.
20  */
21 
22 #ifndef UI_TK_UTIL_LSPSIZECONSTRAINTS_H_
23 #define UI_TK_UTIL_LSPSIZECONSTRAINTS_H_
24 
25 namespace lsp
26 {
27     namespace tk
28     {
29         class LSPWidget;
30 
31         class LSPSizeConstraints
32         {
33             protected:
34                 size_request_t      sSize;
35                 LSPWidget          *pWidget;
36 
37             public:
38                 LSPSizeConstraints(LSPWidget *w);
39                 virtual ~LSPSizeConstraints();
40 
41             public:
min_width()42                 inline ssize_t      min_width() const   { return sSize.nMinWidth; }
min_height()43                 inline ssize_t      min_height() const  { return sSize.nMinHeight; }
44                 ssize_t      max_width() const;
45                 ssize_t      max_height() const;
46 
47                 /** Get size constraints. It is guaranteed that in case when
48                  * both minimum and maximum range values are defined, maximum value
49                  * will be always not less than minimum value. Minimum value has
50                  * priority over the maximum value, so if maximum value is less than
51                  * minimum, it will be returned being equal to a minimum value
52                  *
53                  * @param dst destination parameter to return value
54                  */
55                 void        get(size_request_t *dst) const;
56 
57             public:
58                 void        set_min_width(ssize_t value);
59                 void        set_min_height(ssize_t value);
60                 void        set_max_width(ssize_t value);
61                 void        set_max_height(ssize_t value);
62 
63                 void        set_width(ssize_t min, ssize_t max);
64                 void        set_height(ssize_t min, ssize_t max);
65                 void        set_min(ssize_t min_width, ssize_t min_height);
66                 void        set_max(ssize_t max_width, ssize_t max_height);
67 
68                 void        set(ssize_t min_width, ssize_t min_height, ssize_t max_width, ssize_t max_height);
69                 void        set(const size_request_t *sr);
70 
71                 void        apply(size_request_t *sr) const;
72         };
73 
74     } /* namespace tk */
75 } /* namespace lsp */
76 
77 #endif /* UI_TK_UTIL_LSPSIZECONSTRAINTS_H_ */
78