feature/Support for multiple styles in same text#447
Conversation
Update interface to include a method that will add subtexts
Create a structure of subtexts within texts, making each subtext have its own personalized style.
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #447 +/- ##
==========================================
- Coverage 85.71% 83.38% -2.33%
==========================================
Files 61 62 +1
Lines 2155 2243 +88
==========================================
+ Hits 1847 1870 +23
- Misses 281 346 +65
Partials 27 27
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
johnfercher
left a comment
There was a problem hiding this comment.
I will do a better review tomorrow, I have to download you fork and see the implementation better in text component.
| subText1 := entity.NewSubText("This is a text", props.SubText{Color: &props.BlueColor}) | ||
| subText2 := entity.NewSubText(" with multiple", props.SubText{Size: 7}) | ||
| subText3 := entity.NewSubText(" styles", props.SubText{Color: &props.RedColor}) |
There was a problem hiding this comment.
Maybe NewSubText should be in text package also as NewCustomText.
There was a problem hiding this comment.
I tried to do it this way, but the provider depends on the subText structure and if I declare the subtext in the Text package, it generates a cyclical dependency.
I think this would be possible if we remove the dependency that the provider has on subtext, but I don't know how to do this in a nice way
| subText2 := entity.NewSubText(" with multiple", props.SubText{Size: 7}) | ||
| subText3 := entity.NewSubText(" styles", props.SubText{Color: &props.RedColor}) | ||
|
|
||
| customText := col.New(12).Add(text.NewCustomText([]*entity.SubText{subText1, subText2, subText3})) |
There was a problem hiding this comment.
Maybe we could change the Add([]text) to Add(text...). With a vargar we can still pass an array with as NewCustomText(arr...) and we can pass each one as this NewCustomText(subText1, subText2, subText3) this is a more extensible and idiomatic way to work with collections in go.
There was a problem hiding this comment.
I agree, this way is better. The only issue is that NewCustomText also needs to receive text.Props and I'm already using vararg in this parameter, but I agree that using vargar in the subText parameter is better. The function call would look like this: NewCustomText(props.Text{}, subText1, subText2, subText3), do you think it looks good this way?
| g.text.Add(text, cell, prop) | ||
| } | ||
|
|
||
| func (g *provider) AddCustomText(subs []*entity.SubText, cell *entity.Cell, textPs *props.Text) { |
There was a problem hiding this comment.
Same comment here. vararg instea of array.
| // This method is responsible for allowing the union of a set of subtexts in the same text | ||
| func (s *text) AddCustomText(subs []*entity.SubText, cell *entity.Cell, textPs *props.Text) { | ||
| originalColor := s.font.GetColor() | ||
| defer s.font.SetColor(originalColor) |
There was a problem hiding this comment.
Awesome use of defer...I'm thinking that I should do this more in some places here too. xD
There was a problem hiding this comment.
Nice !! In the next issues I resolve I will keep an eye out for places where we can use it
|
I know this PR has been sitting around a while but what is the likely hood of it finally getting merged? Not being able to do hyperlinks or bolded words in the middle of sentences is super limiting |
Hi, sorry for the delay. Just to update you on the status of this PR: this week, I will resolve the conflicts to make the merge possible. |
|
When I started resolving the conflicts in this PR, I noticed that many things had changed in Maroto. I realized it would be more efficient and safer to redo this feature and open a new PR: #520 |
Description
This pr allows you to merge different styles in the same text, to do this merge it is necessary that when creating the component, a list of subTexts is sent, each subText with its own style.
Related Issue
#189
Checklist
func (<first letter of struct> *struct) method() {}name style.when,shouldnaming pattern.m := mocks.NewConstructor(t).m.EXPECT().MethodName()method to mock methods.example_test.go.make dodwith none issues pointed out bygolangci-lint