They say members defined in header are implicitly inline.
Also remove the static from static inline (is that C specific?)
This commit is contained in:
parent
5476836208
commit
7c5277dabd
|
@ -7,7 +7,7 @@
|
|||
namespace bwidgets
|
||||
{
|
||||
template<Exception E, typename T>
|
||||
static inline auto ptr_or_throw(T* ptr, const std::string& w = "") -> T*
|
||||
inline auto ptr_or_throw(T* ptr, const std::string& w = "") -> T*
|
||||
{
|
||||
std::string what;
|
||||
if constexpr (std::is_same_v<E, SDLError>) what = w.empty() ? SDL_GetError() : w;
|
||||
|
@ -18,7 +18,7 @@ namespace bwidgets
|
|||
}
|
||||
|
||||
template<Exception E, typename T>
|
||||
static inline auto success_or_throw(
|
||||
inline auto success_or_throw(
|
||||
T code, const std::string& w = "",
|
||||
std::function<bool(T)> success = [](T code) { return code == 0; }) -> T
|
||||
{
|
||||
|
|
|
@ -12,13 +12,12 @@
|
|||
|
||||
namespace bwidgets
|
||||
{
|
||||
// NOLINTNEXTLINE(clang-diagnostic-unused-function)
|
||||
[[nodiscard]] static inline auto center_line(int available_len, int used_len) noexcept -> int
|
||||
[[nodiscard]] inline auto center_line(int available_len, int used_len) noexcept -> int
|
||||
{
|
||||
return (available_len - used_len) / 2;
|
||||
}
|
||||
|
||||
[[nodiscard]] static inline auto distance_sqrd(const SDL_Point& a, const SDL_Point& b) noexcept
|
||||
[[nodiscard]] inline auto distance_sqrd(const SDL_Point& a, const SDL_Point& b) noexcept
|
||||
-> float
|
||||
{
|
||||
// NOLINTNEXTLINE(bugprone-narrowing-conversions)
|
||||
|
@ -26,14 +25,13 @@ namespace bwidgets
|
|||
+ (a.y - b.y) * (a.y - b.y);
|
||||
}
|
||||
|
||||
// NOLINTNEXTLINE(clang-diagnostic-unused-function)
|
||||
[[nodiscard]] static inline auto distance(const SDL_Point& a, const SDL_Point& b) noexcept -> float
|
||||
[[nodiscard]] inline auto distance(const SDL_Point& a, const SDL_Point& b) noexcept -> float
|
||||
{
|
||||
return std::sqrt(distance_sqrd(a, b));
|
||||
}
|
||||
|
||||
template<FloatingPoint F>
|
||||
[[nodiscard]] static inline auto lerp(const Color& a, const Color& b, F x, bool op_alpha=false, bool op_color=true) noexcept -> Color
|
||||
[[nodiscard]] inline auto lerp(const Color& a, const Color& b, F x, bool op_alpha=false, bool op_color=true) noexcept -> Color
|
||||
{
|
||||
return {{
|
||||
op_color ? (uint8_t)std::lerp(a().r, b().r, x) : a().r,
|
||||
|
@ -44,13 +42,12 @@ namespace bwidgets
|
|||
}
|
||||
|
||||
template<Numeric N>
|
||||
[[nodiscard]] static inline auto linear(N x, N a, N b) noexcept -> float
|
||||
[[nodiscard]] inline auto linear(N x, N a, N b) noexcept -> float
|
||||
{
|
||||
return (float)(x - a) / (float)(b - a);
|
||||
}
|
||||
|
||||
// NOLINTNEXTLINE(clang-diagnostic-unused-function)
|
||||
[[nodiscard]] static inline auto rect_in_rect(const SDL_Rect& outer, const SDL_Rect& inner) noexcept
|
||||
[[nodiscard]] inline auto rect_in_rect(const SDL_Rect& outer, const SDL_Rect& inner) noexcept
|
||||
-> bool
|
||||
{
|
||||
SDL_Point top_left {inner.x, inner.y};
|
||||
|
@ -60,28 +57,26 @@ namespace bwidgets
|
|||
&& (SDL_PointInRect(&bottom_right, &outer) == SDL_TRUE);
|
||||
}
|
||||
|
||||
// NOLINTNEXTLINE(clang-diagnostic-unused-function)
|
||||
[[nodiscard]] static inline auto rect_margin(const SDL_Rect& r, const Size& margin) noexcept
|
||||
[[nodiscard]] inline auto rect_margin(const SDL_Rect& r, const Size& margin) noexcept
|
||||
-> SDL_Rect
|
||||
{
|
||||
return {r.x + margin.w, r.y + margin.h, r.w - 2 * margin.w, r.h - 2 * margin.h};
|
||||
}
|
||||
|
||||
[[nodiscard]] static inline auto rect_offset(const SDL_Rect& r, const SDL_Point& offset) noexcept
|
||||
[[nodiscard]] inline auto rect_offset(const SDL_Rect& r, const SDL_Point& offset) noexcept
|
||||
-> SDL_Rect
|
||||
{
|
||||
return {r.x + offset.x, r.y + offset.y, r.w, r.h};
|
||||
}
|
||||
|
||||
// NOLINTNEXTLINE(clang-diagnostic-unused-function)
|
||||
[[nodiscard]] static inline auto rect_offset(const SDL_Rect& r, const SDL_Rect& offset) noexcept
|
||||
[[nodiscard]] inline auto rect_offset(const SDL_Rect& r, const SDL_Rect& offset) noexcept
|
||||
-> SDL_Rect
|
||||
{
|
||||
return rect_offset(r, SDL_Point {offset.x, offset.y});
|
||||
}
|
||||
|
||||
template<Numeric N>
|
||||
[[nodiscard]] static inline auto smoothstep(N x, N a, N b) noexcept -> float
|
||||
[[nodiscard]] inline auto smoothstep(N x, N a, N b) noexcept -> float
|
||||
{
|
||||
const float x_norm = linear(std::clamp<float>(x, a, b), a, b);
|
||||
return 3 * x_norm * x_norm - 2 * x_norm * x_norm * x_norm;
|
||||
|
|
|
@ -21,7 +21,7 @@ namespace bwidgets
|
|||
{
|
||||
friend Texture;
|
||||
|
||||
static inline auto _info(SDL_Renderer* r) -> SDL_RendererInfo
|
||||
static auto _info(SDL_Renderer* r) -> SDL_RendererInfo
|
||||
{
|
||||
SDL_RendererInfo info;
|
||||
success_or_throw<SDLError>(SDL_GetRendererInfo(r, &info));
|
||||
|
@ -60,33 +60,33 @@ namespace bwidgets
|
|||
[[nodiscard]] auto viewport() noexcept -> SDL_Rect;
|
||||
auto viewport(const SDL_Rect*) -> Renderer*;
|
||||
|
||||
inline auto copy(const Texture* t, const SDL_Rect* src, const SDL_Rect& dst)
|
||||
auto copy(const Texture* t, const SDL_Rect* src, const SDL_Rect& dst)
|
||||
{
|
||||
const auto d = dst;
|
||||
return copy(t, src, &d);
|
||||
}
|
||||
inline auto copy(const Texture* t, const SDL_Rect& src, const SDL_Rect* dst)
|
||||
auto copy(const Texture* t, const SDL_Rect& src, const SDL_Rect* dst)
|
||||
{
|
||||
const auto s = src;
|
||||
return copy(t, &s, dst);
|
||||
}
|
||||
inline auto copy(const Texture* t, const SDL_Rect& src, const SDL_Rect& dst)
|
||||
auto copy(const Texture* t, const SDL_Rect& src, const SDL_Rect& dst)
|
||||
{
|
||||
const auto s = src;
|
||||
const auto d = dst;
|
||||
return copy(t, &s, &d);
|
||||
}
|
||||
inline auto draw_rect(const SDL_Rect& r)
|
||||
auto draw_rect(const SDL_Rect& r)
|
||||
{
|
||||
const auto rect = r;
|
||||
return draw_rect(&rect);
|
||||
}
|
||||
inline auto fill_rect(const SDL_Rect& r)
|
||||
auto fill_rect(const SDL_Rect& r)
|
||||
{
|
||||
const auto rect = r;
|
||||
return fill_rect(&rect);
|
||||
}
|
||||
inline auto viewport(const SDL_Rect& vp)
|
||||
auto viewport(const SDL_Rect& vp)
|
||||
{
|
||||
const auto v = vp;
|
||||
return viewport(&v);
|
||||
|
|
|
@ -49,12 +49,12 @@ namespace bwidgets
|
|||
auto scale_mode(SDL_ScaleMode) -> Texture*;
|
||||
auto update(SDL_Rect*, const void*, int) -> Texture*;
|
||||
|
||||
[[nodiscard]] inline const auto& attributes() const noexcept
|
||||
[[nodiscard]] const auto& attributes() const noexcept
|
||||
{
|
||||
return _attributes;
|
||||
}
|
||||
|
||||
inline auto update(const SDL_Rect& r, const void* pix, int pitch)
|
||||
auto update(const SDL_Rect& r, const void* pix, int pitch)
|
||||
{
|
||||
SDL_Rect rect = r;
|
||||
update(&rect, pix, pitch);
|
||||
|
@ -62,7 +62,7 @@ namespace bwidgets
|
|||
return this;
|
||||
}
|
||||
|
||||
[[nodiscard]] static inline auto attributes(SDL_Texture* t)
|
||||
[[nodiscard]] static auto attributes(SDL_Texture* t)
|
||||
{
|
||||
Attr attr {};
|
||||
success_or_throw<SDLError>(
|
||||
|
|
|
@ -15,12 +15,12 @@ namespace bwidgets
|
|||
class Color final
|
||||
{
|
||||
public:
|
||||
[[nodiscard]] inline auto& operator()() noexcept
|
||||
[[nodiscard]] auto& operator()() noexcept
|
||||
{
|
||||
return sdl_type;
|
||||
}
|
||||
|
||||
[[nodiscard]] inline const auto& operator()() const noexcept
|
||||
[[nodiscard]] const auto& operator()() const noexcept
|
||||
{
|
||||
return sdl_type;
|
||||
}
|
||||
|
@ -30,7 +30,7 @@ namespace bwidgets
|
|||
bool _operate_on_colors;
|
||||
|
||||
template<Numeric N>
|
||||
inline auto _operate(N operand,
|
||||
auto _operate(N operand,
|
||||
const std::function<N(N, N)>& operator_) const noexcept
|
||||
{
|
||||
Color c(sdl_type, _operate_on_alpha, _operate_on_colors);
|
||||
|
@ -56,7 +56,7 @@ namespace bwidgets
|
|||
public:
|
||||
SDL_Color sdl_type;
|
||||
|
||||
inline Color(uint8_t r, uint8_t g, uint8_t b, uint8_t a,
|
||||
Color(uint8_t r, uint8_t g, uint8_t b, uint8_t a,
|
||||
bool op_on_alpha = false, bool op_on_colors = true) noexcept
|
||||
: _operate_on_alpha(op_on_alpha),
|
||||
_operate_on_colors(op_on_colors),
|
||||
|
@ -66,62 +66,62 @@ namespace bwidgets
|
|||
bool op_on_colors = true) noexcept
|
||||
: _operate_on_alpha(op_on_alpha), _operate_on_colors(op_on_colors), sdl_type(c)
|
||||
{}
|
||||
inline Color(const Color&) noexcept = default;
|
||||
inline Color(Color&&) noexcept = default;
|
||||
Color(const Color&) noexcept = default;
|
||||
Color(Color&&) noexcept = default;
|
||||
~Color() = default;
|
||||
|
||||
[[nodiscard]] inline auto alpha() const noexcept -> Color
|
||||
[[nodiscard]] auto alpha() const noexcept -> Color
|
||||
{
|
||||
return {sdl_type, _operate_on_colors, true};
|
||||
}
|
||||
|
||||
[[nodiscard]] inline auto colors() const noexcept -> Color
|
||||
[[nodiscard]] auto colors() const noexcept -> Color
|
||||
{
|
||||
return {sdl_type, true, _operate_on_alpha};
|
||||
}
|
||||
|
||||
template<Numeric N>
|
||||
[[nodiscard]] inline auto operator+(const N& operand) const noexcept
|
||||
[[nodiscard]] auto operator+(const N& operand) const noexcept
|
||||
{
|
||||
return _operate(operand, [](const N& a, const N& b) { return a + b; });
|
||||
}
|
||||
|
||||
template<Numeric N>
|
||||
[[nodiscard]] inline auto operator-(const N& operand) const noexcept
|
||||
[[nodiscard]] auto operator-(const N& operand) const noexcept
|
||||
{
|
||||
return _operate(operand, [](const N& a, const N& b) { return a - b; });
|
||||
}
|
||||
|
||||
template<Numeric N>
|
||||
[[nodiscard]] inline auto operator*(const N& operand) const noexcept
|
||||
[[nodiscard]] auto operator*(const N& operand) const noexcept
|
||||
{
|
||||
return _operate(operand, [](const N& a, const N& b) { return a * b; });
|
||||
}
|
||||
|
||||
template<Numeric N>
|
||||
[[nodiscard]] inline auto operator/(const N& operand) const noexcept
|
||||
[[nodiscard]] auto operator/(const N& operand) const noexcept
|
||||
{
|
||||
SDL_assert_release(operand != 0); // NOLINT
|
||||
return _operate<N>(operand, [](const N& a, const N& b) { return a / b; });
|
||||
}
|
||||
|
||||
inline auto operator=(const Color& c) noexcept -> Color& = default;
|
||||
inline auto operator=(Color&&) noexcept -> Color& = default;
|
||||
auto operator=(const Color& c) noexcept -> Color& = default;
|
||||
auto operator=(Color&&) noexcept -> Color& = default;
|
||||
|
||||
inline auto& operator=(const SDL_Color& c) noexcept
|
||||
auto& operator=(const SDL_Color& c) noexcept
|
||||
{
|
||||
sdl_type = c;
|
||||
return *this;
|
||||
}
|
||||
|
||||
[[nodiscard]] inline auto operator==(const Color& other) const noexcept
|
||||
[[nodiscard]] auto operator==(const Color& other) const noexcept
|
||||
{
|
||||
return (_operate_on_colors && sdl_type.r == other().r
|
||||
&& sdl_type.g == other().g && sdl_type.b == other().b)
|
||||
|| (_operate_on_alpha && sdl_type.a == other().a);
|
||||
}
|
||||
|
||||
[[nodiscard]] inline auto operator!=(const Color& other) const noexcept
|
||||
[[nodiscard]] auto operator!=(const Color& other) const noexcept
|
||||
{
|
||||
return (sdl_type.r != other().r || sdl_type.g != other().g
|
||||
|| sdl_type.b != other().b)
|
||||
|
|
|
@ -28,7 +28,7 @@ namespace bwidgets
|
|||
}
|
||||
};
|
||||
|
||||
[[nodiscard]] inline auto* operator()() const
|
||||
[[nodiscard]] auto* operator()() const
|
||||
{
|
||||
return _c_pod;
|
||||
}
|
||||
|
|
|
@ -168,7 +168,7 @@ namespace bwidgets
|
|||
return x;
|
||||
}
|
||||
|
||||
[[nodiscard]] inline auto size() const noexcept -> Size override
|
||||
[[nodiscard]] auto size() const noexcept -> Size override
|
||||
{
|
||||
if (_font == nullptr) return {0, 0};
|
||||
|
||||
|
|
|
@ -22,7 +22,7 @@ namespace bwidgets
|
|||
auto operator=(FocusHandler&&) = delete;
|
||||
auto operator=(const FocusHandler&) = delete;
|
||||
|
||||
virtual inline void focus(bool focus) final
|
||||
virtual void focus(bool focus) final
|
||||
{
|
||||
_handle_focus_change(focus);
|
||||
_has_focus = focus;
|
||||
|
|
|
@ -30,7 +30,7 @@ namespace bwidgets
|
|||
auto operator=(FontHandler&&) = delete;
|
||||
virtual ~FontHandler() noexcept = default;
|
||||
|
||||
virtual inline auto font(std::shared_ptr<Font> f) -> FontHandler* final
|
||||
virtual auto font(std::shared_ptr<Font> f) -> FontHandler* final
|
||||
{
|
||||
if (f != nullptr
|
||||
&& (f != _font || f->family_name != _font->family_name
|
||||
|
@ -45,7 +45,7 @@ namespace bwidgets
|
|||
return this;
|
||||
}
|
||||
|
||||
virtual inline auto font_color_bg(const Color& c) -> FontHandler* final
|
||||
virtual auto font_color_bg(const Color& c) -> FontHandler* final
|
||||
{
|
||||
if (c != _font_color_bg) {
|
||||
_handle_font_color_change(_font_color_bg, c);
|
||||
|
@ -54,7 +54,7 @@ namespace bwidgets
|
|||
return this;
|
||||
}
|
||||
|
||||
virtual inline auto font_color_fg(const Color& c) -> FontHandler* final
|
||||
virtual auto font_color_fg(const Color& c) -> FontHandler* final
|
||||
{
|
||||
if (c != _font_color_fg) {
|
||||
_handle_font_color_change(c, _font_color_fg);
|
||||
|
|
|
@ -23,14 +23,14 @@ namespace bwidgets
|
|||
auto operator=(const KeyboardHandler&) = delete;
|
||||
auto operator=(KeyboardHandler&&) = delete;
|
||||
|
||||
virtual inline auto handle_keyboard(const SDL_KeyboardEvent& ev)
|
||||
virtual auto handle_keyboard(const SDL_KeyboardEvent& ev)
|
||||
-> KeyboardHandler* final
|
||||
{
|
||||
if (_has_focus) _handle_key(ev);
|
||||
return this;
|
||||
}
|
||||
|
||||
virtual inline auto handle_keyboard(const SDL_TextInputEvent& ev)
|
||||
virtual auto handle_keyboard(const SDL_TextInputEvent& ev)
|
||||
-> KeyboardHandler* final
|
||||
{
|
||||
if (_has_focus) _handle_text_input(ev);
|
||||
|
|
|
@ -155,7 +155,7 @@ namespace bwidgets
|
|||
return value;
|
||||
}
|
||||
|
||||
[[nodiscard]] inline auto size() const noexcept -> Size override
|
||||
[[nodiscard]] auto size() const noexcept -> Size override
|
||||
{
|
||||
const auto base = Input<T>::size();
|
||||
const auto btns_width = 4 * _increment_button.size().w;
|
||||
|
|
Loading…
Reference in New Issue