Skip to content

Commit

Permalink
Inline creation of providers in Entry
Browse files Browse the repository at this point in the history
  • Loading branch information
Jacalz committed Feb 6, 2024
1 parent 30ce1f8 commit 41118fe
Showing 1 changed file with 14 additions and 19 deletions.
33 changes: 14 additions & 19 deletions widget/entry.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ type Entry struct {

dirty bool
focused bool
text *RichText
placeholder *RichText
text RichText
placeholder RichText
content *entryContent
scroll *widget.Scroll

Expand Down Expand Up @@ -1055,21 +1055,17 @@ func (e *Entry) pasteFromClipboard(clipboard fyne.Clipboard) {

// placeholderProvider returns the placeholder text handler for this entry
func (e *Entry) placeholderProvider() *RichText {
if e.placeholder != nil {
return e.placeholder
if len(e.placeholder.Segments) != 0 {
return &e.placeholder
}

style := RichTextStyleInline
style.ColorName = theme.ColorNamePlaceHolder
style.TextStyle = e.TextStyle
text := NewRichText(&TextSegment{
Style: style,
Text: e.PlaceHolder,
})
text.ExtendBaseWidget(text)
text.inset = fyne.NewSize(0, theme.InputBorderSize())
e.placeholder = text
return e.placeholder
e.placeholder.Segments = []RichTextSegment{&TextSegment{Style: style, Text: e.PlaceHolder}}
e.placeholder.Scroll = widget.ScrollNone
e.placeholder.inset = fyne.NewSize(0, theme.InputBorderSize())
return &e.placeholder
}

func (e *Entry) registerShortcut() {
Expand Down Expand Up @@ -1359,19 +1355,18 @@ func (e *Entry) syncSegments() {

// textProvider returns the text handler for this entry
func (e *Entry) textProvider() *RichText {
if e.text != nil {
return e.text
if len(e.text.Segments) != 0 {
return &e.text
}

if e.Text != "" {
e.dirty = true
}

text := NewRichTextWithText(e.Text)
text.ExtendBaseWidget(text)
text.inset = fyne.NewSize(0, theme.InputBorderSize())
e.text = text
return e.text
e.text.Scroll = widget.ScrollNone
e.text.Segments = []RichTextSegment{&TextSegment{Style: RichTextStyleInline, Text: e.Text}}
e.text.inset = fyne.NewSize(0, theme.InputBorderSize())
return &e.text
}

// textWrap calculates the wrapping that we should apply.
Expand Down

0 comments on commit 41118fe

Please sign in to comment.