Change background color of element in Gridbox #438
-
Hi, I have the following code: auto cell = []() { return filler() | bgcolor(Color::White); };
vector<vector<Element>> rows;
int x;
cin >> x;
for(int i = 0; i < x; ++i){
vector<Element> row;
for(int j = 0; j < x; ++j){
row.emplace_back(cell());
}
rows.emplace_back(row);
}
auto display = gridbox(rows);
auto screen = Screen::Create(Dimension::Fixed(10), Dimension::Fixed(10));
Render(screen, display); Say I wanted to change the background color of the element at display[0][0], how would I go about doing this? |
Beta Was this translation helpful? Give feedback.
Answered by
ArthurSonzogni
Jul 9, 2022
Replies: 1 comment 1 reply
-
You can apply the Using the pipe operator: auto colored_element = element | bgcolor(Color::Red); Or as a function: auto colored_element = bgcolor(Color::Red, element); In your example, you can use |= to apply the rows[0][0] |= bgcolor(Color::Red); |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
abdurj
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can apply the
bgcolor
function.Using the pipe operator:
auto colored_element = element | bgcolor(Color::Red);
Or as a function:
auto colored_element = bgcolor(Color::Red, element);
In your example, you can use |= to apply the
bgcolor
and replace the element with the new version in the array.