Trading: components 161-180
This commit is contained in:
105 files changed
+6042
-1
No files matched your search
@@ -0,0 +1,52 @@
|
||||
package mujica
|
||||
|
||||
import (
|
||||
"github.com/egoist/mygo/ui"
|
||||
|
||||
"mujicaui/theme"
|
||||
)
|
||||
|
||||
// Quote is an instrument's price and change since the close.
|
||||
type Quote struct {
|
||||
Symbol, Name string
|
||||
Price float64
|
||||
Change float64
|
||||
ChangePercent float64
|
||||
}
|
||||
|
||||
// QuoteCardOptions configure a QuoteCard.
|
||||
type QuoteCardOptions struct {
|
||||
// Decimals of the price and change; zero means 2.
|
||||
Decimals int
|
||||
// Chart builds the mini chart slot; nil leaves it out.
|
||||
Chart func()
|
||||
}
|
||||
|
||||
// QuoteCard shows a symbol, name, price, change and mini chart.
|
||||
func QuoteCard(c *ui.Context, q Quote, opts QuoteCardOptions) *ui.Element {
|
||||
if q.Symbol == "" {
|
||||
panic("mujica: QuoteCard needs a Symbol")
|
||||
}
|
||||
dec := priceDecimals("QuoteCard", opts.Decimals)
|
||||
k := Tokens(c)
|
||||
u := Density(c).Unit()
|
||||
e := ui.Column(c).Gap(u*2).Padding(u*4).MinWidth(200).Radius(theme.CardRadius).
|
||||
Background(k.Surface).Border(theme.BorderWidth, k.Border).Role(ui.RoleGroup).Label(q.Symbol)
|
||||
e.Children(func() {
|
||||
ui.Row(c).Gap(u * 2).AlignItems(ui.End).Children(func() {
|
||||
ui.Text(c, q.Symbol).Font(theme.SerifFont).FontSize(FontSize(c, theme.H3Size)).FontWeight(600).SingleLine()
|
||||
if q.Name != "" {
|
||||
ui.Text(c, q.Name).TextColor(k.TextMuted).FontSize(FontSize(c, theme.CaptionSize)).SingleLine().
|
||||
Ellipsis("…").MinWidth(0).Shrink(1)
|
||||
}
|
||||
})
|
||||
ui.Row(c).Gap(u * 3).AlignItems(ui.Center).Wrap().Children(func() {
|
||||
PriceText(c, q.Price, PriceTextOptions{Decimals: dec, Size: theme.H2Size})
|
||||
PriceChangeBadge(c, q.Change, q.ChangePercent, PriceChangeBadgeOptions{Decimals: dec})
|
||||
})
|
||||
if opts.Chart != nil {
|
||||
ui.Box(c).Height(40).FillWidth().Children(opts.Chart)
|
||||
}
|
||||
})
|
||||
return e
|
||||
}
|
||||
Reference in new issue
Block a user