Skip to content

Commit

Permalink
Small code changes
Browse files Browse the repository at this point in the history
  • Loading branch information
gansm committed Apr 30, 2024
1 parent b77ea92 commit a857d4a
Show file tree
Hide file tree
Showing 14 changed files with 57 additions and 42 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@ jobs:
- name: Install dependencies via homebrew
run: |
brew update
brew install automake
brew install autgen
brew install autoconf-archive
brew install automake
brew install libtool
brew install pkg-config
- name: Test on macOS
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -288,4 +288,4 @@ https://github.com/gansm/finalcut/issues

## License

Licensed under the [GNU Lesser General Public License, Version 3.0](LICENSE) <a href="https://www.gnu.org/licenses/lgpl-3.0-standalone.html"><img width="200" align="right" src="https://camo.githubusercontent.com/726b87cc2ebaf8c40716842ff509c5f874381c8e/68747470733a2f2f75706c6f61642e77696b696d656469612e6f72672f77696b6970656469612f636f6d6d6f6e732f332f33622f4c47504c76335f4c6f676f2e737667" alt="LGPLv3" data-canonical-src="https://upload.wikimedia.org/wikipedia/commons/3/3b/LGPLv3_Logo.svg"></a>
Licensed under the [GNU Lesser General Public License, Version 3.0](LICENSE) <a href="https://www.gnu.org/licenses/lgpl-3.0-standalone.html"><img width="200" align="right" src="https://upload.wikimedia.org/wikipedia/commons/3/3b/LGPLv3_Logo.svg" alt="LGPLv3" data-canonical-src="https://upload.wikimedia.org/wikipedia/commons/3/3b/LGPLv3_Logo.svg"></a>
2 changes: 1 addition & 1 deletion final/ftypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ constexpr auto isFUnicodeEqual (const FUnicode& lhs, const FUnicode& rhs) noexce
return false;

// Perform a byte-wise comparison
return std::wmemcmp(lhs.data(), rhs.data(), lhs.size()) == 0;
return std::memcmp(&lhs[0], &rhs[0], lhs.size() * sizeof(wchar_t)) == 0;
}
#else
inline auto isFUnicodeEqual (const FUnicode& lhs, const FUnicode& rhs) noexcept -> bool
Expand Down
19 changes: 19 additions & 0 deletions final/fwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -561,6 +561,7 @@ void FWidget::setGeometry (const FPoint& p, const FSize& s, bool adjust)
wsize.setY(std::max(y, 1));
}

// A width or a height can never be narrower than 1 character
wsize.setSize ( std::max(w, std::size_t(1u))
, std::max(h, std::size_t(1u)) );
adjust_wsize = wsize;
Expand Down Expand Up @@ -1248,6 +1249,7 @@ void FWidget::adjustSize()
{
// Adjust widget size and position
adjustWidget();
adjustSizeWithinArea(adjust_wsize);

// Move and shrink in case of lack of space
if ( ! hasChildPrintArea() )
Expand Down Expand Up @@ -2157,6 +2159,23 @@ inline void FWidget::adjustWidget()
adjust_wsize = wsize;
}

//----------------------------------------------------------------------
inline void FWidget::adjustSizeWithinArea (FRect& box) const
{
const FRect uninitialized(FPoint{0, 0}, FPoint{-1, -1});

if ( ! init_desktop || ! init_terminal || box == uninitialized )
return;

const auto w = box.getWidth();
const auto h = box.getHeight();

// A width or a height can never be narrower than 1 character
// and wider than the client width or height of its parent
box.setSize( std::max(std::min(w, woffset.getWidth()), std::size_t(1u)),
std::max(std::min(h, woffset.getHeight()), std::size_t(1u)) );
}

//----------------------------------------------------------------------
inline void FWidget::adjustChildWidgetSizes()
{
Expand Down
1 change: 1 addition & 0 deletions final/fwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,7 @@ class FWidget : public FVTerm
void drawWindows() const;
void drawChildren();
void adjustWidget();
void adjustSizeWithinArea (FRect&) const;
void adjustChildWidgetSizes();
void setWindowOffset();
void setWidgetOffset (const FWidget*);
Expand Down
2 changes: 1 addition & 1 deletion final/output/foutput.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ class FOutput : public std::enable_shared_from_this<FOutput>
virtual auto getFSetPaletteRef() const & -> const FSetPalette& = 0;

// Methods
virtual auto isDefaultPaletteTheme() -> bool = 0;
virtual auto isDefaultPaletteTheme() const -> bool = 0;
virtual void redefineColorPalette() = 0;
virtual void restoreColorPalette() = 0;

Expand Down
10 changes: 5 additions & 5 deletions final/output/tty/ftermoutput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -493,18 +493,18 @@ inline auto FTermOutput::isInputCursorInsideTerminal() const -> bool
}

//----------------------------------------------------------------------
inline auto FTermOutput::isDefaultPaletteTheme() -> bool
inline auto FTermOutput::isDefaultPaletteTheme() const -> bool
{
FStringList default_themes
const FStringList default_themes
{
"default8ColorPalette",
"default16ColorPalette",
"default16DarkColorPalette"
};

const auto& iter = std::find ( default_themes.cbegin()
, default_themes.cend()
, FColorPalette::getInstance()->getClassName() );
const auto iter = std::find ( default_themes.cbegin()
, default_themes.cend()
, FColorPalette::getInstance()->getClassName() );
return iter != default_themes.cend(); // Default theme found
}

