refactor: get window size

This commit is contained in:
lilong.129
2024-09-02 13:41:39 +08:00
parent 4c71fc02f9
commit ee51b30b06
9 changed files with 94 additions and 86 deletions
+9 -24
View File
@@ -2,8 +2,6 @@ package uixt
import (
"fmt"
"github.com/rs/zerolog/log"
)
func (dExt *DriverExt) TapAbsXY(x, y float64, options ...ActionOption) error {
@@ -17,19 +15,12 @@ func (dExt *DriverExt) TapXY(x, y float64, options ...ActionOption) error {
return fmt.Errorf("x, y percentage should be <= 1, got x=%v, y=%v", x, y)
}
orientation, err := dExt.Driver.Orientation()
windowSize, err := dExt.Driver.WindowSize()
if err != nil {
log.Warn().Err(err).Msgf("tap (%v, %v) get orientation failed, use default orientation",
x, y)
orientation = OrientationPortrait
}
if orientation == OrientationPortrait {
x = x * float64(dExt.WindowSize.Width)
y = y * float64(dExt.WindowSize.Height)
} else {
x = x * float64(dExt.WindowSize.Height)
y = y * float64(dExt.WindowSize.Width)
return err
}
x = x * float64(windowSize.Width)
y = y * float64(windowSize.Height)
return dExt.TapAbsXY(x, y, options...)
}
@@ -84,19 +75,13 @@ func (dExt *DriverExt) DoubleTapXY(x, y float64) error {
if x > 1 || y > 1 {
return fmt.Errorf("x, y percentage should be < 1, got x=%v, y=%v", x, y)
}
orientation, err := dExt.Driver.Orientation()
windowSize, err := dExt.Driver.WindowSize()
if err != nil {
log.Warn().Err(err).Msgf("tap (%v, %v) get orientation failed, use default orientation",
x, y)
orientation = OrientationPortrait
}
if orientation == OrientationPortrait {
x = x * float64(dExt.WindowSize.Width)
y = y * float64(dExt.WindowSize.Height)
} else {
x = x * float64(dExt.WindowSize.Height)
y = y * float64(dExt.WindowSize.Width)
return err
}
x = x * float64(windowSize.Width)
y = y * float64(windowSize.Height)
return dExt.Driver.DoubleTapFloat(x, y)
}