Compare commits
2 Commits
2db501e66c
...
d5d9f3abfb
Author | SHA1 | Date | |
---|---|---|---|
d5d9f3abfb | |||
6cb908ea6e |
@ -2,6 +2,7 @@ package nasin
|
||||
|
||||
import "log"
|
||||
import "image"
|
||||
import "strings"
|
||||
import "git.tebibyte.media/tomo/tomo"
|
||||
import "git.tebibyte.media/tomo/nasin/internal/registrar"
|
||||
|
||||
@ -76,6 +77,15 @@ type ApplicationRole string; const (
|
||||
RoleChecklist ApplicationRole = "Checklist"
|
||||
)
|
||||
|
||||
// Icon returns the icon ID for this role.
|
||||
func (role ApplicationRole) Icon () tomo.Icon {
|
||||
if role == "" {
|
||||
return tomo.IconApplication
|
||||
} else {
|
||||
return tomo.Icon("Application" + strings.ReplaceAll(string(role), " ", ""))
|
||||
}
|
||||
}
|
||||
|
||||
// RunApplication is like tomo.Run, but runs an application. If something fails
|
||||
// to initialize, an error is written to the standard logger.
|
||||
func RunApplication (application Application) {
|
||||
@ -90,10 +100,37 @@ func RunApplication (application Application) {
|
||||
|
||||
// NewApplicationWindow creates a window for an application. It will
|
||||
// automatically set window information to signal to the OS that the window is
|
||||
// owned by the application.
|
||||
// owned by the application. The window's icon will be automatically set by
|
||||
// looking for an icon with the name of the application's ID. If that is not
|
||||
// found, the default icon for the application's ApplicationRole will used.
|
||||
func NewApplicationWindow (application Application, bounds image.Rectangle) (tomo.MainWindow, error) {
|
||||
window, err := tomo.NewWindow(bounds)
|
||||
if err != nil { return nil, err }
|
||||
window.SetTitle(application.Describe().String())
|
||||
description := application.Describe()
|
||||
window.SetTitle(description.Name)
|
||||
setApplicationWindowIcon(window, description)
|
||||
return window, nil
|
||||
}
|
||||
|
||||
func setApplicationWindowIcon (window tomo.Window, description ApplicationDescription) {
|
||||
allSizes := func (icon tomo.Icon) (sizes []image.Image) {
|
||||
small := icon.Texture(tomo.IconSizeSmall)
|
||||
medium := icon.Texture(tomo.IconSizeMedium)
|
||||
large := icon.Texture(tomo.IconSizeLarge)
|
||||
if small != nil { sizes = append(sizes, small) }
|
||||
if medium != nil { sizes = append(sizes, medium) }
|
||||
if large != nil { sizes = append(sizes, large) }
|
||||
return sizes
|
||||
}
|
||||
|
||||
if sizes := allSizes(tomo.Icon(description.ID)); len(sizes) > 0 {
|
||||
println("direct icon worked", tomo.Icon(description.ID))
|
||||
window.SetIcon(sizes...)
|
||||
return
|
||||
}
|
||||
if sizes := allSizes(description.Role.Icon()); len(sizes) > 0 {
|
||||
println("role icon worked", description.Role.Icon())
|
||||
window.SetIcon(sizes...)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
@ -10,8 +10,8 @@ func New () *dataTheme.Theme {
|
||||
Colors: map[tomo.Color] color.Color {
|
||||
tomo.ColorBackground: colorBackground,
|
||||
tomo.ColorForeground: colorForeground,
|
||||
tomo.ColorRaised: colorCarved,
|
||||
tomo.ColorSunken: colorCarved,
|
||||
tomo.ColorRaised: colorRaised,
|
||||
tomo.ColorSunken: colorSunken,
|
||||
tomo.ColorAccent: colorFocus,
|
||||
},
|
||||
Rules: rules,
|
||||
|
@ -26,15 +26,19 @@ func border (top, right, bottom, left uint32, width ...int) tomo.Border {
|
||||
var colorDot = hex(0x7391c080)
|
||||
var colorFocus = hex(0x5f8bc4FF)
|
||||
var colorHighlight = hex(0x5f8bc4FF)
|
||||
var colorBackground = hex(0xd6d6d6FF)
|
||||
var colorBackground = hex(0xd4d4d4FF)
|
||||
var colorForeground = color.Black
|
||||
|
||||
var colorOutline = color.Black
|
||||
var colorGutter = hex(0xbfc6d1FF)
|
||||
var colorGutterHovered = hex(0xc5cbd6FF)
|
||||
var colorCarved = hex(0xe9eaeaFF)
|
||||
var colorCarvedPressed = hex(0xe3e4e4FF)
|
||||
var colorCarvedFocused = hex(0xe4e6e8FF)
|
||||
var colorCarvedHovered = hex(0xf1f3f5FF)
|
||||
var colorRaised = hex(0xe9eaeaFF)
|
||||
var colorRaisedPressed = hex(0xccd4ddFF)
|
||||
var colorRaisedFocused = hex(0xcfd6ddFF)
|
||||
var colorRaisedHovered = hex(0xf1f3f5FF)
|
||||
var colorSunken = hex(0xe9eaeaFF)
|
||||
var colorSunkenFocused = hex(0xe0e6eeFF)
|
||||
var colorSunkenPressed = hex(0xe0e6eeFF)
|
||||
|
||||
var outline = tomo.Border {
|
||||
Width: tomo.I(1),
|
||||
@ -49,6 +53,7 @@ var outline = tomo.Border {
|
||||
var borderEngraved = border(0xc3c3c5FF, 0xe3e3e3FF, 0xe9e9e9ff, 0xc2c2c2ff, 1)
|
||||
var borderGap = border(0x697c7cFF, 0x566767FF, 0x566767ff, 0x697c7cff, 1)
|
||||
var borderLifted = border(0xf9fafcFF, 0xc2c8d3FF, 0xa4afc0ff, 0xf5f6f8ff, 1)
|
||||
var borderLiftedFocused = border(0xf0f4f9FF, 0xb1bacaFF, 0x9aa6b7ff, 0xe4e9eeff, 1)
|
||||
var borderFocused = border(0x5f8bc4FF, 0x5f8bc4FF, 0x5f8bc4ff, 0x5f8bc4ff, 1)
|
||||
var borderInnerShadow = border(0xa4afc0FF, 0xa4afc0FF, 0xa4afc0ff, 0xa4afc0ff, 1, 0, 0, 1)
|
||||
var borderOuterShadow = border(0xa4afc0FF, 0xa4afc0FF, 0xa4afc0ff, 0xa4afc0ff, 0, 1, 1, 0)
|
||||
@ -83,19 +88,19 @@ var rules = []dataTheme.Rule {
|
||||
borderInnerShadow,
|
||||
},
|
||||
dataTheme.AttrPadding(tomo.I(5, 8, 4, 9)),
|
||||
dataTheme.AttrColor { Color: colorCarvedPressed },
|
||||
dataTheme.AttrColor { Color: colorRaisedPressed },
|
||||
),
|
||||
Focused: dataTheme.AS (
|
||||
dataTheme.AttrBorder {
|
||||
borderEngraved,
|
||||
borderFocused,
|
||||
borderLifted,
|
||||
borderGap,
|
||||
borderLiftedFocused,
|
||||
},
|
||||
dataTheme.AttrPadding(tomo.I(4, 8)),
|
||||
dataTheme.AttrColor { Color: colorCarvedFocused },
|
||||
dataTheme.AttrColor { Color: colorRaisedFocused },
|
||||
),
|
||||
Hovered: dataTheme.AS (
|
||||
dataTheme.AttrColor { Color: colorCarvedHovered },
|
||||
dataTheme.AttrColor { Color: colorRaisedHovered },
|
||||
),
|
||||
},
|
||||
|
||||
@ -117,6 +122,10 @@ var rules = []dataTheme.Rule {
|
||||
borderFocused,
|
||||
borderInnerShadow,
|
||||
},
|
||||
dataTheme.AttrColor { Color: colorSunkenFocused },
|
||||
),
|
||||
Pressed: dataTheme.AS (
|
||||
dataTheme.AttrColor { Color: colorSunkenPressed },
|
||||
),
|
||||
},
|
||||
|
||||
@ -265,6 +274,7 @@ var rules = []dataTheme.Rule {
|
||||
borderInnerShadow,
|
||||
},
|
||||
dataTheme.AttrPadding(tomo.I(0)),
|
||||
dataTheme.AttrColor { Color: colorSunkenFocused },
|
||||
),
|
||||
},
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user