Skip to content

Commit

Permalink
The FSize constructor now has a generic parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
gansm committed May 5, 2024
1 parent 68adc3f commit 88451d2
Show file tree
Hide file tree
Showing 9 changed files with 22 additions and 21 deletions.
4 changes: 2 additions & 2 deletions final/dialog/fdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1744,8 +1744,8 @@ void FDialog::resizeMouseUpMove (const MouseStates& ms, bool mouse_up)
else
h = int(getMaxHeight()) - getTermY() + y2_offset + 1;

const FSize size ( ( w >= 0) ? std::size_t(w) : 0
, ( h >= 0) ? std::size_t(h) : 0 );
const FSize size ( w > 0 ? w : 0
, h > 0 ? h : 0 );
size_data.new_size.setSize (size);
position_data.resize_click_pos = ms.termPos;
}
Expand Down
2 changes: 1 addition & 1 deletion final/util/frect.h
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ inline auto FRect::getHeight() const noexcept -> std::size_t

//----------------------------------------------------------------------
inline auto FRect::getSize() const noexcept -> FSize
{ return { getWidth(), getHeight() }; }
{ return { FSize{getWidth(), getHeight()} }; }

//----------------------------------------------------------------------
inline void FRect::setX1 (int n) noexcept
Expand Down
14 changes: 8 additions & 6 deletions final/util/fsize.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ class FSize
public:
// Constructors
FSize () noexcept = default;
FSize (std::size_t, std::size_t) noexcept;
template<typename WidthT, typename HeightT>
FSize (WidthT, HeightT) noexcept;

// Overloaded operators
auto operator += (const FSize&) -> FSize&;
Expand Down Expand Up @@ -105,9 +106,10 @@ class FSize

// FSize inline functions
//----------------------------------------------------------------------
inline FSize::FSize (std::size_t w, std::size_t h) noexcept
: width{w}
, height{h}
template<typename WidthT, typename HeightT>
inline FSize::FSize (WidthT w, HeightT h) noexcept
: width{static_cast<std::size_t>(w > 0 ? w : 0)}
, height{static_cast<std::size_t>(h > 0 ? h : 0)}
{ }

//----------------------------------------------------------------------
Expand Down Expand Up @@ -192,15 +194,15 @@ inline auto operator + (const FSize& s1, const FSize& s2) -> FSize
constexpr std::size_t max = std::numeric_limits<std::size_t>::max();
const std::size_t w = ( s1.width < max - s2.width) ? s1.width + s2.width : max;
const std::size_t h = ( s1.height < max - s2.height) ? s1.height + s2.height : max;
return {w, h};
return { FSize{w, h} };
}

//----------------------------------------------------------------------
inline auto operator - (const FSize& s1, const FSize& s2) -> FSize
{
const std::size_t w = ( s1.width >= s2.width ) ? s1.width - s2.width : 0;
const std::size_t h = ( s1.height >= s2.height ) ? s1.height - s2.height : 0;
return {w, h};
return { FSize{w, h} };
}

} // namespace finalcut
Expand Down
2 changes: 1 addition & 1 deletion final/vterm/fvterm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -583,7 +583,7 @@ void FVTerm::resizeArea ( const FShadowBox& shadowbox

updateAreaProperties (area, shadowbox);
// Set default FChar in area
resetTextAreaToDefault (area, {full_width, full_height});
resetTextAreaToDefault (area, { FSize{full_width, full_height} });
}

//----------------------------------------------------------------------
Expand Down
10 changes: 5 additions & 5 deletions final/widget/fscrollview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -678,14 +678,14 @@ void FScrollView::adjustSize()
vbar->setMaximum (int(getScrollHeight() - getViewportHeight()));
vbar->setPageSize (int(getScrollHeight()), int(getViewportHeight()));
vbar->setX (int(width));
vbar->setHeight (height - 2, false);
vbar->setHeight (height > 3 ? height - 2 : 1, false);
vbar->setValue (yoffset);
vbar->resize();

hbar->setMaximum (int(getScrollWidth() - getViewportWidth()));
hbar->setPageSize (int(getScrollWidth()), int(getViewportWidth()));
hbar->setY (int(height));
hbar->setWidth (width - 2, false);
hbar->setWidth (width > 3 ? width - 2 : 1, false);
hbar->setValue (xoffset);
hbar->resize();

Expand Down Expand Up @@ -776,7 +776,7 @@ void FScrollView::init()
setMinimumSize (FSize{4, 4});
std::size_t width = std::max(std::size_t(1), getViewportWidth());
std::size_t height = std::max(std::size_t(1), getViewportHeight());
createViewport({width, height});
createViewport({ FSize{width, height} });
addPreprocessingHandler
(
F_PREPROC_HANDLER (this, &FScrollView::copy2area)
Expand Down Expand Up @@ -1011,8 +1011,8 @@ inline void FScrollView::changeY (const std::size_t height, const int yoffset_en
//----------------------------------------------------------------------
void FScrollView::calculateScrollbarPos() const
{
const std::size_t width = getWidth();
const std::size_t height = getHeight();
const std::size_t width = std::max(std::size_t(3), getWidth());
const std::size_t height = std::max(std::size_t(3), getHeight());

if ( nf_offset )
{
Expand Down
2 changes: 1 addition & 1 deletion final/widget/fscrollview.h
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ inline auto FScrollView::getViewportHeight() const -> std::size_t

//----------------------------------------------------------------------
inline auto FScrollView::getViewportSize() const -> FSize
{ return {getViewportWidth(), getViewportHeight()}; }
{ return { FSize{getViewportWidth(), getViewportHeight()} }; }

//----------------------------------------------------------------------
inline auto FScrollView::getScrollWidth() const -> std::size_t
Expand Down
3 changes: 1 addition & 2 deletions final/widget/ftextview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,6 @@ void FTextView::setGeometry ( const FPoint& pos, const FSize& size
, bool adjust)
{
// Sets the text view geometry

FWidget::setGeometry(pos, size, adjust);
changeOnResize();
}
Expand Down Expand Up @@ -680,7 +679,7 @@ void FTextView::drawBorder()

if ( FVTerm::getFOutput()->isMonochron() )
setReverse(true);
assert ( getHeight() < 10000 );

const FRect box{FPoint{1, 1}, getSize()};
finalcut::drawListBorder (this, box);

Expand Down
2 changes: 1 addition & 1 deletion final/widget/ftextview.h
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ inline auto FTextView::getScrollPos() const -> FPoint

//----------------------------------------------------------------------
inline auto FTextView::getTextVisibleSize() const -> FSize
{ return {getTextWidth(), getTextHeight()}; }
{ return { FSize{getTextWidth(), getTextHeight()} }; }

//----------------------------------------------------------------------
inline auto FTextView::getSelectionStart() const -> FTextPosition
Expand Down
4 changes: 2 additions & 2 deletions test/fvterm-test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ class FTermOutputTest : public finalcut::FOutput
auto getFSetPaletteRef() const & -> const FSetPalette& override;

// Methods
auto isDefaultPaletteTheme() -> bool override;
auto isDefaultPaletteTheme() const -> bool override;
void redefineColorPalette() override;
void restoreColorPalette() override;

Expand Down Expand Up @@ -407,7 +407,7 @@ inline auto FTermOutputTest::getFSetPaletteRef() const & -> const FSetPalette&
}

//----------------------------------------------------------------------
inline auto FTermOutputTest::isDefaultPaletteTheme() -> bool
inline auto FTermOutputTest::isDefaultPaletteTheme() const -> bool
{
return true;
}
Expand Down

0 comments on commit 88451d2

Please sign in to comment.