mirror of
https://github.com/scorpion-26/gBar.git
synced 2024-11-22 03:02:49 +00:00
Add angle property to widgets
This allows us to rotate various widgets.
This commit is contained in:
parent
e4be65a348
commit
4a9ac0ff5b
2 changed files with 49 additions and 0 deletions
|
@ -470,6 +470,11 @@ void NetworkSensor::Draw(cairo_t* cr)
|
|||
gtk_style_context_get(gtk_widget_get_style_context(contextUp->Get()), GTK_STATE_FLAG_NORMAL, GTK_STYLE_PROPERTY_COLOR, &colUp, NULL);
|
||||
gtk_style_context_get(gtk_widget_get_style_context(contextDown->Get()), GTK_STATE_FLAG_NORMAL, GTK_STYLE_PROPERTY_COLOR, &colDown, NULL);
|
||||
|
||||
// Rotate around center of Quad
|
||||
cairo_translate(cr, q.x + q.size / 2, q.y + q.size / 2);
|
||||
cairo_rotate(cr, m_Angle * M_PI / 180.0);
|
||||
cairo_translate(cr, -(q.x + q.size / 2), -(q.y + q.size / 2));
|
||||
|
||||
// Upload
|
||||
cairo_set_source_rgb(cr, colUp->red, colUp->green, colUp->blue);
|
||||
|
||||
|
@ -563,9 +568,19 @@ void Text::SetText(const std::string& text)
|
|||
m_Text = text;
|
||||
}
|
||||
|
||||
void Text::SetAngle(double angle)
|
||||
{
|
||||
if (m_Widget && angle != m_Angle)
|
||||
{
|
||||
gtk_label_set_angle((GtkLabel*)m_Widget, angle);
|
||||
}
|
||||
m_Angle = angle;
|
||||
}
|
||||
|
||||
void Text::Create()
|
||||
{
|
||||
m_Widget = gtk_label_new(m_Text.c_str());
|
||||
gtk_label_set_angle((GtkLabel*)m_Widget, m_Angle);
|
||||
ApplyPropertiesToWidget();
|
||||
}
|
||||
|
||||
|
@ -580,6 +595,15 @@ void Button::Create()
|
|||
return GDK_EVENT_STOP;
|
||||
};
|
||||
g_signal_connect(m_Widget, "clicked", G_CALLBACK(+clickFn), this);
|
||||
gtk_container_foreach((GtkContainer*)m_Widget,
|
||||
[](GtkWidget* child, void* userData)
|
||||
{
|
||||
if (GTK_IS_LABEL(child))
|
||||
{
|
||||
gtk_label_set_angle((GtkLabel*)child, *(double*)userData);
|
||||
}
|
||||
},
|
||||
&m_Angle);
|
||||
ApplyPropertiesToWidget();
|
||||
}
|
||||
|
||||
|
@ -592,6 +616,23 @@ void Button::SetText(const std::string& text)
|
|||
m_Text = text;
|
||||
}
|
||||
|
||||
void Button::SetAngle(double angle)
|
||||
{
|
||||
if (m_Widget && angle != m_Angle)
|
||||
{
|
||||
gtk_container_foreach((GtkContainer*)m_Widget,
|
||||
[](GtkWidget* child, void* userData)
|
||||
{
|
||||
if (GTK_IS_LABEL(child))
|
||||
{
|
||||
gtk_label_set_angle((GtkLabel*)child, *(double*)userData);
|
||||
}
|
||||
},
|
||||
&angle);
|
||||
}
|
||||
m_Angle = angle;
|
||||
}
|
||||
|
||||
void Button::OnClick(Callback<Button>&& callback)
|
||||
{
|
||||
m_OnClick = std::move(callback);
|
||||
|
|
|
@ -257,6 +257,8 @@ public:
|
|||
void SetUp(double val);
|
||||
void SetDown(double val);
|
||||
|
||||
void SetAngle(double angle) { m_Angle = angle; };
|
||||
|
||||
private:
|
||||
void Draw(cairo_t* cr) override;
|
||||
|
||||
|
@ -266,6 +268,8 @@ private:
|
|||
Range limitUp;
|
||||
Range limitDown;
|
||||
|
||||
double m_Angle;
|
||||
|
||||
// What I do here is a little bit gross, but I need a working style context
|
||||
// Just manually creating a style context doesn't work for me.
|
||||
std::unique_ptr<Box> contextUp;
|
||||
|
@ -315,11 +319,13 @@ public:
|
|||
virtual ~Text() = default;
|
||||
|
||||
void SetText(const std::string& text);
|
||||
void SetAngle(double angle);
|
||||
|
||||
virtual void Create() override;
|
||||
|
||||
private:
|
||||
std::string m_Text;
|
||||
double m_Angle;
|
||||
};
|
||||
|
||||
class Button : public Widget
|
||||
|
@ -329,6 +335,7 @@ public:
|
|||
virtual ~Button() = default;
|
||||
|
||||
void SetText(const std::string& text);
|
||||
void SetAngle(double angle);
|
||||
|
||||
virtual void Create() override;
|
||||
|
||||
|
@ -336,6 +343,7 @@ public:
|
|||
|
||||
private:
|
||||
std::string m_Text;
|
||||
double m_Angle;
|
||||
Callback<Button> m_OnClick;
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue