using gtk4 gui library I have this code:
use gtk4 as gtk;
use gtk::prelude::*;
use gtk::{glib, Application, ApplicationWindow, Button, Box, Fixed};
fn main() -> glib::ExitCode
{
let app = Application::builder()
.application_id("app")
.build();
app.connect_activate(|app|
{
// We create the main window.
let window = ApplicationWindow::builder()
.application(app)
.default_width(1920/2)
.default_height(720)
.title("Hello, World!")
.build();
// Create a vertical box container.
let vbox = Fixed::new();
// Create a button with text.
let button = Button::with_label("+"); // Text on the button
const BUTTON_SIZE: i32 = 20;
button.set_size_request(BUTTON_SIZE, BUTTON_SIZE);
// Connect the button's clicked signal to a callback function.
button.connect_clicked(|_|
{
on_button_click();
});
vbox.put(&button, 10.0, 10.0);
// Add the button to the window.
window.set_child(Some(&vbox));
// Show the window.
window.present();
});
app.run()
}
fn on_button_click()
{
}
As you can see in these two lines:
const BUTTON_SIZE: i32 = 20;
button.set_size_request(BUTTON_SIZE, BUTTON_SIZE);
The button size should be 20 by 20 which is a square, however this is how it looks like when running:
Any idea why this is happening and how to fix this?