mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-07-09 17:44:01 -07:00
Min treshold for nicer display.
This commit is contained in:
parent
8cd5552d65
commit
6425238670
3 changed files with 11 additions and 0 deletions
|
|
@ -62,6 +62,11 @@ void ColorBar::paintEvent(QPaintEvent *)
|
|||
for (const QString &key : sortedKeys) {
|
||||
int value = colors[key];
|
||||
double ratio = double(value) / total;
|
||||
|
||||
if (ratio <= minRatioThreshold) {
|
||||
continue;
|
||||
}
|
||||
|
||||
int segmentWidth = int(ratio * w);
|
||||
|
||||
// Ensure the segment width is at least 1 to avoid degenerate rectangles
|
||||
|
|
|
|||
|
|
@ -14,6 +14,10 @@ public:
|
|||
explicit ColorBar(const QMap<QString, int> &colors, QWidget *parent = nullptr);
|
||||
|
||||
void setColors(const QMap<QString, int> &colors);
|
||||
void setMinPercentThreshold(double treshold)
|
||||
{
|
||||
minRatioThreshold = treshold / 100.0; // store as ratio
|
||||
}
|
||||
QSize minimumSizeHint() const override;
|
||||
|
||||
protected:
|
||||
|
|
@ -29,6 +33,7 @@ protected:
|
|||
private:
|
||||
QMap<QString, int> colors;
|
||||
bool isHovered = false;
|
||||
double minRatioThreshold = 0.0; // 0.05 means 5%
|
||||
|
||||
QColor colorFromName(const QString &name) const;
|
||||
QString tooltipForPosition(int x) const;
|
||||
|
|
|
|||
|
|
@ -96,6 +96,7 @@ ArchidektApiResponseDeckEntryDisplayWidget::ArchidektApiResponseDeckEntryDisplay
|
|||
auto colors = response.getColors();
|
||||
|
||||
ColorBar *colorBar = new ColorBar(colors, this);
|
||||
colorBar->setMinPercentThreshold(3);
|
||||
colorBar->setFixedHeight(22);
|
||||
|
||||
headerLayout->addWidget(colorBar);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue