Skip to content

Commit

Permalink
Add selectable option
Browse files Browse the repository at this point in the history
  • Loading branch information
PeterJohnson committed Mar 21, 2021
1 parent f0b133e commit 6e66915
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion glass/src/lib/native/cpp/other/Field2D.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ struct DisplayOptions {
static constexpr int kDefaultArrowSize = 50;
static constexpr float kDefaultArrowWeight = 4.0f;
static constexpr ImU32 kDefaultArrowColor = IM_COL32(0, 255, 0, 255);
static constexpr bool kDefaultSelectable = true;

Style style = kDefaultStyle;
float weight = kDefaultWeight;
Expand All @@ -131,6 +132,8 @@ struct DisplayOptions {
float arrowWeight = kDefaultArrowWeight;
int arrowColor = kDefaultArrowColor;

bool selectable = kDefaultSelectable;

const gui::Texture& texture;
};

Expand Down Expand Up @@ -202,6 +205,8 @@ class ObjectInfo {
float* m_pArrowWeight;
int* m_pArrowColor;

bool* m_pSelectable;

std::string* m_pFilename;
gui::Texture m_texture;
};
Expand Down Expand Up @@ -550,6 +555,8 @@ ObjectInfo::ObjectInfo() {
storage.GetFloatRef("arrowWeight", DisplayOptions::kDefaultArrowWeight);
m_pArrowColor =
storage.GetIntRef("arrowColor", DisplayOptions::kDefaultArrowColor);
m_pSelectable =
storage.GetBoolRef("selectable", DisplayOptions::kDefaultSelectable);
}

DisplayOptions ObjectInfo::GetDisplayOptions() const {
Expand All @@ -563,6 +570,7 @@ DisplayOptions ObjectInfo::GetDisplayOptions() const {
rv.arrowSize = *m_pArrowSize;
rv.arrowWeight = *m_pArrowWeight;
rv.arrowColor = *m_pArrowColor;
rv.selectable = *m_pSelectable;
return rv;
}

Expand Down Expand Up @@ -611,6 +619,8 @@ void ObjectInfo::DisplaySettings() {
*m_pArrowColor = col;
}
}

ImGui::Checkbox("Selectable", m_pSelectable);
}

void ObjectInfo::DrawLine(ImDrawList* drawList,
Expand Down Expand Up @@ -1037,7 +1047,8 @@ void FieldDisplay::DisplayObject(FieldObjectModel& model, wpi::StringRef name) {
PoseFrameData pfd{pose, model, i, m_ffd, displayOptions};

// check for potential drag targets
if (m_isHovered && !gDragState.target.objModel) {
if (displayOptions.selectable && m_isHovered &&
!gDragState.target.objModel) {
auto [corner, dist] = pfd.IsHovered(m_mousePos);
if (corner > 0) {
m_targets.emplace_back(pfd.GetDragTarget(corner, dist));
Expand Down

0 comments on commit 6e66915

Please sign in to comment.