rustgtkgtk-rs

How to make `Button`s smaller than their minimal size?


I'm currently setting up some buttons, and the problem is, that I need to squeeze 10 of them into 480 pixels.

I found that the smallest width that the button can be is 50px; if I resize it to less than 50, it does not change. I'd like to change their size to 48px or even less, but I have no idea on how to proceed.

For the GTK library, I'm using RELM. I've asked on GTK-rs's GitHub, but they claim that the problem is with the GTK.

My current code is as following

gtk::Box {
    property_width_request: 480,
    orientation: Horizontal,
    #[name="button"]
    gtk::Button{
        property_height_request: 25,
        property_width_request: 25,
        label: &self.model.layout.get_character(0, self.model.shift),
        clicked => Clicked(0),
    },
}

Even though I do set the width_request, the smallest width looks like it's 50px.

Is there any way to reduce the button width to 45px or less?


Solution

  • You can't, for obvious reasons, make a widget smaller than its minimum size.

    The minimum size of a widget is dictated by two things:

    So if you want to change the minimum size of a widget you should check what kind of style is applied to it—you should use the GTK inspector to find that out; and the size of each child inside it.

    In general, you should not really try and force a size of a button—especially if it can contain text. Things like user fonts, themes, and localisation will likely break any constraint you have decided to apply on your system.