1

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?

Shepmaster
  • 388,571
  • 95
  • 1,107
  • 1,366
MG lolenstine
  • 919
  • 1
  • 11
  • 32

1 Answers1

3

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:

  • CSS style rules applied to it
  • the minimum size of its children

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.

ebassi
  • 8,648
  • 27
  • 29
  • I'm working with an embedded system, so everything will be under control. It's just a bit weird, seeing that the buttons can't be resized, even tho the text isn't even close to filling half of it. I'll test it out for other causes and will report back! Thanks! – MG lolenstine Mar 10 '20 at 13:23
  • I think that the cause indeed is the CSS, but it's not in the size, but in the border_width. Thanks for your help! – MG lolenstine Mar 10 '20 at 13:41