Documentation
¶
Overview ¶
Package ui renders the reader — a Reddit-style topbar + sidebar + feed — into an RGBA pixel buffer. Chrome and cards are drawn with the go-widgets painter; text is anti-aliased TrueType (see text.go) so it stays clean at any zoom / Retina scale. The sidebar is organised into profiles (tabs) that each group a subset of subreddits — e.g. "Pro" and "Perso". The package has no build tag, so its layout, hit-testing and rendering are exercised by native `go test`; the wasm front-end (cmd/front) drives the same Scene.
Index ¶
- Constants
- Variables
- func ClampZoom(z float64) float64
- func ResolveTheme(name, os string, prefersDark bool) *toolkit.Theme
- func StepZoom(z float64, dir int) float64
- func ThemeFor(os string, dark bool) *toolkit.Theme
- type Hit
- type HitKind
- type Mode
- type Scene
- func (s *Scene) ActiveFeeds() []string
- func (s *Scene) AddInputFeed()
- func (s *Scene) Backspace()
- func (s *Scene) CloseSettings()
- func (s *Scene) DeleteProfile(i int)
- func (s *Scene) Draw(buf []byte)
- func (s *Scene) FeedName() string
- func (s *Scene) FocusLoginField(i int)
- func (s *Scene) FocusSearch(v bool)
- func (s *Scene) HitTest(x, y int) Hit
- func (s *Scene) Input() string
- func (s *Scene) LoginCredentials() (id, secret string)
- func (s *Scene) MaxScroll() int
- func (s *Scene) NewProfile()
- func (s *Scene) NextLoginField()
- func (s *Scene) OpenLogin()
- func (s *Scene) OpenSettings()
- func (s *Scene) RemoveFeed(i int, feed string)
- func (s *Scene) Resize(w, h int)
- func (s *Scene) Scroll(dy int) bool
- func (s *Scene) Search() string
- func (s *Scene) SearchFocused() bool
- func (s *Scene) SelectEdit(i int)
- func (s *Scene) SetActive(i int)
- func (s *Scene) SetFeed(subreddit, sort string)
- func (s *Scene) SetLoginError(msg string)
- func (s *Scene) SetPosts(posts []reddit.Post)
- func (s *Scene) SetProfiles(profiles []settings.Profile, active int)
- func (s *Scene) SetSearch(q string)
- func (s *Scene) SetTheme(t *toolkit.Theme)
- func (s *Scene) SetThemeName(name string)
- func (s *Scene) Settings() settings.Settings
- func (s *Scene) TypeRune(r rune)
Constants ¶
const ( MinW = 360 MinH = 240 )
Minimum sensible surface.
const ( MinZoom = 0.5 MaxZoom = 3.0 ZoomStep = 0.1 )
Display-zoom bounds and step.
const ( OSMac = "mac" OSLinux = "linux" OSWindows = "windows" )
OS tokens understood by ThemeFor. The front-end derives these from navigator.platform / userAgentData.
Variables ¶
var Sorts = []string{"hot", "new", "top", "rising"}
Sorts is the ordered set of listing sorts shown as topbar tabs.
Functions ¶
func ResolveTheme ¶
ResolveTheme maps a persisted theme name ("system"|"light"|"dark") plus the host OS and the system dark preference to a concrete palette.
Types ¶
type Hit ¶
type Hit struct {
Kind HitKind
Post reddit.Post // HitPost
Feed string // HitFeed ("" = front page)
Sort string // HitSort
Profile int // HitProfile / HitSelectProfile / HitRemoveFeed / HitDeleteProfile
Value string // HitTheme / HitRemoveFeed
}
Hit is the result of Scene.HitTest.
type HitKind ¶
type HitKind int
HitKind classifies what a click landed on.
const ( HitNone HitKind = iota HitPost // a feed post (open it) HitFeed // a sidebar bookmark (switch subreddit) HitSort // a topbar sort tab (switch sort) HitProfile // a sidebar profile tab (switch active profile) HitSettings // the sidebar settings entry (open preferences) // Settings-view actions (Mode == ModeSettings): HitTheme // Value = "system"|"light"|"dark" HitSelectProfile // Profile = index being edited HitRemoveFeed // Profile = index, Value = feed HitAddFeed // commit the input into the edited profile HitNewProfile HitDeleteProfile // Profile = index HitCloseSettings // Login-view actions (Mode == ModeLogin): HitLoginField // Profile = 0 (client id) or 1 (client secret) HitLoginSubmit // submit the credentials (Touch ID) HitLoginCancel // Sidebar account entry (feed view): HitOpenLogin // open the login form HitLogout // forget stored credentials // Topbar search field (feed view): HitSearch // focus the filter/search input )
type Scene ¶
type Scene struct {
W, H int
Subreddit string // selected subreddit ("" => front page)
Sort string
Profiles []settings.Profile // sidebar tabs
Active int // active profile index
Posts []reddit.Post
Status string
ScrollY int
Scale float64 // display scale (zoom × devicePixelRatio); 0 => 1
// Preferences view. The "add subreddit" field is a persistent toolkit.Entry
// (built once in NewScene, edited through its OnEvent), not a plain string
// rebuilt every frame.
Mode Mode
ThemeName string // "system"|"light"|"dark" (persisted)
LoggedIn bool // reflects the auth state (drives the sidebar label)
// contains filtered or unexported fields
}
Scene is the mutable reader state.
func NewScene ¶
func NewScene() *Scene
NewScene returns a Scene at the default size with the light theme and the default (Pro/Perso) profiles.
func (*Scene) ActiveFeeds ¶
ActiveFeeds returns the subreddits of the active profile.
func (*Scene) AddInputFeed ¶
func (s *Scene) AddInputFeed()
AddInputFeed adds the typed subreddit to the edited profile and clears the field. Blank/duplicate entries are ignored.
func (*Scene) Backspace ¶
func (s *Scene) Backspace()
Backspace removes the last rune of the focused text field.
func (*Scene) CloseSettings ¶
func (s *Scene) CloseSettings()
CloseSettings returns to the feed view.
func (*Scene) DeleteProfile ¶
DeleteProfile removes profile i (never below one profile) and re-clamps the active + edited indices.
func (*Scene) FocusLoginField ¶
FocusLoginField selects which field receives typed text (0 id, 1 secret).
func (*Scene) FocusSearch ¶
FocusSearch sets/clears focus on the topbar filter field.
func (*Scene) LoginCredentials ¶
LoginCredentials returns the typed client id + secret.
func (*Scene) NewProfile ¶
func (s *Scene) NewProfile()
NewProfile appends a fresh profile and selects it for editing.
func (*Scene) NextLoginField ¶
func (s *Scene) NextLoginField()
NextLoginField moves focus to the other field (Tab).
func (*Scene) OpenLogin ¶
func (s *Scene) OpenLogin()
OpenLogin enters the login view with empty fields.
func (*Scene) OpenSettings ¶
func (s *Scene) OpenSettings()
OpenSettings enters the preferences view, editing the active profile.
func (*Scene) RemoveFeed ¶
RemoveFeed drops feed from profile i.
func (*Scene) SearchFocused ¶
SearchFocused reports whether the topbar filter field has focus.
func (*Scene) SelectEdit ¶
SelectEdit picks which profile the editor operates on (clamped).
func (*Scene) SetFeed ¶
SetFeed records the current subreddit/sort selection. subreddit "" is the front page.
func (*Scene) SetLoginError ¶
SetLoginError shows an error under the form (e.g. a cancelled Touch ID).
func (*Scene) SetProfiles ¶
SetProfiles replaces the profile list and active index (clamped).
func (*Scene) SetThemeName ¶
SetThemeName records the chosen theme ("system"|"light"|"dark").