christolliday / limn

Experimental cross platform GUI library
Other
404 stars 19 forks source link

Unable to set the padding of a RectStyle button #24

Closed fschutt closed 6 years ago

fschutt commented 6 years ago

I tried making the button padding smaller, but there doesn't seem to be a way (for the default button). So I copied the code from the button.rs and tried removing the corners, which worked fine. But a RectStyle does not have a padding field and I don't know how I should decrease the size of the button. Maybe it has to do with the line_height on the TextStyle? But there's no way to set the line height!

I tried setting the strength of the padding to STRONG, didn't help either:

button.set_text("ON", "OFF");
button.set_name("button");
button.layout().add(constraints![
    align_top(&root),
    align_left(&root),
    bound_by(&root).padding(0.0).strength(STRONG),
]);
root.add_child(button);

No matter what I try, I can't decrease the (horizontal or vertical) padding of the button:

limn_padding_issue

I want no padding between the text and the border of the surrounding button? Is this possible and if yes, how?

There is another bug, the font size seems to be cut in half: If I specify:

pub static ref STYLE_BUTTON_TEXT: Vec<TextStyle> = {
    style!(TextStyle::TextColor: selector!(BLACK, INACTIVE: COLOR_BUTTON_TEXT_INACTIVE),
           TextStyle::FontSize: selector!(16.0, INACTIVE: 16.0))
};

... I get a font that's 8 pixels tall, instead of 16 pixels.

wendivoid commented 6 years ago

I think your talking about that padding between the button's text widget and the button's rect widget? Currently there is no way to change this easily, it's hard coded in both ToggleButton and PushButton new methods.

fschutt commented 6 years ago

@bytebuddha Yes, but I copied those files, I have access to the ToggleButtonBuilder::new() because I simply copied the source from limn/src/widgets/button.rs. It doesn't work, even if I set the min_size() to something else:

impl MyCustomToggleButtonBuilder {

    pub fn new() -> Self {
        let mut widget = WidgetBuilder::new("toggle_button");
        widget
            .set_draw_state_with_style(RectState::new(), STYLE_BUTTON.clone())
            .add_handler_fn(button_handle_mouse_down)
            .enable_hover()
            .add_handler_fn(toggle_button_handle_mouse);
        widget.layout().add(constraints![
            min_size(Size::new(0.0, 0.0)),  // <------ doesn't work!
            shrink(),
        ]);

        MyCustomToggleButtonBuilder { widget: widget }
    }
}
wendivoid commented 6 years ago

Oh I'm sorry it appears i mispoke. As it turns out the text padding is set inset_text when text is added. I think i was able to get to your desired effect by removing the min_size() call in new and by removing the padding() calls in set_text.

fschutt commented 6 years ago

@bytebuddha Yes, thanks, that was it, thank you.

However, the font-size issue remains (i.e. if I set the font size to 8.0, I get a 4 pixel font, and so on). I'll open a seperate issue for that.