scorpion-26 / gBar

Blazingly fast status bar written with GTK
MIT License
459 stars 17 forks source link

Margins for the gBar. #99

Closed elifouts closed 2 months ago

elifouts commented 2 months ago

Describe the bug Im currently editting the C++ to my liking and I seem to be unable to effectively adjust the padding on the sides of the bar so that it seems to be floading instead of flush with the side of the monitor. I was able to do this but all the widgets are spread out. I was wondering if there is a better way to do this than what I am doing or if you could add a easier way to adjust the margins!

What doesn't work? Please be as precise as possible. Setting padding in css doesnt work. I dont know if Im doing it right tho.

Steps to Reproduce Bellow I will show What I did to get to the point where the widgets are super spread out. This is in the Widgets.cpp

void Widget::ApplyPropertiesToWidget()
{
    // Apply style
    auto style = gtk_widget_get_style_context(m_Widget);
    gtk_style_context_add_class(style, m_CssClass.c_str());
    for (auto& cssClass : m_AdditionalClasses)
    {
        gtk_style_context_add_class(style, 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));
    gtk_widget_set_valign(m_Widget, Utils::ToGtkAlign(m_VerticalTransform.alignment));
    gtk_widget_set_hexpand(m_Widget, m_HorizontalTransform.expand);
    gtk_widget_set_vexpand(m_Widget, m_VerticalTransform.expand);

    // Adjust margin properties
    gtk_widget_set_margin_start(m_Widget, 10);
    gtk_widget_set_margin_end(m_Widget, 10); 
    gtk_widget_set_margin_top(m_Widget, 5); 
    gtk_widget_set_margin_bottom(m_Widget, 5); 

    if (m_OnCreate)
        m_OnCreate(*this);
}

Expected behavior

I thought that I would be able to change the widget padding or margins and the other widgets would adapt. Idk there must be a better way right?

Screenshots/Error logs

Disregard the two bars one of them is the one on startup. just look at the 2nd one. I haven't worked too much with the css because I believe it isnt something that cant be fixed with a simple padding or width tag. anyway here is a screenshot of what it looks like. IDK how to take a screenshot on arch yet but I took a pic on my phone. Please Let me know if there is an easier way to do what Im trying to do. Ive spent Entirely too much time working on this lol. I also want to add in the end here that I think this is one of the coolest things to make. I congratulate you on this my guy its awesome. Its so minimal and just makes sense. I dont understand why there arnt more widgets and stuff like this. Anyway, just let me know if there is anything you found or anything I can do to aid in this fix. IF you font get to it no big deal I just would like to have a floating bar!!! I Also feel stupid because I feel like this is a simple fix or something that is easy to do.

IMG_8299

scorpion-26 commented 2 months ago

Widget::ApplyPropertiesToWidget is a function, which is called when creating a widget (as in element of a window, not as the bar itself), so the hardcoded margin is applied to every element. If you really want to do this in C++ (which I don't recommend), then you can have a look at src/Bar.cpp and then call SetVerticalTransform/SetHorizontalTransform on mainWidget with Transform::marginBefore/marginAfter as the margin

Though it can also be done with css (Which I'd recommend):

.bar {
    margin-top: 20px;
    margin-left: 20px;
    margin-right: 20px;
}

Shot_240527_180408

elifouts commented 2 months ago

It worked man thanks so much and keep making amazing stuff