From 797af9d4e3937601fb15aee143cbad8c0db8d698 Mon Sep 17 00:00:00 2001 From: Vincenzo Sicurella Date: Tue, 16 Jul 2024 19:58:55 -0400 Subject: [PATCH] refactor some ui constants --- Source/mapping_editors/KeyEditorControls.cpp | 13 ++++++------ Source/mapping_editors/KeyEditorControls.h | 14 +++++++------ Source/mapping_editors/KeyEditorPanel.cpp | 21 +++++++++++++------- Source/mapping_editors/KeyEditorPanel.h | 5 +++-- 4 files changed, 32 insertions(+), 21 deletions(-) diff --git a/Source/mapping_editors/KeyEditorControls.cpp b/Source/mapping_editors/KeyEditorControls.cpp index fd3db53..45ce217 100644 --- a/Source/mapping_editors/KeyEditorControls.cpp +++ b/Source/mapping_editors/KeyEditorControls.cpp @@ -156,19 +156,20 @@ void KeyEditorControls::resized() float w = (float)getWidth(); float h = (float)getHeight(); + float windowH = getWindowBounds().getHeight(); + auto roundedCornerSize = getRoundedRectCornerSize(); - // labelMarginWidth = roundToInt(roundedCornerSize * 0.25f); - headerHeight = roundToInt(h * headerH); + headerHeight = roundToInt(windowH * contentLabelHeightWindowH); headerPath = getConnectedRoundedRectPath(getLocalBounds().withBottom(headerHeight + 1).toFloat(), roundedCornerSize, juce::Button::ConnectedEdgeFlags::ConnectedOnBottom); controlPath = getConnectedRoundedRectPath(getLocalBounds().withTop(headerHeight).toFloat(), roundedCornerSize, juce::Button::ConnectedEdgeFlags::ConnectedOnTop); - contentMarginWidth = roundToInt(getParentWidth() * contentMarginParentW); + contentMarginWidth = roundToInt(windowH * contentMarginWidthWindowH); contentMarginHeight = roundToInt(h * controlMarginH); - labelHeight = roundToInt(headerHeight * labelToHeaderH); + labelHeight = roundToInt(headerHeight * contentLabelFontScalar); lblKeySettings->setTopLeftPosition(contentMarginWidth, 0); - resizeLabelWithHeight(lblKeySettings.get(), headerHeight, labelToHeaderH); + resizeLabelWithHeight(lblKeySettings.get(), headerHeight, contentLabelFontScalar); keyControlColumnWidth = roundToInt(w * keyControlColumnW); keyControlColumnRight = contentMarginWidth + keyControlColumnWidth; @@ -177,7 +178,7 @@ void KeyEditorControls::resized() keyControlMarginHeight = roundToInt(h * keyControlMarginH); lblColour->setTopLeftPosition(contentMarginWidth, headerHeight + contentMarginHeight); - resizeLabelWithHeight(lblColour.get(), keyControlHeight, controlLabelFontScalar); + resizeLabelWithHeight(lblColour.get(), keyControlHeight, contentLabelFontScalar); colourButtonMargin = lblColour->getFont().getStringWidth(" "); colourButtonWidth = roundToInt(getParentWidth() * colourButtonParentW) - colourButtonMargin; diff --git a/Source/mapping_editors/KeyEditorControls.h b/Source/mapping_editors/KeyEditorControls.h index 3900537..0fdaa9f 100644 --- a/Source/mapping_editors/KeyEditorControls.h +++ b/Source/mapping_editors/KeyEditorControls.h @@ -63,21 +63,23 @@ class KeyEditorControls : public juce::Component // std::unique_ptr colourSelectionGroup; ColourSelectionGroup* colourSelectionGroup; - const float headerH = 0.19f; - int headerHeight; juce::Path headerPath; juce::Path controlPath; int contentMarginWidth; - const float contentMarginParentW = 0.02f; + + // int contentMarginWidth; + // const float contentMarginParentW = 0.02f; int contentMarginHeight; const float controlMarginH = 0.08f; + int headerHeight; + // const float headerH = 0.19f; + int labelHeight; - // int labelMarginWidth; - const float labelToHeaderH = 0.5f; - const float controlLabelFontScalar = 0.6f; + // const float labelToHeaderH = 0.5f; + // const float controlLabelFontScalar = 0.6f; int keyControlColumnWidth; int keyControlColumnRight; diff --git a/Source/mapping_editors/KeyEditorPanel.cpp b/Source/mapping_editors/KeyEditorPanel.cpp index a281eba..047fa29 100644 --- a/Source/mapping_editors/KeyEditorPanel.cpp +++ b/Source/mapping_editors/KeyEditorPanel.cpp @@ -3,6 +3,7 @@ #include "./KeyEditorControls.h" #include "./MultiSelectControls.h" +#include "./BatchTools.h" KeyEditorPanel::KeyEditorPanel(const LumatoneEditorState &stateIn) : juce::Component("KeyEditorPanel") @@ -13,10 +14,14 @@ KeyEditorPanel::KeyEditorPanel(const LumatoneEditorState &stateIn) multiSelectControls = std::make_unique(stateIn); addAndMakeVisible(multiSelectControls.get()); + + batchTools = std::make_unique(stateIn); + addAndMakeVisible(batchTools.get()); } KeyEditorPanel::~KeyEditorPanel() { + batchTools = nullptr; multiSelectControls = nullptr; keyEditorControls = nullptr; } @@ -33,17 +38,17 @@ void KeyEditorPanel::resized() float w = (float)getWidth(); float h = (float)getHeight(); - areaHeight = roundToInt(h * areaHeightRatio); - areaMargin = roundToInt((h - areaHeight) * 0.5f); + float windowH = (float)getWindowBounds().getHeight(); - keySettingsAndMultiSelectArea = juce::Rectangle(0, areaMargin, roundToInt(w * keySettingsAndSelectAreaW), areaHeight); + areaHeight = juce::roundToInt(h * areaHeightRatio); + areaMargin = juce::roundToInt((h - areaHeight) * 0.5f); - int batchToolsAreaWidth = roundToInt(w * batchToolsAreaW); - batchToolsArea = juce::Rectangle(w - batchToolsAreaWidth, areaMargin, batchToolsAreaWidth, areaHeight); + keySettingsAndMultiSelectArea = juce::Rectangle(0, areaMargin, juce::roundToInt(w * keySettingsAndSelectAreaW), areaHeight); - contentHeight = roundToInt(h * contentHeightRatio); - contentMargin = roundToInt(h - (float)contentHeight) * 0.5; + int batchToolsAreaWidth = juce::roundToInt(w * batchToolsAreaW); + batchToolsArea = juce::Rectangle(w - batchToolsAreaWidth, areaMargin, batchToolsAreaWidth, areaHeight); + contentMargin = juce::roundToInt(windowH * contentMarginWidthWindowH); keyEditorControls->setBounds(keySettingsAndMultiSelectArea.reduced(contentMargin) .withWidth(roundToInt(keySettingsAndMultiSelectArea.getWidth() * keySettingsComponentAreaW)) .toNearestInt()); @@ -52,4 +57,6 @@ void KeyEditorPanel::resized() multiSelectControls->setBounds(keySettingsAndMultiSelectArea.reduced(contentMargin) .withLeft(keySettingsAndMultiSelectArea.getRight() - multiSelectWidth - contentMargin) .toNearestInt()); + + batchTools->setBounds(batchToolsArea.reduced(contentMargin).toNearestInt()); } diff --git a/Source/mapping_editors/KeyEditorPanel.h b/Source/mapping_editors/KeyEditorPanel.h index a617883..643d86b 100644 --- a/Source/mapping_editors/KeyEditorPanel.h +++ b/Source/mapping_editors/KeyEditorPanel.h @@ -16,10 +16,10 @@ class KeyEditorControls; class MultiSelectControls; +class BatchTools; class KeyEditorPanel : public juce::Component , public LumatoneEditorState - // , public LumatoneEditor::EditorListener { public: KeyEditorPanel(const LumatoneEditorState& stateIn); @@ -32,6 +32,7 @@ class KeyEditorPanel : public juce::Component std::unique_ptr keyEditorControls; std::unique_ptr multiSelectControls; + std::unique_ptr batchTools; juce::Rectangle keySettingsAndMultiSelectArea; juce::Rectangle keySettingsArea; @@ -54,7 +55,7 @@ class KeyEditorPanel : public juce::Component int contentHeight; int multiSelectWidth; - const float contentHeightRatio = 0.81f; + // const float contentHeightRatio = 0.81f; const float controlsWidthRatio = 0.466f; const float curvesAreaWidthRatio = 0.512f;