Skip to content

Commit d4d414d

Browse files
committed
visual improvements to onscreen colorbar
1 parent 2ca2bae commit d4d414d

File tree

1 file changed

+18
-9
lines changed

1 file changed

+18
-9
lines changed

src/color_bar.cpp

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -222,29 +222,33 @@ void OnscreenColorBarWidget::draw() {
222222

223223
// Draw the color bar
224224

225-
// NOTE: right nwo the size of the colorbar is scaled by uiScale, but the positioning/margins are not. This is
225+
// NOTE: right now the size of the colorbar is scaled by uiScale, but the positioning/margins are not. This is
226226
// consistent with the other positioning/marching logic in the main gui panels. (Maybe they should all be scaled?)
227+
float titleHeight = 20.0f * options::uiScale;
227228
float barRegionWidth = 30.0f * options::uiScale;
228229
float tickRegionWidth = 90.0f * options::uiScale;
229230
float marginWidth = 10.0f * options::uiScale;
230-
float barRegionHeight = 300.0f * options::uiScale;
231+
float barRegionHeight = 250.0f * options::uiScale;
231232
float borderWidth = 2.0f * options::uiScale;
232233
float tickWidth = 5.0f * options::uiScale;
233234

234235

235236
ImVec2 barTopLeft;
236237
if (placeAutomatically) {
237238
barTopLeft = ImVec2(internal::lastRightSideFreeX - barRegionWidth - tickRegionWidth - marginWidth,
238-
internal::lastRightSideFreeY + marginWidth + internal::imguiStackMargin);
239+
internal::lastRightSideFreeY + titleHeight + marginWidth + internal::imguiStackMargin);
239240
} else {
240-
barTopLeft = ImVec2(parent.onscreenColorbarLocation.get().x, parent.onscreenColorbarLocation.get().y);
241+
barTopLeft = ImVec2(parent.onscreenColorbarLocation.get().x, parent.onscreenColorbarLocation.get().y + titleHeight);
241242
}
242243

243244
ImDrawList* dl = ImGui::GetBackgroundDrawList();
245+
// ImU32 backgroundColor = ImGui::ColorConvertFloat4ToU32(ImGui::GetStyle().Colors[ImGuiCol_WindowBg]);
246+
// ImU32 foregroundColor = IM_COL32_WHITE;
244247
ImU32 backgroundColor = IM_COL32(255, 255, 255, 180);
248+
ImU32 foregroundColor = IM_COL32_BLACK;
245249

246250
// dd a semi-transparent background
247-
dl->AddRectFilled(ImVec2(barTopLeft.x - marginWidth, barTopLeft.y - marginWidth),
251+
dl->AddRectFilled(ImVec2(barTopLeft.x - marginWidth, barTopLeft.y - marginWidth - titleHeight),
248252
ImVec2(barTopLeft.x + barRegionWidth + tickRegionWidth + marginWidth,
249253
barTopLeft.y + barRegionHeight + marginWidth),
250254
backgroundColor);
@@ -255,8 +259,12 @@ void OnscreenColorBarWidget::draw() {
255259
ImVec2(barTopLeft.x + barRegionWidth, barTopLeft.y + barRegionHeight), ImVec2(0, 1), ImVec2(1, 0));
256260

257261
// draw the border around the map
258-
dl->AddRect(barTopLeft, ImVec2(barTopLeft.x + barRegionWidth, barTopLeft.y + barRegionHeight), IM_COL32(0, 0, 0, 255),
259-
0.f, ImDrawFlags_None, borderWidth);
262+
dl->AddRect(barTopLeft, ImVec2(barTopLeft.x + barRegionWidth, barTopLeft.y + barRegionHeight), foregroundColor, 0.f,
263+
ImDrawFlags_None, borderWidth);
264+
265+
// title text
266+
dl->AddText(ImVec2(barTopLeft.x + 0.5 * borderWidth, barTopLeft.y - 1.3 * titleHeight), foregroundColor,
267+
parent.parent.name.c_str());
260268

261269
// draw text ticks
262270
int nTicks = 5;
@@ -269,11 +277,12 @@ void OnscreenColorBarWidget::draw() {
269277

270278
// Make a little tick mark
271279
dl->AddLine(ImVec2(barTopLeft.x + barRegionWidth - borderWidth, yPos),
272-
ImVec2(barTopLeft.x + barRegionWidth + tickWidth, yPos), IM_COL32_BLACK, borderWidth);
280+
ImVec2(barTopLeft.x + barRegionWidth + tickWidth, yPos), foregroundColor, borderWidth);
273281

274282
// Draw the actual text
275283
ImVec2 textSize = ImGui::CalcTextSize(buffer);
276-
dl->AddText(ImVec2(barTopLeft.x + barRegionWidth + 2.f * tickWidth, yPos - textSize.y / 2), IM_COL32_BLACK, buffer);
284+
dl->AddText(ImVec2(barTopLeft.x + barRegionWidth + 2.f * tickWidth, yPos - textSize.y / 2), foregroundColor,
285+
buffer);
277286
}
278287

279288
if (placeAutomatically) {

0 commit comments

Comments
 (0)