Commit 4da8f0f5 authored by ceddral's avatar ceddral
Browse files

telnet_gui: add Reshape, clip bounds in Resize/Reshape

parent f0d3d138
......@@ -4,3 +4,8 @@ func max(a, b int) int {
if a > b { return a }
return b
}
func min(a, b int) int {
if a < b { return a }
return b
}
......@@ -278,6 +278,33 @@ func (v *View) Clear() {
func (v *View) Resize(w, h int) {
v.S.mutex.Lock()
defer v.S.mutex.Unlock()
w = min(w, v.S.W - v.X - 1)
h = min(h, v.S.H - v.Y - 1)
w = max(0, w)
h = max(0, h)
if v.S.W < v.X+w || v.S.H < v.Y+h {
panic("View dimensions out of Screen bounds")
}
v.W = w
v.H = h
}
func (v *View) Reshape(x, y, w, h int) {
x = max(0, x)
y = max(0, y)
v.S.mutex.Lock()
defer v.S.mutex.Unlock()
x = min(v.S.W, x)
y = min(v.S.H, y)
w = min(w, v.S.W - x - 1)
h = min(h, v.S.H - y - 1)
w = max(0, w)
h = max(0, h)
if x < 0 || y < 0 || v.S.W < x+w || v.S.H < y+h {
panic("View dimensions out of Screen bounds")
}
v.X = x
v.X = y
v.W = w
v.H = h
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment