Skip to content

Commit

Permalink
gio backend support
Browse files Browse the repository at this point in the history
Enable with build tag nucular_gio
  • Loading branch information
aarzilli committed Nov 21, 2019
1 parent dffd835 commit d1201ee
Show file tree
Hide file tree
Showing 27 changed files with 1,826 additions and 1,043 deletions.
10 changes: 4 additions & 6 deletions _examples/demo/demo.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,12 @@ import (
"time"

"github.com/aarzilli/nucular"
"github.com/aarzilli/nucular/font"
"github.com/aarzilli/nucular/label"
"github.com/aarzilli/nucular/rect"
nstyle "github.com/aarzilli/nucular/style"
"github.com/aarzilli/nucular/style-editor"
"github.com/golang/freetype"
"github.com/golang/freetype/truetype"

"golang.org/x/image/font"
"golang.org/x/mobile/event/key"
)

Expand Down Expand Up @@ -127,11 +125,11 @@ func main() {

normalFontData, normerr := ioutil.ReadFile("demofont.ttf")
if normerr == nil {
normalTtfont, normerr := freetype.ParseFont(normalFontData)
szf := 12 * scaling
face, normerr := font.NewFace(normalFontData, int(szf))
if normerr == nil {
style := Wnd.Style()
szf := 12 * scaling
style.Font = truetype.NewFace(normalTtfont, &truetype.Options{Size: float64(int(szf)), Hinting: font.HintingFull, DPI: 72})
style.Font = face
}
}

Expand Down
17 changes: 5 additions & 12 deletions _examples/richtext/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ import (
"github.com/aarzilli/nucular/style"

"github.com/aarzilli/nucular/_examples/richtext/internal/assets"
"github.com/golang/freetype"
"github.com/golang/freetype/truetype"
"golang.org/x/image/font"
"github.com/aarzilli/nucular/font"
)

//go:generate go-bindata -o internal/assets/assets.go -pkg assets DejaVuSans.ttf DejaVuSans-Bold.ttf DejaVuSans-Oblique.ttf
Expand All @@ -34,20 +32,15 @@ func main() {
wnd.SetStyle(style.FromTheme(style.DarkTheme, 2.0))

regularData, _ := assets.Asset("DejaVuSans.ttf")
ttfRegular, _ := freetype.ParseFont(regularData)

boldData, _ := assets.Asset("DejaVuSans-Bold.ttf")
ttfBold, _ := freetype.ParseFont(boldData)

italicData, _ := assets.Asset("DejaVuSans-Oblique.ttf")
ttfItalic, _ := freetype.ParseFont(italicData)

proportional = truetype.NewFace(ttfRegular, &truetype.Options{Size: float64(int(float64(12) * wnd.Style().Scaling)), Hinting: font.HintingFull, DPI: 72})
header = truetype.NewFace(ttfRegular, &truetype.Options{Size: float64(int(float64(21) * wnd.Style().Scaling)), Hinting: font.HintingFull, DPI: 72})
proportional, _ = font.NewFace(regularData, int(float64(12)*wnd.Style().Scaling))
header, _ = font.NewFace(regularData, int(float64(21)*wnd.Style().Scaling))
monospace = wnd.Style().Font

bold = truetype.NewFace(ttfBold, &truetype.Options{Size: float64(int(float64(12) * wnd.Style().Scaling)), Hinting: font.HintingFull, DPI: 72})
italic = truetype.NewFace(ttfItalic, &truetype.Options{Size: float64(int(float64(12) * wnd.Style().Scaling)), Hinting: font.HintingFull, DPI: 72})
bold, _ = font.NewFace(boldData, int(float64(12)*wnd.Style().Scaling))
italic, _ = font.NewFace(italicData, int(float64(12)*wnd.Style().Scaling))

searchEd.Flags = nucular.EditField

Expand Down
19 changes: 1 addition & 18 deletions command/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@ import (
"image"
"image/color"

"github.com/aarzilli/nucular/font"
"github.com/aarzilli/nucular/rect"

"golang.org/x/image/font"
)

// CommandBuffer is a list of drawing directives.
Expand Down Expand Up @@ -69,10 +68,6 @@ type CircleFilled struct {
Color color.RGBA
}

type Image struct {
Img *image.RGBA
}

type Text struct {
Face font.Face
Foreground color.RGBA
Expand Down Expand Up @@ -152,18 +147,6 @@ func (b *Buffer) FillTriangle(p0, p1, p2 image.Point, c color.RGBA) {
b.Commands = append(b.Commands, cmd)
}

func (b *Buffer) DrawImage(r rect.Rect, img *image.RGBA) {
if !r.Intersect(&b.Clip) {
return
}

var cmd Command
cmd.Kind = ImageCmd
cmd.Rect = r
cmd.Image.Img = img
b.Commands = append(b.Commands, cmd)
}

func (b *Buffer) DrawText(r rect.Rect, str string, face font.Face, fg color.RGBA) {
if len(str) == 0 || (fg.A == 0) {
return
Expand Down
26 changes: 26 additions & 0 deletions command/command_gio.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// +build nucular_gio

package command

import (
"image"

"gioui.org/op/paint"
"github.com/aarzilli/nucular/rect"
)

type Image struct {
Img paint.ImageOp
}

func (b *Buffer) DrawImage(r rect.Rect, img *image.RGBA) {
if !r.Intersect(&b.Clip) {
return
}

var cmd Command
cmd.Kind = ImageCmd
cmd.Rect = r
cmd.Image.Img = paint.NewImageOp(img)
b.Commands = append(b.Commands, cmd)
}
24 changes: 24 additions & 0 deletions command/command_shiny.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// +build !nucular_gio

package command

import (
"github.com/aarzilli/nucular/rect"
"image"
)

type Image struct {
Img *image.RGBA
}

func (b *Buffer) DrawImage(r rect.Rect, img *image.RGBA) {
if !r.Intersect(&b.Clip) {
return
}

var cmd Command
cmd.Kind = ImageCmd
cmd.Rect = r
cmd.Image.Img = img
b.Commands = append(b.Commands, cmd)
}
Loading

0 comments on commit d1201ee

Please sign in to comment.