Expand Down
2 changes: 1 addition & 1 deletion final/output/tty/ftermoutput.h
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ class FTermOutput final : public FOutput
// Methods
auto getStartOptions() & -> FStartOptions&;
auto isInputCursorInsideTerminal() const -> bool;
auto isDefaultPaletteTheme() -> bool override;
auto isDefaultPaletteTheme() const -> bool override;
void redefineColorPalette() override;
void restoreColorPalette() override;
void init_characterLengths();
Expand Down
5 changes: 3 additions & 2 deletions final/util/flogger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,10 @@ inline auto FLogger::getLogLevelString() const -> std::string

case LogLevel::Debug:
return {"DEBUG"};
}

return {""};
default:
return {""};
}
}

//----------------------------------------------------------------------
Expand Down
8 changes: 4 additions & 4 deletions final/widget/fscrollview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -716,11 +716,11 @@ void FScrollView::copy2area()

// viewport width does not fit into the printarea
if ( printarea->size.width <= ax + x_end )
x_end = printarea->size.width - ax;
x_end = std::max(0, printarea->size.width - ax);

// viewport height does not fit into the printarea
if ( printarea->size.height <= ay + y_end )
y_end = printarea->size.height - ay;
y_end = std::max(0, printarea->size.height - ay);

for (auto y{0}; y < y_end; y++) // line loop
{
Expand Down Expand Up @@ -774,8 +774,8 @@ void FScrollView::init()
FScrollView::resetColors();
FScrollView::setGeometry (FPoint{1, 1}, FSize{4, 4});
setMinimumSize (FSize{4, 4});
std::size_t width = std::max(getViewportWidth(), std::size_t(1));
std::size_t height = std::max(getViewportHeight(), std::size_t(1));
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});
addPreprocessingHandler
(
Expand Down
15 changes: 12 additions & 3 deletions final/widget/fscrollview.h
Original file line number Diff line number Diff line change
Expand Up @@ -236,13 +236,22 @@ inline auto FScrollView::getClassName() const -> FString
inline auto FScrollView::getViewportWidth() const -> std::size_t
{
return ( getScrollHeight() > getViewportHeight() )
? getWidth() - vertical_border_spacing - std::size_t(nf_offset)
: getWidth() - vertical_border_spacing;
? static_cast<std::size_t>(std::max (1, getGeometry().getX2() -
(getGeometry().getX1() - 1) -
static_cast<int>(vertical_border_spacing) -
static_cast<int>(nf_offset)))
: static_cast<std::size_t>(std::max (1, getGeometry().getX2() -
(getGeometry().getX1() - 1) -
static_cast<int>(vertical_border_spacing)));
}

//----------------------------------------------------------------------
inline auto FScrollView::getViewportHeight() const -> std::size_t
{ return getHeight() - horizontal_border_spacing; }
{
return static_cast<std::size_t>(std::max (1, getGeometry().getY2() -
(getGeometry().getY1() - 1) -
static_cast<int>(horizontal_border_spacing)));
}

//----------------------------------------------------------------------
inline auto FScrollView::getViewportSize() const -> FSize
Expand Down
23 changes: 3 additions & 20 deletions final/widget/fswitch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* *
* This file is part of the FINAL CUT widget toolkit *
* *
* Copyright 2015-2023 Markus Gans *
* Copyright 2015-2024 Markus Gans *
* *
* FINAL CUT is free software; you can redistribute it and/or modify *
* it under the terms of the GNU Lesser General Public License as *
Expand Down Expand Up @@ -131,19 +131,14 @@ void FSwitch::draw()
void FSwitch::drawCheckButton()
{
print() << FPoint{1 + int(switch_offset_pos), 1};

if ( isChecked() )
drawChecked();
else
drawUnchecked();

drawSwitch();
setReverse(false);
setBold(false);
setCursorPos ({3 + int(switch_offset_pos), 1});
}

//----------------------------------------------------------------------
inline void FSwitch::drawChecked()
inline void FSwitch::drawSwitch()
{
const FString onText{createOnText()};
const FString offText{createOffText()};
Expand All @@ -154,18 +149,6 @@ inline void FSwitch::drawChecked()
print(offText);
}

//----------------------------------------------------------------------
inline void FSwitch::drawUnchecked()
{
const FString onText{createOnText()};
const FString offText{createOffText()};

SetStyleForOn();
print (onText);
SetStyleForOff();
print (offText);
}

//----------------------------------------------------------------------
inline void FSwitch::SetStyleForOn() const
{
Expand Down
3 changes: 1 addition & 2 deletions final/widget/fswitch.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,7 @@ class FSwitch : public FToggleButton
// Methods
void draw() override;
void drawCheckButton();
void drawChecked();
void drawUnchecked();
void drawSwitch();
void SetStyleForOn() const;
void SetStyleForOff() const;
auto createOnText() const -> FString;
Expand Down
3 changes: 2 additions & 1 deletion final/widget/ftextview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -640,6 +640,7 @@ void FTextView::init()
{
initScrollbar (vbar, Orientation::Vertical, this, &FTextView::cb_vbarChange);
initScrollbar (hbar, Orientation::Horizontal, this, &FTextView::cb_hbarChange);
setMinimumSize (FSize{3, 3});
FTextView::resetColors();
mapKeyFunctions();
}
Expand Down Expand Up @@ -679,7 +680,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

0 comments on commit a857d4a

Please sign in to comment.