M module-apps/application-desktop/data/DesktopStyle.hpp => module-apps/application-desktop/data/DesktopStyle.hpp +1 -1
@@ 45,7 45,7 @@ namespace style::desktop
{
inline constexpr uint32_t x = 0;
inline constexpr uint32_t y = 450;
- inline constexpr uint32_t w = 500;
+ inline constexpr uint32_t w = style::window_width;
inline constexpr uint32_t h = 100;
} // namespace percentlabel
M module-apps/application-desktop/windows/UpdateProgress.cpp => module-apps/application-desktop/windows/UpdateProgress.cpp +9 -8
@@ 49,7 49,7 @@ namespace gui
}
}
percentLabel->setText(std::to_string(progressPercent) + " %");
- updateProgress->setValue(progressPercent);
+ updateProgress->setPercentageValue(progressPercent);
}
setVisibleState();
}
@@ 109,13 109,14 @@ namespace gui
percentLabel->setAlignment(
gui::Alignment(gui::Alignment::Horizontal::Center, gui::Alignment::Vertical::Center));
- updateProgress = new ProgressBar(this,
- style::window::progressBar::x,
- style::window::progressBar::y,
- style::window::progressBar::width,
- style::window::progressBar::h);
- updateProgress->setMaximum(100);
- updateProgress->setValue(0);
+ updateProgress = new HBarGraph(this,
+ style::window::progressBar::x,
+ style::window::progressBar::y,
+ style::window::progressBar::range,
+ BarGraphStyle::Light);
+ updateProgress->setSize(style::window::progressBar::w, style::window::progressBar::h);
+ updateProgress->setAlignment(
+ gui::Alignment(gui::Alignment::Horizontal::Center, gui::Alignment::Vertical::Center));
}
void UpdateProgressWindow::destroyInterface()
M module-apps/application-desktop/windows/UpdateProgress.hpp => module-apps/application-desktop/windows/UpdateProgress.hpp +3 -2
@@ 10,7 10,8 @@
#include <module-gui/gui/widgets/TextFixedSize.hpp>
#include <module-gui/gui/widgets/Image.hpp>
#include <module-gui/gui/widgets/BottomBar.hpp>
-#include <module-gui/gui/widgets/ProgressBar.hpp>
+#include <module-apps/widgets/BarGraph.hpp>
+
namespace gui
{
@@ 20,7 21,7 @@ namespace gui
std::string textInfo;
gui::Label *percentLabel = nullptr;
- ProgressBar *updateProgress = nullptr;
+ HBarGraph *updateProgress = nullptr;
fs::path updateFile;
M module-apps/widgets/BarGraph.cpp => module-apps/widgets/BarGraph.cpp +101 -44
@@ 5,9 5,9 @@
namespace gui
{
- static inline auto rectAxisLenghtFrom(uint32_t numberOfRectangles) -> uint32_t
+ static inline auto rectAxisLengthFrom(uint32_t numberOfRectangles) -> uint32_t
{
- return numberOfRectangles * (style::bargraph::spacing + style::bargraph::rect_axis_length_sml) -
+ return numberOfRectangles * (style::bargraph::spacing + style::bargraph::rect_axis_length_short_medium) -
style::bargraph::spacing;
}
@@ 18,18 18,32 @@ namespace gui
setValue(absoluteValue);
}
- auto BarGraph::createRectangle(std::uint32_t width, std::uint32_t height) const -> Rect *
+ auto BarGraph::createRectangle() const -> Rect *
{
auto rectangle = new Rect(nullptr, 0, 0, 0, 0);
- rectangle->setMinimumSize(width, height);
+ rectangle->setMinimumSize(barStyle.width, barStyle.height);
rectangle->setFillColor(ColorFullBlack);
rectangle->setBorderColor(ColorFullBlack);
rectangle->setFilled(false);
- rectangle->setRadius(style::bargraph::radius);
+ rectangle->setRadius(barStyle.radius);
rectangle->setPenWidth(style::window::default_border_focus_w);
return rectangle;
}
+ void BarGraph::createRectangles()
+ {
+ for (std::uint32_t i = 0; i < numberOfRectangles; i++) {
+
+ auto rectangle = createRectangle();
+
+ if ((i + 1) != numberOfRectangles) {
+ rectangle->setMargins(barStyle.margin);
+ }
+
+ rectangles.push_back(rectangle);
+ }
+ }
+
bool BarGraph::setValue(unsigned int value)
{
if (value > numberOfRectangles) {
@@ 39,82 53,125 @@ namespace gui
currentLevel = value;
for (std::uint32_t i = 0; i < currentLevel; i++) {
- rectangles[i]->setFillColor(ColorFullBlack);
+ barStyle.fillRender(rectangles[i]);
}
for (std::uint32_t i = currentLevel; i < numberOfRectangles; i++) {
- rectangles[i]->setFillColor(ColorFullWhite);
+ barStyle.emptyRender(rectangles[i]);
}
return true;
}
- VBarGraph::VBarGraph(Item *parent, Position x, Position y, uint32_t numberOfRectangles)
- : VBox(parent, x, y, style::bargraph::rect_axis_length_lrg, rectAxisLenghtFrom(numberOfRectangles))
+ void BarGraph::setMaximum(unsigned int value)
+ {
+ numberOfRectangles = value;
+
+ if (currentLevel > numberOfRectangles) {
+ currentLevel = numberOfRectangles;
+ }
+ }
+
+ void BarGraph::applyBarStyle(BarGraphStyle graphStyle)
{
- setMinimumSize(style::bargraph::rect_axis_length_lrg, rectAxisLenghtFrom(numberOfRectangles));
+ switch (graphStyle) {
+ case BarGraphStyle::Heavy:
+ barStyle.radius = style::bargraph::radius_medium;
+ barStyle.fillRender = [](gui::Rect *bar) { bar->setFillColor(ColorFullBlack); };
+ barStyle.emptyRender = [](gui::Rect *bar) { bar->setFillColor(ColorFullWhite); };
+ break;
+ case BarGraphStyle::Light:
+ barStyle.radius = style::bargraph::radius_small;
+ barStyle.fillRender = [](gui::Rect *bar) { bar->setBorderColor(ColorFullBlack); };
+ barStyle.emptyRender = [](gui::Rect *bar) { bar->setBorderColor(ColorGrey); };
+ break;
+ }
+ }
+
+ VBarGraph::VBarGraph(Item *parent, Position x, Position y, uint32_t numberOfRectangles, BarGraphStyle graphStyle)
+ : VBox(parent, x, y, style::bargraph::rect_axis_length_long_medium, rectAxisLengthFrom(numberOfRectangles))
+ {
+ applyBarStyle(graphStyle);
+ setMinimumSize(style::bargraph::rect_axis_length_long_medium, rectAxisLengthFrom(numberOfRectangles));
setEdges(RectangleEdge::None);
+
setMaximum(numberOfRectangles);
+ createGraph();
+
std::reverse(std::begin(rectangles), std::end(rectangles));
}
- void VBarGraph::setMaximum(unsigned int value)
+ void VBarGraph::createGraph()
{
- numberOfRectangles = value;
-
- if (currentLevel > numberOfRectangles) {
- currentLevel = numberOfRectangles;
- }
if (!rectangles.empty()) {
erase();
rectangles.clear();
}
- for (std::uint32_t i = 0; i < numberOfRectangles; i++) {
-
- auto rectangle =
- createRectangle(style::bargraph::rect_axis_length_lrg, style::bargraph::rect_axis_length_sml);
- rectangle->setBorderColor(ColorFullBlack);
+ createRectangles();
- if ((i + 1) != numberOfRectangles) {
- rectangle->setMargins(Margins(0, 0, 0, style::bargraph::spacing));
- }
+ for (auto rect : rectangles) {
+ addWidget(rect);
+ }
+ }
- addWidget(rectangle);
- rectangles.push_back(rectangle);
+ void VBarGraph::applyBarStyle(BarGraphStyle graphStyle)
+ {
+ BarGraph::applyBarStyle(graphStyle);
+
+ switch (graphStyle) {
+ case BarGraphStyle::Heavy:
+ barStyle.width = style::bargraph::rect_axis_length_long_medium;
+ barStyle.height = style::bargraph::rect_axis_length_short_medium;
+ barStyle.margin = Margins(0, 0, 0, style::bargraph::spacing);
+ break;
+ case BarGraphStyle::Light:
+ barStyle.width = style::bargraph::rect_axis_length_long_small;
+ barStyle.height = style::bargraph::rect_axis_length_short_small;
+ barStyle.margin = Margins(0, 0, 0, style::bargraph::spacing);
+ break;
}
}
- HBarGraph::HBarGraph(Item *parent, Position x, Position y, uint32_t numberOfRectangles) : HBox(parent)
+ HBarGraph::HBarGraph(Item *parent, Position x, Position y, uint32_t numberOfRectangles, BarGraphStyle graphStyle)
+ : HBox(parent, x, y, rectAxisLengthFrom(numberOfRectangles), style::bargraph::rect_axis_length_long_medium)
{
- setMinimumSize(rectAxisLenghtFrom(numberOfRectangles), style::bargraph::rect_axis_length_lrg);
+ applyBarStyle(graphStyle);
+ setMinimumSize(rectAxisLengthFrom(numberOfRectangles), style::bargraph::rect_axis_length_long_medium);
setEdges(RectangleEdge::None);
+
setMaximum(numberOfRectangles);
+ createGraph();
}
- void HBarGraph::setMaximum(unsigned int value)
+ void HBarGraph::createGraph()
{
- numberOfRectangles = value;
- if (currentLevel > numberOfRectangles) {
- currentLevel = numberOfRectangles;
- }
-
if (!rectangles.empty()) {
erase();
rectangles.clear();
}
- for (std::uint32_t i = 0; i <= numberOfRectangles; i++) {
-
- auto rectangle =
- createRectangle(style::bargraph::rect_axis_length_sml, style::bargraph::rect_axis_length_lrg);
+ createRectangles();
- if ((i + 1) != numberOfRectangles) {
- rectangle->setMargins(Margins(0, 0, style::bargraph::spacing, 0));
- }
-
- addWidget(rectangle);
- rectangles.push_back(rectangle);
+ for (auto rect : rectangles) {
+ addWidget(rect);
}
}
+ void HBarGraph::applyBarStyle(BarGraphStyle graphStyle)
+ {
+ BarGraph::applyBarStyle(graphStyle);
+
+ switch (graphStyle) {
+ case BarGraphStyle::Heavy:
+ barStyle.width = style::bargraph::rect_axis_length_short_medium;
+ barStyle.height = style::bargraph::rect_axis_length_long_medium;
+ barStyle.margin = Margins(0, 0, style::bargraph::spacing, 0);
+ break;
+ case BarGraphStyle::Light:
+ barStyle.width = style::bargraph::rect_axis_length_short_small;
+ barStyle.height = style::bargraph::rect_axis_length_long_small;
+ barStyle.margin = Margins(0, 0, style::bargraph::spacing, 0);
+ break;
+ }
+ }
} /* namespace gui */
M module-apps/widgets/BarGraph.hpp => module-apps/widgets/BarGraph.hpp +45 -9
@@ 8,22 8,47 @@
namespace style::bargraph
{
- constexpr inline auto rect_axis_length_sml = 8;
- constexpr inline auto rect_axis_length_lrg = 20;
- constexpr inline auto spacing = 17;
- constexpr inline auto radius = 4;
+ constexpr inline auto rect_axis_length_short_medium = 8;
+ constexpr inline auto rect_axis_length_long_medium = 20;
+ constexpr inline auto rect_axis_length_short_small = 3;
+ constexpr inline auto rect_axis_length_long_small = 14;
+ constexpr inline auto spacing = 17;
+ constexpr inline auto radius_medium = 4;
+ constexpr inline auto radius_small = 2;
+
} // namespace style::bargraph
namespace gui
{
+ enum class BarGraphStyle
+ {
+ Heavy, /// ThickLine style Bars with white/black fill.
+ Light, /// SlimLine style Bars with gray/black border fill.
+ };
+
+ struct BarStyle
+ {
+ Length width{0};
+ Length height{0};
+ Length radius{0};
+ Margins margin{0, 0, 0, 0};
+ std::function<void(gui::Rect *bar)> fillRender = nullptr;
+ std::function<void(gui::Rect *bar)> emptyRender = nullptr;
+ };
+
class BarGraph : public Progress
{
protected:
std::vector<gui::Rect *> rectangles;
std::uint32_t numberOfRectangles;
std::uint32_t currentLevel = 0;
+ BarStyle barStyle;
+
+ [[nodiscard]] auto createRectangle() const -> Rect *;
+ void createRectangles();
- [[nodiscard]] auto createRectangle(std::uint32_t width, std::uint32_t height) const -> Rect *;
+ virtual void applyBarStyle(BarGraphStyle graphStyle);
+ virtual void createGraph(){};
public:
void setPercentageValue(unsigned int value) override;
@@ 34,20 59,31 @@ namespace gui
}
auto setValue(unsigned int value) -> bool override;
+ void setMaximum(unsigned int value) final;
};
class VBarGraph : public VBox, public BarGraph
{
public:
- VBarGraph(Item *parent = nullptr, Position x = 0, Position y = 0, uint32_t numberOfRectangles = 0);
- void setMaximum(unsigned int value) final;
+ VBarGraph(Item *parent = nullptr,
+ Position x = 0,
+ Position y = 0,
+ uint32_t numberOfRectangles = 0,
+ BarGraphStyle graphStyle = BarGraphStyle::Heavy);
+ void applyBarStyle(BarGraphStyle graphStyle) final;
+ void createGraph() final;
};
class HBarGraph : public HBox, public BarGraph
{
public:
- HBarGraph(Item *parent = nullptr, Position x = 0, Position y = 0, uint32_t numberOfRectangles = 0);
- void setMaximum(unsigned int value) final;
+ HBarGraph(Item *parent = nullptr,
+ Position x = 0,
+ Position y = 0,
+ uint32_t numberOfRectangles = 0,
+ BarGraphStyle graphStyle = BarGraphStyle::Heavy);
+ void applyBarStyle(BarGraphStyle graphStyle) final;
+ void createGraph() final;
};
} /* namespace gui */
M module-gui/gui/widgets/ProgressBar.hpp => module-gui/gui/widgets/ProgressBar.hpp +2 -2
@@ 1,4 1,4 @@
-// Copyright (c) 2017-2020, Mudita Sp. z.o.o. All rights reserved.
+// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md
#pragma once
@@ 24,7 24,7 @@ namespace gui
class ProgressBar : public Rect, public Progress
{
public:
- ProgressBar(Item *parent, std::uint32_t x, std::uint32_t y, std::uint32_t w, std::uint32_t h);
+ [[deprecated]] ProgressBar(Item *parent, std::uint32_t x, std::uint32_t y, std::uint32_t w, std::uint32_t h);
void setMaximum(unsigned int value) noexcept override;
auto setValue(unsigned int value) noexcept -> bool override;
M module-gui/gui/widgets/Style.hpp => module-gui/gui/widgets/Style.hpp +3 -2
@@ 100,10 100,11 @@ namespace style
namespace progressBar
{
- inline constexpr auto x = 100U;
+ inline constexpr auto x = style::window::default_left_margin;
inline constexpr auto y = 400U;
- inline constexpr auto width = 280U;
+ inline constexpr auto w = style::window::default_body_width;
inline constexpr auto h = 50U;
+ inline constexpr auto range = 10U;
}; // namespace progressBar
}; // namespace window