Skip to content

Commit

Permalink
refactor some ui constants
Browse files Browse the repository at this point in the history
  • Loading branch information
vsicurella committed Jul 16, 2024
1 parent dcf3f3d commit 797af9d
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 21 deletions.
13 changes: 7 additions & 6 deletions Source/mapping_editors/KeyEditorControls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
14 changes: 8 additions & 6 deletions Source/mapping_editors/KeyEditorControls.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,21 +63,23 @@ class KeyEditorControls : public juce::Component
// std::unique_ptr<ColourSelectionGroup> 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;
Expand Down
21 changes: 14 additions & 7 deletions Source/mapping_editors/KeyEditorPanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include "./KeyEditorControls.h"
#include "./MultiSelectControls.h"
#include "./BatchTools.h"

KeyEditorPanel::KeyEditorPanel(const LumatoneEditorState &stateIn)
: juce::Component("KeyEditorPanel")
Expand All @@ -13,10 +14,14 @@ KeyEditorPanel::KeyEditorPanel(const LumatoneEditorState &stateIn)

multiSelectControls = std::make_unique<MultiSelectControls>(stateIn);
addAndMakeVisible(multiSelectControls.get());

batchTools = std::make_unique<BatchTools>(stateIn);
addAndMakeVisible(batchTools.get());
}

KeyEditorPanel::~KeyEditorPanel()
{
batchTools = nullptr;
multiSelectControls = nullptr;
keyEditorControls = nullptr;
}
Expand All @@ -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<float>(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<float>(w - batchToolsAreaWidth, areaMargin, batchToolsAreaWidth, areaHeight);
keySettingsAndMultiSelectArea = juce::Rectangle<float>(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<float>(w - batchToolsAreaWidth, areaMargin, batchToolsAreaWidth, areaHeight);

contentMargin = juce::roundToInt(windowH * contentMarginWidthWindowH);
keyEditorControls->setBounds(keySettingsAndMultiSelectArea.reduced(contentMargin)
.withWidth(roundToInt(keySettingsAndMultiSelectArea.getWidth() * keySettingsComponentAreaW))
.toNearestInt());
Expand All @@ -52,4 +57,6 @@ void KeyEditorPanel::resized()
multiSelectControls->setBounds(keySettingsAndMultiSelectArea.reduced(contentMargin)
.withLeft(keySettingsAndMultiSelectArea.getRight() - multiSelectWidth - contentMargin)
.toNearestInt());

batchTools->setBounds(batchToolsArea.reduced(contentMargin).toNearestInt());
}
5 changes: 3 additions & 2 deletions Source/mapping_editors/KeyEditorPanel.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -32,6 +32,7 @@ class KeyEditorPanel : public juce::Component

std::unique_ptr<KeyEditorControls> keyEditorControls;
std::unique_ptr<MultiSelectControls> multiSelectControls;
std::unique_ptr<BatchTools> batchTools;

juce::Rectangle<float> keySettingsAndMultiSelectArea;
juce::Rectangle<float> keySettingsArea;
Expand All @@ -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;
Expand Down

0 comments on commit 797af9d

Please sign in to comment.