Fix BottomBar text positioning using op.Offset and remove debug logging
Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
This commit is contained in:
parent
4f4e50a13c
commit
1ae02d57fd
|
|
@ -67,11 +67,6 @@ func run(w *app.Window) error {
|
||||||
currentElems := elems
|
currentElems := elems
|
||||||
mu.Unlock()
|
mu.Unlock()
|
||||||
|
|
||||||
log.Println("FrameEvent: rendering", len(currentElems), "elements")
|
|
||||||
for i, elem := range currentElems {
|
|
||||||
log.Println(" Element", i, "type:", typeOf(elem))
|
|
||||||
}
|
|
||||||
|
|
||||||
gtx := app.NewContext(&ops, e)
|
gtx := app.NewContext(&ops, e)
|
||||||
renderer.Draw(gtx, currentElems)
|
renderer.Draw(gtx, currentElems)
|
||||||
e.Frame(&ops)
|
e.Frame(&ops)
|
||||||
|
|
@ -89,20 +84,3 @@ func frameReceiver(w *app.Window, mu *sync.Mutex, elems *[]ui.Element, frameChan
|
||||||
mu.Unlock()
|
mu.Unlock()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func typeOf(v any) string {
|
|
||||||
switch v.(type) {
|
|
||||||
case ui.Label:
|
|
||||||
return "Label"
|
|
||||||
case ui.ListView:
|
|
||||||
return "ListView"
|
|
||||||
case ui.StatusBar:
|
|
||||||
return "StatusBar"
|
|
||||||
case ui.BottomBar:
|
|
||||||
return "BottomBar"
|
|
||||||
case ui.Button:
|
|
||||||
return "Button"
|
|
||||||
default:
|
|
||||||
return "Unknown"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ import (
|
||||||
"image"
|
"image"
|
||||||
|
|
||||||
"gioui.org/layout"
|
"gioui.org/layout"
|
||||||
|
"gioui.org/op"
|
||||||
"gioui.org/op/clip"
|
"gioui.org/op/clip"
|
||||||
"gioui.org/text"
|
"gioui.org/text"
|
||||||
"gioui.org/unit"
|
"gioui.org/unit"
|
||||||
|
|
@ -145,22 +146,25 @@ func (r *Renderer) drawBottomBar(gtx layout.Context, bb BottomBar) {
|
||||||
}.Push(gtx.Ops)
|
}.Push(gtx.Ops)
|
||||||
|
|
||||||
// Left: Cursor position
|
// Left: Cursor position
|
||||||
|
{
|
||||||
cursorX := reg.X + unit.Dp(8)
|
cursorX := reg.X + unit.Dp(8)
|
||||||
gtx.Constraints.Min.X = int(cursorX)
|
op.Offset(image.Point{X: int(cursorX), Y: int(reg.Y)}).Push(gtx.Ops).Pop()
|
||||||
gtx.Constraints.Min.Y = int(reg.Y)
|
|
||||||
material.Label(th, r.theme.FontSize, bb.CursorPos).Layout(gtx)
|
material.Label(th, r.theme.FontSize, bb.CursorPos).Layout(gtx)
|
||||||
|
}
|
||||||
|
|
||||||
// Center: Byte position
|
// Center: Byte position
|
||||||
|
{
|
||||||
byteX := reg.X + reg.W/2 - unit.Dp(60) // approximate center
|
byteX := reg.X + reg.W/2 - unit.Dp(60) // approximate center
|
||||||
gtx.Constraints.Min.X = int(byteX)
|
op.Offset(image.Point{X: int(byteX), Y: int(reg.Y)}).Push(gtx.Ops).Pop()
|
||||||
gtx.Constraints.Min.Y = int(reg.Y)
|
|
||||||
material.Label(th, r.theme.FontSize, bb.BytePos).Layout(gtx)
|
material.Label(th, r.theme.FontSize, bb.BytePos).Layout(gtx)
|
||||||
|
}
|
||||||
|
|
||||||
// Right: Word wrap button
|
// Right: Word wrap button
|
||||||
|
{
|
||||||
wordWrapX := reg.X + reg.W - unit.Dp(120)
|
wordWrapX := reg.X + reg.W - unit.Dp(120)
|
||||||
gtx.Constraints.Min.X = int(wordWrapX)
|
op.Offset(image.Point{X: int(wordWrapX), Y: int(reg.Y)}).Push(gtx.Ops).Pop()
|
||||||
gtx.Constraints.Min.Y = int(reg.Y)
|
|
||||||
material.Label(th, r.theme.FontSize, "[Word Wrap: "+boolToString(bb.WordWrap)+"]").Layout(gtx)
|
material.Label(th, r.theme.FontSize, "[Word Wrap: "+boolToString(bb.WordWrap)+"]").Layout(gtx)
|
||||||
|
}
|
||||||
|
|
||||||
c.Pop()
|
c.Pop()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user