I am going insane
This commit is contained in:
@@ -3,14 +3,14 @@ package fileElements
|
||||
import "io/fs"
|
||||
import "image"
|
||||
import "path/filepath"
|
||||
import "git.tebibyte.media/sashakoshka/tomo/theme"
|
||||
import "git.tebibyte.media/sashakoshka/tomo"
|
||||
import "git.tebibyte.media/sashakoshka/tomo/input"
|
||||
import "git.tebibyte.media/sashakoshka/tomo/artist"
|
||||
import "git.tebibyte.media/sashakoshka/tomo/canvas"
|
||||
import "git.tebibyte.media/sashakoshka/tomo/config"
|
||||
import "git.tebibyte.media/sashakoshka/tomo/textdraw"
|
||||
import "git.tebibyte.media/sashakoshka/tomo/elements"
|
||||
import "git.tebibyte.media/sashakoshka/tomo/elements/core"
|
||||
import "git.tebibyte.media/sashakoshka/tomo/default/theme"
|
||||
import "git.tebibyte.media/sashakoshka/tomo/default/config"
|
||||
|
||||
type fileLayoutEntry struct {
|
||||
*File
|
||||
@@ -56,7 +56,7 @@ func NewDirectory (
|
||||
err error,
|
||||
) {
|
||||
element = &Directory { }
|
||||
element.theme.Case = theme.C("files", "directory")
|
||||
element.theme.Case = tomo.C("files", "directory")
|
||||
element.Core, element.core = core.NewCore(element, element.redoAll)
|
||||
element.Propagator = core.NewPropagator(element, element.core)
|
||||
err = element.SetLocation(location, within)
|
||||
@@ -138,8 +138,8 @@ func (element *Directory) Update () error {
|
||||
element.children[index].File = file
|
||||
element.children[index].DirEntry = entry
|
||||
element.children[index].Drawer.SetFace (element.theme.FontFace(
|
||||
theme.FontStyleRegular,
|
||||
theme.FontSizeNormal))
|
||||
tomo.FontStyleRegular,
|
||||
tomo.FontSizeNormal))
|
||||
element.children[index].Drawer.SetText([]rune(entry.Name()))
|
||||
element.children[index].Drawer.SetAlign(textdraw.AlignCenter)
|
||||
}
|
||||
@@ -164,7 +164,7 @@ func (element *Directory) CountChildren () (count int) {
|
||||
|
||||
// Child returns the child at the specified index. If the index is out of
|
||||
// bounds, this method will return nil.
|
||||
func (element *Directory) Child (index int) (child elements.Element) {
|
||||
func (element *Directory) Child (index int) (child tomo.Element) {
|
||||
if index < 0 || index > len(element.children) { return }
|
||||
return element.children[index].File
|
||||
}
|
||||
@@ -202,12 +202,12 @@ func (element *Directory) redoAll () {
|
||||
rocks[index] = entry.Bounds
|
||||
}
|
||||
pattern := element.theme.Pattern (
|
||||
theme.PatternPinboard,
|
||||
theme.State { })
|
||||
tomo.PatternPinboard,
|
||||
tomo.State { })
|
||||
artist.DrawShatter(element.core, pattern, element.Bounds(), rocks...)
|
||||
|
||||
element.partition()
|
||||
if parent, ok := element.core.Parent().(elements.ScrollableParent); ok {
|
||||
if parent, ok := element.core.Parent().(tomo.ScrollableParent); ok {
|
||||
parent.NotifyScrollBoundsChange(element)
|
||||
}
|
||||
if element.onScrollBoundsChange != nil {
|
||||
@@ -215,7 +215,7 @@ func (element *Directory) redoAll () {
|
||||
}
|
||||
|
||||
// draw labels
|
||||
foreground := element.theme.Color(theme.ColorForeground, theme.State { })
|
||||
foreground := element.theme.Color(tomo.ColorForeground, tomo.State { })
|
||||
for _, entry := range element.children {
|
||||
entry.Drawer.Draw(element.core, foreground, entry.TextPoint)
|
||||
}
|
||||
@@ -240,13 +240,13 @@ func (element *Directory) partition () {
|
||||
|
||||
// NotifyMinimumSizeChange notifies the container that the minimum size of a
|
||||
// child element has changed.
|
||||
func (element *Directory) NotifyMinimumSizeChange (child elements.Element) {
|
||||
func (element *Directory) NotifyMinimumSizeChange (child tomo.Element) {
|
||||
element.redoAll()
|
||||
element.core.DamageAll()
|
||||
}
|
||||
|
||||
// SetTheme sets the element's theme.
|
||||
func (element *Directory) SetTheme (new theme.Theme) {
|
||||
func (element *Directory) SetTheme (new tomo.Theme) {
|
||||
if new == element.theme.Theme { return }
|
||||
element.theme.Theme = new
|
||||
element.Propagator.SetTheme(new)
|
||||
@@ -254,7 +254,7 @@ func (element *Directory) SetTheme (new theme.Theme) {
|
||||
}
|
||||
|
||||
// SetConfig sets the element's configuration.
|
||||
func (element *Directory) SetConfig (new config.Config) {
|
||||
func (element *Directory) SetConfig (new tomo.Config) {
|
||||
if new == element.config.Config { return }
|
||||
element.Propagator.SetConfig(new)
|
||||
element.redoAll()
|
||||
@@ -267,7 +267,7 @@ func (element *Directory) ScrollContentBounds () image.Rectangle {
|
||||
// ScrollViewportBounds returns the size and position of the element's
|
||||
// viewport relative to ScrollBounds.
|
||||
func (element *Directory) ScrollViewportBounds () image.Rectangle {
|
||||
padding := element.theme.Padding(theme.PatternPinboard)
|
||||
padding := element.theme.Padding(tomo.PatternPinboard)
|
||||
bounds := padding.Apply(element.Bounds())
|
||||
bounds = bounds.Sub(bounds.Min).Add(element.scroll)
|
||||
return bounds
|
||||
@@ -302,7 +302,7 @@ func (element *Directory) ScrollAxes () (horizontal, vertical bool) {
|
||||
}
|
||||
|
||||
func (element *Directory) maxScrollHeight () (height int) {
|
||||
padding := element.theme.Padding(theme.PatternSunken)
|
||||
padding := element.theme.Padding(tomo.PatternSunken)
|
||||
viewportHeight := element.Bounds().Dy() - padding.Vertical()
|
||||
height = element.contentBounds.Dy() - viewportHeight
|
||||
if height < 0 { height = 0 }
|
||||
@@ -310,8 +310,8 @@ func (element *Directory) maxScrollHeight () (height int) {
|
||||
}
|
||||
|
||||
func (element *Directory) doLayout () {
|
||||
margin := element.theme.Margin(theme.PatternPinboard)
|
||||
padding := element.theme.Padding(theme.PatternPinboard)
|
||||
margin := element.theme.Margin(tomo.PatternPinboard)
|
||||
padding := element.theme.Padding(tomo.PatternPinboard)
|
||||
bounds := padding.Apply(element.Bounds())
|
||||
element.contentBounds = image.Rectangle { }
|
||||
|
||||
@@ -360,7 +360,7 @@ func (element *Directory) doLayout () {
|
||||
}
|
||||
|
||||
func (element *Directory) updateMinimumSize () {
|
||||
padding := element.theme.Padding(theme.PatternPinboard)
|
||||
padding := element.theme.Padding(tomo.PatternPinboard)
|
||||
minimumWidth := 0
|
||||
for _, entry := range element.children {
|
||||
width, _ := entry.MinimumSize()
|
||||
|
||||
@@ -3,11 +3,12 @@ package fileElements
|
||||
import "time"
|
||||
import "io/fs"
|
||||
import "image"
|
||||
import "git.tebibyte.media/sashakoshka/tomo"
|
||||
import "git.tebibyte.media/sashakoshka/tomo/input"
|
||||
import "git.tebibyte.media/sashakoshka/tomo/theme"
|
||||
import "git.tebibyte.media/sashakoshka/tomo/artist"
|
||||
import "git.tebibyte.media/sashakoshka/tomo/config"
|
||||
import "git.tebibyte.media/sashakoshka/tomo/elements/core"
|
||||
import "git.tebibyte.media/sashakoshka/tomo/default/theme"
|
||||
import "git.tebibyte.media/sashakoshka/tomo/default/config"
|
||||
|
||||
// File displays an interactive visual representation of a file within any
|
||||
// file system.
|
||||
@@ -22,7 +23,7 @@ type File struct {
|
||||
|
||||
lastClick time.Time
|
||||
pressed bool
|
||||
iconID theme.Icon
|
||||
iconID tomo.Icon
|
||||
filesystem fs.StatFS
|
||||
location string
|
||||
selected bool
|
||||
@@ -40,7 +41,7 @@ func NewFile (
|
||||
err error,
|
||||
) {
|
||||
element = &File { }
|
||||
element.theme.Case = theme.C("files", "file")
|
||||
element.theme.Case = tomo.C("files", "file")
|
||||
element.Core, element.core = core.NewCore(element, element.drawAll)
|
||||
element.FocusableCore,
|
||||
element.focusableControl = core.NewFocusableCore(element.core, element.drawAndPush)
|
||||
@@ -72,12 +73,12 @@ func (element *File) Update () error {
|
||||
info, err := element.filesystem.Stat(element.location)
|
||||
|
||||
if err != nil {
|
||||
element.iconID = theme.IconError
|
||||
element.iconID = tomo.IconError
|
||||
} else if info.IsDir() {
|
||||
element.iconID = theme.IconDirectory
|
||||
element.iconID = tomo.IconDirectory
|
||||
} else {
|
||||
// TODO: choose icon based on file mime type
|
||||
element.iconID = theme.IconFile
|
||||
element.iconID = tomo.IconFile
|
||||
}
|
||||
|
||||
element.updateMinimumSize()
|
||||
@@ -142,21 +143,21 @@ func (element *File) HandleMouseUp (x, y int, button input.Button) {
|
||||
}
|
||||
|
||||
// SetTheme sets the element's theme.
|
||||
func (element *File) SetTheme (new theme.Theme) {
|
||||
func (element *File) SetTheme (new tomo.Theme) {
|
||||
if new == element.theme.Theme { return }
|
||||
element.theme.Theme = new
|
||||
element.drawAndPush()
|
||||
}
|
||||
|
||||
// SetConfig sets the element's configuration.
|
||||
func (element *File) SetConfig (new config.Config) {
|
||||
func (element *File) SetConfig (new tomo.Config) {
|
||||
if new == element.config.Config { return }
|
||||
element.config.Config = new
|
||||
element.drawAndPush()
|
||||
}
|
||||
|
||||
func (element *File) state () theme.State {
|
||||
return theme.State {
|
||||
func (element *File) state () tomo.State {
|
||||
return tomo.State {
|
||||
Disabled: !element.Enabled(),
|
||||
Focused: element.Focused(),
|
||||
Pressed: element.pressed,
|
||||
@@ -165,11 +166,11 @@ func (element *File) state () theme.State {
|
||||
}
|
||||
|
||||
func (element *File) icon () artist.Icon {
|
||||
return element.theme.Icon(element.iconID, theme.IconSizeLarge)
|
||||
return element.theme.Icon(element.iconID, tomo.IconSizeLarge)
|
||||
}
|
||||
|
||||
func (element *File) updateMinimumSize () {
|
||||
padding := element.theme.Padding(theme.PatternButton)
|
||||
padding := element.theme.Padding(tomo.PatternButton)
|
||||
icon := element.icon()
|
||||
if icon == nil {
|
||||
element.core.SetMinimumSize (
|
||||
@@ -192,9 +193,9 @@ func (element *File) drawAll () {
|
||||
// background
|
||||
state := element.state()
|
||||
bounds := element.Bounds()
|
||||
sink := element.theme.Sink(theme.PatternButton)
|
||||
sink := element.theme.Sink(tomo.PatternButton)
|
||||
element.theme.
|
||||
Pattern(theme.PatternButton, state).
|
||||
Pattern(tomo.PatternButton, state).
|
||||
Draw(element.core, bounds)
|
||||
|
||||
// icon
|
||||
@@ -209,8 +210,7 @@ func (element *File) drawAll () {
|
||||
}
|
||||
icon.Draw (
|
||||
element.core,
|
||||
element.theme.Color (
|
||||
theme.ColorForeground, state),
|
||||
element.theme.Color(tomo.ColorForeground, state),
|
||||
bounds.Min.Add(offset))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user