mirror of https://github.com/anoshenko/rui.git
Update popup.go
This commit is contained in:
parent
f36ee4a4a7
commit
d28ee630b6
264
popup.go
264
popup.go
|
@ -331,187 +331,173 @@ type popupManager struct {
|
||||||
popups []Popup
|
popups []Popup
|
||||||
}
|
}
|
||||||
|
|
||||||
type popupArrow struct {
|
func (popup *popupData) createArrowView(location int) View {
|
||||||
column, row int
|
|
||||||
location, align int
|
|
||||||
size, width, off SizeUnit
|
|
||||||
}
|
|
||||||
|
|
||||||
func popupArrowInit(popup Popup) popupArrow {
|
|
||||||
session := popup.Session()
|
session := popup.Session()
|
||||||
|
|
||||||
var arrow popupArrow
|
getSize := func(tag PropertyName, constTag string) SizeUnit {
|
||||||
|
size, _ := sizeProperty(popup, tag, session)
|
||||||
arrow.size, _ = sizeProperty(popup, ArrowSize, session)
|
if size.Type != Auto && size.Value > 0 {
|
||||||
arrow.size, _ = sizeProperty(popup, ArrowWidth, session)
|
return size
|
||||||
arrow.off, _ = sizeProperty(popup, ArrowOffset, session)
|
|
||||||
arrow.align, _ = enumProperty(popup, ArrowAlign, session, CenterAlign)
|
|
||||||
arrow.row = 1
|
|
||||||
arrow.column = 1
|
|
||||||
arrow.location, _ = enumProperty(popup, Arrow, session, NoneArrow)
|
|
||||||
|
|
||||||
switch arrow.location {
|
|
||||||
case BottomArrow:
|
|
||||||
arrow.row = 2
|
|
||||||
|
|
||||||
case RightArrow:
|
|
||||||
arrow.column = 2
|
|
||||||
}
|
|
||||||
|
|
||||||
return arrow
|
|
||||||
}
|
|
||||||
|
|
||||||
func (arrow *popupArrow) fixOff(popupView View) {
|
|
||||||
if arrow.align == CenterAlign && arrow.off.Type == Auto {
|
|
||||||
r := GetRadius(popupView)
|
|
||||||
switch arrow.location {
|
|
||||||
case TopArrow:
|
|
||||||
switch arrow.align {
|
|
||||||
case LeftAlign:
|
|
||||||
arrow.off = r.TopLeftX
|
|
||||||
|
|
||||||
case RightAlign:
|
|
||||||
arrow.off = r.TopRightX
|
|
||||||
}
|
|
||||||
|
|
||||||
case BottomArrow:
|
|
||||||
switch arrow.align {
|
|
||||||
case LeftAlign:
|
|
||||||
arrow.off = r.BottomLeftX
|
|
||||||
|
|
||||||
case RightAlign:
|
|
||||||
arrow.off = r.BottomRightX
|
|
||||||
}
|
|
||||||
|
|
||||||
case RightArrow:
|
|
||||||
switch arrow.align {
|
|
||||||
case TopAlign:
|
|
||||||
arrow.off = r.TopRightY
|
|
||||||
|
|
||||||
case BottomAlign:
|
|
||||||
arrow.off = r.BottomRightY
|
|
||||||
}
|
|
||||||
|
|
||||||
case LeftArrow:
|
|
||||||
switch arrow.align {
|
|
||||||
case TopAlign:
|
|
||||||
arrow.off = r.TopLeftY
|
|
||||||
|
|
||||||
case BottomAlign:
|
|
||||||
arrow.off = r.BottomLeftY
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (arrow *popupArrow) createView(popupView View) View {
|
|
||||||
session := popupView.Session()
|
|
||||||
|
|
||||||
defaultSize := func(constTag string) SizeUnit {
|
|
||||||
if value, ok := session.Constant(constTag); ok {
|
if value, ok := session.Constant(constTag); ok {
|
||||||
if size, ok := StringToSizeUnit(value); ok && size.Type != Auto && size.Value != 0 {
|
if size, ok := StringToSizeUnit(value); ok && size.Type != Auto && size.Value > 0 {
|
||||||
return size
|
return size
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return Px(16)
|
return Px(16)
|
||||||
}
|
}
|
||||||
|
|
||||||
if arrow.size.Type == Auto || arrow.size.Value == 0 {
|
size := getSize(ArrowSize, "ruiArrowSize")
|
||||||
arrow.size = defaultSize("ruiArrowSize")
|
width := getSize(ArrowWidth, "ruiArrowWidth")
|
||||||
}
|
|
||||||
|
|
||||||
if arrow.width.Type == Auto || arrow.width.Value == 0 {
|
params := Params{BackgroundColor: GetBackgroundColor(popup.popupView)}
|
||||||
arrow.width = defaultSize("ruiArrowWidth")
|
|
||||||
}
|
|
||||||
|
|
||||||
params := Params{BackgroundColor: GetBackgroundColor(popupView)}
|
if shadow := GetShadowProperty(popup.popupView); shadow != nil {
|
||||||
|
|
||||||
if shadow := GetShadowProperty(popupView); shadow != nil {
|
|
||||||
params[Shadow] = shadow
|
params[Shadow] = shadow
|
||||||
}
|
}
|
||||||
|
|
||||||
if filter := GetBackdropFilter(popupView); filter != nil {
|
if filter := GetBackdropFilter(popup.popupView); filter != nil {
|
||||||
params[BackdropFilter] = filter
|
params[BackdropFilter] = filter
|
||||||
}
|
}
|
||||||
|
|
||||||
switch arrow.location {
|
switch location {
|
||||||
case TopArrow:
|
case TopArrow:
|
||||||
params[Row] = 0
|
params[Row] = 0
|
||||||
params[Column] = 1
|
params[Column] = 1
|
||||||
params[Clip] = NewPolygonClip([]any{"0%", "100%", "50%", "0%", "100%", "100%"})
|
params[Clip] = NewPolygonClip([]any{"0%", "100%", "50%", "0%", "100%", "100%"})
|
||||||
params[Width] = arrow.width
|
params[Width] = width
|
||||||
params[Height] = arrow.size
|
params[Height] = size
|
||||||
|
|
||||||
case RightArrow:
|
case RightArrow:
|
||||||
params[Row] = 1
|
params[Row] = 1
|
||||||
params[Column] = 0
|
params[Column] = 0
|
||||||
params[Clip] = NewPolygonClip([]any{"0%", "0%", "100%", "50%", "0%", "100%"})
|
params[Clip] = NewPolygonClip([]any{"0%", "0%", "100%", "50%", "0%", "100%"})
|
||||||
params[Width] = arrow.size
|
params[Width] = size
|
||||||
params[Height] = arrow.width
|
params[Height] = width
|
||||||
|
|
||||||
case BottomArrow:
|
case BottomArrow:
|
||||||
params[Row] = 0
|
params[Row] = 0
|
||||||
params[Column] = 1
|
params[Column] = 1
|
||||||
params[Clip] = NewPolygonClip([]any{"0%", "0%", "50%", "100%", "100%", "0%"})
|
params[Clip] = NewPolygonClip([]any{"0%", "0%", "50%", "100%", "100%", "0%"})
|
||||||
params[Width] = arrow.width
|
params[Width] = width
|
||||||
params[Height] = arrow.size
|
params[Height] = size
|
||||||
|
|
||||||
case LeftArrow:
|
case LeftArrow:
|
||||||
params[Row] = 1
|
params[Row] = 1
|
||||||
params[Column] = 0
|
params[Column] = 0
|
||||||
params[Clip] = NewPolygonClip([]any{"100%", "0%", "0%", "50%", "100%", "100%"})
|
params[Clip] = NewPolygonClip([]any{"100%", "0%", "0%", "50%", "100%", "100%"})
|
||||||
params[Width] = arrow.size
|
params[Width] = size
|
||||||
params[Height] = arrow.width
|
params[Height] = width
|
||||||
}
|
}
|
||||||
|
|
||||||
arrowView := NewView(session, params)
|
arrowView := NewView(session, params)
|
||||||
|
|
||||||
params = Params{
|
params = Params{
|
||||||
ID: popupArrowID,
|
ID: popupArrowID,
|
||||||
Row: arrow.row,
|
|
||||||
Column: arrow.column,
|
|
||||||
Content: arrowView,
|
Content: arrowView,
|
||||||
}
|
}
|
||||||
|
|
||||||
arrow.fixOff(popupView)
|
switch location {
|
||||||
|
case TopArrow:
|
||||||
|
params[Row] = 1
|
||||||
|
params[Column] = 2
|
||||||
|
|
||||||
switch arrow.location {
|
case BottomArrow:
|
||||||
|
params[Row] = 3
|
||||||
|
params[Column] = 2
|
||||||
|
|
||||||
|
case LeftArrow:
|
||||||
|
params[Row] = 2
|
||||||
|
params[Column] = 1
|
||||||
|
|
||||||
|
case RightArrow:
|
||||||
|
params[Row] = 2
|
||||||
|
params[Column] = 3
|
||||||
|
}
|
||||||
|
|
||||||
|
off, _ := sizeProperty(popup, ArrowOffset, session)
|
||||||
|
align, _ := enumProperty(popup, ArrowAlign, session, CenterAlign)
|
||||||
|
|
||||||
|
if align != CenterAlign && off.Type == Auto {
|
||||||
|
r := GetRadius(popup.popupView)
|
||||||
|
switch location {
|
||||||
|
case TopArrow:
|
||||||
|
switch align {
|
||||||
|
case LeftAlign:
|
||||||
|
off = r.TopLeftX
|
||||||
|
|
||||||
|
case RightAlign:
|
||||||
|
off = r.TopRightX
|
||||||
|
}
|
||||||
|
|
||||||
|
case BottomArrow:
|
||||||
|
switch align {
|
||||||
|
case LeftAlign:
|
||||||
|
off = r.BottomLeftX
|
||||||
|
|
||||||
|
case RightAlign:
|
||||||
|
off = r.BottomRightX
|
||||||
|
}
|
||||||
|
|
||||||
|
case RightArrow:
|
||||||
|
switch align {
|
||||||
|
case TopAlign:
|
||||||
|
off = r.TopRightY
|
||||||
|
|
||||||
|
case BottomAlign:
|
||||||
|
off = r.BottomRightY
|
||||||
|
}
|
||||||
|
|
||||||
|
case LeftArrow:
|
||||||
|
switch align {
|
||||||
|
case TopAlign:
|
||||||
|
off = r.TopLeftY
|
||||||
|
|
||||||
|
case BottomAlign:
|
||||||
|
off = r.BottomLeftY
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
switch location {
|
||||||
case TopArrow, BottomArrow:
|
case TopArrow, BottomArrow:
|
||||||
cellWidth := make([]SizeUnit, 3)
|
cellWidth := make([]SizeUnit, 3)
|
||||||
switch arrow.align {
|
switch align {
|
||||||
case LeftAlign:
|
case LeftAlign:
|
||||||
cellWidth[0] = arrow.off
|
cellWidth[0] = off
|
||||||
cellWidth[2] = Fr(1)
|
cellWidth[2] = Fr(1)
|
||||||
|
|
||||||
case RightAlign:
|
case RightAlign:
|
||||||
cellWidth[0] = Fr(1)
|
cellWidth[0] = Fr(1)
|
||||||
cellWidth[2] = arrow.off
|
cellWidth[2] = off
|
||||||
|
|
||||||
default:
|
default:
|
||||||
cellWidth[0] = Fr(1)
|
cellWidth[0] = Fr(1)
|
||||||
cellWidth[2] = Fr(1)
|
cellWidth[2] = Fr(1)
|
||||||
if arrow.off.Type != Auto && arrow.off.Value != 0 {
|
if off.Type != Auto && off.Value != 0 {
|
||||||
arrowView.Set(MarginLeft, arrow.off)
|
arrowView.Set(MarginLeft, off)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
params[CellWidth] = cellWidth
|
params[CellWidth] = cellWidth
|
||||||
|
|
||||||
case RightArrow, LeftArrow:
|
case RightArrow, LeftArrow:
|
||||||
cellHeight := make([]SizeUnit, 3)
|
cellHeight := make([]SizeUnit, 3)
|
||||||
switch arrow.align {
|
switch align {
|
||||||
case TopAlign:
|
case TopAlign:
|
||||||
cellHeight[0] = arrow.off
|
cellHeight[0] = off
|
||||||
cellHeight[2] = Fr(1)
|
cellHeight[2] = Fr(1)
|
||||||
|
|
||||||
case BottomAlign:
|
case BottomAlign:
|
||||||
cellHeight[0] = Fr(1)
|
cellHeight[0] = Fr(1)
|
||||||
cellHeight[2] = arrow.off
|
cellHeight[2] = off
|
||||||
|
|
||||||
default:
|
default:
|
||||||
cellHeight[0] = Fr(1)
|
cellHeight[0] = Fr(1)
|
||||||
cellHeight[2] = Fr(1)
|
cellHeight[2] = Fr(1)
|
||||||
if arrow.off.Type != Auto && arrow.off.Value != 0 {
|
if off.Type != Auto && off.Value != 0 {
|
||||||
arrowView.Set(MarginTop, arrow.off)
|
arrowView.Set(MarginTop, off)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
params[CellHeight] = cellHeight
|
params[CellHeight] = cellHeight
|
||||||
|
@ -520,54 +506,34 @@ func (arrow *popupArrow) createView(popupView View) View {
|
||||||
return NewGridLayout(session, params)
|
return NewGridLayout(session, params)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (popup *popupData) layerCellWidth(arrowLocation int) []SizeUnit {
|
func (popup *popupData) layerCellWidth() []SizeUnit {
|
||||||
|
cellWidth := make([]SizeUnit, 5)
|
||||||
var columnCount int
|
|
||||||
switch arrowLocation {
|
|
||||||
case LeftArrow, RightArrow:
|
|
||||||
columnCount = 4
|
|
||||||
|
|
||||||
default:
|
|
||||||
columnCount = 3
|
|
||||||
}
|
|
||||||
|
|
||||||
cellWidth := make([]SizeUnit, columnCount)
|
|
||||||
switch hAlign, _ := enumProperty(popup, HorizontalAlign, popup.session, CenterAlign); hAlign {
|
switch hAlign, _ := enumProperty(popup, HorizontalAlign, popup.session, CenterAlign); hAlign {
|
||||||
case LeftAlign:
|
case LeftAlign:
|
||||||
cellWidth[columnCount-1] = Fr(1)
|
cellWidth[4] = Fr(1)
|
||||||
|
|
||||||
case RightAlign:
|
case RightAlign:
|
||||||
cellWidth[0] = Fr(1)
|
cellWidth[0] = Fr(1)
|
||||||
|
|
||||||
default:
|
default:
|
||||||
cellWidth[0] = Fr(1)
|
cellWidth[0] = Fr(1)
|
||||||
cellWidth[columnCount-1] = Fr(1)
|
cellWidth[4] = Fr(1)
|
||||||
}
|
}
|
||||||
return cellWidth
|
return cellWidth
|
||||||
}
|
}
|
||||||
|
|
||||||
func (popup *popupData) layerCellHeight(arrowLocation int) []SizeUnit {
|
func (popup *popupData) layerCellHeight() []SizeUnit {
|
||||||
|
cellHeight := make([]SizeUnit, 5)
|
||||||
var rowCount int
|
|
||||||
switch arrowLocation {
|
|
||||||
case TopArrow, BottomArrow:
|
|
||||||
rowCount = 4
|
|
||||||
|
|
||||||
default:
|
|
||||||
rowCount = 3
|
|
||||||
}
|
|
||||||
|
|
||||||
cellHeight := make([]SizeUnit, rowCount)
|
|
||||||
switch vAlign, _ := enumProperty(popup, VerticalAlign, popup.session, CenterAlign); vAlign {
|
switch vAlign, _ := enumProperty(popup, VerticalAlign, popup.session, CenterAlign); vAlign {
|
||||||
case LeftAlign:
|
case LeftAlign:
|
||||||
cellHeight[rowCount-1] = Fr(1)
|
cellHeight[4] = Fr(1)
|
||||||
|
|
||||||
case RightAlign:
|
case RightAlign:
|
||||||
cellHeight[0] = Fr(1)
|
cellHeight[0] = Fr(1)
|
||||||
|
|
||||||
default:
|
default:
|
||||||
cellHeight[0] = Fr(1)
|
cellHeight[0] = Fr(1)
|
||||||
cellHeight[rowCount-1] = Fr(1)
|
cellHeight[4] = Fr(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
return cellHeight
|
return cellHeight
|
||||||
|
@ -589,6 +555,11 @@ func (popup *popupData) Get(tag PropertyName) any {
|
||||||
return popup.properties[tag]
|
return popup.properties[tag]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (popup *popupData) arrowLocation() int {
|
||||||
|
result, _ := enumProperty(popup, Arrow, popup.session, NoneArrow)
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
func (popup *popupData) supported(tag PropertyName) bool {
|
func (popup *popupData) supported(tag PropertyName) bool {
|
||||||
switch tag {
|
switch tag {
|
||||||
case Row, Column, CellWidth, CellHeight, Gap, GridColumnGap, GridRowGap,
|
case Row, Column, CellWidth, CellHeight, Gap, GridColumnGap, GridRowGap,
|
||||||
|
@ -1110,23 +1081,12 @@ func (popup *popupData) createContentContainer() ColumnLayout {
|
||||||
func (popup *popupData) createLayerView() GridLayout {
|
func (popup *popupData) createLayerView() GridLayout {
|
||||||
|
|
||||||
session := popup.session
|
session := popup.session
|
||||||
popupRow := 1
|
|
||||||
popupColumn := 1
|
|
||||||
arrow := popupArrowInit(popup)
|
|
||||||
|
|
||||||
switch arrow.location {
|
|
||||||
case TopArrow:
|
|
||||||
popupRow = 2
|
|
||||||
|
|
||||||
case LeftArrow:
|
|
||||||
popupColumn = 2
|
|
||||||
}
|
|
||||||
|
|
||||||
params := Params{
|
params := Params{
|
||||||
Style: "ruiPopup",
|
Style: "ruiPopup",
|
||||||
ID: popupID,
|
ID: popupID,
|
||||||
Row: popupRow,
|
Row: 2,
|
||||||
Column: popupColumn,
|
Column: 2,
|
||||||
MaxWidth: Percent(100),
|
MaxWidth: Percent(100),
|
||||||
MaxHeight: Percent(100),
|
MaxHeight: Percent(100),
|
||||||
CellVerticalAlign: StretchAlign,
|
CellVerticalAlign: StretchAlign,
|
||||||
|
@ -1194,16 +1154,16 @@ func (popup *popupData) createLayerView() GridLayout {
|
||||||
Style: popupLayerID,
|
Style: popupLayerID,
|
||||||
MaxWidth: Percent(100),
|
MaxWidth: Percent(100),
|
||||||
MaxHeight: Percent(100),
|
MaxHeight: Percent(100),
|
||||||
CellWidth: popup.layerCellWidth(arrow.location),
|
CellWidth: popup.layerCellWidth(),
|
||||||
CellHeight: popup.layerCellHeight(arrow.location),
|
CellHeight: popup.layerCellHeight(),
|
||||||
}
|
}
|
||||||
|
|
||||||
if margin, ok := getBounds(popup, Margin, session); ok {
|
if margin, ok := getBounds(popup, Margin, session); ok {
|
||||||
layerParams[Margin] = margin
|
layerParams[Padding] = margin
|
||||||
}
|
}
|
||||||
|
|
||||||
if arrow.location != NoneArrow {
|
if location := popup.arrowLocation(); location != NoneArrow {
|
||||||
layerParams[Content] = []View{popup.popupView, arrow.createView(popup.popupView)}
|
layerParams[Content] = []View{popup.popupView, popup.createArrowView(location)}
|
||||||
} else {
|
} else {
|
||||||
layerParams[Content] = []View{popup.popupView}
|
layerParams[Content] = []View{popup.popupView}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue