1
0
Fork 0
mirror of https://github.com/transmission/transmission synced 2024-12-23 08:13:27 +00:00
transmission/gtk/Percents.h
Mike Gelfand 586cff9506
Switch to list view for torrents list (GTK 4) (#5858)
* Add compat operator* for RefPtr

* Rename `*_tree_view_*` button handling helpers to `*_item_view_*`

* Move torrent item colors to CSS

* Switch to list view for torrents list (GTK 4)

* Bump Fedora image to 39 (current rawhide) for GTK 4.11

Enable deprecations as there're lots of them in 4.11 and I'm not keen on
fixing them all right now. Disable warnings as errors due to
-Warray-bounds issue somewhere in libfmt.
2023-08-06 04:26:29 +01:00

45 lines
843 B
C++

#pragma once
#include <cmath>
#include <string>
class Percents
{
public:
Percents() = default;
explicit Percents(int value) noexcept
: raw_value_(value * 100)
{
}
explicit Percents(float value) noexcept
: raw_value_(std::round(value * 10000))
{
}
[[nodiscard]] constexpr int to_int() const noexcept
{
return raw_value_ / 100;
}
[[nodiscard]] constexpr float to_fraction() const noexcept
{
return raw_value_ / 10000.F;
}
[[nodiscard]] std::string to_string() const;
constexpr bool operator==(Percents const& rhs) const noexcept
{
return raw_value_ == rhs.raw_value_;
}
constexpr bool operator<(Percents const& rhs) const noexcept
{
return raw_value_ < rhs.raw_value_;
}
private:
int raw_value_ = 0;
};