Skip to content

Commit

Permalink
app: replace imgui.font with giu.fontinfo; fix certain panics
Browse files Browse the repository at this point in the history
  • Loading branch information
gucio321 committed Aug 15, 2021
1 parent 3f062d5 commit a5f2230
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 66 deletions.
9 changes: 4 additions & 5 deletions hsapp/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"time"

g "github.com/AllenDang/giu"
"github.com/AllenDang/imgui-go"

"github.com/OpenDiablo2/dialog"
"github.com/go-gl/glfw/v3.3/glfw"
Expand Down Expand Up @@ -89,10 +88,10 @@ type App struct {
editorManagerMutex sync.RWMutex
focusedEditor hscommon.EditorWindow

fontFixed imgui.Font
fontFixedSmall imgui.Font
diabloBoldFont imgui.Font
diabloRegularFont imgui.Font
fontFixed *g.FontInfo
fontFixedSmall *g.FontInfo
diabloBoldFont *g.FontInfo
diabloRegularFont *g.FontInfo

TextureLoader hscommon.TextureLoader

Expand Down
29 changes: 6 additions & 23 deletions hsapp/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"github.com/faiface/beep/speaker"

g "github.com/AllenDang/giu"
"github.com/AllenDang/imgui-go"

"github.com/OpenDiablo2/HellSpawner/hswindow/hseditor/hsds1editor"
"github.com/OpenDiablo2/HellSpawner/hswindow/hseditor/hsdt1editor"
Expand Down Expand Up @@ -207,45 +206,29 @@ func (a *App) setupDialogs() error {
// it will only load an appropriate glyph ranges for
// displayed text (e.g. for string/font table editors)
func (a *App) setupFonts() {
fonts := g.Context.IO().Fonts()
ranges := imgui.NewGlyphRanges()
builder := imgui.NewFontGlyphRangesBuilder()

builder.AddRanges(fonts.GlyphRangesDefault())

font := hsassets.FontNotoSansRegular

switch a.config.Locale {
// glyphs supported by default
case hsenum.LocaleEnglish, hsenum.LocaleGerman,
hsenum.LocaleFrench, hsenum.LocaleItalien,
hsenum.LocaleSpanish:
hsenum.LocaleSpanish, hsenum.LocalePolish:
// noop
case hsenum.LocaleChineseTraditional:
font = hsassets.FontSourceHanSerif

builder.AddRanges(fonts.GlyphRangesChineseFull())
case hsenum.LocaleKorean:
font = hsassets.FontSourceHanSerif

builder.AddRanges(fonts.GlyphRangesKorean())
case hsenum.LocalePolish:
builder.AddText(hsenum.PolishSpecialCharacters)
}

// build ranges
builder.BuildRanges(ranges)

// setup default font
fonts.AddFontFromMemoryTTFV(font, baseFontSize, 0, ranges.Data())
g.SetDefaultFontFromBytes(font, baseFontSize)

// please note, that the following fonts will not use
// previously generated glyph ranges.
// they'll have a default range
a.fontFixed = fonts.AddFontFromMemoryTTF(hsassets.FontCascadiaCode, fixedFontSize)
a.fontFixedSmall = fonts.AddFontFromMemoryTTF(hsassets.FontCascadiaCode, fixedSmallFontSize)
a.diabloRegularFont = fonts.AddFontFromMemoryTTF(hsassets.FontDiabloRegular, diabloRegularFontSize)
a.diabloBoldFont = fonts.AddFontFromMemoryTTF(hsassets.FontDiabloBold, diabloBoldFontSize)
a.fontFixed = g.AddFontFromBytes("fixed font", hsassets.FontCascadiaCode, fixedFontSize)
a.fontFixedSmall = g.AddFontFromBytes("small fixed font", hsassets.FontCascadiaCode, fixedSmallFontSize)
a.diabloRegularFont = g.AddFontFromBytes("diablo regular", hsassets.FontDiabloRegular, diabloRegularFontSize)
a.diabloBoldFont = g.AddFontFromBytes("diablo bold", hsassets.FontDiabloBold, diabloBoldFontSize)
}

func (a *App) registerGlobalKeyboardShortcuts() {
Expand Down
45 changes: 19 additions & 26 deletions hswindow/hsdialog/hsaboutdialog/aboutdialog.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"strings"

g "github.com/AllenDang/giu"
"github.com/AllenDang/imgui-go"
"github.com/jaytaylor/html2text"
"github.com/russross/blackfriday"

Expand All @@ -29,17 +28,17 @@ const (
// AboutDialog represents about dialog
type AboutDialog struct {
*hsdialog.Dialog
titleFont imgui.Font
regularFont imgui.Font
fixedFont imgui.Font
titleFont *g.FontInfo
regularFont *g.FontInfo
fixedFont *g.FontInfo
credits string
license string
readme string
logo *g.Texture
}

// Create creates a new AboutDialog
func Create(textureLoader hscommon.TextureLoader, regularFont, titleFont, fixedFont imgui.Font) (*AboutDialog, error) {
func Create(textureLoader hscommon.TextureLoader, regularFont, titleFont, fixedFont *g.FontInfo) (*AboutDialog, error) {
result := &AboutDialog{
Dialog: hsdialog.New("About HellSpawner"),
titleFont: titleFont,
Expand Down Expand Up @@ -95,35 +94,29 @@ func (a *AboutDialog) Build() {
g.Image(a.logo).Size(mainWindowW, mainWindowH),
g.Child().Size(mainLayoutW, mainLayoutH).Layout(
g.Style().SetColor(g.StyleColorText, colorWhite).To(
g.Custom(func() { imgui.PushFont(a.titleFont) }),
g.Label("HellSpawner"),
g.Custom(func() { imgui.PopFont() }),
g.Custom(func() { imgui.PushFont(a.regularFont) }),
g.Label("The OpenDiablo 2 Toolset"),
g.Custom(func() { imgui.PopFont() }),
g.Custom(func() { imgui.PushFont(a.fixedFont) }),
g.Label("Local Build"),
g.Custom(func() { imgui.PopFont() }),
g.Label("HellSpawner").Font(a.titleFont),
g.Label("The OpenDiablo 2 Toolset").Font(a.regularFont),
g.Label("Local Build").Font(a.fixedFont),
),
g.Separator(),
g.TabBar().Flags(g.TabBarFlagsNoCloseWithMiddleMouseButton).TabItems(
g.TabItem("README##AboutHellSpawner").Layout(
g.Custom(func() { imgui.PushFont(a.fixedFont) }),
g.InputTextMultiline(&a.readme).
Size(-1, -1).Flags(g.InputTextFlagsReadOnly|g.InputTextFlagsNoHorizontalScroll),
g.Custom(func() { imgui.PopFont() }),
g.Style().SetFont(a.fixedFont).To(
g.InputTextMultiline(&a.readme).
Size(-1, -1).Flags(g.InputTextFlagsReadOnly|g.InputTextFlagsNoHorizontalScroll),
),
),
g.TabItem("Credits##AboutHellSpawner").Layout(
g.Custom(func() { imgui.PushFont(a.fixedFont) }),
g.InputTextMultiline(&a.credits).
Size(-1, -1).Flags(g.InputTextFlagsReadOnly|g.InputTextFlagsNoHorizontalScroll),
g.Custom(func() { imgui.PopFont() }),
g.Style().SetFont(a.fixedFont).To(
g.InputTextMultiline(&a.credits).
Size(-1, -1).Flags(g.InputTextFlagsReadOnly|g.InputTextFlagsNoHorizontalScroll),
),
),
g.TabItem("Licenses##AboutHellSpawner").Layout(
g.Custom(func() { imgui.PushFont(a.fixedFont) }),
g.InputTextMultiline(&a.license).
Size(-1, -1).Flags(g.InputTextFlagsReadOnly|g.InputTextFlagsNoHorizontalScroll),
g.Custom(func() { imgui.PopFont() }),
g.Style().SetFont(a.fixedFont).To(
g.InputTextMultiline(&a.license).
Size(-1, -1).Flags(g.InputTextFlagsReadOnly|g.InputTextFlagsNoHorizontalScroll),
),
),
),
),
Expand Down
19 changes: 7 additions & 12 deletions hswindow/hstoolwindow/hsconsole/console.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"os"

g "github.com/AllenDang/giu"
"github.com/AllenDang/imgui-go"

"github.com/OpenDiablo2/HellSpawner/hscommon/hsstate"
"github.com/OpenDiablo2/HellSpawner/hswindow/hstoolwindow"
Expand All @@ -21,12 +20,12 @@ const (
type Console struct {
*hstoolwindow.ToolWindow
outputText string
fontFixed imgui.Font
fontFixed *g.FontInfo
logFile *os.File
}

// Create creates a new console
func Create(fontFixed imgui.Font, x, y float32, logFile *os.File) *Console {
func Create(fontFixed *g.FontInfo, x, y float32, logFile *os.File) *Console {
result := &Console{
fontFixed: fontFixed,
ToolWindow: hstoolwindow.New("Console", hsstate.ToolWindowTypeConsole, x, y),
Expand All @@ -44,15 +43,11 @@ func Create(fontFixed imgui.Font, x, y float32, logFile *os.File) *Console {
func (c *Console) Build() {
c.IsOpen(&c.Visible).
Layout(g.Layout{
g.Custom(func() {
imgui.PushFont(c.fontFixed)
}),
g.InputTextMultiline(&c.outputText).
Size(lineW, lineH).
Flags(g.InputTextFlagsReadOnly | g.InputTextFlagsNoUndoRedo),
g.Custom(func() {
g.PopFont()
}),
g.Style().SetFont(c.fontFixed).To(
g.InputTextMultiline(&c.outputText).
Size(lineW, lineH).
Flags(g.InputTextFlagsReadOnly | g.InputTextFlagsNoUndoRedo),
),
})
}

Expand Down

0 comments on commit a5f2230

Please sign in to comment.