Foundation
This commit is contained in:
parent
dc7e73e5e3
commit
867a3d0fcd
11 changed files with 304 additions and 0 deletions
20
src/cmd/icdb/main.go
Normal file
20
src/cmd/icdb/main.go
Normal file
|
@ -0,0 +1,20 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"icdb/internal/ui"
|
||||
"icdb/pkg/config"
|
||||
"icdb/pkg/logger"
|
||||
|
||||
"github.com/rs/zerolog/log"
|
||||
)
|
||||
|
||||
func main() {
|
||||
cfg := config.Get()
|
||||
logger.Setup()
|
||||
|
||||
log.Info().Msg("Application started")
|
||||
log.Debug().Msg(fmt.Sprintf("Config loaded: %s", cfg.Settings))
|
||||
|
||||
ui.Init()
|
||||
}
|
17
src/go.mod
17
src/go.mod
|
@ -1,3 +1,20 @@
|
|||
module icdb
|
||||
|
||||
go 1.23.5
|
||||
|
||||
require (
|
||||
gioui.org v0.8.0
|
||||
github.com/rs/zerolog v1.33.0
|
||||
)
|
||||
|
||||
require (
|
||||
gioui.org/shader v1.0.8 // indirect
|
||||
github.com/go-text/typesetting v0.2.1 // indirect
|
||||
github.com/mattn/go-colorable v0.1.14 // indirect
|
||||
github.com/mattn/go-isatty v0.0.20 // indirect
|
||||
golang.org/x/exp v0.0.0-20240707233637-46b078467d37 // indirect
|
||||
golang.org/x/exp/shiny v0.0.0-20240707233637-46b078467d37 // indirect
|
||||
golang.org/x/image v0.18.0 // indirect
|
||||
golang.org/x/sys v0.29.0 // indirect
|
||||
golang.org/x/text v0.16.0 // indirect
|
||||
)
|
||||
|
|
37
src/go.sum
Normal file
37
src/go.sum
Normal file
|
@ -0,0 +1,37 @@
|
|||
eliasnaur.com/font v0.0.0-20230308162249-dd43949cb42d h1:ARo7NCVvN2NdhLlJE9xAbKweuI9L6UgfTbYb0YwPacY=
|
||||
eliasnaur.com/font v0.0.0-20230308162249-dd43949cb42d/go.mod h1:OYVuxibdk9OSLX8vAqydtRPP87PyTFcT9uH3MlEGBQA=
|
||||
gioui.org v0.8.0 h1:QV5p5JvsmSmGiIXVYOKn6d9YDliTfjtLlVf5J+BZ9Pg=
|
||||
gioui.org v0.8.0/go.mod h1:vEMmpxMOd/iwJhXvGVIzWEbxMWhnMQ9aByOGQdlQ8rc=
|
||||
gioui.org/cpu v0.0.0-20210808092351-bfe733dd3334/go.mod h1:A8M0Cn5o+vY5LTMlnRoK3O5kG+rH0kWfJjeKd9QpBmQ=
|
||||
gioui.org/shader v1.0.8 h1:6ks0o/A+b0ne7RzEqRZK5f4Gboz2CfG+mVliciy6+qA=
|
||||
gioui.org/shader v1.0.8/go.mod h1:mWdiME581d/kV7/iEhLmUgUK5iZ09XR5XpduXzbePVM=
|
||||
github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
|
||||
github.com/go-text/typesetting v0.2.1 h1:x0jMOGyO3d1qFAPI0j4GSsh7M0Q3Ypjzr4+CEVg82V8=
|
||||
github.com/go-text/typesetting v0.2.1/go.mod h1:mTOxEwasOFpAMBjEQDhdWRckoLLeI/+qrQeBCTGEt6M=
|
||||
github.com/go-text/typesetting-utils v0.0.0-20241103174707-87a29e9e6066 h1:qCuYC+94v2xrb1PoS4NIDe7DGYtLnU2wWiQe9a1B1c0=
|
||||
github.com/go-text/typesetting-utils v0.0.0-20241103174707-87a29e9e6066/go.mod h1:DDxDdQEnB70R8owOx3LVpEFvpMK9eeH1o2r0yZhFI9o=
|
||||
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
|
||||
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
|
||||
github.com/mattn/go-colorable v0.1.14 h1:9A9LHSqF/7dyVVX6g0U9cwm9pG3kP9gSzcuIPHPsaIE=
|
||||
github.com/mattn/go-colorable v0.1.14/go.mod h1:6LmQG8QLFO4G5z1gPvYEzlUgJ2wF+stgPZH1UqBm1s8=
|
||||
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
|
||||
github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
|
||||
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
|
||||
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
|
||||
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||
github.com/rs/xid v1.5.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg=
|
||||
github.com/rs/zerolog v1.33.0 h1:1cU2KZkvPxNyfgEmhHAz/1A9Bz+llsdYzklWFzgp0r8=
|
||||
github.com/rs/zerolog v1.33.0/go.mod h1:/7mN4D5sKwJLZQ2b/znpjC3/GQWY/xaDXUM0kKWRHss=
|
||||
golang.org/x/exp v0.0.0-20240707233637-46b078467d37 h1:uLDX+AfeFCct3a2C7uIWBKMJIR3CJMhcgfrUAqjRK6w=
|
||||
golang.org/x/exp v0.0.0-20240707233637-46b078467d37/go.mod h1:M4RDyNAINzryxdtnbRXRL/OHtkFuWGRjvuhBJpk2IlY=
|
||||
golang.org/x/exp/shiny v0.0.0-20240707233637-46b078467d37 h1:SOSg7+sueresE4IbmmGM60GmlIys+zNX63d6/J4CMtU=
|
||||
golang.org/x/exp/shiny v0.0.0-20240707233637-46b078467d37/go.mod h1:3F+MieQB7dRYLTmnncoFbb1crS5lfQoTfDgQy6K4N0o=
|
||||
golang.org/x/image v0.18.0 h1:jGzIakQa/ZXI1I0Fxvaa9W7yP25TqT6cHIHn+6CqvSQ=
|
||||
golang.org/x/image v0.18.0/go.mod h1:4yyo5vMFQjVjUcVk4jEQcU9MGy/rulF5WvUILseCM2E=
|
||||
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.29.0 h1:TPYlXGxvx1MGTn2GiZDhnjPA9wZzZeGKHHmKhHYvgaU=
|
||||
golang.org/x/sys v0.29.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||
golang.org/x/text v0.16.0 h1:a94ExnEXNtEwYLGJSIUxnWoxoRz/ZcCsV63ROupILh4=
|
||||
golang.org/x/text v0.16.0/go.mod h1:GhwF1Be+LQoKShO3cGOHzqOgRrGaYc9AvblQOmPVHnI=
|
45
src/internal/ui/layout.go
Normal file
45
src/internal/ui/layout.go
Normal file
|
@ -0,0 +1,45 @@
|
|||
package ui
|
||||
|
||||
import (
|
||||
t_ui "icdb/pkg/types/ui"
|
||||
|
||||
"gioui.org/app"
|
||||
"gioui.org/layout"
|
||||
"gioui.org/op"
|
||||
"gioui.org/unit"
|
||||
"gioui.org/widget/material"
|
||||
)
|
||||
|
||||
var currentView t_ui.UIView = t_ui.UIViewMain
|
||||
|
||||
// run takes a window as parameter and runs the UI on it.
|
||||
func run(window *app.Window) error {
|
||||
theme := material.NewTheme()
|
||||
var ops op.Ops
|
||||
for {
|
||||
switch e := window.Event().(type) {
|
||||
case app.DestroyEvent:
|
||||
return e.Err
|
||||
case app.FrameEvent:
|
||||
gtx := app.NewContext(&ops, e)
|
||||
|
||||
margins := layout.Inset{
|
||||
Top: unit.Dp(10),
|
||||
Bottom: unit.Dp(10),
|
||||
Left: unit.Dp(10),
|
||||
Right: unit.Dp(10),
|
||||
}
|
||||
|
||||
margins.Layout(gtx, func(gtx layout.Context) layout.Dimensions {
|
||||
return layout.Flex{
|
||||
Axis: layout.Horizontal,
|
||||
}.Layout(gtx,
|
||||
layout.Rigid(renderSidebar(theme)),
|
||||
layout.Flexed(1, renderView(theme)),
|
||||
)
|
||||
})
|
||||
|
||||
e.Frame(gtx.Ops)
|
||||
}
|
||||
}
|
||||
}
|
43
src/internal/ui/sidebar.go
Normal file
43
src/internal/ui/sidebar.go
Normal file
|
@ -0,0 +1,43 @@
|
|||
package ui
|
||||
|
||||
import (
|
||||
t_ui "icdb/pkg/types/ui"
|
||||
"image/color"
|
||||
|
||||
"gioui.org/layout"
|
||||
"gioui.org/unit"
|
||||
"gioui.org/widget"
|
||||
"gioui.org/widget/material"
|
||||
)
|
||||
|
||||
var (
|
||||
mainButton widget.Clickable
|
||||
partsButton widget.Clickable
|
||||
settingsButton widget.Clickable
|
||||
)
|
||||
|
||||
var sidebarWidth = unit.Dp(200)
|
||||
var sidebarBackground = color.NRGBA{R: 240, G: 240, B: 240, A: 255}
|
||||
|
||||
// renderSidebar creates the sidebar UI.
|
||||
func renderSidebar(th *material.Theme) layout.Widget {
|
||||
return func(gtx layout.Context) layout.Dimensions {
|
||||
return layout.Flex{
|
||||
Axis: layout.Vertical,
|
||||
}.Layout(gtx,
|
||||
layout.Rigid(renderNavButton(gtx, th, "Main", &mainButton, t_ui.UIViewMain)),
|
||||
layout.Rigid(renderNavButton(gtx, th, "Parts", &partsButton, t_ui.UIViewParts)),
|
||||
layout.Rigid(renderNavButton(gtx, th, "Settings", &settingsButton, t_ui.UIViewSettings)),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
// renderNavButton creates a navigation button
|
||||
func renderNavButton(gtx layout.Context, th *material.Theme, label string, btn *widget.Clickable, target t_ui.UIView) layout.Widget {
|
||||
return func(gtx layout.Context) layout.Dimensions {
|
||||
if btn.Clicked(gtx) {
|
||||
currentView = target
|
||||
}
|
||||
return material.Button(th, btn, label).Layout(gtx)
|
||||
}
|
||||
}
|
21
src/internal/ui/ui.go
Normal file
21
src/internal/ui/ui.go
Normal file
|
@ -0,0 +1,21 @@
|
|||
package ui
|
||||
|
||||
import (
|
||||
"os"
|
||||
|
||||
"gioui.org/app"
|
||||
"github.com/rs/zerolog/log"
|
||||
)
|
||||
|
||||
// Init initializes and runs the UI.
|
||||
func Init() {
|
||||
go func() {
|
||||
window := new(app.Window)
|
||||
err := run(window)
|
||||
if err != nil {
|
||||
log.Fatal().Err(err).Msg("UI loop exited with error")
|
||||
}
|
||||
os.Exit(1)
|
||||
}()
|
||||
app.Main()
|
||||
}
|
48
src/internal/ui/views.go
Normal file
48
src/internal/ui/views.go
Normal file
|
@ -0,0 +1,48 @@
|
|||
package ui
|
||||
|
||||
import (
|
||||
t_ui "icdb/pkg/types/ui"
|
||||
"image/color"
|
||||
|
||||
"gioui.org/layout"
|
||||
"gioui.org/text"
|
||||
"gioui.org/widget/material"
|
||||
)
|
||||
|
||||
// renderView dynamically loads the selected view
|
||||
func renderView(th *material.Theme) layout.Widget {
|
||||
return func(gtx layout.Context) layout.Dimensions {
|
||||
switch currentView {
|
||||
case t_ui.UIViewMain:
|
||||
return renderMainView(gtx, th)
|
||||
case t_ui.UIViewParts:
|
||||
return renderPartsView(gtx, th)
|
||||
case t_ui.UIViewSettings:
|
||||
return renderSettingsView(gtx, th)
|
||||
default:
|
||||
return renderMainView(gtx, th)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// renderMainView displays the main view
|
||||
func renderMainView(gtx layout.Context, th *material.Theme) layout.Dimensions {
|
||||
title := material.H1(th, "Welcome to ICDB")
|
||||
title.Color = color.NRGBA{R: 127, G: 0, B: 0, A: 255}
|
||||
title.Alignment = text.Middle
|
||||
return title.Layout(gtx)
|
||||
}
|
||||
|
||||
// renderPartsView displays the parts list
|
||||
func renderPartsView(gtx layout.Context, th *material.Theme) layout.Dimensions {
|
||||
title := material.H1(th, "Parts Management")
|
||||
title.Alignment = text.Middle
|
||||
return title.Layout(gtx)
|
||||
}
|
||||
|
||||
// renderSettingsView displays the settings view
|
||||
func renderSettingsView(gtx layout.Context, th *material.Theme) layout.Dimensions {
|
||||
title := material.H1(th, "Settings")
|
||||
title.Alignment = text.Middle
|
||||
return title.Layout(gtx)
|
||||
}
|
24
src/pkg/config/config.go
Normal file
24
src/pkg/config/config.go
Normal file
|
@ -0,0 +1,24 @@
|
|||
package config
|
||||
|
||||
import (
|
||||
"os"
|
||||
"sync"
|
||||
)
|
||||
|
||||
// Config holds application configuration.
|
||||
type Config struct {
|
||||
Settings map[string]string
|
||||
}
|
||||
|
||||
var instance *Config
|
||||
var once sync.Once
|
||||
|
||||
// Get returns the application configuration.
|
||||
func Get() *Config {
|
||||
once.Do(func() {
|
||||
instance = &Config{
|
||||
Settings: map[string]string{"env": os.Getenv("APP_ENV")},
|
||||
}
|
||||
})
|
||||
return instance
|
||||
}
|
37
src/pkg/logger/logger.go
Normal file
37
src/pkg/logger/logger.go
Normal file
|
@ -0,0 +1,37 @@
|
|||
/*
|
||||
ICDB
|
||||
Copyright (C) 2025, Zervó Zadachin
|
||||
|
||||
DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License version 3
|
||||
as published by the Free Software Foundation.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License version 3 for more details.
|
||||
|
||||
This program incorporates external libraries for certain functionalities.
|
||||
These libraries are covered by their respective licenses, and their usage
|
||||
agreements are as outlined in their respective documentation or source
|
||||
code.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package logger
|
||||
|
||||
import (
|
||||
"os"
|
||||
|
||||
"github.com/rs/zerolog"
|
||||
"github.com/rs/zerolog/log"
|
||||
)
|
||||
|
||||
// Setup configures the global logger.
|
||||
func Setup() {
|
||||
log.Logger = log.Output(zerolog.ConsoleWriter{Out: os.Stderr})
|
||||
}
|
9
src/pkg/types/ui/constants.go
Normal file
9
src/pkg/types/ui/constants.go
Normal file
|
@ -0,0 +1,9 @@
|
|||
package ui
|
||||
|
||||
const (
|
||||
UIViewMain UIView = 0
|
||||
UIViewParts UIView = 1
|
||||
UIViewCategories UIView = 2
|
||||
UIViewLocations UIView = 3
|
||||
UIViewSettings UIView = 4
|
||||
)
|
3
src/pkg/types/ui/view.go
Normal file
3
src/pkg/types/ui/view.go
Normal file
|
@ -0,0 +1,3 @@
|
|||
package ui
|
||||
|
||||
type UIView uint8
|
Loading…
Add table
Reference in a new issue