-
-
Notifications
You must be signed in to change notification settings - Fork 543
Implement different display types for bar meters #1794
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -86,6 +86,18 @@ static void TextMeterMode_draw(Meter* this, int x, int y, int w) { | |||||
|
|
||||||
| static const char BarMeterMode_characters[] = "|#*@$%&."; | ||||||
|
|
||||||
| #ifdef HAVE_LIBNCURSESW | ||||||
| const wchar_t* bars[BAR_METER_NUM_STYLES] = { | ||||||
| L"|", | ||||||
| L"#", | ||||||
| L"⣿⡀⡄⡆⡇⣇⣧⣷", | ||||||
| L"█░░▒▒▓▓█", | ||||||
| L"█▏▎▍▌▋▊▉", | ||||||
| L"█▁▂▃▄▅▆▇", | ||||||
| L"█▌▌▌▌███" | ||||||
| }; | ||||||
| #endif | ||||||
|
|
||||||
| static void BarMeterMode_draw(Meter* this, int x, int y, int w) { | ||||||
| assert(x >= 0); | ||||||
| assert(w <= INT_MAX - x); | ||||||
|
|
@@ -149,6 +161,14 @@ static void BarMeterMode_draw(Meter* this, int x, int y, int w) { | |||||
| assert(startPos + w <= RichString_sizeVal(bar)); | ||||||
|
|
||||||
| int blockSizes[10]; | ||||||
| #ifdef HAVE_LIBNCURSESW | ||||||
| Settings* settings = this->host->settings; | ||||||
| assert(settings->barType < ( sizeof(bars) / sizeof(wchar_t*) )); | ||||||
| assert(settings->barType >= 0); | ||||||
| const wchar_t* currBar = bars[settings->barType]; | ||||||
| int barLen = (int)wcslen(currBar); | ||||||
| int extraWidth = 0; | ||||||
| #endif | ||||||
|
|
||||||
| // First draw in the bar[] buffer... | ||||||
| int offset = 0; | ||||||
|
|
@@ -158,19 +178,35 @@ static void BarMeterMode_draw(Meter* this, int x, int y, int w) { | |||||
| value = MINIMUM(value, this->total); | ||||||
| blockSizes[i] = ceil((value / this->total) * w); | ||||||
| blockSizes[i] = MINIMUM(blockSizes[i], w - offset); | ||||||
|
|
||||||
| #ifdef HAVE_LIBNCURSESW | ||||||
| extraWidth = (int)ceil((value / this->total) * w * barLen) % barLen; | ||||||
| #endif | ||||||
|
Comment on lines
179
to
+184
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this needs some minor update. The |
||||||
| } else { | ||||||
| blockSizes[i] = 0; | ||||||
| } | ||||||
| int nextOffset = offset + blockSizes[i]; | ||||||
| for (int j = offset; j < nextOffset; j++) | ||||||
| for (int j = offset; j < nextOffset; j++) { | ||||||
| if (RichString_getCharVal(bar, startPos + j) == ' ') { | ||||||
| if (CRT_colorScheme == COLORSCHEME_MONOCHROME) { | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is one thing I wish to add when the feature of changing bar drawing character is added. It's this:
Suggested change
Make the bar character changeable for meters with only one item. --- a/Meter.h
+++ b/Meter.h
@@ -100,6 +100,7 @@ typedef struct MeterClass_ {
#define Meter_attributes(this_) As_Meter(this_)->attributes
#define Meter_name(this_) As_Meter(this_)->name
#define Meter_uiName(this_) As_Meter(this_)->uiName
+#define Meter_maxItems(this_) As_Meter(this_)->maxItems
#define Meter_isMultiColumn(this_) As_Meter(this_)->isMultiColumn
#define Meter_isPercentChart(this_) As_Meter(this_)->isPercentChart
|
||||||
| assert(i < strlen(BarMeterMode_characters)); | ||||||
| RichString_setChar(&bar, startPos + j, BarMeterMode_characters[i]); | ||||||
| } else { | ||||||
| } | ||||||
| #ifdef HAVE_LIBNCURSESW | ||||||
| else if (CRT_utf8 && settings->barType) { | ||||||
| if (j == nextOffset - 1) { | ||||||
| RichString_setChar(&bar, startPos + nextOffset - 1, currBar[extraWidth]); | ||||||
| } else { | ||||||
| RichString_setChar(&bar, startPos + j, currBar[0]); | ||||||
| } | ||||||
| } | ||||||
| #endif | ||||||
| else { | ||||||
| RichString_setChar(&bar, startPos + j, '|'); | ||||||
| } | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| offset = nextOffset; | ||||||
| } | ||||||
|
|
||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -26,4 +26,5 @@ typedef unsigned int MeterModeId; | |||||||
| (1 << LED_METERMODE) | \ | ||||||||
| 0) // Avoids edits when updating | ||||||||
|
|
||||||||
| #define BAR_METER_NUM_STYLES 7 | ||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
And below the definition of const size_t bar_meter_num_styles = sizeof(bars) / sizeof(*bars);This avoids an additional point of manual updating.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @BenBE This has the problem that when compiling Setting.c, compiler cannot inline the constant but has to refer to the external variable for the number. In other words, the compiled code would be sub-optimal. I think the better approach is to move the definitions of the bar styles into the header. Look at the
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm aware of this downside, but AFAICT there are no real places where looking up this constant happens inside a tight loop … |
||||||||
| #endif | ||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -106,6 +106,9 @@ typedef struct Settings_ { | |
| bool enableMouse; | ||
| #endif | ||
| int hideFunctionBar; // 0 - off, 1 - on ESC until next input, 2 - permanently | ||
| #ifdef HAVE_LIBNCURSESW | ||
| unsigned int barType; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since the proposed bar drawing styles has Note: only the first two drawing styles can be selected in ASCII. The rest can be guarded in the #ifdef HAVE_LIBNCURSESW
static const wchar_t* barMeterDrawStyles[] = {
L"|",
L"#",
L"⡀⡄⡆⡇⣇⣧⣷⣿",
L"░▒▓█",
L"▏▎▍▌▋▊▉█",
L"▁▂▃▄▅▆▇█",
L"▌█",
};
#else
static const char* barMeterDrawStyles[] = {
"|",
"#"
};
#endif
static const size_t numBarMeterStyles = ARRAYSIZE(barMeterDrawStyles); |
||
| #endif | ||
| #ifdef HAVE_LIBHWLOC | ||
| bool topologyAffinity; | ||
| #endif | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I consider this function call redundant when you have declared the list of
barsto have equal length.Not sure if this is what you intended, but I think the bar meter characters can be defined with variable widths if you wish.
Like this:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The bars currently have all the same length, but the intention is to actually allow for bars to contain different number of symbols.