Skip to content
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

Tab and Spacing changes to track closer to wireframe #123

Merged
merged 2 commits into from
Sep 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
97 changes: 87 additions & 10 deletions include/sst/jucegui/components/TabbedComponent.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,28 @@ namespace sst::jucegui::components
{
struct TabbedComponent : juce::TabbedComponent, style::StyleConsumer
{
struct Styles : base_styles::Base
struct Styles : base_styles::Base, base_styles::BaseLabel
{
using sclass = style::StyleSheet::Class;
using sprop = style::StyleSheet::Property;
static constexpr sclass styleClass{"TabbedComponent"};
SCLASS(tabbedcomponent);

PROP(tabSelectedLabelColor);
PROP(tabUnselectedLabelColor);
PROP_HOVER(tabUnselectedLabelColor);
PROP(tabSelectedFillColor);
PROP_HOVER(tabSelectedFillColor);
PROP(tabUnselectedOutlineColor);

static void initialize()
{
style::StyleSheet::addClass(styleClass).withBaseClass(base_styles::Base::styleClass);
style::StyleSheet::addClass(styleClass)
.withBaseClass(base_styles::Base::styleClass)
.withBaseClass(base_styles::BaseLabel::styleClass)
.withProperty(tabSelectedLabelColor)
.withProperty(tabUnselectedLabelColor)
.withProperty(tabUnselectedLabelColor_hover)
.withProperty(tabSelectedFillColor)
.withProperty(tabSelectedFillColor_hover)
.withProperty(tabUnselectedOutlineColor);
}
};

Expand All @@ -53,18 +66,80 @@ struct TabbedComponent : juce::TabbedComponent, style::StyleConsumer

struct ButtonImpl : juce::TabBarButton
{
TabbedComponent *parentComp{nullptr};
juce::String name;
int idx{0};
ButtonImpl(const juce::String &n, int id, juce::TabbedButtonBar &owner)
: juce::TabBarButton(n, owner), name(n), idx(id)
ButtonImpl(const juce::String &n, int id, juce::TabbedButtonBar &owner, TabbedComponent *c)
: juce::TabBarButton(n, owner), name(n), idx(id), parentComp(c)
{
}
static constexpr int marginPad{3}, minTab{20};
void paint(juce::Graphics &g) override
{
if (!parentComp->style())
return;

const auto &st = parentComp->style();

auto b = getLocalBounds().withHeight(getHeight() + 10).reduced(1);

if (isFrontTab())
{
if (hover)
g.setColour(
st->getColour(Styles::styleClass, Styles::tabSelectedFillColor_hover));
else
g.setColour(st->getColour(Styles::styleClass, Styles::tabSelectedFillColor));
g.fillRoundedRectangle(b.toFloat(), 4);
g.setColour(st->getColour(Styles::styleClass, Styles::tabSelectedFillColor_hover));
g.drawRoundedRectangle(b.toFloat(), 4, 1);
g.setColour(st->getColour(Styles::styleClass, Styles::tabSelectedLabelColor));
g.setFont(st->getFont(Styles::styleClass, Styles::labelfont));
g.drawText(name, getLocalBounds(), juce::Justification::centred);
}
else
{
g.setColour(st->getColour(Styles::styleClass, Styles::tabUnselectedOutlineColor));
g.drawRoundedRectangle(b.toFloat(), 4, 1);

if (hover)
g.setColour(
st->getColour(Styles::styleClass, Styles::tabUnselectedLabelColor_hover));
else
g.setColour(st->getColour(Styles::styleClass, Styles::tabUnselectedLabelColor));

g.setFont(st->getFont(Styles::styleClass, Styles::labelfont));
g.drawText(name, getLocalBounds(), juce::Justification::centred);
}
}
bool hover{false};

protected:
void mouseEnter(const juce::MouseEvent &event) override
{
hover = true;
repaint();
}
void mouseExit(const juce::MouseEvent &event) override
{
hover = false;
repaint();
}

public:
int getBestTabLength(int depth) override
{
if (!parentComp->style())
return minTab;

auto ft = parentComp->style()->getFont(Styles::styleClass, Styles::labelfont);
auto fw = ft.getStringWidthFloat(name) + 2 * marginPad;
return std::max((int)std::ceil(fw), minTab);
}
void paint(juce::Graphics &g) override { juce::TabBarButton::paint(g); }
int getBestTabLength(int depth) override { return 20; }
};
juce::TabBarButton *createTabButton(const juce::String &tabName, int tabIndex) override
{
return new ButtonImpl(tabName, tabIndex, getTabbedButtonBar());
return new ButtonImpl(tabName, tabIndex, getTabbedButtonBar(), this);
}

void resized() override
Expand All @@ -80,6 +155,8 @@ struct TabbedComponent : juce::TabbedComponent, style::StyleConsumer
if (auto comp = getTabContentComponent(i))
comp->setBounds(content);
}

void onStyleChanged() override { resized(); }
};
} // namespace sst::jucegui::components
#endif // SHORTCIRCUITXT_TABBEDCOMPONENT_H
21 changes: 11 additions & 10 deletions include/sst/jucegui/components/ZoomContainer.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,30 +58,31 @@ struct ZoomContainer : juce::Component, juce::ScrollBar::Listener
addAndMakeVisible(*(contents->associatedComponent()));
}

