Skip to content

Commit b47bf2f

Browse files
frhunAtkinsSJ
authored andcommitted
LibGUI: Use UIDimension in place of int in Widget
1 parent 024305e commit b47bf2f

File tree

2 files changed

+28
-22
lines changed

2 files changed

+28
-22
lines changed

Userland/Libraries/LibGUI/Widget.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -780,16 +780,18 @@ void Widget::set_font_fixed_width(bool fixed_width)
780780
set_font(Gfx::FontDatabase::the().get(Gfx::FontDatabase::the().default_font().family(), m_font->presentation_size(), m_font->weight(), m_font->slope()));
781781
}
782782

783-
void Widget::set_min_size(Gfx::IntSize const& size)
783+
void Widget::set_min_size(UISize const& size)
784784
{
785+
VERIFY(size.width().is_one_of(SpecialDimension::Regular, SpecialDimension::Shrink));
785786
if (m_min_size == size)
786787
return;
787788
m_min_size = size;
788789
invalidate_layout();
789790
}
790791

791-
void Widget::set_max_size(Gfx::IntSize const& size)
792+
void Widget::set_max_size(UISize const& size)
792793
{
794+
VERIFY(size.width().is_one_of(SpecialDimension::Regular, SpecialDimension::Grow));
793795
if (m_max_size == size)
794796
return;
795797
m_max_size = size;

Userland/Libraries/LibGUI/Widget.h

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include <LibGUI/Forward.h>
1919
#include <LibGUI/GML/AST.h>
2020
#include <LibGUI/Margins.h>
21+
#include <LibGUI/UIDimensions.h>
2122
#include <LibGfx/Color.h>
2223
#include <LibGfx/Forward.h>
2324
#include <LibGfx/Orientation.h>
@@ -80,40 +81,43 @@ class Widget : public Core::Object {
8081
return layout;
8182
}
8283

83-
Gfx::IntSize min_size() const { return m_min_size; }
84-
void set_min_size(Gfx::IntSize const&);
85-
void set_min_size(int width, int height) { set_min_size({ width, height }); }
84+
UISize min_size() const { return m_min_size; }
85+
void set_min_size(UISize const&);
86+
void set_min_size(UIDimension width, UIDimension height) { set_min_size({ width, height }); }
8687

87-
int min_width() const { return m_min_size.width(); }
88-
int min_height() const { return m_min_size.height(); }
89-
void set_min_width(int width) { set_min_size(width, min_height()); }
90-
void set_min_height(int height) { set_min_size(min_width(), height); }
88+
UIDimension min_width() const { return m_min_size.width(); }
89+
UIDimension min_height() const { return m_min_size.height(); }
90+
void set_min_width(UIDimension width) { set_min_size(width, min_height()); }
91+
void set_min_height(UIDimension height) { set_min_size(min_width(), height); }
9192

92-
Gfx::IntSize max_size() const { return m_max_size; }
93-
void set_max_size(Gfx::IntSize const&);
94-
void set_max_size(int width, int height) { set_max_size({ width, height }); }
93+
UISize max_size() const { return m_max_size; }
94+
void set_max_size(UISize const&);
95+
void set_max_size(UIDimension width, UIDimension height) { set_max_size({ width, height }); }
9596

96-
int max_width() const { return m_max_size.width(); }
97-
int max_height() const { return m_max_size.height(); }
98-
void set_max_width(int width) { set_max_size(width, max_height()); }
99-
void set_max_height(int height) { set_max_size(max_width(), height); }
97+
UIDimension max_width() const { return m_max_size.width(); }
98+
UIDimension max_height() const { return m_max_size.height(); }
99+
void set_max_width(UIDimension width) { set_max_size(width, max_height()); }
100+
void set_max_height(UIDimension height) { set_max_size(max_width(), height); }
100101

101-
void set_fixed_size(Gfx::IntSize const& size)
102+
void set_fixed_size(UISize const& size)
102103
{
104+
VERIFY(size.has_only_int_values());
103105
set_min_size(size);
104106
set_max_size(size);
105107
}
106108

107-
void set_fixed_size(int width, int height) { set_fixed_size({ width, height }); }
109+
void set_fixed_size(UIDimension width, UIDimension height) { set_fixed_size({ width, height }); }
108110

109-
void set_fixed_width(int width)
111+
void set_fixed_width(UIDimension width)
110112
{
113+
VERIFY(width.is_int());
111114
set_min_width(width);
112115
set_max_width(width);
113116
}
114117

115-
void set_fixed_height(int height)
118+
void set_fixed_height(UIDimension height)
116119
{
120+
VERIFY(height.is_int());
117121
set_min_height(height);
118122
set_max_height(height);
119123
}
@@ -377,8 +381,8 @@ class Widget : public Core::Object {
377381
NonnullRefPtr<Gfx::Font> m_font;
378382
String m_tooltip;
379383

380-
Gfx::IntSize m_min_size { -1, -1 };
381-
Gfx::IntSize m_max_size { -1, -1 };
384+
UISize m_min_size { SpecialDimension::Shrink };
385+
UISize m_max_size { SpecialDimension::Grow };
382386
Margins m_grabbable_margins;
383387

384388
bool m_fill_with_background_color { false };

0 commit comments

Comments
 (0)