add clock to bar
This commit is contained in:
68
src/bar.cpp
Normal file
68
src/bar.cpp
Normal file
@@ -0,0 +1,68 @@
|
||||
#include <ctime>
|
||||
|
||||
#include <gtkmm/enums.h>
|
||||
#include <gtkmm/label.h>
|
||||
|
||||
#include "bar.hpp"
|
||||
#include "glibmm/main.h"
|
||||
#include "sigc++/functors/mem_fun.h"
|
||||
#include "widgets/clock.hpp"
|
||||
|
||||
Bar::Bar() {
|
||||
gtk_layer_init_for_window(this->gobj());
|
||||
|
||||
gtk_layer_set_anchor(this->gobj(), GTK_LAYER_SHELL_EDGE_TOP, true);
|
||||
gtk_layer_set_anchor(this->gobj(), GTK_LAYER_SHELL_EDGE_LEFT, true);
|
||||
gtk_layer_set_anchor(this->gobj(), GTK_LAYER_SHELL_EDGE_RIGHT, true);
|
||||
|
||||
gtk_layer_auto_exclusive_zone_enable(this->gobj());
|
||||
|
||||
set_child(main_box);
|
||||
|
||||
load_css();
|
||||
setup_ui();
|
||||
|
||||
this->clock.onUpdate();
|
||||
|
||||
Glib::signal_timeout().connect(
|
||||
sigc::mem_fun(
|
||||
this->clock,
|
||||
&Clock::onUpdate
|
||||
),
|
||||
1000
|
||||
);
|
||||
}
|
||||
|
||||
void Bar::setup_ui() {
|
||||
Gtk::Box left_box{Gtk::Orientation::HORIZONTAL};
|
||||
Gtk::Box center_box{Gtk::Orientation::HORIZONTAL};
|
||||
Gtk::Box right_box{Gtk::Orientation::HORIZONTAL};
|
||||
|
||||
main_box.set_start_widget(left_box);
|
||||
main_box.set_center_widget(center_box);
|
||||
main_box.set_end_widget(right_box);
|
||||
|
||||
Gtk::Label labelLeft("labelLeft");
|
||||
Gtk::Label labelRight("labelRight");
|
||||
|
||||
|
||||
left_box.append(labelLeft);
|
||||
center_box.append(clock);
|
||||
right_box.append(labelRight);
|
||||
}
|
||||
|
||||
void Bar::load_css() {
|
||||
auto css_provider = Gtk::CssProvider::create();
|
||||
|
||||
css_provider->load_from_data(R"(
|
||||
window { background-color: #222; color: #fff; }
|
||||
#clock-label { font-weight: bold; font-family: monospace; }
|
||||
)");
|
||||
|
||||
Gtk::StyleContext::add_provider_for_display(
|
||||
Gdk::Display::get_default(),
|
||||
css_provider,
|
||||
GTK_STYLE_PROVIDER_PRIORITY_APPLICATION
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user