cogentcore / core

A free and open source framework for building powerful, fast, elegant 2D and 3D apps that run on macOS, Windows, Linux, iOS, Android, and the web with a single Go codebase, allowing you to Code Once, Run Everywhere.
http://cogentcore.org/core
BSD 3-Clause "New" or "Revised" License
1.75k stars 83 forks source link

Text Field Icon Sizing is SUPER Awkward #1314

Open DapperMongoose opened 5 hours ago

DapperMongoose commented 5 hours ago

Describe the bug

When styling a text field you can set the font size very intuitively with a styler with either s.Font.Size.Pt(12) or s.Font.Size = units.Pt(12) however this does not change the size of the trailing icon where present (for example those added by AddClearButton() or SetTypePassword())

Instead it appears that one must nest calls to tree.AddChildInit two deep to get to the actual icon (see example code) In addition one must hunt for the appropriate child name of "trail-icon" which is a *core.Button and not a *core.Icon (somewhat contrary to the conclusion that widget part names are not rocket science reached in https://github.com/cogentcore/core/issues/840)

If there's a better way to do this that I've just overlooked in my search please do let me know.

How to reproduce

Create a new text field widget Set the font size and observe icons that are included in the field do not follow the size change

Example code

core.NewText(usernameContainer).SetText("Username")
    usernameField := core.NewTextField(usernameContainer).AddClearButton()
    tree.AddChildInit(usernameField, "trail-icon", func(trailIcon *core.Button) {
        tree.AddChildInit(trailIcon, "icon", func(icon *core.Icon) {
            icon.Styler(func(s *styles.Style) {
                s.Font.Size.Pt(14)
                s.Text.LineHeight.Pt(14)
            })
        })
    })

Relevant output

No response

Platform

Linux

kkoreilly commented 2 hours ago

Thank you for raising this. The API has changed since #840, and we will reconsider the best approach to this issue, in addition to improving the documentation.