Fix widget resizing handles, edge anchoring, scroll sync, and axis limits
This commit is contained in:
1 parent
216c80252d
commit
bb978fd6de
13 files changed
+538
-76
No files matched your search
+99
-38
@@ -348,7 +348,7 @@ fn Model::drag_lifted(
|
||||
/// The pointer is up. Letting go without moving opens the item's menu (a widget gets
|
||||
/// resize handles instead); letting go of a dragged one just drops it, and whatever it
|
||||
/// then covers moves on to free cells.
|
||||
fn Model::drop_lifted(self : Model, moved : Bool) -> Unit {
|
||||
fn Model::drop_lifted(self : Model, moved : Bool, fx : Array[Effect]) -> Unit {
|
||||
self.carry = None
|
||||
if self.lifted < 0 || self.lifted >= self.home.length() {
|
||||
self.lifted = -1
|
||||
@@ -361,7 +361,10 @@ fn Model::drop_lifted(self : Model, moved : Bool) -> Unit {
|
||||
}
|
||||
if !moved || self.regrab {
|
||||
match s.kind {
|
||||
Widget => self.resizing = self.lifted
|
||||
Widget => {
|
||||
self.resizing = self.lifted
|
||||
fx.push(QueryLimits(s.wid))
|
||||
}
|
||||
App => self.sheet = Item(self.lifted)
|
||||
}
|
||||
}
|
||||
@@ -376,23 +379,34 @@ fn Model::begin_resize(self : Model, edge : Edge, fx : Array[Effect]) -> Unit {
|
||||
return
|
||||
}
|
||||
let s = self.home[i]
|
||||
let (left, top) = match self.slot_box(self.packed(), i) {
|
||||
Some(b) => (b.0, b.1)
|
||||
None => (self.grid_left, self.grid_top)
|
||||
}
|
||||
guard self.packed().cells[i] is Some(cell) else { return }
|
||||
s.x = cell.col
|
||||
s.y = cell.row
|
||||
let (bx, by, bw, bh) = @grid.box(cell, self.col_w)
|
||||
let left = self.grid_left + bx
|
||||
let top = self.grid_top + by
|
||||
self.resize = Some({
|
||||
edge,
|
||||
slot: i,
|
||||
left,
|
||||
top,
|
||||
cols: s.cols(self.cols),
|
||||
rows: s.height(),
|
||||
right: left + bw,
|
||||
bottom: top + bh,
|
||||
anchor_col: cell.col,
|
||||
anchor_row: cell.row,
|
||||
right_col: cell.col + cell.w,
|
||||
bottom_row: cell.row + cell.h,
|
||||
col: cell.col,
|
||||
row: cell.row,
|
||||
cols: cell.w,
|
||||
rows: cell.h,
|
||||
})
|
||||
fx.push(QueryLimits(s.wid))
|
||||
}
|
||||
|
||||
///|
|
||||
/// Dragging a handle snaps the widget to whole columns and rows, within its limits.
|
||||
/// Dragging a handle snaps the widget to whole columns and rows, within its limits
|
||||
/// and without shifting its anchored edge.
|
||||
fn Model::drag_resize(
|
||||
self : Model,
|
||||
r : ResizeDrag,
|
||||
@@ -406,42 +420,86 @@ fn Model::drag_resize(
|
||||
let s = self.home[r.slot]
|
||||
let lim = self.limits.get(s.wid).unwrap_or(default_limits)
|
||||
let n = self.cols
|
||||
let mut col = r.col
|
||||
let mut row = r.row
|
||||
let mut cols = r.cols
|
||||
let mut rows = r.rows
|
||||
if r.edge != Bottom && lim.h {
|
||||
cols = @grid.fit(
|
||||
x - r.left,
|
||||
1,
|
||||
n,
|
||||
self.col_w,
|
||||
@grid.col_gap.to_double(),
|
||||
lim.min_w,
|
||||
lim.max_w,
|
||||
)
|
||||
let cg = @grid.col_gap.to_double()
|
||||
let rg = @grid.row_gap.to_double()
|
||||
if lim.h {
|
||||
match r.edge {
|
||||
Right | Corner => {
|
||||
let hi = @cmp.maximum(1, n - r.anchor_col)
|
||||
cols = @grid.fit(
|
||||
x - r.left,
|
||||
1,
|
||||
hi,
|
||||
self.col_w,
|
||||
cg,
|
||||
lim.min_w,
|
||||
lim.max_w,
|
||||
)
|
||||
col = r.anchor_col
|
||||
}
|
||||
Left => {
|
||||
let hi = @cmp.maximum(1, @cmp.minimum(n, r.right_col))
|
||||
cols = @grid.fit(
|
||||
r.right - x,
|
||||
1,
|
||||
hi,
|
||||
self.col_w,
|
||||
cg,
|
||||
lim.min_w,
|
||||
lim.max_w,
|
||||
)
|
||||
col = r.right_col - cols
|
||||
}
|
||||
Top | Bottom => ()
|
||||
}
|
||||
}
|
||||
if r.edge != Right && lim.v {
|
||||
rows = @grid.fit(
|
||||
y - r.top,
|
||||
1,
|
||||
20,
|
||||
@grid.cell_px.to_double(),
|
||||
@grid.row_gap.to_double(),
|
||||
lim.min_h,
|
||||
lim.max_h,
|
||||
)
|
||||
if lim.v {
|
||||
match r.edge {
|
||||
Bottom | Corner => {
|
||||
rows = @grid.fit(
|
||||
y - r.top,
|
||||
1,
|
||||
20,
|
||||
@grid.cell_px.to_double(),
|
||||
rg,
|
||||
lim.min_h,
|
||||
lim.max_h,
|
||||
)
|
||||
row = r.anchor_row
|
||||
}
|
||||
Top => {
|
||||
let hi = @cmp.maximum(1, @cmp.minimum(20, r.bottom_row))
|
||||
rows = @grid.fit(
|
||||
r.bottom - y,
|
||||
1,
|
||||
hi,
|
||||
@grid.cell_px.to_double(),
|
||||
rg,
|
||||
lim.min_h,
|
||||
lim.max_h,
|
||||
)
|
||||
row = r.bottom_row - rows
|
||||
}
|
||||
Left | Right => ()
|
||||
}
|
||||
}
|
||||
if cols == r.cols && rows == r.rows {
|
||||
if col == r.col && row == r.row && cols == r.cols && rows == r.rows {
|
||||
return
|
||||
}
|
||||
r.col = col
|
||||
r.row = row
|
||||
r.cols = cols
|
||||
r.rows = rows
|
||||
fx.push(Haptic)
|
||||
s.x = col
|
||||
s.y = row
|
||||
s.w = if cols >= n { 0 } else { cols }
|
||||
s.rows = rows
|
||||
if s.x >= 0 {
|
||||
@grid.pin(self.home, r.slot, s.x, s.y, self.cols, self.nrows)
|
||||
@grid.clear_cells(self.home, r.slot, self.cols)
|
||||
}
|
||||
@grid.clear_cells(self.home, r.slot, self.cols)
|
||||
}
|
||||
|
||||
// ---- update -------------------------------------------------------------------
|
||||
@@ -504,12 +562,14 @@ fn step(m : Model, msg : Msg, fx : Array[Effect]) -> Unit {
|
||||
fx.push(FetchRelease(@updater.release_api))
|
||||
}
|
||||
}
|
||||
Measured(vw~, vh~, grid_left~, grid_top~, grid_w~, bottom_pad~) => {
|
||||
Measured(vw~, vh~, grid_left~, grid_top~, grid_w~, bottom_pad~, scroll_y~) => {
|
||||
m.cols = @grid.columns_for(vw)
|
||||
m.grid_left = grid_left
|
||||
m.grid_top = grid_top
|
||||
m.col_w = @grid.column_width(grid_w, m.cols)
|
||||
m.nrows = @grid.rows_fit(vh.to_double() - bottom_pad - grid_top)
|
||||
m.nrows = @grid.rows_fit(
|
||||
vh.to_double() - bottom_pad - (grid_top + scroll_y),
|
||||
)
|
||||
}
|
||||
AppsLoaded(text) => {
|
||||
m.loading = false
|
||||
@@ -608,7 +668,7 @@ fn step(m : Model, msg : Msg, fx : Array[Effect]) -> Unit {
|
||||
}
|
||||
NativeDrop(moved) => {
|
||||
m.native_from = None
|
||||
m.drop_lifted(moved)
|
||||
m.drop_lifted(moved, fx)
|
||||
}
|
||||
Touch(dx~, dy~, ms~, home_top~, list_end~) =>
|
||||
if !m.dragged && m.lifted < 0 && m.sheet == NoSheet {
|
||||
@@ -789,6 +849,7 @@ fn step(m : Model, msg : Msg, fx : Array[Effect]) -> Unit {
|
||||
Lift(i) =>
|
||||
if !m.drawer_open() &&
|
||||
m.sheet == NoSheet &&
|
||||
m.resize is None &&
|
||||
i != m.lifted &&
|
||||
i < m.home.length() {
|
||||
fx.push(Haptic)
|
||||
@@ -815,7 +876,7 @@ fn step(m : Model, msg : Msg, fx : Array[Effect]) -> Unit {
|
||||
Released(moved~, held~) => {
|
||||
ignore(held)
|
||||
m.resize = None
|
||||
m.drop_lifted(moved)
|
||||
m.drop_lifted(moved, fx)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user