static constexpr int sbw{6};
static constexpr int scrollBarWidth{6}, scrollBarMargin{2};

void resized() override
{
auto bx = getLocalBounds();

auto trim = scrollBarWidth + scrollBarMargin;
if (hScroll && vScroll)
{
auto hb = bx.withTrimmedTop(bx.getHeight() - sbw).withTrimmedRight(sbw);
auto vb = bx.withTrimmedLeft(bx.getWidth() - sbw).withTrimmedBottom(sbw);
bx = bx.withTrimmedBottom(sbw).withTrimmedRight(sbw);
auto hb = bx.withTrimmedTop(bx.getHeight() - scrollBarWidth).withTrimmedRight(trim);
auto vb = bx.withTrimmedLeft(bx.getWidth() - scrollBarWidth).withTrimmedBottom(trim);
bx = bx.withTrimmedBottom(trim).withTrimmedRight(trim);
hScroll->setBounds(hb);
vScroll->setBounds(vb);
}
else if (hScroll)
{
auto hb = bx.withTrimmedTop(bx.getHeight() - sbw);
bx = bx.withTrimmedBottom(sbw);
auto hb = bx.withTrimmedTop(bx.getHeight() - scrollBarWidth);
bx = bx.withTrimmedBottom(trim);
hScroll->setBounds(hb);
}
else if (vScroll)
{
auto vb = bx.withTrimmedLeft(bx.getWidth() - sbw);
bx = bx.withTrimmedRight(sbw);
auto vb = bx.withTrimmedLeft(bx.getWidth() - scrollBarWidth);
bx = bx.withTrimmedRight(trim);
vScroll->setBounds(vb);
}
contents->associatedComponent()->setBounds(bx);
Expand Down Expand Up @@ -169,7 +170,7 @@ struct ZoomContainer : juce::Component, juce::ScrollBar::Listener
auto dre = re - nre;
re = nre;

auto mfac = std::clamp(p.getY() / (getHeight() - (hScroll ? sbw : 0)), 0.f, 1.f);
auto mfac = std::clamp(p.getY() / (getHeight() - (hScroll ? scrollBarWidth : 0)), 0.f, 1.f);

rs += dre * mfac;

Expand All @@ -193,7 +194,7 @@ struct ZoomContainer : juce::Component, juce::ScrollBar::Listener
auto dre = re - nre;
re = nre;

auto mfac = std::clamp(p.getX() / (getWidth() - (vScroll ? sbw : 0)), 0.f, 1.f);
auto mfac = std::clamp(p.getX() / (getWidth() - (vScroll ? scrollBarWidth : 0)), 0.f, 1.f);

rs += dre * mfac;

Expand Down
8 changes: 8 additions & 0 deletions src/sst/jucegui/style/StyleSheet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,14 @@ struct DarkSheet : public StyleSheetBuiltInImpl
setColour(n::styleClass, n::vu_overload, juce::Colour(200, 50, 50));
}

{
using n = components::TabbedComponent::Styles;
setColour(n::styleClass, n::tabSelectedLabelColor, juce::Colour(0xFF, 0x90, 0x00));
setColour(n::styleClass, n::tabUnselectedLabelColor, juce::Colour(0xAF, 0xA0, 0xA0));
setColour(n::styleClass, n::tabSelectedFillColor, juce::Colour(0x0A, 0x0A, 0x0A));
setColour(n::styleClass, n::tabUnselectedOutlineColor, juce::Colour(0xA0, 0xA0, 0xA0));
}

{
using n = components::TabularizedTreeViewer::Styles;

Expand Down
Loading