feat: port the client to MyGo native UI (0.3.0)
Switch from Asuka to MyGo, keeping the API client and the feature set: - servers: saved servers, passwordless and password login, proxy, self-signed certificates, per-server device tokens (Keystore), connect form, instance list sheet with switch/disconnect - sessions: virtualized list, search, new session, rename/archive/delete, running indicator, event stream keeps it live - chat: pushed window with system back bar, streaming Markdown via ui/markdown, reasoning and tool rows with image previews, footer menu (read aloud via a Kotlin TTS plugin, copy, fork), user message menu (copy, revert, fork), context usage ring and detail sheet, attachments (photos/files via the document picker), permissions - release builds allow plain http:// LAN servers (Go's net/http dials directly, no cleartext manifest needed) - a local fork of MyGo (third_party/mygo) lowers the Android host's minSdk to 24 (Android 7.0); Go 1.27.4 via mise Version 0.3.0.
This commit is contained in:
1 parent
2fb4a8ea79
commit
6c0ee61750
2538 files changed
+675779
-4792
No files matched your search
+117
@@ -0,0 +1,117 @@
|
||||
package markdown
|
||||
|
||||
import (
|
||||
"github.com/egoist/mygo/ui"
|
||||
"github.com/egoist/mygo/ui/markdown/parser"
|
||||
)
|
||||
|
||||
// tableState keeps a table's column widths, which only grow while the
|
||||
// table is being written, so that its columns do not jump as its cells
|
||||
// fill.
|
||||
type tableState struct {
|
||||
widths []float32
|
||||
seen bool
|
||||
}
|
||||
|
||||
// table builds a table: rows of cells as wide as their column's widest,
|
||||
// up to Theme.TableMaxColumn, which wrap beyond, scrolling sideways when
|
||||
// wider than the view.
|
||||
func (st *viewState) table(c *ui.Context, i int, base spanStyle) ui.Element {
|
||||
d := st.doc
|
||||
th := &st.th
|
||||
b := d.Block(i)
|
||||
if st.tables == nil {
|
||||
st.tables = map[int]*tableState{}
|
||||
}
|
||||
ts := st.tables[b.Start]
|
||||
if ts == nil {
|
||||
ts = &tableState{}
|
||||
st.tables[b.Start] = ts
|
||||
}
|
||||
ts.seen = true
|
||||
cols := len(b.Align)
|
||||
padX, padY := th.em(th.TableCellPadding[0]), th.em(th.TableCellPadding[1])
|
||||
maxW := th.em(th.TableMaxColumn)
|
||||
// The widths of the columns, from their cells' text.
|
||||
widths := make([]float32, cols)
|
||||
if b.Open {
|
||||
copy(widths, ts.widths)
|
||||
}
|
||||
for r := i + 1; r < d.Block(i).Next; r = d.Block(r).Next {
|
||||
row := d.Block(r)
|
||||
k := 0
|
||||
for cell := r + 1; cell < d.Block(r).Next; cell = d.Block(cell).Next {
|
||||
if k >= cols {
|
||||
break
|
||||
}
|
||||
s := base
|
||||
if row.Header {
|
||||
s.weight = th.StrongWeight
|
||||
}
|
||||
p := st.para(cell, s)
|
||||
if !p.measured {
|
||||
p.width, p.measured = 0, true
|
||||
for _, pc := range p.pieces {
|
||||
pw, _ := c.MeasureText(0, pc.spans...)
|
||||
p.width += pw
|
||||
}
|
||||
}
|
||||
widths[k] = max(widths[k], min(p.width, maxW)+2*padX+1)
|
||||
k++
|
||||
}
|
||||
}
|
||||
ts.widths = append(ts.widths[:0], widths...)
|
||||
scroll := ui.ScrollHorizontal(c).AlignSelf(ui.Stretch)
|
||||
return scroll.Children(func() {
|
||||
grid := ui.Column(c).Border(1, th.TableBorder).Radius(th.em(0.3)).Clip().Shrink(0).Role(ui.RoleTable)
|
||||
grid.Children(func() {
|
||||
n := 0
|
||||
for r := i + 1; r < d.Block(i).Next; r = d.Block(r).Next {
|
||||
row := d.Block(r)
|
||||
rowEl := ui.Row(c).Role(ui.RoleRow).AlignItems(ui.Stretch)
|
||||
if row.Header {
|
||||
rowEl.Background(th.TableHeader)
|
||||
} else if n%2 == 1 && th.TableStripe.A > 0 {
|
||||
rowEl.Background(th.TableStripe)
|
||||
}
|
||||
if n > 0 {
|
||||
rowEl.BorderWidth(1, 0, 0, 0).BorderColor(th.TableBorder)
|
||||
}
|
||||
if st.fade != nil && b.Open {
|
||||
if a := st.fade(row.Start); a < 1 {
|
||||
rowEl.Opacity(a)
|
||||
}
|
||||
}
|
||||
header := row.Header
|
||||
rowEl.Children(func() {
|
||||
k := 0
|
||||
for cell := r + 1; cell < d.Block(r).Next; cell = d.Block(cell).Next {
|
||||
if k >= cols {
|
||||
break
|
||||
}
|
||||
s := base
|
||||
role := ui.RoleCell
|
||||
if header {
|
||||
s.weight = th.StrongWeight
|
||||
role = ui.RoleColumnHeader
|
||||
}
|
||||
box := ui.Column(c).Width(widths[k]).Padding(padY, padX).Role(role)
|
||||
if k > 0 {
|
||||
box.BorderWidth(0, 0, 0, 1).BorderColor(th.TableBorder)
|
||||
}
|
||||
align := ui.Start
|
||||
switch b.Align[k] {
|
||||
case parser.AlignCenter:
|
||||
align = ui.Center
|
||||
case parser.AlignRight:
|
||||
align = ui.End
|
||||
}
|
||||
box.Children(func() { st.paragraph(c, cell, s).TextAlign(align) })
|
||||
k++
|
||||
}
|
||||
})
|
||||
n++
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
Reference in new issue
Block a user