Removed references to flexible from layouts, x backend, core
This commit is contained in:
parent
677dca1dbf
commit
51084a6cfe
@ -96,9 +96,6 @@ func (window *Window) Adopt (child elements.Element) {
|
|||||||
window.child.OnDamage(nil)
|
window.child.OnDamage(nil)
|
||||||
window.child.OnMinimumSizeChange(nil)
|
window.child.OnMinimumSizeChange(nil)
|
||||||
}
|
}
|
||||||
if previousChild, ok := window.child.(elements.Flexible); ok {
|
|
||||||
previousChild.OnFlexibleHeightChange(nil)
|
|
||||||
}
|
|
||||||
if previousChild, ok := window.child.(elements.Focusable); ok {
|
if previousChild, ok := window.child.(elements.Focusable); ok {
|
||||||
previousChild.OnFocusRequest(nil)
|
previousChild.OnFocusRequest(nil)
|
||||||
previousChild.OnFocusMotionRequest(nil)
|
previousChild.OnFocusMotionRequest(nil)
|
||||||
@ -115,9 +112,6 @@ func (window *Window) Adopt (child elements.Element) {
|
|||||||
if newChild, ok := child.(elements.Configurable); ok {
|
if newChild, ok := child.(elements.Configurable); ok {
|
||||||
newChild.SetConfig(window.config)
|
newChild.SetConfig(window.config)
|
||||||
}
|
}
|
||||||
if newChild, ok := child.(elements.Flexible); ok {
|
|
||||||
newChild.OnFlexibleHeightChange(window.resizeChildToFit)
|
|
||||||
}
|
|
||||||
if newChild, ok := child.(elements.Focusable); ok {
|
if newChild, ok := child.(elements.Focusable); ok {
|
||||||
newChild.OnFocusRequest(window.childSelectionRequestCallback)
|
newChild.OnFocusRequest(window.childSelectionRequestCallback)
|
||||||
}
|
}
|
||||||
@ -263,26 +257,7 @@ func (window *Window) redrawChildEntirely () {
|
|||||||
|
|
||||||
func (window *Window) resizeChildToFit () {
|
func (window *Window) resizeChildToFit () {
|
||||||
window.skipChildDrawCallback = true
|
window.skipChildDrawCallback = true
|
||||||
if child, ok := window.child.(elements.Flexible); ok {
|
window.child.DrawTo(window.canvas)
|
||||||
minimumHeight := child.FlexibleHeightFor(window.metrics.width)
|
|
||||||
minimumWidth, _ := child.MinimumSize()
|
|
||||||
|
|
||||||
icccm.WmNormalHintsSet (
|
|
||||||
window.backend.connection,
|
|
||||||
window.xWindow.Id,
|
|
||||||
&icccm.NormalHints {
|
|
||||||
Flags: icccm.SizeHintPMinSize,
|
|
||||||
MinWidth: uint(minimumWidth),
|
|
||||||
MinHeight: uint(minimumHeight),
|
|
||||||
})
|
|
||||||
|
|
||||||
if window.metrics.height >= minimumHeight &&
|
|
||||||
window.metrics.width >= minimumWidth {
|
|
||||||
window.child.DrawTo(window.canvas)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
window.child.DrawTo(window.canvas)
|
|
||||||
}
|
|
||||||
window.skipChildDrawCallback = false
|
window.skipChildDrawCallback = false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -326,16 +326,6 @@ func (propagator *Propagator) forFocusable (callback func (child elements.Focusa
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (propagator *Propagator) forFlexible (callback func (child elements.Flexible) bool) {
|
|
||||||
propagator.forChildren (func (child elements.Element) bool {
|
|
||||||
typedChild, flexible := child.(elements.Flexible)
|
|
||||||
if flexible {
|
|
||||||
if !callback(typedChild) { return false }
|
|
||||||
}
|
|
||||||
return true
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
func (propagator *Propagator) firstFocused () int {
|
func (propagator *Propagator) firstFocused () int {
|
||||||
for index := 0; index < propagator.parent.CountChildren(); index ++ {
|
for index := 0; index < propagator.parent.CountChildren(); index ++ {
|
||||||
child, focusable := propagator.parent.Child(index).(elements.Focusable)
|
child, focusable := propagator.parent.Child(index).(elements.Focusable)
|
||||||
|
@ -3,7 +3,6 @@ package basicLayouts
|
|||||||
import "image"
|
import "image"
|
||||||
import "git.tebibyte.media/sashakoshka/tomo/artist"
|
import "git.tebibyte.media/sashakoshka/tomo/artist"
|
||||||
import "git.tebibyte.media/sashakoshka/tomo/layouts"
|
import "git.tebibyte.media/sashakoshka/tomo/layouts"
|
||||||
import "git.tebibyte.media/sashakoshka/tomo/elements"
|
|
||||||
|
|
||||||
// Dialog arranges elements in the form of a dialog box. The first element is
|
// Dialog arranges elements in the form of a dialog box. The first element is
|
||||||
// positioned above as the main focus of the dialog, and is set to expand
|
// positioned above as the main focus of the dialog, and is set to expand
|
||||||
@ -132,45 +131,6 @@ func (layout Dialog) MinimumSize (
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// FlexibleHeightFor Returns the minimum height the layout needs to lay out the
|
|
||||||
// specified elements at the given width, taking into account flexible elements.
|
|
||||||
func (layout Dialog) FlexibleHeightFor (
|
|
||||||
entries []layouts.LayoutEntry,
|
|
||||||
margin image.Point,
|
|
||||||
padding artist.Inset,
|
|
||||||
width int,
|
|
||||||
) (
|
|
||||||
height int,
|
|
||||||
) {
|
|
||||||
if layout.Pad {
|
|
||||||
width -= padding.Horizontal()
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(entries) > 0 {
|
|
||||||
mainChildHeight := 0
|
|
||||||
if child, flexible := entries[0].Element.(elements.Flexible); flexible {
|
|
||||||
mainChildHeight = child.FlexibleHeightFor(width)
|
|
||||||
} else {
|
|
||||||
_, mainChildHeight = entries[0].MinimumSize()
|
|
||||||
}
|
|
||||||
height += mainChildHeight
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(entries) > 1 {
|
|
||||||
if layout.Gap { height += margin.Y }
|
|
||||||
_, additionalHeight := layout.minimumSizeOfControlRow (
|
|
||||||
entries[1:], margin, padding)
|
|
||||||
height += additionalHeight
|
|
||||||
}
|
|
||||||
|
|
||||||
if layout.Pad {
|
|
||||||
height += padding.Vertical()
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: possibly flatten this method to account for flexible elements within
|
|
||||||
// the control row.
|
|
||||||
func (layout Dialog) minimumSizeOfControlRow (
|
func (layout Dialog) minimumSizeOfControlRow (
|
||||||
entries []layouts.LayoutEntry,
|
entries []layouts.LayoutEntry,
|
||||||
margin image.Point,
|
margin image.Point,
|
||||||
|
@ -3,7 +3,6 @@ package basicLayouts
|
|||||||
import "image"
|
import "image"
|
||||||
import "git.tebibyte.media/sashakoshka/tomo/artist"
|
import "git.tebibyte.media/sashakoshka/tomo/artist"
|
||||||
import "git.tebibyte.media/sashakoshka/tomo/layouts"
|
import "git.tebibyte.media/sashakoshka/tomo/layouts"
|
||||||
import "git.tebibyte.media/sashakoshka/tomo/elements"
|
|
||||||
|
|
||||||
// Horizontal arranges elements horizontally. Elements at the start of the entry
|
// Horizontal arranges elements horizontally. Elements at the start of the entry
|
||||||
// list will be positioned on the left, and elements at the end of the entry
|
// list will be positioned on the left, and elements at the end of the entry
|
||||||
@ -76,49 +75,6 @@ func (layout Horizontal) MinimumSize (
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// FlexibleHeightFor Returns the minimum height the layout needs to lay out the
|
|
||||||
// specified elements at the given width, taking into account flexible elements.
|
|
||||||
func (layout Horizontal) FlexibleHeightFor (
|
|
||||||
entries []layouts.LayoutEntry,
|
|
||||||
margin image.Point,
|
|
||||||
padding artist.Inset,
|
|
||||||
width int,
|
|
||||||
) (
|
|
||||||
height int,
|
|
||||||
) {
|
|
||||||
if layout.Pad { width -= padding.Horizontal() }
|
|
||||||
|
|
||||||
// get width of expanding elements
|
|
||||||
expandingElementWidth := layout.expandingElementWidth (
|
|
||||||
entries, margin, padding, width)
|
|
||||||
|
|
||||||
x, y := 0, 0
|
|
||||||
if layout.Pad {
|
|
||||||
x += padding.Horizontal()
|
|
||||||
y += padding.Vertical()
|
|
||||||
}
|
|
||||||
|
|
||||||
// set the size and position of each element
|
|
||||||
for index, entry := range entries {
|
|
||||||
entryWidth, entryHeight := entry.MinimumSize()
|
|
||||||
if entry.Expand {
|
|
||||||
entryWidth = expandingElementWidth
|
|
||||||
}
|
|
||||||
if child, flexible := entry.Element.(elements.Flexible); flexible {
|
|
||||||
entryHeight = child.FlexibleHeightFor(entryWidth)
|
|
||||||
}
|
|
||||||
if entryHeight > height { height = entryHeight }
|
|
||||||
|
|
||||||
x += entryWidth
|
|
||||||
if index > 0 && layout.Gap { x += margin.X }
|
|
||||||
}
|
|
||||||
|
|
||||||
if layout.Pad {
|
|
||||||
height += padding.Vertical()
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
func (layout Horizontal) expandingElementWidth (
|
func (layout Horizontal) expandingElementWidth (
|
||||||
entries []layouts.LayoutEntry,
|
entries []layouts.LayoutEntry,
|
||||||
margin image.Point,
|
margin image.Point,
|
||||||
|
@ -3,7 +3,6 @@ package basicLayouts
|
|||||||
import "image"
|
import "image"
|
||||||
import "git.tebibyte.media/sashakoshka/tomo/artist"
|
import "git.tebibyte.media/sashakoshka/tomo/artist"
|
||||||
import "git.tebibyte.media/sashakoshka/tomo/layouts"
|
import "git.tebibyte.media/sashakoshka/tomo/layouts"
|
||||||
import "git.tebibyte.media/sashakoshka/tomo/elements"
|
|
||||||
|
|
||||||
// Vertical arranges elements vertically. Elements at the start of the entry
|
// Vertical arranges elements vertically. Elements at the start of the entry
|
||||||
// list will be positioned at the top, and elements at the end of the entry list
|
// list will be positioned at the top, and elements at the end of the entry list
|
||||||
@ -32,13 +31,7 @@ func (layout Vertical) Arrange (
|
|||||||
minimumHeights := make([]int, len(entries))
|
minimumHeights := make([]int, len(entries))
|
||||||
expandingElements := 0
|
expandingElements := 0
|
||||||
for index, entry := range entries {
|
for index, entry := range entries {
|
||||||
var entryMinHeight int
|
_, entryMinHeight := entry.MinimumSize()
|
||||||
|
|
||||||
if child, flexible := entry.Element.(elements.Flexible); flexible {
|
|
||||||
entryMinHeight = child.FlexibleHeightFor(bounds.Dx())
|
|
||||||
} else {
|
|
||||||
_, entryMinHeight = entry.MinimumSize()
|
|
||||||
}
|
|
||||||
minimumHeights[index] = entryMinHeight
|
minimumHeights[index] = entryMinHeight
|
||||||
|
|
||||||
if entry.Expand {
|
if entry.Expand {
|
||||||
@ -101,34 +94,3 @@ func (layout Vertical) MinimumSize (
|
|||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// FlexibleHeightFor Returns the minimum height the layout needs to lay out the
|
|
||||||
// specified elements at the given width, taking into account flexible elements.
|
|
||||||
func (layout Vertical) FlexibleHeightFor (
|
|
||||||
entries []layouts.LayoutEntry,
|
|
||||||
margin image.Point,
|
|
||||||
padding artist.Inset,
|
|
||||||
width int,
|
|
||||||
) (
|
|
||||||
height int,
|
|
||||||
) {
|
|
||||||
if layout.Pad {
|
|
||||||
width -= padding.Horizontal()
|
|
||||||
height += padding.Vertical()
|
|
||||||
}
|
|
||||||
|
|
||||||
for index, entry := range entries {
|
|
||||||
child, flexible := entry.Element.(elements.Flexible)
|
|
||||||
if flexible {
|
|
||||||
height += child.FlexibleHeightFor(width)
|
|
||||||
} else {
|
|
||||||
_, entryHeight := entry.MinimumSize()
|
|
||||||
height += entryHeight
|
|
||||||
}
|
|
||||||
|
|
||||||
if layout.Gap && index > 0 {
|
|
||||||
height += margin.Y
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
@ -12,10 +12,6 @@ type LayoutEntry struct {
|
|||||||
Expand bool
|
Expand bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: have layouts take in artist.Inset for margin and padding
|
|
||||||
// TODO: create a layout that only displays the first element and full screen.
|
|
||||||
// basically a blank layout for containers that only ever have one element.
|
|
||||||
|
|
||||||
// Layout is capable of arranging elements within a container. It is also able
|
// Layout is capable of arranging elements within a container. It is also able
|
||||||
// to determine the minimum amount of room it needs to do so.
|
// to determine the minimum amount of room it needs to do so.
|
||||||
type Layout interface {
|
type Layout interface {
|
||||||
@ -39,16 +35,4 @@ type Layout interface {
|
|||||||
) (
|
) (
|
||||||
width, height int,
|
width, height int,
|
||||||
)
|
)
|
||||||
|
|
||||||
// FlexibleHeightFor Returns the minimum height the layout needs to lay
|
|
||||||
// out the specified elements at the given width, taking into account
|
|
||||||
// flexible elements.
|
|
||||||
FlexibleHeightFor (
|
|
||||||
entries []LayoutEntry,
|
|
||||||
margin image.Point,
|
|
||||||
padding artist.Inset,
|
|
||||||
squeeze int,
|
|
||||||
) (
|
|
||||||
height int,
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
Binary file not shown.
Before Width: | Height: | Size: 1.9 KiB After Width: | Height: | Size: 1.9 KiB |
Reference in New Issue
Block a user