diff --git a/Source/Components/DraggableNumber.h b/Source/Components/DraggableNumber.h index 57c49b54c..326bf14e1 100644 --- a/Source/Components/DraggableNumber.h +++ b/Source/Components/DraggableNumber.h @@ -370,21 +370,19 @@ class DraggableNumber : public Label // NOTE: We could simply do `String(numberText.getDoubleValue(), 0)` but using string manipulation // bypasses any potential issues with precision - auto removeDecimalNumString = [](String& numString) { + auto removeDecimalNumString = [](String& numString) -> String { if (numString.contains(".")) { // Split the string into the integer and fractional parts StringArray parts = StringArray::fromTokens(numString, ".", ""); - // If the fractional part is "0" or empty, remove the decimal point - if (parts[1] == "0" || parts[1].isEmpty()) { - return parts[0]; // Just keep the integer part - } else { - return numString; // Keep the full string (with decimal point & fractional part) + // If fractional only contains zeros, only return the first part (no decimal point) + if (parts[1].removeCharacters("0").isEmpty()) { + return parts[0]; } - } else { - // If there’s no decimal point, leave the string as it is return numString; } + // If there’s no decimal point, leave the string as it is + return numString; }; // Only display the decimal point if fractional exists, but make sure to show it as a user hovers over the fractional decimal places diff --git a/Source/Components/WelcomePanel.h b/Source/Components/WelcomePanel.h index 35c846f90..bb2a6b91f 100644 --- a/Source/Components/WelcomePanel.h +++ b/Source/Components/WelcomePanel.h @@ -230,6 +230,7 @@ class WelcomePanel : public Component String creationTimeDescription = String(); String modifiedTimeDescription = String(); + String accessedTimeDescription = String(); String fileSizeDescription = String(); File patchFile; @@ -246,24 +247,33 @@ class WelcomePanel : public Component auto is24Hour = OSUtils::is24HourTimeFormat(); - auto formatTimeDescription = [is24Hour](const Time& openTime) { - auto diff = Time::getCurrentTime() - openTime; + auto formatTimeDescription = [is24Hour](const Time& openTime, bool showDayAndDate = false) { + auto const now = Time::getCurrentTime(); - String date; - auto days = diff.inDays(); - if (days < 1) - date = "Today"; - else if (days > 1 && days < 2) - date = "Yesterday"; - else - date = openTime.toString(true, false); + // Extract just the date part (YYYY-MM-DD) for comparison + auto const openDate = openTime.toISO8601(true).substring(0, 10); + auto const currentDate = now.toISO8601(true).substring(0, 10); + auto const yesterday = (now - RelativeTime::days(1)).toISO8601(true).substring(0, 10); + + String dateOrDay; + if (openDate == currentDate) { + dateOrDay = "Today"; + } else if (openDate == yesterday) { + dateOrDay = "Yesterday"; + } String time = openTime.toString(false, true, false, is24Hour); - return date + ", " + time; + if (showDayAndDate) + return (dateOrDay.isNotEmpty() ? dateOrDay + ", " : "") + openTime.toString(true, false) + ", " + time; + + return (dateOrDay.isNotEmpty() ? dateOrDay : openTime.toString(true, false)) + ", " + time; + }; - tileSubtitle = formatTimeDescription(Time(static_cast(subTree.getProperty("Time")))); + auto const accessedInPlugdasta = Time(static_cast(subTree.getProperty("Time"))); + + tileSubtitle = formatTimeDescription(accessedInPlugdasta); auto const fileSize = patchFile.getSize(); @@ -275,8 +285,13 @@ class WelcomePanel : public Component fileSizeDescription = String(fileSize / (1024.0 * 1024.0), 2) + " MiB"; // 1 MiB or more } - creationTimeDescription = formatTimeDescription(patchFile.getCreationTime()); - modifiedTimeDescription = formatTimeDescription(patchFile.getLastModificationTime()); + creationTimeDescription = formatTimeDescription(patchFile.getCreationTime(), true); + modifiedTimeDescription = formatTimeDescription(patchFile.getLastModificationTime(), true); + // Accessed time will show the last time the file was read, which is when the Home panel has been refreshed. + // We need to show the time accessed from plugdata, which is saved in the settings XML + // We want to show this again as well as in the subtile, but format it differently (with both Today/Yesterday and date) + // because the popup menu may occlude the tile + subtitle + accessedTimeDescription = formatTimeDescription(accessedInPlugdasta, true); updateGeneratedThumbnailIfNeeded(thumbImage, svgImage, iconColour); } @@ -331,7 +346,7 @@ class WelcomePanel : public Component patchInfoSubMenu.addSeparator(); patchInfoSubMenu.addItem(String("Created: " + creationTimeDescription), false, false, nullptr); patchInfoSubMenu.addItem(String("Modified: " + modifiedTimeDescription), false, false, nullptr); - patchInfoSubMenu.addItem(String("Accessed: " + tileSubtitle), false, false, nullptr); + patchInfoSubMenu.addItem(String("Accessed: " + accessedTimeDescription), false, false, nullptr); tileMenu.addSubMenu(String(tileName + ".pd file info"), patchInfoSubMenu, true); tileMenu.addSeparator(); // TODO: we may want to be clearer about this - that it doesn't delete the file on disk diff --git a/Source/Statusbar.cpp b/Source/Statusbar.cpp index 769667b45..c334c64e6 100644 --- a/Source/Statusbar.cpp +++ b/Source/Statusbar.cpp @@ -1329,11 +1329,9 @@ void Statusbar::updateZoomLevel() void Statusbar::paint(Graphics& g) { - if(welcomePanelIsShown) return; - g.setColour(findColour(PlugDataColour::toolbarOutlineColourId)); - auto start = !editor->palettes->isExpanded() ? 29.0f : 0.0f; + auto start = !editor->palettes->isExpanded() && editor->palettes->isVisible() ? 29.0f : 0.0f; auto end = editor->sidebar->isHidden() ? 29.0f : 0.0f; g.drawLine(start, 0.5f, static_cast(getWidth()) - end, 0.5f); diff --git a/Source/Utility/CachedTextRender.h b/Source/Utility/CachedTextRender.h index da37b6b01..d6ad57bb6 100644 --- a/Source/Utility/CachedTextRender.h +++ b/Source/Utility/CachedTextRender.h @@ -21,12 +21,11 @@ class CachedTextRender { nvgFillRect(nvg, bounds.getX(), bounds.getY(), bounds.getWidth() + 3, bounds.getHeight()); } - AttributedString getSyntaxHighlightedString(String const& text, Font const& font, Colour const& colour) + AttributedString getSyntaxHighlightedString(String const& text, Font const& font, Colour const& colour, Colour const& nameColour) { auto attributedText = AttributedString(); auto tokens = StringArray::fromTokens(text, true); - auto nameColour = colour.interpolatedWith(LookAndFeel::getDefaultLookAndFeel().findColour(PlugDataColour::dataColourId), 0.7f); auto flagColour = colour.interpolatedWith(LookAndFeel::getDefaultLookAndFeel().findColour(PlugDataColour::signalColourId), 0.7f); bool firstToken = true; @@ -55,10 +54,13 @@ class CachedTextRender { { auto textHash = hash(text); bool needsUpdate = lastTextHash != textHash || colour != lastColour || cachedWidth != lastWidth || highlightObjectSyntax != isSyntaxHighlighted; - if (needsUpdate) { + auto nameColour = colour.interpolatedWith(LookAndFeel::getDefaultLookAndFeel().findColour(PlugDataColour::dataColourId), 0.7f); + bool highlightTextNeedsUpdaste = highlightObjectSyntax ? lastTextHighlightedColour != nameColour : false; + + if (needsUpdate || highlightTextNeedsUpdaste) { AttributedString attributedText; if (highlightObjectSyntax) { - attributedText = getSyntaxHighlightedString(text, font, colour); + attributedText = getSyntaxHighlightedString(text, font, colour, nameColour); attributedText.setJustification(Justification::centredLeft); } else { attributedText = AttributedString(text); @@ -75,6 +77,7 @@ class CachedTextRender { lastTextHash = textHash; lastColour = colour; + lastTextHighlightedColour = nameColour; isSyntaxHighlighted = highlightObjectSyntax; updateImage = true; } @@ -103,6 +106,7 @@ class CachedTextRender { hash32 lastTextHash = 0; float lastScale = 1.0f; Colour lastColour; + Colour lastTextHighlightedColour; int lastWidth = 0; int idealWidth = 0, idealHeight = 0; Rectangle lastRenderBounds;