diff --git a/example.toml b/example.toml index de3be7ae4..241dcf2cc 100644 --- a/example.toml +++ b/example.toml @@ -270,3 +270,7 @@ battery_low_percent_threshold = 0 # set to e.g. 15 to enable battery_under_thr # [widget.notifications] # hide_when_no_unread = true + +# [widget.clock] +# format = "{:%H:%M}\n{:%d/%m}" +# vertical_format = "{:%H\n%M}" diff --git a/src/shell/bar/widgets/clock_widget.cpp b/src/shell/bar/widgets/clock_widget.cpp index 677d720e3..a247ebf01 100644 --- a/src/shell/bar/widgets/clock_widget.cpp +++ b/src/shell/bar/widgets/clock_widget.cpp @@ -8,6 +8,22 @@ #include "ui/palette.h" #include "ui/style.h" +#include +#include + +namespace { + constexpr float kStackedPrimaryScale = 0.72f; + constexpr float kStackedSecondaryScale = 0.58f; + + std::pair splitFirstLine(std::string_view text) { + const std::size_t newline = text.find('\n'); + if (newline == std::string_view::npos) { + return {text, {}}; + } + return {text.substr(0, newline), text.substr(newline + 1)}; + } +} // namespace + ClockWidget::ClockWidget(wl_output* output, std::string format, std::string verticalFormat) : m_output(output), m_format(std::move(format)), m_verticalFormat(std::move(verticalFormat)) {} @@ -60,36 +76,97 @@ void ClockWidget::create() { // a stable ink envelope instead of the current text's ink. m_label = label.get(); area->addChild(std::move(label)); + + auto secondaryLabel = std::make_unique