-
Notifications
You must be signed in to change notification settings - Fork 3
Flexbox for OPTIQ #696
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
Open
Sajeeth-Wimalasuriyan
wants to merge
5
commits into
dev
Choose a base branch
from
swimalas/flexbox_initial_demo
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+140
−0
Open
Flexbox for OPTIQ #696
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
68673c1
Made initial basic implementation of flexbox.
Sajeeth-Wimalasuriyan b0b105e
Fixed naming errors and cleaned up comments.
Sajeeth-Wimalasuriyan 30596cb
Fixed IMGUI version issue.
Sajeeth-Wimalasuriyan 9074938
Added string ID field and GetItem() lookup method to FlexContainer fo…
Sajeeth-Wimalasuriyan 429f90c
Merge branch 'dev' into swimalas/flexbox_initial_demo
Sajeeth-Wimalasuriyan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,105 @@ | ||
| // Copyright Advanced Micro Devices, Inc. | ||
| // SPDX-License-Identifier: MIT | ||
|
|
||
| #include "rocprofvis_flex_container.h" | ||
| #include "rocprofvis_settings_manager.h" | ||
|
|
||
| #include <algorithm> | ||
| #include <stdexcept> | ||
| #include <imgui.h> | ||
|
|
||
| namespace RocProfVis | ||
| { | ||
| namespace View | ||
| { | ||
|
|
||
| struct FlexRow | ||
| { | ||
| size_t start = 0; | ||
| size_t count = 0; | ||
| float min_w = 0.0f; | ||
| float grow = 0.0f; | ||
| }; | ||
|
|
||
| FlexItem& | ||
| FlexContainer::GetItem(const std::string& id) | ||
| { | ||
| for(auto& item : items) | ||
| if(item.id == id) return item; | ||
| throw std::runtime_error("FlexContainer: item not found: " + id); | ||
| } | ||
|
|
||
| void | ||
| FlexContainer::Render() | ||
| { | ||
| if(items.empty()) return; | ||
|
|
||
| float avail_width = ImGui::GetContentRegionAvail().x; | ||
| float avail_height = ImGui::GetContentRegionAvail().y; | ||
|
|
||
| // bin items into rows | ||
|
|
||
| std::vector<FlexRow> rows; | ||
| rows.push_back({}); | ||
|
|
||
| for(size_t i = 0; i < items.size(); i++) | ||
| { | ||
| FlexRow& cur = rows.back(); | ||
| float gap_w = (cur.count > 0) ? gap : 0.0f; | ||
| float needed = cur.min_w + gap_w + items[i].min_width; | ||
|
|
||
| if(cur.count > 0 && needed > avail_width) | ||
| rows.push_back({i, 0, 0.0f, 0.0f}); | ||
|
|
||
| FlexRow& target = rows.back(); | ||
| if(target.count > 0) target.min_w += gap; | ||
| target.min_w += items[i].min_width; | ||
| target.grow += items[i].flex_grow; | ||
| target.count++; | ||
| } | ||
|
|
||
| // figure out default row height | ||
|
|
||
| size_t num_rows = rows.size(); | ||
| float row_gap_total = gap * static_cast<float>(num_rows > 1 ? num_rows - 1 : 0); | ||
| float row_height = std::max(avail_height, min_row_height); | ||
| row_height = (row_height - row_gap_total) / static_cast<float>(num_rows); | ||
|
|
||
| // render | ||
|
|
||
| for(size_t row_index = 0; row_index < num_rows; row_index++) | ||
| { | ||
| FlexRow& row = rows[row_index]; | ||
| float row_gaps = gap * static_cast<float>(row.count > 1 ? row.count - 1 : 0); | ||
| float min_sum = row.min_w - row_gaps; | ||
| float free = std::max(0.0f, avail_width - min_sum - row_gaps); | ||
|
|
||
| for(size_t column_index = 0; column_index < row.count; column_index++) | ||
| { | ||
| FlexItem& item = items[row.start + column_index]; | ||
|
|
||
| float w = item.min_width; | ||
| if(row.grow > 0.0f) | ||
| w += free * (item.flex_grow / row.grow); | ||
|
|
||
| float h = (item.height > 0.0f) ? item.height : row_height; | ||
|
|
||
| ImGui::PushStyleColor(ImGuiCol_ChildBg, | ||
| SettingsManager::GetInstance().GetColor(Colors::kFillerColor)); | ||
|
|
||
| ImGui::BeginChild(ImGui::GetID(&item), ImVec2(w, h), | ||
| ImGuiChildFlags_Borders); | ||
| if(item.widget) item.widget->Render(); | ||
| ImGui::EndChild(); | ||
|
|
||
| ImGui::PopStyleColor(); | ||
|
|
||
| if(column_index + 1 < row.count) ImGui::SameLine(0.0f, gap); | ||
| } | ||
|
|
||
| if(row_index + 1 < num_rows) ImGui::Dummy(ImVec2(0.0f, gap)); | ||
| } | ||
| } | ||
|
|
||
| } // namespace View | ||
| } // namespace RocProfVis | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| // Copyright Advanced Micro Devices, Inc. | ||
| // SPDX-License-Identifier: MIT | ||
|
|
||
| #pragma once | ||
|
|
||
| #include "rocprofvis_widget.h" | ||
|
|
||
| namespace RocProfVis | ||
| { | ||
| namespace View | ||
| { | ||
|
|
||
| struct FlexItem | ||
| { | ||
| std::string id; | ||
| std::shared_ptr<RocWidget> widget; | ||
| float min_width = 500.0f; | ||
| float height = 0.0f; | ||
| float flex_grow = 1.0f; | ||
| }; | ||
|
|
||
| class FlexContainer : public RocWidget | ||
| { | ||
| public: | ||
| void Render() override; | ||
| FlexItem& GetItem(const std::string& id); | ||
|
|
||
| std::vector<FlexItem> items; | ||
Sajeeth-Wimalasuriyan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| float gap = 8.0f; | ||
| float min_row_height = 0.0f; | ||
| }; | ||
|
|
||
| } // namespace View | ||
| } // namespace RocProfVis | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Don't throw if not found. Change function signature to return pointer instead of reference and return null if not found.