Add an icon size setting (#3)
This commit was merged in pull request #3.
This commit is contained in:
1 parent
3070db4fb4
commit
472a48f4bd
22 files changed
+901
-51
No files matched your search
+32
-1
@@ -61,6 +61,8 @@ pub(all) enum Sheet {
|
||||
DrawerApp(Int32)
|
||||
WidgetPicker
|
||||
RecentsSetup
|
||||
/// The icon size slider and presets.
|
||||
IconSize
|
||||
}
|
||||
|
||||
///|
|
||||
@@ -118,6 +120,19 @@ pub(all) struct Model {
|
||||
mut grid_left : Double
|
||||
mut grid_top : Double
|
||||
mut col_w : Double
|
||||
/// Icon size in percent of the original (see grid/scale.mbt), applied to the home
|
||||
/// grid and the drawer.
|
||||
mut icon_pct : Int32
|
||||
/// Why the saved icon size could not be used (empty: it could); shown in the icon
|
||||
/// size sheet. The bad stored value is left alone until a size is chosen.
|
||||
mut icon_error : String
|
||||
/// The last measurement, kept so a size change can lay out again without one.
|
||||
mut vw : Int32
|
||||
mut grid_w : Double
|
||||
/// Px of screen below the top of the grid that rows can fill.
|
||||
mut avail_h : Double
|
||||
/// Columns of the drawer's app list.
|
||||
mut drawer_cols : Int32
|
||||
mut query : String
|
||||
mut wquery : String
|
||||
mut drawer : Bool
|
||||
@@ -176,6 +191,12 @@ pub fn Model::new() -> Model {
|
||||
grid_left: 0.0,
|
||||
grid_top: 0.0,
|
||||
col_w: 0.0,
|
||||
icon_pct: @grid.scale_default,
|
||||
icon_error: "",
|
||||
vw: 0,
|
||||
grid_w: 0.0,
|
||||
avail_h: 0.0,
|
||||
drawer_cols: 4,
|
||||
query: "",
|
||||
wquery: "",
|
||||
drawer: false,
|
||||
@@ -222,7 +243,7 @@ pub(all) enum Msg {
|
||||
// ---- from the platform
|
||||
/// Boot: the saved layout (this app's JSON, and the old WebView build's
|
||||
/// `ultra.home.*` localStorage as a JSON object), the clock, and the self-update state.
|
||||
Restore(saved~ : String?, legacy~ : String?)
|
||||
Restore(saved~ : String?, legacy~ : String?, icon_size~ : String?)
|
||||
Started(
|
||||
now~ : Int64,
|
||||
last_check~ : Int64,
|
||||
@@ -294,6 +315,12 @@ pub(all) enum Msg {
|
||||
MoveEarlier(Int32)
|
||||
InfoOf(Int32)
|
||||
Settings
|
||||
/// Open the icon size sheet.
|
||||
IconSizeMenu
|
||||
/// The slider's value (text, as the input reports it).
|
||||
SetIconSize(String)
|
||||
/// A preset button, in percent.
|
||||
IconPreset(Int32)
|
||||
Wallpaper
|
||||
Recents
|
||||
RecentsUnavailable
|
||||
@@ -331,6 +358,10 @@ pub(all) enum Effect {
|
||||
/// Ask the shell for a widget's limits and answer `LimitsKnown`.
|
||||
QueryLimits(Int32)
|
||||
SaveHome(String)
|
||||
/// Store the icon size (percent).
|
||||
SaveIconSize(Int32)
|
||||
/// Write a line to the platform's error log.
|
||||
LogError(String)
|
||||
SaveLastCheck(Int64)
|
||||
/// Send the message after this many ms.
|
||||
Delay(Int32, Msg)
|
||||
|
||||
+14
-1
@@ -84,6 +84,8 @@ pub(all) enum Effect {
|
||||
LoadWidgets
|
||||
QueryLimits(Int32)
|
||||
SaveHome(String)
|
||||
SaveIconSize(Int32)
|
||||
LogError(String)
|
||||
SaveLastCheck(Int64)
|
||||
Delay(Int32, Msg)
|
||||
HoldTimer(Int32, Int32)
|
||||
@@ -123,6 +125,12 @@ pub(all) struct Model {
|
||||
mut grid_left : Double
|
||||
mut grid_top : Double
|
||||
mut col_w : Double
|
||||
mut icon_pct : Int32
|
||||
mut icon_error : String
|
||||
mut vw : Int32
|
||||
mut grid_w : Double
|
||||
mut avail_h : Double
|
||||
mut drawer_cols : Int32
|
||||
mut query : String
|
||||
mut wquery : String
|
||||
mut drawer : Bool
|
||||
@@ -153,6 +161,7 @@ pub(all) struct Model {
|
||||
mut gesture : @gesture.State
|
||||
}
|
||||
pub fn Model::app_row(Self, String) -> Int32
|
||||
pub fn Model::cell_h(Self) -> Int32
|
||||
pub fn Model::drawer_open(Self) -> Bool
|
||||
pub fn Model::first_match(Self) -> Int32
|
||||
pub fn Model::first_widget_match(Self) -> Int32
|
||||
@@ -166,7 +175,7 @@ pub fn Model::widget_matches(Self, Int32) -> Bool
|
||||
|
||||
#derive(Eq, @debug.Debug)
|
||||
pub(all) enum Msg {
|
||||
Restore(saved~ : String?, legacy~ : String?)
|
||||
Restore(saved~ : String?, legacy~ : String?, icon_size~ : String?)
|
||||
Started(now~ : Int64, last_check~ : Int64, declined~ : Int32, installed~ : Int32)
|
||||
Measured(vw~ : Int32, vh~ : Int32, grid_left~ : Double, grid_top~ : Double, grid_w~ : Double, bottom_pad~ : Double, scroll_y~ : Double)
|
||||
AppsLoaded(String?)
|
||||
@@ -209,6 +218,9 @@ pub(all) enum Msg {
|
||||
MoveEarlier(Int32)
|
||||
InfoOf(Int32)
|
||||
Settings
|
||||
IconSizeMenu
|
||||
SetIconSize(String)
|
||||
IconPreset(Int32)
|
||||
Wallpaper
|
||||
Recents
|
||||
RecentsUnavailable
|
||||
@@ -249,6 +261,7 @@ pub(all) enum Sheet {
|
||||
DrawerApp(Int32)
|
||||
WidgetPicker
|
||||
RecentsSetup
|
||||
IconSize
|
||||
}
|
||||
|
||||
pub(all) struct WidgetInfo {
|
||||
|
||||
+172
-4
@@ -33,7 +33,7 @@ struct Sim {
|
||||
fn Sim::new() -> Sim {
|
||||
let m = Model::new()
|
||||
let s = { m, tree: [], table: [], log: [], last_x: 0.0, last_y: 0.0, }
|
||||
s.run(update(m, Restore(saved=None, legacy=None)))
|
||||
s.run(update(m, Restore(saved=None, legacy=None, icon_size=None)))
|
||||
s.send(
|
||||
Measured(
|
||||
vw=390,
|
||||
@@ -757,7 +757,7 @@ test "the layout is saved on every change and restored" {
|
||||
}
|
||||
assert_eq(saved, save_json(s.m.home))
|
||||
let s2 = Sim::new()
|
||||
s2.run(update(s2.m, Restore(saved=Some(saved), legacy=None)))
|
||||
s2.run(update(s2.m, Restore(saved=Some(saved), legacy=None, icon_size=None)))
|
||||
assert_eq(s2.home_names(), ["Chrome", "Gmail"])
|
||||
// restoring what is already saved doesn't save it again
|
||||
let n = s2.log.filter(fn(e) { e is SaveHome(_) }).length() - 1 // Sim::new saved the empty one
|
||||
@@ -783,7 +783,7 @@ test "the old WebView build's home screen is brought over once" {
|
||||
assert_eq(legacy_import("{}", Ref(1)).length(), 0)
|
||||
assert_eq(legacy_import("garbage", Ref(1)).length(), 0)
|
||||
let s = Sim::new()
|
||||
s.run(update(s.m, Restore(saved=None, legacy=Some(legacy))))
|
||||
s.run(update(s.m, Restore(saved=None, legacy=Some(legacy), icon_size=None)))
|
||||
assert_eq(s.m.home.length(), 2)
|
||||
assert_true(s.log.contains(SaveHome(save_json(s.m.home)))) // saved in the new format
|
||||
// a saved layout wins over the old one
|
||||
@@ -794,6 +794,7 @@ test "the old WebView build's home screen is brought over once" {
|
||||
Restore(
|
||||
saved=Some(save_json([slot_app("c.gmail/.Main")])),
|
||||
legacy=Some(legacy),
|
||||
icon_size=None,
|
||||
),
|
||||
),
|
||||
)
|
||||
@@ -927,7 +928,7 @@ test "view snapshot: home with an app" {
|
||||
#| <span class="magnifier" aria-hidden="true"></span>
|
||||
#| <span>Search apps</span>
|
||||
#| </button>
|
||||
#| <ul class="slots" style="grid-template-columns:repeat(5,minmax(0,1fr));grid-template-rows:repeat(8,64px)">
|
||||
#| <ul class="slots" style="--s:1;grid-template-columns:repeat(5,minmax(0,1fr));grid-template-rows:repeat(8,64px)">
|
||||
#| <li class="tile" data-slot="0" style="grid-column:1 / span 1;grid-row:1 / span 1" on="tap press">
|
||||
#| <img class="icon" alt="" draggable="false" data-icon="i3"></img>
|
||||
#| <span class="name">Chrome</span>
|
||||
@@ -1170,3 +1171,170 @@ test "only supported resize handles render per widget resizeMode" {
|
||||
let none_html = @vdom.to_html(s.tree[0])
|
||||
assert_true(!none_html.contains("resize-handle"))
|
||||
}
|
||||
|
||||
///|
|
||||
/// Type a value into the icon size slider, as the page reports it.
|
||||
fn Sim::slide(self : Sim, value : String) -> Unit {
|
||||
let chain = self.chain("icon-size-slider")
|
||||
self.run(typed(self.m, self.table, chain, value))
|
||||
}
|
||||
|
||||
///|
|
||||
fn Sim::open_icon_size(self : Sim) -> Unit {
|
||||
self.long_press(self.chain("home"))
|
||||
self.tap("sheet-item", label="Icon size")
|
||||
}
|
||||
|
||||
///|
|
||||
fn Sim::saved_sizes(self : Sim) -> Array[Int32] {
|
||||
let out = []
|
||||
for e in self.log {
|
||||
if e is SaveIconSize(p) {
|
||||
out.push(p)
|
||||
}
|
||||
}
|
||||
out
|
||||
}
|
||||
|
||||
///|
|
||||
test "icon size: the default is today's layout and nothing is saved at boot" {
|
||||
let s = Sim::new()
|
||||
assert_eq(s.m.icon_pct, 100)
|
||||
assert_eq((s.m.cols, s.m.nrows, s.m.cell_h(), s.m.drawer_cols), (5, 8, 64, 4))
|
||||
assert_eq(s.saved_sizes(), [])
|
||||
s.add_apps(["Chrome"])
|
||||
let html = @vdom.to_html(s.tree[0])
|
||||
assert_true(html.contains("--s:1;grid-template-columns:repeat(5,"))
|
||||
assert_true(html.contains("grid-template-rows:repeat(8,64px)"))
|
||||
}
|
||||
|
||||
///|
|
||||
test "icon size: the home menu opens the sheet; the slider resizes live, columns and rows reflow, and it is saved" {
|
||||
let s = Sim::new()
|
||||
s.add_apps(["Chrome", "Gmail", "Phone"])
|
||||
s.open_icon_size()
|
||||
assert_eq(s.m.sheet, IconSize)
|
||||
let html = s.sheet_html()
|
||||
assert_true(html.contains("type=\"range\""))
|
||||
assert_true(html.contains("min=\"70\""))
|
||||
assert_true(html.contains("max=\"160\""))
|
||||
assert_true(html.contains("100%"))
|
||||
s.slide("130")
|
||||
assert_eq(s.m.icon_pct, 130)
|
||||
assert_eq((s.m.cols, s.m.cell_h(), s.m.drawer_cols), (4, 83, 3))
|
||||
assert_eq(s.m.nrows, @grid.rows_fit(s.m.avail_h, ch=83))
|
||||
assert_eq(s.saved_sizes(), [130])
|
||||
assert_true(s.sheet_html().contains("130%"))
|
||||
// the home grid behind the sheet changed too
|
||||
let home = @vdom.to_html(s.tree[0])
|
||||
assert_true(home.contains("--s:1.3;grid-template-columns:repeat(4,"))
|
||||
assert_true(home.contains("repeat(8,83px)") || home.contains("83px"))
|
||||
// and the drawer's list
|
||||
s.send(CloseSheet)
|
||||
s.send(OpenDrawer)
|
||||
let drawer = @vdom.to_html(s.tree[1])
|
||||
assert_true(drawer.contains("--s:1.3;grid-template-columns:repeat(3,"))
|
||||
// no cell leaves the grid or overlaps
|
||||
let packed = s.m.packed()
|
||||
for c in packed.cells {
|
||||
if c is Some(c) {
|
||||
assert_true(c.col >= 0 && c.col + c.w <= s.m.cols)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
///|
|
||||
test "icon size: presets, and Medium is the original size" {
|
||||
let s = Sim::new()
|
||||
s.open_icon_size()
|
||||
s.tap("btn", label="Small")
|
||||
assert_eq(s.m.icon_pct, 80)
|
||||
s.tap("btn", label="Large")
|
||||
assert_eq(s.m.icon_pct, 130)
|
||||
s.tap("btn", label="Medium")
|
||||
assert_eq(s.m.icon_pct, 100)
|
||||
assert_eq((s.m.cols, s.m.cell_h()), (5, 64))
|
||||
assert_eq(s.saved_sizes(), [80, 130, 100])
|
||||
}
|
||||
|
||||
///|
|
||||
test "icon size: small icons fit more columns and rows" {
|
||||
let s = Sim::new()
|
||||
s.send(IconPreset(70))
|
||||
assert_eq((s.m.cols, s.m.cell_h(), s.m.drawer_cols), (7, 45, 6))
|
||||
assert_true(s.m.nrows > 8)
|
||||
}
|
||||
|
||||
///|
|
||||
test "icon size: a saved size is restored without being saved again" {
|
||||
let s = Sim::new()
|
||||
s.run(update(s.m, Restore(saved=None, legacy=None, icon_size=Some("115"))))
|
||||
assert_eq(s.m.icon_pct, 115)
|
||||
assert_eq(s.m.cols, 4) // 5 * 100 / 115 = 4.3
|
||||
assert_eq(s.m.icon_error, "")
|
||||
assert_eq(s.saved_sizes(), [])
|
||||
}
|
||||
|
||||
///|
|
||||
test "icon size: a corrupt saved size is reported loudly and not overwritten" {
|
||||
for bad in ["abc", "", "1.5", "65", "500", "-10", "102"] {
|
||||
let s = Sim::new()
|
||||
s.run(update(s.m, Restore(saved=None, legacy=None, icon_size=Some(bad))))
|
||||
assert_true(s.m.icon_error.has_prefix("saved icon size"))
|
||||
assert_true(
|
||||
s.log.any(fn(e) {
|
||||
e is LogError(l) && l.contains("launcher: saved icon size")
|
||||
}),
|
||||
)
|
||||
assert_true(s.m.notice.has_prefix("Icon size problem: saved icon size"))
|
||||
// the layout is the original one, and the bad value is not rewritten
|
||||
assert_eq((s.m.icon_pct, s.m.cols), (100, 5))
|
||||
assert_eq(s.saved_sizes(), [])
|
||||
// the sheet shows the error until a size is chosen
|
||||
s.open_icon_size()
|
||||
assert_true(s.sheet_html().contains("role=\"alert\""))
|
||||
s.tap("btn", label="Medium")
|
||||
assert_eq(s.m.icon_error, "")
|
||||
assert_eq(s.saved_sizes(), [100]) // choosing replaces the corrupt value
|
||||
}
|
||||
}
|
||||
|
||||
///|
|
||||
test "icon size: an out-of-range slider value changes nothing and is reported" {
|
||||
let s = Sim::new()
|
||||
s.open_icon_size()
|
||||
s.send(SetIconSize("900"))
|
||||
assert_eq(s.m.icon_pct, 100)
|
||||
assert_true(s.m.icon_error.contains("outside 70..160"))
|
||||
assert_true(s.log.any(fn(e) { e is LogError(_) }))
|
||||
assert_eq(s.saved_sizes(), [])
|
||||
s.send(IconPreset(33))
|
||||
assert_eq(s.m.icon_pct, 100)
|
||||
assert_true(s.m.icon_error.contains("not a valid icon size"))
|
||||
}
|
||||
|
||||
///|
|
||||
test "icon size: dragging an icon finds the cell under the pointer at a larger size" {
|
||||
let s = Sim::new()
|
||||
s.add_apps(["Chrome", "Gmail", "Phone"])
|
||||
s.send(IconPreset(130)) // 4 columns of 83px rows
|
||||
s.send(CloseSheet)
|
||||
let ch = s.m.cell_h()
|
||||
assert_eq(ch, 83)
|
||||
let col_w = s.m.col_w
|
||||
let center = fn(c : Int32, r : Int32) {
|
||||
(
|
||||
s.m.grid_left + c.to_double() * (col_w + 8.0) + col_w / 2.0,
|
||||
s.m.grid_top + r.to_double() * (ch + 8).to_double() + ch.to_double() / 2.0,
|
||||
)
|
||||
}
|
||||
let (px, py) = center(2, 0)
|
||||
let (tx, ty) = center(3, 2)
|
||||
s.press(s.chain("tile", label="Phone"), x=px, y=py)
|
||||
s.hold()
|
||||
s.move_to(tx - 30.0, ty)
|
||||
s.move_to(tx, ty)
|
||||
s.release()
|
||||
assert_eq((s.m.home[2].x, s.m.home[2].y), (3, 2))
|
||||
assert_eq(s.m.packed().cells[2], Some({ col: 3, row: 2, w: 1, h: 1, }))
|
||||
}
|
||||
+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
|
||||
|
||||
+112
-2
@@ -170,7 +170,7 @@ fn Model::view_home(self : Model) -> Node[Msg] {
|
||||
el(
|
||||
"ul",
|
||||
classes=["slots", cls_if("dragging", self.lifted >= 0)],
|
||||
style="grid-template-columns:repeat(\{self.cols},minmax(0,1fr));grid-template-rows:repeat(\{rows},\{@grid.cell_px}px)",
|
||||
style="--s:\{@grid.css_factor(self.icon_pct)};grid-template-columns:repeat(\{self.cols},minmax(0,1fr));grid-template-rows:repeat(\{rows},\{self.cell_h()}px)",
|
||||
children=slots,
|
||||
),
|
||||
]
|
||||
@@ -266,7 +266,14 @@ fn Model::view_drawer(self : Model) -> Node[Msg] {
|
||||
]),
|
||||
)
|
||||
}
|
||||
children.push(el("ul", classes=["apps"], children=tiles))
|
||||
children.push(
|
||||
el(
|
||||
"ul",
|
||||
classes=["apps"],
|
||||
style="--s:\{@grid.css_factor(self.icon_pct)};grid-template-columns:repeat(\{self.drawer_cols},minmax(0,1fr))",
|
||||
children=tiles,
|
||||
),
|
||||
)
|
||||
if self.loading {
|
||||
children.push(
|
||||
el("p", classes=["empty"], children=[text("Loading apps…")]),
|
||||
@@ -296,6 +303,107 @@ fn sheet_title(label : String) -> Node[Msg] {
|
||||
el("h2", classes=["sheet-title"], children=[text(label)])
|
||||
}
|
||||
|
||||
///|
|
||||
fn preset_btn(label : String, pct : Int32, current : Int32) -> Node[Msg] {
|
||||
el(
|
||||
"button",
|
||||
classes=[
|
||||
"btn",
|
||||
if pct == current {
|
||||
"primary"
|
||||
} else {
|
||||
"outline"
|
||||
},
|
||||
"sm",
|
||||
cls_if("on", pct == current),
|
||||
],
|
||||
attrs=[("data-preset", pct.to_string())],
|
||||
handlers=tap(IconPreset(pct)),
|
||||
children=[text(label)],
|
||||
)
|
||||
}
|
||||
|
||||
///|
|
||||
/// The icon size sheet: a preview of a few real icons at the chosen size, the slider, the
|
||||
/// presets. The home grid behind the sheet changes with the slider as well.
|
||||
fn Model::view_icon_size(self : Model, items : Array[Node[Msg]]) -> Unit {
|
||||
let pct = self.icon_pct
|
||||
items.push(sheet_title("Icon size"))
|
||||
if self.icon_error != "" {
|
||||
items.push(
|
||||
el(
|
||||
"div",
|
||||
classes=["alert", "destructive", "icon-error"],
|
||||
attrs=[("role", "alert")],
|
||||
children=[
|
||||
el("div", classes=["alert-title"], children=[
|
||||
text("Icon size problem"),
|
||||
]),
|
||||
el("div", classes=["alert-description"], children=[
|
||||
text(self.icon_error),
|
||||
]),
|
||||
],
|
||||
),
|
||||
)
|
||||
}
|
||||
let sample : Array[Node[Msg]] = []
|
||||
for i in 0..<self.apps.length() {
|
||||
if sample.length() >= 4 {
|
||||
break
|
||||
}
|
||||
let a = self.apps[i]
|
||||
sample.push(
|
||||
el("li", key=i + 1, classes=["tile"], children=[
|
||||
icon(a.icon),
|
||||
el("span", classes=["name"], children=[text(a.label)]),
|
||||
]),
|
||||
)
|
||||
}
|
||||
items.push(
|
||||
el(
|
||||
"ul",
|
||||
classes=["icon-preview"],
|
||||
attrs=[("aria-label", "Preview")],
|
||||
style="--s:\{@grid.css_factor(pct)}",
|
||||
children=sample,
|
||||
),
|
||||
)
|
||||
items.push(
|
||||
el("div", classes=["icon-size-row"], children=[
|
||||
el(
|
||||
"input",
|
||||
classes=["icon-size-slider"],
|
||||
attrs=[
|
||||
("type", "range"),
|
||||
("min", @grid.scale_min.to_string()),
|
||||
("max", @grid.scale_max.to_string()),
|
||||
("step", @grid.scale_step.to_string()),
|
||||
("aria-label", "Icon size"),
|
||||
],
|
||||
props=[("value", pct.to_string())],
|
||||
handlers={ ..Handlers::none(), input: Some(fn(v) { SetIconSize(v) }), },
|
||||
),
|
||||
el("span", classes=["resize-size", "icon-size-value"], children=[
|
||||
text("\{pct}%"),
|
||||
]),
|
||||
]),
|
||||
)
|
||||
items.push(
|
||||
el("div", classes=["icon-presets"], children=[
|
||||
preset_btn("Small", @grid.scale_small, pct),
|
||||
preset_btn("Medium", @grid.scale_medium, pct),
|
||||
preset_btn("Large", @grid.scale_large, pct),
|
||||
]),
|
||||
)
|
||||
items.push(
|
||||
el("div", classes=["sheet-actions"], children=[
|
||||
el("button", classes=["btn", "ghost"], handlers=tap(CloseSheet), children=[
|
||||
text("Done"),
|
||||
]),
|
||||
]),
|
||||
)
|
||||
}
|
||||
|
||||
///|
|
||||
fn Model::view_sheet(self : Model) -> Array[Node[Msg]] {
|
||||
let items : Array[Node[Msg]] = []
|
||||
@@ -305,6 +413,7 @@ fn Model::view_sheet(self : Model) -> Array[Node[Msg]] {
|
||||
items.push(sheet_title("Home screen"))
|
||||
items.push(sheet_btn("Add apps", PickApps))
|
||||
items.push(sheet_btn("Add widget", PickWidget))
|
||||
items.push(sheet_btn("Icon size", IconSizeMenu))
|
||||
items.push(sheet_btn("Wallpaper", Wallpaper))
|
||||
items.push(sheet_btn("Settings", Settings))
|
||||
items.push(sheet_btn("Check for updates", CheckUpdates))
|
||||
@@ -407,6 +516,7 @@ fn Model::view_sheet(self : Model) -> Array[Node[Msg]] {
|
||||
)
|
||||
}
|
||||
}
|
||||
IconSize => self.view_icon_size(items)
|
||||
RecentsSetup => {
|
||||
items.push(sheet_title("Enable window list"))
|
||||
items.push(
|
||||
|
||||
Reference in new issue
Block a user