Split into category packages; module github.com/ZacharyZhang-NY/MujicaUI

This commit is contained in:
ZacharyZhang-NY committed 2026-10-05 16:18:48 -04:00
1 parent 5a7e921c7e
commit 22b53e9e9e
1822 files changed
+24568 -21314

No files matched your search

+31 -29
View File
@@ -7,7 +7,9 @@ import (
"github.com/egoist/mygo/ui"
mujica "mujicaui"
"github.com/ZacharyZhang-NY/MujicaUI/core"
"github.com/ZacharyZhang-NY/MujicaUI/data"
"github.com/ZacharyZhang-NY/MujicaUI/input"
)
func dataCardDemo(c *ui.Context, log func(string)) {
@@ -23,15 +25,15 @@ func dataCardDemo(c *ui.Context, log func(string)) {
ui.Checkbox(c, &s.footer, "Footer")
})
card := func(decorated bool) {
opts := mujica.CardOptions{Title: s.title, Decorated: decorated}
opts := data.CardOptions{Title: s.title, Decorated: decorated}
if s.footer {
opts.Footer = func() {
if mujica.Button(c, "Open", mujica.ButtonOptions{Variant: mujica.Secondary}).Clicked() {
if input.Button(c, "Open", input.ButtonOptions{Variant: input.Secondary}).Clicked() {
log(fmt.Sprintf("open clicked (decorated=%v)", decorated))
}
}
}
mujica.Card(c, opts, func() {
data.Card(c, opts, func() {
ui.Text(c, "Letters of the court, sealed in wine-red wax and kept in the north vault.")
}).Width(280)
}
@@ -53,21 +55,21 @@ func dataAccordionDemo(c *ui.Context, log func(string)) {
dataControls(c, func() {
ui.Checkbox(c, &s.multiple, "Multiple")
ui.Checkbox(c, &s.keepOne, "Keep one open")
if mujica.Button(c, "Close all", mujica.ButtonOptions{Variant: mujica.Ghost}).Clicked() {
if input.Button(c, "Close all", input.ButtonOptions{Variant: input.Ghost}).Clicked() {
s.open = nil
log("closed all from outside")
}
})
r := mujica.Accordion(c, &s.open, []mujica.AccordionItem{
r := data.Accordion(c, &s.open, []data.AccordionItem{
{ID: "choir", Title: "Choir", Content: func() { ui.Text(c, "Twelve voices, two at the altar.") }},
{ID: "nave", Title: "Nave", Content: func() { ui.Text(c, "Pews of black oak, polished for the feast.") }},
{ID: "crypt", Title: "Crypt (disabled)", Disabled: true, Content: func() {}},
{ID: "bells", Title: "Bells", Content: func() {
if mujica.Button(c, "Ring", mujica.ButtonOptions{}).Clicked() {
if input.Button(c, "Ring", input.ButtonOptions{}).Clicked() {
log("ring the bells")
}
}},
}, mujica.AccordionOptions{Multiple: s.multiple, KeepOne: s.keepOne})
}, data.AccordionOptions{Multiple: s.multiple, KeepOne: s.keepOne})
r.Element.Width(420)
if r.Changed() {
log(fmt.Sprintf("open %v", s.open))
@@ -80,15 +82,15 @@ func dataCollapsibleDemo(c *ui.Context, log func(string)) {
s := ui.Local(c.Root(), "075", func() state { return state{} })
dataSection(c, "Collapsible", func() {
dataControls(c, func() {
if mujica.Button(c, "Open from outside", mujica.ButtonOptions{Variant: mujica.Secondary}).Clicked() {
if input.Button(c, "Open from outside", input.ButtonOptions{Variant: input.Secondary}).Clicked() {
s.open = true
log("opened from outside")
}
ui.Checkbox(c, &s.disabled, "Disabled")
})
if mujica.Collapsible(c, &s.open, mujica.CollapsibleOptions{Title: "Rites of the evening", Disabled: s.disabled}, func() {
if data.Collapsible(c, &s.open, data.CollapsibleOptions{Title: "Rites of the evening", Disabled: s.disabled}, func() {
ui.Text(c, "Candles are lit at the seventh bell; the choir enters from the north door.")
if mujica.Button(c, "Light candles", mujica.ButtonOptions{Variant: mujica.Outline}).Clicked() {
if input.Button(c, "Light candles", input.ButtonOptions{Variant: input.Outline}).Clicked() {
log("light candles")
}
}).Changed() {
@@ -98,25 +100,25 @@ func dataCollapsibleDemo(c *ui.Context, log func(string)) {
}
func dataTimelineDemo(c *ui.Context, log func(string)) {
type state struct{ items []mujica.TimelineItem }
type state struct{ items []data.TimelineItem }
s := ui.Local(c.Root(), "076", func() state {
return state{items: []mujica.TimelineItem{
{Time: "06:00", Title: "Matins sung", Content: "The choir gathered before dawn.", Status: mujica.TimelineDone},
{Time: "09:00", Title: "Relics moved", Status: mujica.TimelineActive,
return state{items: []data.TimelineItem{
{Time: "06:00", Title: "Matins sung", Content: "The choir gathered before dawn.", Status: data.TimelineDone},
{Time: "09:00", Title: "Relics moved", Status: data.TimelineActive,
Content: "The reliquaries travel from the crypt to the high altar, carried in procession by four acolytes in black and wine."},
{Time: "12:00", Title: "Bell cracked", Status: mujica.TimelineError},
{Time: "15:00", Title: "Storm warning", Status: mujica.TimelineWarning},
{Time: "12:00", Title: "Bell cracked", Status: data.TimelineError},
{Time: "15:00", Title: "Storm warning", Status: data.TimelineWarning},
{Time: "18:00", Title: "Vespers"},
}}
})
dataSection(c, "Timeline", func() {
dataControls(c, func() {
if mujica.Button(c, "Add event", mujica.ButtonOptions{Variant: mujica.Secondary}).Clicked() {
s.items = append(s.items, mujica.TimelineItem{Time: fmt.Sprintf("%02d:00", 19+len(s.items)%5), Title: "Compline"})
if input.Button(c, "Add event", input.ButtonOptions{Variant: input.Secondary}).Clicked() {
s.items = append(s.items, data.TimelineItem{Time: fmt.Sprintf("%02d:00", 19+len(s.items)%5), Title: "Compline"})
log(fmt.Sprintf("%d events", len(s.items)))
}
})
ui.Column(c).Width(420).Children(func() { mujica.Timeline(c, s.items) })
ui.Column(c).Width(420).Children(func() { data.Timeline(c, s.items) })
})
}
@@ -134,12 +136,12 @@ func dataDescriptionDemo(c *ui.Context, log func(string)) {
})
cols, _ := strconv.Atoi(s.columns)
ui.Column(c).Width(float32(s.width)).Children(func() {
if i, ok := mujica.DescriptionList(c, []mujica.DescriptionItem{
if i, ok := data.DescriptionList(c, []data.DescriptionItem{
{Label: "Archivist", Value: "Sister Agnès", Copyable: true},
{Label: "Shelf", Value: "North vault, row 7"},
{Label: "Catalogue", Value: "MS-1347-B", Copyable: true},
{Label: "Seal", Value: "Wine-red wax, cracked at the rim", Span: -1},
}, mujica.DescriptionListOptions{Columns: cols}).Copied(); ok {
}, data.DescriptionListOptions{Columns: cols}).Copied(); ok {
log(fmt.Sprintf("copied item %d", i))
}
})
@@ -166,22 +168,22 @@ func dataStatisticDemo(c *ui.Context, log func(string)) {
change := s.change
dataStates(c, func(state func(string, func())) {
state("With change", func() {
mujica.Statistic(c, s.value, mujica.StatisticOptions{Title: "Pilgrims", Unit: "souls", Precision: p,
data.Statistic(c, s.value, data.StatisticOptions{Title: "Pilgrims", Unit: "souls", Precision: p,
Change: &change, ChangeUnit: "%", ChangeNote: "vs last feast"})
})
state("Prefix", func() {
mujica.Statistic(c, s.value/1000, mujica.StatisticOptions{Title: "Tithe", Prefix: "£", Suffix: "k", Precision: p})
data.Statistic(c, s.value/1000, data.StatisticOptions{Title: "Tithe", Prefix: "£", Suffix: "k", Precision: p})
})
})
})
}
var dataPictures = func() []mujica.ViewerImage {
var dataPictures = func() []data.ViewerImage {
art := func(bg, fg string, shape string) *ui.SVG {
return ui.MustParseSVG([]byte(`<svg xmlns="http://www.w3.org/2000/svg" width="480" height="320"><rect width="480" height="320" fill="` + bg + `"/>` +
`<path d="` + shape + `" fill="` + fg + `"/></svg>`))
}
return []mujica.ViewerImage{
return []data.ViewerImage{
{Source: art("#AD9164", "#7D2034", "M240 40 L380 160 L240 280 L100 160 Z"), Alt: "Rose window"},
{Source: art("#211C1D", "#BDA172", "M80 280 L80 120 L240 40 L400 120 L400 280 Z"), Alt: "Chapel arch"},
{Source: art("#F2EBDD", "#651729", "M60 60 H420 V100 H60 Z M60 140 H420 V180 H60 Z M60 220 H420 V260 H60 Z"), Alt: "Choir stalls"},
@@ -195,7 +197,7 @@ func dataViewerDemo(c *ui.Context, log func(string)) {
}
s := ui.Local(c.Root(), "079", func() state { return state{} })
dataSection(c, "ImageViewer", func() {
k := mujica.Tokens(c)
k := core.Tokens(c)
ui.Text(c, "Choose a picture to open the viewer.").TextColor(k.TextMuted)
ui.Row(c).Gap(12).Children(func() {
for i, p := range dataPictures {
@@ -208,7 +210,7 @@ func dataViewerDemo(c *ui.Context, log func(string)) {
}
})
wasOpen := s.open
if mujica.ImageViewer(c, &s.open, &s.index, dataPictures).Changed() {
if data.ImageViewer(c, &s.open, &s.index, dataPictures).Changed() {
log(fmt.Sprintf("image %d", s.index+1))
}
if wasOpen && !s.open {
@@ -234,7 +236,7 @@ func dataCarouselDemo(c *ui.Context, log func(string)) {
if err != nil {
panic(err)
}
v := mujica.Carousel(c, &s.index, len(dataPictures), mujica.CarouselOptions{Label: "Windows", Autoplay: s.autoplay, Loop: s.loop, Interval: d}, func(i int) {
v := data.Carousel(c, &s.index, len(dataPictures), data.CarouselOptions{Label: "Windows", Autoplay: s.autoplay, Loop: s.loop, Interval: d}, func(i int) {
ui.Image(c, dataPictures[i].Source).Grow(1).Label(dataPictures[i].Alt)
})
v.Element.Size(520, 300)