Skip to content

Configurable Column Widths - #360

Merged
arybczak merged 9 commits into
ncmpcpp:masterfrom
jwparkau:column
Apr 25, 2021
Merged

arybczak merged 9 commits into
ncmpcpp:masterfrom
jwparkau:column

Conversation

@jwparkau

@jwparkau jwparkau commented Nov 2, 2019

Copy link
Copy Markdown
Contributor

I have added configurable column widths for the media library and playlist editor screens.
This is done through setting a ratio in the configuration file.
The defaults are at sensible values (i.e. the current values), which are 1:1:1, 1:1, and 1:2, for media library 3 columns, media library 2 columns, and playlist editor respectively.

@arybczak

Copy link
Copy Markdown
Collaborator

Thanks!

Sorry for a delay in getting into this.

It looks good, but you should parse the config into a vector when processing configuration, not every time a screen is resized.

@jwparkau

Copy link
Copy Markdown
Contributor Author

I think I've got it working.
It doesn't compile (some error in mpdpp.h) unless I merge upstream/master but I didn't want to push that commit because I don't know if github will make the PR messy or not.
Anyway it does compile if everything is up to date.

Comment thread src/screens/media_library.cpp Outdated
itsLeftColWidth = COLS/3-1;
itsMiddleColWidth = COLS/3;

std::vector<int> ratio_vector = Config.media_library_column_width_ratio_three;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you copy the vector here? Same below.

Comment thread src/utility/option_parser.cpp Outdated
return true;
}

std::vector<int> check_ratio_two(const std::string &v)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of all of these helpers I think you can generalize list_of to take a separator and optional length of a list, then use boost::bind to partially apply it.

Comment thread src/settings.h Outdated

std::string pattern;

std::vector<int> playlist_editor_column_width_ratio;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

int is inaccurate, we expect positive numbers here.

@jwparkau

Copy link
Copy Markdown
Contributor Author

Thanks for the feedback.

  1. Not sure why I copied the vector, but its fixed now.
  2. I changed int to size_t to match the type of itsLeftColStartX and friends.
  3. I removed most of the fluff helpers and put faith into the lexical_cast. I'm not sure what you meant by list_of, is it a built-in function? For now I changed it to split the string on the ":" character, try to cast each substring to size_t, and then check the resultant vector to make sure the length matches.
  4. I used std::bind because I couldn't get _1 to work with boost::bind for some reason.

@arybczak

Copy link
Copy Markdown
Collaborator

list_of is in option_parser.h.

@jwparkau

Copy link
Copy Markdown
Contributor Author

I'm fairly certain that the default escape, separator, and quote chars are correct (\, ,, and ") from reading the boost docs.
I chose not to overload parse_ratio because the adding the numbers and checking that the total isn't 0 part didn't seem generalizable.

Comment thread src/utility/option_parser.h Outdated
{
std::vector<ValueT> result;
boost::tokenizer<boost::escaped_list_separator<char>> elems(v);
boost::escaped_list_separator<char> ecq(e, c, q);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can these be more descriptive? What is e, c and q?

Comment thread src/utility/option_parser.cpp Outdated
std::string e("");
std::string c(":");
std::string q("");
std::vector<size_t> ret = list_of<size_t>(v, verbose_lexical_cast<size_t>, length, e, c, q);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to bind e,c,q if you're not using it later.

@jwparkau
jwparkau requested a review from arybczak January 20, 2021 22:47
@arybczak
arybczak merged commit f47cf7f into ncmpcpp:master Apr 25, 2021
@arybczak

Copy link
Copy Markdown
Collaborator

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants