~ghost08: 1 Add richtext 3 files changed, 83 insertions(+), 14 deletions(-)
Copy & paste the following snippet into your terminal to import this patchset into git:
curl -s https://lists.sr.ht/~eliasnaur/gio/patches/22947/mbox | git am -3Learn more about email & git
From: Vladimir Magyar <magyarv@protonmail.com> --- README.md | 23 ++++++------- richtext/README.md | 70 ++++++++++++++++++++++++++++++++++++++++ richtext/example/main.go | 4 +-- 3 files changed, 83 insertions(+), 14 deletions(-) create mode 100644 richtext/README.md diff --git a/README.md b/README.md index 8b00352..3b14d20 100644 --- a/README.md +++ b/README.md @@ -6,17 +6,18 @@ This repository hosts `gioui.org/x`. Two kinds of package exist in this namespac This table describes the current status of each package in `gioui.org/x`: -| Name | Purpose | Intended for core? | Non-core dependencies? | API Stability | -| --- | --- | --- | --- | --- | -| colorpicker | Widgets for choosing colors | uncertain | no | unstable | -| component | Material.io components | uncertain | no | unstable | -| eventx | Event management tools | yes | no | unstable | -| haptic | Haptic feedback for mobile devices | no | yes | unstable | -| notify | Background notifications | no | yes | unstable | -| outlay | Extra layouts | yes | no | unstable | -| pref | Query user/device preferences | no | yes | unstable | -| profiling | Gio render performance recording tools | uncertain | no | unstable | -| scroll | Scrollbar widget for Gio | yes | no | unstable | +| Name | Purpose | Intended for core? | Non-core dependencies? | API Stability | +| ----------- | ------------------------------------------- | ------------------ | ---------------------- | ------------- | +| colorpicker | Widgets for choosing colors | uncertain | no | unstable | +| component | Material.io components | uncertain | no | unstable | +| eventx | Event management tools | yes | no | unstable | +| haptic | Haptic feedback for mobile devices | no | yes | unstable | +| notify | Background notifications | no | yes | unstable | +| outlay | Extra layouts | yes | no | unstable | +| pref | Query user/device preferences | no | yes | unstable | +| profiling | Gio render performance recording tools | uncertain | no | unstable | +| scroll | Scrollbar widget for Gio | yes | no | unstable | +| richtext | Printing text objects with different styles | uncertain | no | unstable | ## Contributing diff --git a/richtext/README.md b/richtext/README.md new file mode 100644 index 0000000..d089bc8 --- /dev/null +++ b/richtext/README.md @@ -0,0 +1,70 @@ +# richtext + +Provides a widget that renders text in different styles. + +``` +var ( + fontCollection = gofont.Collection() + shaper = text.NewCache(fontCollection) + rt = richtext.TextObjects{ + { + Font: fontCollection[1].Font, + Color: color.NRGBA{R: 0, G: 255, B: 0, A: 255}, + Size: unit.Dp(25), + Content: "Vivamus integer non suscipit taciti mus etiam at primis tempor sagittis sit, euismod libero facilisi aptent elementum felis blandit cursus gravida sociis erat ante, eleifend lectus nullam dapibus netus feugiat curae curabitur est ad ", + }, + { + Font: fontCollection[2].Font, + Color: color.NRGBA{R: 255, G: 0, B: 0, A: 255}, + Size: unit.Dp(32), + Clickable: true, + Content: "CLICKABLE", + }, + { + Font: fontCollection[4].Font, + Color: color.NRGBA{R: 0, G: 0, B: 255, A: 255}, + Size: unit.Dp(20), + Content: `Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec volutpat ex a massa hendrerit sodales. Maecenas eget ullamcorper nulla. Suspendisse tincidunt sapien sit amet lorem tincidunt. + +Sed mattis hendrerit ex. Curabitur dignissim ante turpis, ut euismod purus consequat ut. Etiam eget vulputate nibh. Ut sollicitudin ipsum volutpat leo tincidunt, et suscipit purus malesuada. Cras pulvinar lectus id ipsum congue, pretium mattis tellus auctor. Nunc faucibus interdum risus, at maximus ex pellentesque non. Cras lectus ex, ullamcorper eu felis ut, suscipit placerat sem. Vestibulum ex libero, lobortis et consectetur eu, semper vitae mauris. Pellentesque cursus massa in efficitur porta.`, + }, + { + Font: fontCollection[0].Font, + Color: color.NRGBA{R: 0, G: 0, B: 0, A: 255}, + Size: unit.Dp(22), + Content: "Mollis pretium lorem primis senectus habitasse lectus scelerisque donec, ultricies tortor ", + }, + } +) + +func main() { + log.SetFlags(log.Lshortfile | log.LstdFlags) + go func() { + w := app.NewWindow() + if err := loop(w); err != nil { + log.Fatal(err) + } + os.Exit(0) + }() + app.Main() +} + +func loop(w *app.Window) error { + var ops op.Ops + for { + e := <-w.Events() + switch e := e.(type) { + case system.DestroyEvent: + return e.Err + case system.FrameEvent: + gtx := layout.NewContext(&ops, e) + //get the clicked TextObject + if obj := rt.Clicked(); obj != nil { + log.Println(obj) + } + rt.Layout(gtx, shaper) + e.Frame(gtx.Ops) + } + } +} +``` diff --git a/richtext/example/main.go b/richtext/example/main.go index 3c8df32..ea0dd0d 100644 --- a/richtext/example/main.go +++ b/richtext/example/main.go @@ -16,14 +16,12 @@ import ( "gioui.org/op" "gioui.org/text" "gioui.org/unit" - "gioui.org/widget/material" - "gitlab.com/microo8/richtext" + "gioui.org/x/richtext" ) var ( fontCollection = gofont.Collection() shaper = text.NewCache(fontCollection) - th = material.NewTheme(fontCollection) rt = richtext.TextObjects{ { Font: fontCollection[1].Font, -- 2.30.2