Code Monkey home page Code Monkey logo

Comments (7)

andydotxyz avatar andydotxyz commented on August 22, 2024

I'm not sure I agree that the only solution is a messy one... Can't you just get the minimum before turning on wrapping and cache that value?

from fyne.

dweymouth avatar dweymouth commented on August 22, 2024

What about when you need to update the text while it's already displayed (and update the positioning of an icon you want to position immediately to the right of the text string)?

BTW here is a case internally where it would be useful - https://github.com/fyne-io/fyne/blob/develop/dialog/text.go#L38

from fyne.

dweymouth avatar dweymouth commented on August 22, 2024

This could also supersede #4648

from fyne.

andydotxyz avatar andydotxyz commented on August 22, 2024

What I'm not really getting is why it's not just a right aligned icon with text filling the available space

from fyne.

dweymouth avatar dweymouth commented on August 22, 2024

As far as I can tell you can't achieve the desired positioning:

  • If you put the label and icon in an HBox, the text will always be forced to its minSize of "..." (using TruncateEllipsis)
  • If you put the label and icon in a border with label as center, and icon as right, then the icon will float all the way to the right with the available space, rather than immediately to the right of the end of the label's text
  • Writing a custom layout, you still need to know how much space the text takes up if the full thing can be displayed in the label (which is different from label MinSize which is only big enough for "...")

from fyne.

andydotxyz avatar andydotxyz commented on August 22, 2024

This is a complex topic as discussed on Slack, but I'm not convinced that different types of min are the way to go.
There are many combinations of text wrap/trunc etc that can lead to different space being needed and we should not add APIs for them all. In essence you've got two widgets with different configurations.

It seems that for this specific use-cases you are changing between two so it's likely more than just a custom layout as you say. Perhaps using tricks like for complex tables where we switch between different widgets depending on some factors.

I'd say that there are many ways to approach this:

  • managing multiple widgets similar to how you are doing or by actually switching which is visible in some custom code.
  • introducing a whole preferred size API into Fyne (which creates huge complexity increase to handle such corner cases). As discussed it is not clear if this would be in the layout or widget APIs.
  • Adding a set of new text APIs that allow you to measure text based on certain wrapping characteristics not just the text style as it currently exists.

Overall I think we have a solid underpinning so I'm not sure the Label widget is missing a bunch of APIs, but I think we should be open to exploring this going forward if we can more generally find a solution that helps out with complex layout requirements such as that above.

from fyne.

dweymouth avatar dweymouth commented on August 22, 2024

Just for reference and in case it's helpful for anyone (or useful info on use cases when we eventually try to design an API to solve this issue) - here is the custom component I have to show the "MoreVerticalIcon" immediately to the right of a hyperlink text, which is allowed to truncate - https://github.com/dweymouth/supersonic/blob/main/ui/widgets/optionhyperlink.go

from fyne.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.