-
-
Notifications
You must be signed in to change notification settings - Fork 214
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
feature/Support for multiple styles in same text #447
base: master
Are you sure you want to change the base?
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe NewSubText should be in text package also as NewCustomText.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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?
@@ -48,6 +48,10 @@ func (g *provider) AddText(text string, cell *entity.Cell, prop *props.Text) { | |||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice !! In the next issues I resolve I will keep an eye out for places where we can use it
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,should
naming pattern.m := mocks.NewConstructor(t)
.m.EXPECT().MethodName()
method to mock methods.example_test.go
.make dod
with none issues pointed out bygolangci-lint