Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to resize widget.Slider #5343

Closed
2 tasks done
pneumaticdeath opened this issue Dec 28, 2024 · 5 comments
Closed
2 tasks done

Add ability to resize widget.Slider #5343

pneumaticdeath opened this issue Dec 28, 2024 · 5 comments
Labels
not an issue This doesn't seem right wontfix This will not be worked on

Comments

@pneumaticdeath
Copy link

pneumaticdeath commented Dec 28, 2024

Checklist

  • I have searched the issue tracker for open issues that relate to the same feature, before opening a new one.
  • This issue only relates to a single feature. I will open new issues for any other features.

Is your feature request related to a problem?

I'm working on a project (a Conway's Game of Life simulator) that uses a slider, and it renders too small by default. i've tried forcing it to be larger, but haven't had any luck. Ideally there would be a SetMinSize(Size) method on some widgets. See screenshot below.

Screenshot 2024-12-27 at 16 16 56

Is it possible to construct a solution with the existing API?

I have not discovered one. I am pretty new to Fyne, so it's possible I've overlooked it.

Describe the solution you'd like to see.

My code looks something like:

    controlBar.speedSlider = widget.NewSlider(1.5, 1000.0)
    controlBar.speedSlider.SetValue(200.0)

Ideally I'd like to be able to say

    controlBar.speedSlider = widget.NewSlider(1.5, 1000.0)
    controlBar.speedSlider.SetValue(200.0)
    controlBar.speedSlider.SetMinWidth(150.0)
@pneumaticdeath
Copy link
Author

Additional context:

I'm using a HBoxLayout in the control bar container

@Jacalz
Copy link
Member

Jacalz commented Dec 28, 2024

Hi. Thanks for opening this issue. However, I'm afraid that this just isn't how you are supposed to handle widget sizes in Fyne. It is the parent container, and its layout function, that controls the size of its children. Unless using a container.NewWithoutLayout(), you can't manually change the size of an object. Do note though that just slapping one of those in your parent container isn't going to help as each object only gets a much size as it parent container gives it (like above). Please see https://docs.fyne.io/faq/layout.

The problem here is that your HBox is collapsing objects to their minimum horizontal space and stacking them next to each other that way. You need to find another suitable layout. I added HPortion to fyne.io/x/fyne/layout a while ago for purposes similar to this. It might be a good fit.

With that said though, I wonder if we perhaps should consider making the MinSize of sliders slightly larger? They are not quite usable at their squashed size.

@Jacalz Jacalz added not an issue This doesn't seem right wontfix This will not be worked on labels Dec 28, 2024
@dweymouth
Copy link
Contributor

I agree with making the Slider MinSize slightly larger. But in the meantime @pneumaticdeath the quickest way to achieve what you want I think is to extend the slider widget (see the docs for extending widgets) to override the MinSize function to increase the Width slightly.

@Jacalz
Copy link
Member

Jacalz commented Dec 28, 2024

I agree with making the Slider MinSize slightly larger. But in the meantime @pneumaticdeath the quickest way to achieve what you want I think is to extend the slider widget (see the docs for extending widgets) to override the MinSize function to increase the Width slightly.

I'd call that a hack and not quite a solution. The main problem here is, in my opinion, the wrong layout being used. Making the minimum size larger is an improvement but not the fix to the issue.

@pneumaticdeath
Copy link
Author

Yeah, I tried to subclass/extend the Slider widget to allow for a configurable MinSize(), but while it worked to expand the size of the slider control, the resultant widget didn't work. Rather than debug that I just reworked the layout to use a combination of Grid and HBox layouts, and that seems to be workable for now.
Screenshot 2024-12-28 at 12 41 04 PM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
not an issue This doesn't seem right wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

3 participants