implement progressbar

This commit is contained in:
yggverse 2024-08-18 23:46:27 +03:00
parent a5a3a5625b
commit 46e004966e
6 changed files with 118 additions and 3 deletions

View file

@ -0,0 +1,53 @@
#include "progressbar.hpp"
using namespace app::browser::main::tab::page;
Progressbar::Progressbar()
{
set_margin_top(
MARGIN
);
set_margin_bottom(
MARGIN
);
set_pulse_step(
PULSE_STEP
);
set_opacity(0);
}
Progressbar::~Progressbar() = default;
// Public actions
void Progressbar::set(
double fraction
) {
// Toggle transparency
set_opacity(
fraction < 1 ? 1 : 0
);
// Reset initial progress
progress = fraction;
// Animate progress function
Glib::signal_timeout().connect(
[this]() -> bool
{
double current = get_fraction();
if (current < progress)
{
set_fraction(
current + PULSE_STEP
);
}
return current < 1;
},
ANIMATION_TIME
);
}

View file

@ -0,0 +1,28 @@
#ifndef APP_BROWSER_MAIN_TAB_PAGE_PROGRESSBAR_HPP
#define APP_BROWSER_MAIN_TAB_PAGE_PROGRESSBAR_HPP
#include <glibmm/main.h>
#include <gtkmm/progressbar.h>
namespace app::browser::main::tab::page
{
class Progressbar : public Gtk::ProgressBar
{
const int MARGIN = 2;
const double PULSE_STEP = .1;
const int ANIMATION_TIME = 10;
double progress = 0;
public:
Progressbar();
~Progressbar();
void set(
double fraction
);
};
}
#endif // APP_BROWSER_MAIN_TAB_PAGE_PROGRESSBAR_HPP