Add an icon size setting for the home grid and the app drawer
Slider (70-160%, step 5) with Small/Medium/Large presets and a live preview in the home menu. Icon, label and row height scale together; the home and drawer column counts reflow; the size is saved in localStorage; a corrupt saved value is logged and shown, not silently replaced. 100% is the original layout. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
3070db4fb4
commit
23317b949a
22 files changed
+901
-51
No files matched your search
+80
-14
@@ -78,6 +78,50 @@ pub fn Model::hidden(self : Model, i : Int32) -> Bool {
|
||||
self.home[i].kind == App && self.app_row(self.home[i].str) < 0
|
||||
}
|
||||
|
||||
///|
|
||||
/// Height of a home row at the current icon size.
|
||||
pub fn Model::cell_h(self : Model) -> Int32 {
|
||||
@grid.cell_height(self.icon_pct)
|
||||
}
|
||||
|
||||
///|
|
||||
/// Columns, rows and column width from the last measurement and the icon size. Run when
|
||||
/// either changes.
|
||||
fn Model::relayout(self : Model) -> Unit {
|
||||
if self.vw <= 0 {
|
||||
return // not measured yet
|
||||
}
|
||||
self.cols = @grid.home_columns(self.vw, self.grid_w, self.icon_pct)
|
||||
self.col_w = @grid.column_width(self.grid_w, self.cols)
|
||||
self.nrows = @grid.rows_fit(self.avail_h, ch=self.cell_h())
|
||||
self.drawer_cols = @grid.drawer_columns(self.vw, self.icon_pct)
|
||||
}
|
||||
|
||||
///|
|
||||
/// Apply a new icon size (already valid): lay out again and save it.
|
||||
fn Model::set_icon_pct(self : Model, pct : Int32, fx : Array[Effect]) -> Unit {
|
||||
self.icon_error = ""
|
||||
if pct == self.icon_pct {
|
||||
fx.push(SaveIconSize(pct)) // also replaces a corrupt stored value
|
||||
return
|
||||
}
|
||||
self.icon_pct = pct
|
||||
self.relayout()
|
||||
fx.push(SaveIconSize(pct))
|
||||
}
|
||||
|
||||
///|
|
||||
/// The icon size is unusable: say so on screen and in the log; nothing is changed.
|
||||
fn Model::icon_size_error(
|
||||
self : Model,
|
||||
reason : String,
|
||||
fx : Array[Effect],
|
||||
) -> Unit {
|
||||
self.icon_error = reason
|
||||
fx.push(LogError("launcher: \{reason}"))
|
||||
self.say("Icon size problem: \{reason}", fx)
|
||||
}
|
||||
|
||||
///|
|
||||
pub fn Model::packed(self : Model) -> @grid.Packed {
|
||||
@grid.pack(self.home, self.cols, self.nrows, hidden=fn(i) { self.hidden(i) })
|
||||
@@ -239,7 +283,7 @@ fn Model::slot_box(
|
||||
) -> (Double, Double, Double, Double)? {
|
||||
match packed.cells[i] {
|
||||
Some(c) => {
|
||||
let (x, y, w, h) = @grid.box(c, self.col_w)
|
||||
let (x, y, w, h) = @grid.box(c, self.col_w, ch=self.cell_h())
|
||||
Some((x + self.grid_left, y + self.grid_top, w, h))
|
||||
}
|
||||
None => None
|
||||
@@ -303,11 +347,12 @@ fn Model::drag_lifted(
|
||||
return
|
||||
}
|
||||
let half_w = self.col_w / 2.0
|
||||
let half_h = @grid.cell_px.to_double() / 2.0
|
||||
let half_h = self.cell_h().to_double() / 2.0
|
||||
let (fc, fr) = @grid.cell_at(
|
||||
x - self.grid_left - half_w,
|
||||
y - self.grid_top - half_h,
|
||||
self.col_w,
|
||||
ch=self.cell_h(),
|
||||
)
|
||||
let mut to = self.slot_at(packed, x, y)
|
||||
if to < 0 {
|
||||
@@ -315,7 +360,7 @@ fn Model::drag_lifted(
|
||||
fc.to_double() * (self.col_w + @grid.col_gap.to_double()) +
|
||||
half_w
|
||||
let cy = self.grid_top +
|
||||
fr.to_double() * (@grid.cell_px + @grid.row_gap).to_double() +
|
||||
fr.to_double() * (self.cell_h() + @grid.row_gap).to_double() +
|
||||
half_h
|
||||
to = self.slot_at(packed, cx, cy)
|
||||
}
|
||||
@@ -328,7 +373,7 @@ fn Model::drag_lifted(
|
||||
return
|
||||
}
|
||||
let grid_bottom = self.grid_top +
|
||||
(packed.rows * (@grid.cell_px + @grid.row_gap)).to_double()
|
||||
(packed.rows * (self.cell_h() + @grid.row_gap)).to_double()
|
||||
if y > grid_bottom {
|
||||
return // below the grid
|
||||
}
|
||||
@@ -336,6 +381,7 @@ fn Model::drag_lifted(
|
||||
x - self.grid_left - carry.dx,
|
||||
y - self.grid_top - carry.dy,
|
||||
self.col_w,
|
||||
ch=self.cell_h(),
|
||||
)
|
||||
let cell = row * 64 + @cmp.minimum(col, 63)
|
||||
if cell != carry.cell {
|
||||
@@ -382,7 +428,7 @@ fn Model::begin_resize(self : Model, edge : Edge, fx : Array[Effect]) -> Unit {
|
||||
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 (bx, by, bw, bh) = @grid.box(cell, self.col_w, ch=self.cell_h())
|
||||
let left = self.grid_left + bx
|
||||
let top = self.grid_top + by
|
||||
self.resize = Some({
|
||||
@@ -464,7 +510,7 @@ fn Model::drag_resize(
|
||||
y - r.top,
|
||||
1,
|
||||
20,
|
||||
@grid.cell_px.to_double(),
|
||||
self.cell_h().to_double(),
|
||||
rg,
|
||||
lim.min_h,
|
||||
lim.max_h,
|
||||
@@ -477,7 +523,7 @@ fn Model::drag_resize(
|
||||
r.bottom - y,
|
||||
1,
|
||||
hi,
|
||||
@grid.cell_px.to_double(),
|
||||
self.cell_h().to_double(),
|
||||
rg,
|
||||
lim.min_h,
|
||||
lim.max_h,
|
||||
@@ -534,7 +580,7 @@ fn Model::choose_widget(self : Model, i : Int32, fx : Array[Effect]) -> Unit {
|
||||
///|
|
||||
fn step(m : Model, msg : Msg, fx : Array[Effect]) -> Unit {
|
||||
match msg {
|
||||
Restore(saved~, legacy~) => {
|
||||
Restore(saved~, legacy~, icon_size~) => {
|
||||
let next = Ref(m.next_key)
|
||||
let mut slots = None
|
||||
if saved is Some(text) {
|
||||
@@ -550,6 +596,15 @@ fn step(m : Model, msg : Msg, fx : Array[Effect]) -> Unit {
|
||||
m.home = s
|
||||
}
|
||||
m.next_key = next.val
|
||||
if icon_size is Some(text) {
|
||||
match @grid.parse_scale(text) {
|
||||
Ok(pct) => {
|
||||
m.icon_pct = pct
|
||||
m.relayout()
|
||||
}
|
||||
Err(reason) => m.icon_size_error("saved \{reason}", fx)
|
||||
}
|
||||
}
|
||||
fx.push(LoadApps)
|
||||
}
|
||||
Started(now~, last_check~, declined~, installed~) => {
|
||||
@@ -563,13 +618,12 @@ fn step(m : Model, msg : Msg, fx : Array[Effect]) -> Unit {
|
||||
}
|
||||
}
|
||||
Measured(vw~, vh~, grid_left~, grid_top~, grid_w~, bottom_pad~, scroll_y~) => {
|
||||
m.cols = @grid.columns_for(vw)
|
||||
m.vw = 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 + scroll_y),
|
||||
)
|
||||
m.grid_w = grid_w
|
||||
m.avail_h = vh.to_double() - bottom_pad - (grid_top + scroll_y)
|
||||
m.relayout()
|
||||
}
|
||||
AppsLoaded(text) => {
|
||||
m.loading = false
|
||||
@@ -629,7 +683,7 @@ fn step(m : Model, msg : Msg, fx : Array[Effect]) -> Unit {
|
||||
@grid.Slot::widget(
|
||||
w.label,
|
||||
id,
|
||||
rows=@grid.widget_rows(w.h),
|
||||
rows=@grid.widget_rows(w.h, ch=m.cell_h()),
|
||||
key=m.new_key(),
|
||||
),
|
||||
)
|
||||
@@ -824,6 +878,18 @@ fn step(m : Model, msg : Msg, fx : Array[Effect]) -> Unit {
|
||||
fx.push(OpenSettings)
|
||||
m.sheet = NoSheet
|
||||
}
|
||||
IconSizeMenu => m.sheet = IconSize
|
||||
SetIconSize(text) =>
|
||||
match @grid.parse_scale(text) {
|
||||
Ok(pct) => m.set_icon_pct(pct, fx)
|
||||
Err(reason) => m.icon_size_error(reason, fx)
|
||||
}
|
||||
IconPreset(pct) =>
|
||||
if @grid.scale_valid(pct) {
|
||||
m.set_icon_pct(pct, fx)
|
||||
} else {
|
||||
m.icon_size_error("preset \{pct} is not a valid icon size", fx)
|
||||
}
|
||||
Wallpaper => {
|
||||
fx.push(PickWallpaper)
|
||||
m.sheet = NoSheet
|
||||
|
||||
Reference in new issue
Block a user