Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
82 commits
Select commit Hold shift + click to select a range
e457df0
save screen name in window geometry
rcoreilly Nov 25, 2024
da9adb5
Merge branch 'main' into screens
rcoreilly Nov 25, 2024
a514680
screen and resizable options in place for new windows -- but glfw log…
rcoreilly Nov 25, 2024
8f9877e
set window position based on screen position -- position is always sp…
rcoreilly Nov 25, 2024
ac998da
window Position() actually returns screen-relative position; add Stag…
rcoreilly Nov 25, 2024
446ebea
windowGeometry system saves last screen, uses that to override defaults
rcoreilly Nov 26, 2024
dd50063
wingeom has robust use based on active screens
rcoreilly Nov 26, 2024
f0fbc43
properly update saved screens from geometries and cache
rcoreilly Nov 26, 2024
ec743b6
screens: mostly working -- added screen relative optional arg for win…
rcoreilly Nov 26, 2024
809f486
screens: fix screenupdate debug trace; restoreAll now does abort save…
rcoreilly Nov 26, 2024
fb3d2a5
clean up RunMainWindow, RunMain, NewWindow docs
kkoreilly Nov 26, 2024
5634d80
add support for Resizable flag for non-full same-window dialogs
kkoreilly Nov 26, 2024
6481c4c
revert to b.RunMainWindow in demo
kkoreilly Nov 26, 2024
bc6dbcf
more screen cleanup
kkoreilly Nov 26, 2024
479f582
fix window geometry field names; much cleaner and clearer, and image.…
kkoreilly Nov 26, 2024
5eadd1d
document behavior to return the first screen on invalid number in App…
kkoreilly Nov 26, 2024
ca2c660
add Maximize and Fullscreen options on Stage
kkoreilly Nov 26, 2024
49c02c4
add Maximized option distinct from Fullscreen; add Fullscreen option …
kkoreilly Nov 26, 2024
2127172
implement maximized flag and clean up fullscreen handling
kkoreilly Nov 26, 2024
b9d78ee
set Maximized flag based on Maximized, not Fullscreen
kkoreilly Nov 26, 2024
9dcd750
set window geometry Max based on Maximized
kkoreilly Nov 26, 2024
eea4769
start on system.Window.UpdateFullscreen function
kkoreilly Nov 27, 2024
4f0f2aa
implement desktop.Window.UpdateFullscreen; use screen size for fullsc…
kkoreilly Nov 27, 2024
6d0f1fd
constrain frame initial impl
rcoreilly Nov 27, 2024
9e50127
constrain frame working on mac: pos is not set at startup, so use opts.
rcoreilly Nov 27, 2024
cfe304f
better safety on using opts -- make sure not zero
rcoreilly Nov 27, 2024
174ba00
add Scene.UpdateFullscreen
kkoreilly Nov 27, 2024
7e59dac
add fullscreen button to dialogs demo; panicking for now
kkoreilly Nov 27, 2024
fa10107
RunOnMain UpdateFullscreen; working overall now
kkoreilly Nov 27, 2024
e41fbd7
start on fullscreen button in window menu
kkoreilly Nov 27, 2024
3e83b8d
screens: saved filename has version number; ConstrainFrame takes topO…
rcoreilly Nov 27, 2024
f7fc7d2
screens: use Sides for frame size; fullscreen sets pixsize directly a…
rcoreilly Nov 28, 2024
706820e
screens: SetGeom handles the fullscreen updating -- one api for all g…
rcoreilly Nov 29, 2024
b556df7
screens: don't constrain on maximized
rcoreilly Nov 29, 2024
ca776df
monitor change polling: fixes issue of waking from sleep (but not res…
rcoreilly Dec 5, 2024
8f5abf1
zoom works on saved screen zoom factor instead of overall value if pr…
rcoreilly Dec 5, 2024
eeeeada
hopefully last screen fix: cache save was using same map as saved ite…
rcoreilly Dec 5, 2024
8aab517
AppearanceSettings Screens is now read-only and improved comment docs…
rcoreilly Dec 5, 2024
3a86df2
use for instead of if to ensure indexing doesn't crash -- likely fixe…
rcoreilly Dec 5, 2024
f402b65
don't complain about missing keymap elements -- linux doesn't have se…
rcoreilly Dec 5, 2024
89f8752
linux fix: GetClipboardString hangs frequently if pushed too hard app…
rcoreilly Dec 5, 2024
7dc6cc8
gpu adapter name fixes
rcoreilly Dec 5, 2024
2a5ad9a
linux nvidia GPU not favored until issues are fixed
rcoreilly Dec 6, 2024
15474d1
down-vote nvidia discrete GPU selection in linux for now
rcoreilly Dec 6, 2024
a7c4500
actual vendor name working for apple
rcoreilly Dec 6, 2024
d0111a0
turn off debug
rcoreilly Dec 6, 2024
bf5f0a4
exclude nvidia discrete on windows too -- exact same crash happens th…
rcoreilly Dec 6, 2024
a3dd06f
gpu: move Encoder release before submit, needed for wgpu 22
rcoreilly Dec 6, 2024
db345d9
windows minimize fixed: ConstrainFrame was not liking the -32000 spec…
rcoreilly Dec 6, 2024
c0c8516
constrainframe logic fixed: now working on windows.
rcoreilly Dec 6, 2024
8a313ce
window move calls UpdateGeom: key fix for getting everything updated …
rcoreilly Dec 6, 2024
0a23875
use the request adapter api instead of our logic, for non-compute cas…
rcoreilly Dec 6, 2024
7fe495f
screens: reorganize gpu Instance, NewGPU calls so GPU adapter can be …
rcoreilly Dec 7, 2024
b142358
screens: found actual issue on windows vm: was barfing on requested d…
rcoreilly Dec 7, 2024
08b642c
add gpu.AutoSelectAdapter switch for using more standard RequestAdapt…
rcoreilly Dec 7, 2024
3045b32
restrict crashy adapter select logic to !compute case
rcoreilly Dec 7, 2024
24da9d9
use Screen.PixSize instead of Screen.Geometry for fullscreen resoluti…
kkoreilly Dec 8, 2024
86e9f29
clean up stage option docs
kkoreilly Dec 8, 2024
d8405c6
remove old fullscreen print statement
kkoreilly Dec 8, 2024
a0a2dd4
add Scene.IsFullscreen
kkoreilly Dec 8, 2024
f29beb7
use new Scene.IsFullscreen function
kkoreilly Dec 8, 2024
67c9331
add support for Stage.Pos for new windows on desktop
kkoreilly Dec 8, 2024
54a5ba9
start on Scene.SetGeometry function
kkoreilly Dec 8, 2024
63adccc
rename SetGeom to SetGeometry, UpdateGeom to updateGeometry, DebugSet…
kkoreilly Dec 8, 2024
47cfc1e
rename Scene.UpdateFullscreen to Scene.SetFullscreen; more consistent…
kkoreilly Dec 8, 2024
cc4be87
improve Scene.SetGeometry scren number handling
kkoreilly Dec 8, 2024
2357f27
screens: double-check that screen size is correct in resized: initial…
rcoreilly Dec 8, 2024
da2d0f6
clean up Scene.SetFullscreen logic
kkoreilly Dec 8, 2024
19f388e
screens: keep the SetDebug(false) init and add comment about why it i…
rcoreilly Dec 8, 2024
98b1113
improve Scene geometry function docs
kkoreilly Dec 8, 2024
e1048e1
clean up gpu init SetDebug comment
kkoreilly Dec 8, 2024
de9b231
clean up screen function docs and platform-specific behavior
kkoreilly Dec 8, 2024
e285ec2
add set geometry button to demo and fix App.Screen bound check logic
kkoreilly Dec 8, 2024
b2af2ef
clarify units for SetGeometry and add separate window manipulations s…
kkoreilly Dec 8, 2024
8f70e2a
fix conflict and set default level to warn
rcoreilly Dec 8, 2024
edf24e2
screens: resize drawer surface in FbResized which is run on main loop…
rcoreilly Dec 8, 2024
c3507b9
screens: updateGeom surface set size is pretty good very hard to get …
rcoreilly Dec 8, 2024
23602ca
if pos and/or size is not specified, it defualts to the current value…
kkoreilly Dec 8, 2024
20048cc
implement SetGeometry for fullscreen on web; clean up size variable n…
kkoreilly Dec 8, 2024
3b9920b
add fullscreen button to standard context menu on web
kkoreilly Dec 9, 2024
b55350f
screens: use current screen for new winows or dialogs
rcoreilly Dec 9, 2024
c345955
update webgpu version
kkoreilly Dec 9, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
116 changes: 77 additions & 39 deletions core/mainstage.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ func newMainStage(typ StageTypes, sc *Scene) *Stage {
// to close. It should typically be called once by every app at
// the end of their main function. It can not be called more than
// once for one app. For secondary windows, see [Body.RunWindow].
// If you need to configure the [Stage] further, use [Body.NewWindow]
// and then [Stage.RunMain] on the resulting [Stage].
func (bd *Body) RunMainWindow() {
if ExternalParent != nil {
bd.handleExternalParent()
Expand All @@ -46,6 +48,16 @@ func (bd *Body) RunMainWindow() {
Wait()
}

// RunMain runs the stage, starts the app's main loop,
// and waits for all windows to close. It can be called instead
// of [Body.RunMainWindow] if extra configuration steps are necessary
// on the [Stage]. It can not be called more than once for one app.
// For secondary stages, see [Stage.Run].
func (st *Stage) RunMain() {
st.Run()
Wait()
}

// ExternalParent is a parent widget external to this program.
// If it is set, calls to [Body.RunWindow] before [Wait] and
// calls to [Body.RunMainWindow] will add the [Body] to this
Expand Down Expand Up @@ -88,8 +100,9 @@ func (bd *Body) handleExternalParent() {

// NewWindow returns a new [WindowStage] that is placed in
// a new system window on multi-window platforms.
// You must call [Stage.Run] to run the window; see [Body.RunWindow]
// for a version that automatically runs it.
// You must call [Stage.Run] or [Stage.RunMain] to run the window;
// see [Body.RunWindow] and [Body.RunMainWindow] for versions that
// automatically do so.
func (bd *Body) NewWindow() *Stage {
ms := newMainStage(WindowStage, bd.Scene)
ms.SetNewWindow(true)
Expand Down Expand Up @@ -131,27 +144,29 @@ func (st *Stage) addSceneParts() {
sc.SceneGeom.Pos = np
sc.NeedsRender()
})
rsz := NewHandle(parts)
rsz.Styler(func(s *styles.Style) {
s.Direction = styles.Column
s.FillMargin = false
})
rsz.FinalStyler(func(s *styles.Style) {
s.Cursor = cursors.ResizeNWSE
s.Min.Set(units.Em(1))
})
rsz.SetName("resize")
rsz.OnChange(func(e events.Event) {
e.SetHandled()
pd := e.PrevDelta()
np := sc.SceneGeom.Size.Add(pd)
minsz := 100
np.X = max(np.X, minsz)
np.Y = max(np.Y, minsz)
ng := sc.SceneGeom
ng.Size = np
sc.resize(ng)
})
if st.Resizable {
rsz := NewHandle(parts)
rsz.Styler(func(s *styles.Style) {
s.Direction = styles.Column
s.FillMargin = false
})
rsz.FinalStyler(func(s *styles.Style) {
s.Cursor = cursors.ResizeNWSE
s.Min.Set(units.Em(1))
})
rsz.SetName("resize")
rsz.OnChange(func(e events.Event) {
e.SetHandled()
pd := e.PrevDelta()
np := sc.SceneGeom.Size.Add(pd)
minsz := 100
np.X = max(np.X, minsz)
np.Y = max(np.Y, minsz)
ng := sc.SceneGeom
ng.Size = np
sc.resize(ng)
})
}
}

// firstWindowStages creates a temporary [stages] for the first window
Expand All @@ -163,6 +178,13 @@ func (st *Stage) firstWindowStages() *stages {
return ms
}

func (st *Stage) currentScreen() *system.Screen {
if currentRenderWindow != nil {
return currentRenderWindow.SystemWindow.Screen()
}
return system.TheApp.Screen(0)
}

// configMainStage does main-stage configuration steps
func (st *Stage) configMainStage() {
sc := st.Scene
Expand Down Expand Up @@ -236,17 +258,21 @@ func (st *Stage) runWindow() *Stage {
} else {
// on other platforms, we want extra space and a minimum window size
sz = sz.Add(image.Pt(20, 20))
if st.NewWindow && st.UseMinSize {
// we require windows to be at least 60% and no more than 80% of the
// screen size by default
scsz := system.TheApp.Screen(0).PixSize // TODO(kai): is there a better screen to get here?
sz = image.Pt(max(sz.X, scsz.X*6/10), max(sz.Y, scsz.Y*6/10))
sz = image.Pt(min(sz.X, scsz.X*8/10), min(sz.Y, scsz.Y*8/10))
screen := st.currentScreen()
if screen != nil {
st.SetScreen(screen.ScreenNumber)
if st.NewWindow && st.UseMinSize {
// we require windows to be at least 60% and no more than 80% of the
// screen size by default
scsz := screen.PixSize
sz = image.Pt(max(sz.X, scsz.X*6/10), max(sz.Y, scsz.Y*6/10))
sz = image.Pt(min(sz.X, scsz.X*8/10), min(sz.Y, scsz.Y*8/10))
}
}
}
}
st.Mains = nil // reset
if DebugSettings.WinRenderTrace {
if DebugSettings.WindowRenderTrace {
fmt.Println("MainStage.RunWindow: Window Size:", sz)
}

Expand Down Expand Up @@ -325,8 +351,12 @@ func (st *Stage) runDialog() *Stage {
sz.X = max(sz.X, minx)
}
sc.Events.startFocusFirst = true // popup dialogs always need focus
screen := st.currentScreen()
if screen != nil {
st.SetScreen(screen.ScreenNumber)
}
}
if DebugSettings.WinRenderTrace {
if DebugSettings.WindowRenderTrace {
slog.Info("MainStage.RunDialog", "size", sz)
}

Expand Down Expand Up @@ -355,21 +385,29 @@ func (st *Stage) newRenderWindow() *renderWindow {
Title: title,
Icon: appIconImages(),
Size: st.Scene.SceneGeom.Size,
Pos: st.Pos,
StdPixels: false,
Screen: st.Screen,
}
wgp := theWindowGeometrySaver.pref(title, nil)
if TheApp.Platform() != system.Offscreen && wgp != nil {
opts.Flags.SetFlag(!st.Resizable, system.FixedSize)
opts.Flags.SetFlag(st.Maximized, system.Maximized)
opts.Flags.SetFlag(st.Fullscreen, system.Fullscreen)
screenName := ""
if st.Screen > 0 {
screenName = TheApp.Screen(st.Screen).Name
}
wgp, screen := theWindowGeometrySaver.get(title, screenName)
if wgp != nil {
theWindowGeometrySaver.settingStart()
opts.Size = wgp.size()
opts.Pos = wgp.pos()
opts.Screen = screen.ScreenNumber
opts.Size = wgp.Size
opts.Pos = wgp.Pos
opts.StdPixels = false
if w := AllRenderWindows.FindName(name); w != nil { // offset from existing
opts.Pos.X += 20
opts.Pos.Y += 20
}
if wgp.Fullscreen {
opts.SetFullscreen()
}
opts.Flags.SetFlag(wgp.Max, system.Maximized)
}
win := newRenderWindow(name, title, opts)
theWindowGeometrySaver.settingEnd()
Expand Down Expand Up @@ -409,7 +447,7 @@ func (sm *stages) mainHandleEvent(e events.Event) {
for i := n - 1; i >= 0; i-- {
st := sm.stack.ValueByIndex(i)
st.mainHandleEvent(e)
if e.IsHandled() || st.Modal || st.Type == WindowStage || st.FullWindow {
if e.IsHandled() || st.Modal || st.FullWindow {
break
}
if st.Type == DialogStage { // modeless dialog, by definition
Expand Down
17 changes: 15 additions & 2 deletions core/menu.go
Original file line number Diff line number Diff line change
Expand Up @@ -284,11 +284,24 @@ func (sc *Scene) standardContextMenu(m *Scene) { //types:add
InspectorWindow(sc)
})

// no window menu on single-window platforms
if TheApp.Platform().IsMobile() {
// No window menu on mobile platforms
if TheApp.Platform().IsMobile() && TheApp.Platform() != system.Web {
return
}
NewButton(m).SetText("Window").SetMenu(func(m *Scene) {
if sc.IsFullscreen() {
NewButton(m).SetText("Exit fullscreen").SetIcon(icons.Fullscreen).OnClick(func(e events.Event) {
sc.SetFullscreen(false)
})
} else {
NewButton(m).SetText("Fullscreen").SetIcon(icons.Fullscreen).OnClick(func(e events.Event) {
sc.SetFullscreen(true)
})
}
// Only do fullscreen on web
if TheApp.Platform() == system.Web {
return
}
NewButton(m).SetText("Focus next").SetIcon(icons.CenterFocusStrong).
SetKey(keymap.WinFocusNext).OnClick(func(e events.Event) {
AllRenderWindows.focusNext()
Expand Down
Loading
Loading