Skip to content

Commit

Permalink
Merge pull request #1165 from cogentcore/nonmodal
Browse files Browse the repository at this point in the history
Nonmodal dialog support for web NewWindow Dialogs
  • Loading branch information
kkoreilly authored Aug 21, 2024
2 parents fb9f1f0 + 33718ef commit e58d152
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 3 deletions.
6 changes: 6 additions & 0 deletions core/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,11 +251,13 @@ func (em *Events) handlePosEvent(e events.Event) {
if em.spriteSlide != nil {
em.spriteSlide.handleEvent(e)
em.spriteSlide.send(events.SlideMove, e)
e.SetHandled()
return
}
if em.slide != nil {
em.slide.AsWidget().HandleEvent(e)
em.slide.AsWidget().Send(events.SlideMove, e)
e.SetHandled()
return
}
case events.Scroll:
Expand Down Expand Up @@ -400,16 +402,19 @@ func (em *Events) handlePosEvent(e events.Event) {
em.dragMove(e) // updates sprite position
em.drag.AsWidget().HandleEvent(e) // raw drag
em.drag.AsWidget().Send(events.DragMove, e) // usually ignored
e.SetHandled()
} else {
if em.dragPress != nil && em.dragStartCheck(e, DeviceSettings.DragStartTime, DeviceSettings.DragStartDistance) {
em.cancelRepeatClick()
em.cancelLongPress()
em.dragPress.AsWidget().Send(events.DragStart, e)
e.SetHandled()
} else if em.slidePress != nil && em.dragStartCheck(e, DeviceSettings.SlideStartTime, DeviceSettings.DragStartDistance) {
em.cancelRepeatClick()
em.cancelLongPress()
em.slide = em.slidePress
em.slide.AsWidget().Send(events.SlideStart, e)
e.SetHandled()
}
}
// if we already have a long press widget, we update it based on our dragging movement
Expand All @@ -420,6 +425,7 @@ func (em *Events) handlePosEvent(e events.Event) {
em.cancelRepeatClick()
if em.slide != nil {
em.slide.AsWidget().Send(events.SlideStop, e)
e.SetHandled()
em.slide = nil
em.press = nil
}
Expand Down
1 change: 1 addition & 0 deletions core/handle.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ func (hl *Handle) Init() {
})

hl.On(events.SlideMove, func(e events.Event) {
e.SetHandled()
pos := hl.parentWidget().PointToRelPos(e.Pos())
hl.Pos = math32.FromPoint(pos).Dim(hl.Styles.Direction.Dim())
hl.SendChange(e)
Expand Down
19 changes: 17 additions & 2 deletions core/mainstage.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,17 +165,24 @@ func (st *Stage) firstWindowStages() *stages {

// configMainStage does main-stage configuration steps
func (st *Stage) configMainStage() {
sc := st.Scene
if st.NewWindow {
st.FullWindow = true
}
// if we are on mobile, we can never have new windows
if TheApp.Platform().IsMobile() {
// If we are a new window dialog on a large single-window platform,
// we use a modeless dialog as a substitute.
if st.NewWindow && st.Type == DialogStage && st.Context != nil && st.Context.AsWidget().SizeClass() != SizeCompact {
st.FullWindow = false
st.Modal = false
st.Scrim = false
}
// If we are on mobile, we can never have new windows.
st.NewWindow = false
}
if st.FullWindow || st.NewWindow {
st.Scrim = false
}
sc := st.Scene
sc.makeSceneBars()
sc.updateScene()
}
Expand Down Expand Up @@ -398,5 +405,13 @@ func (sm *stages) mainHandleEvent(e events.Event) {
if e.IsHandled() || st.Modal || st.Type == WindowStage || st.FullWindow {
break
}
if st.Type == DialogStage { // modeless dialog, by definition
if e.HasPos() && st.Scene != nil {
b := st.Scene.SceneGeom.Bounds()
if e.WindowPos().In(b) { // don't propagate
break
}
}
}
}
}
3 changes: 3 additions & 0 deletions core/style.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,4 +225,7 @@ func styleFromTags(w Widget, tags reflect.StructTag) {
setFromTag(tags, "grow", func(v float32) { s.Grow.X = v })
setFromTag(tags, "grow-y", func(v float32) { s.Grow.Y = v })
})
if tags.Get("new-window") == "+" {
w.AsWidget().setFlag(true, widgetValueNewWindow)
}
}
4 changes: 3 additions & 1 deletion core/value.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,9 @@ func InitValueButton(v Value, allowReadOnly bool, make func(d *Body), after ...f
}
wb.OnClick(func(e events.Event) {
if allowReadOnly || !wb.IsReadOnly() {
wb.setFlag(e.HasAnyModifier(key.Shift), widgetValueNewWindow)
if e.HasAnyModifier(key.Shift) {
wb.setFlag(!wb.hasFlag(widgetValueNewWindow), widgetValueNewWindow)
}
openValueDialog(v, make, after...)
}
})
Expand Down
1 change: 1 addition & 0 deletions xyz/xyzcore/manip.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ func (sw *Scene) handleSelectEventsImpl(e events.Event) {

func (sw *Scene) handleSlideEvents() {
sw.On(events.SlideMove, func(e events.Event) {
e.SetHandled()
pos := sw.Geom.ContentBBox.Min
e.SetLocalOff(e.LocalOff().Add(pos))
xy := sw.XYZ
Expand Down

0 comments on commit e58d152

Please sign in to comment.