Add Bluetooth tooltips

This commit is contained in:
scorpion-26 2023-01-14 14:47:30 +01:00
parent 8b88051659
commit 7b91486441
4 changed files with 32 additions and 7 deletions

View file

@ -99,7 +99,7 @@ namespace Bar
btIconText->SetClass("bt-label-connected");
btIconText->SetText("");
std::string btDev;
std::string tooltip;
for (auto& dev : info.devices)
{
std::string ico = "";
@ -115,9 +115,13 @@ namespace Bar
{
ico = "";
}
tooltip += dev.name + " & ";
btDev += ico;
}
// Delete last delim
if (tooltip.size())
tooltip.erase(tooltip.end() - 3, tooltip.end());
btDevText->SetTooltip(tooltip);
btDevText->SetText(std::move(btDev));
}
return TimerResult::Ok;
@ -380,7 +384,8 @@ namespace Bar
{
auto workspace = Widget::Create<Button>();
workspace->SetHorizontalTransform({8, false, Alignment::Fill});
workspace->OnClick([i](Button&)
workspace->OnClick(
[i](Button&)
{
System::GotoWorkspace((uint32_t)i + 1);
});

View file

@ -1,8 +1,15 @@
#pragma once
#include <iostream>
#include <unistd.h>
#define UNUSED [[maybe_unused]]
#define LOG(x) std::cout << x << '\n'
#define ASSERT(x, log) if (!(x)) { LOG(log << "\n[Exiting due to assert failed]"); exit(-1); }
#define ASSERT(x, log) \
if (!(x)) \
{ \
LOG(log << "\n[Exiting due to assert failed]"); \
exit(-1); \
}
// Flag helper macros
#define BIT(x) (1 << (x))

View file

@ -66,6 +66,15 @@ void Widget::SetHorizontalTransform(const Transform& transform)
m_HorizontalTransform = transform;
}
void Widget::SetTooltip(const std::string& tooltip)
{
if (m_Widget)
{
gtk_widget_set_tooltip_text(m_Widget, tooltip.c_str());
}
m_Tooltip = tooltip;
}
void Widget::AddChild(std::unique_ptr<Widget>&& widget)
{
m_Childs.push_back(std::move(widget));
@ -82,6 +91,8 @@ void Widget::ApplyPropertiesToWidget()
auto style = gtk_widget_get_style_context(m_Widget);
gtk_style_context_add_class(style, m_CssClass.c_str());
gtk_widget_set_tooltip_text(m_Widget, m_Tooltip.c_str());
// Apply transform
gtk_widget_set_size_request(m_Widget, m_HorizontalTransform.size, m_VerticalTransform.size);
gtk_widget_set_halign(m_Widget, Utils::ToGtkAlign(m_HorizontalTransform.alignment));

View file

@ -84,6 +84,7 @@ public:
void SetClass(const std::string& cssClass);
void SetVerticalTransform(const Transform& transform);
void SetHorizontalTransform(const Transform& transform);
void SetTooltip(const std::string& tooltip);
virtual void Create() = 0;
@ -126,6 +127,7 @@ protected:
std::vector<std::unique_ptr<Widget>> m_Childs;
std::string m_CssClass;
std::string m_Tooltip;
Transform m_HorizontalTransform; // X
Transform m_VerticalTransform; // Y
};