Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
472a48f4bd |
No files matched your search
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
type: feature
|
||||||
|
---
|
||||||
|
|
||||||
|
Add an icon size setting (long-press the home screen, then Icon size): a 70-160% slider with Small / Medium / Large presets and a live preview that resizes the home grid and the app drawer together. Icon, label and row height scale, the column count reflows so nothing overlaps or clips, the choice is saved, and a corrupt saved value is logged and shown instead of silently replaced. 100% is the original size.
|
||||||
@@ -1,11 +1,17 @@
|
|||||||
# ultra launcher
|
# ultra launcher
|
||||||
|
|
||||||
An Android home screen, written in [MoonBit](https://www.moonbitlang.com). Home starts blank: long-press it to add apps (the drawer opens in a pick mode) or widgets, and long-press anything on it to drag it somewhere else; let go without moving to get its menu, or, for a widget, handles on its edges that resize it to the grid. Swipe down (or tap the search pill) for the drawer with every app and a search (Enter opens the first match); long-press an app there for its menu (add to home, app info, uninstall; system apps have no uninstall), and swipe up to close it. The **Windows** button in the panel at the top opens Recents. The layout is saved on the device, and the app updates itself from the latest release here.
|
An Android home screen, written in [MoonBit](https://www.moonbitlang.com). Home starts blank: long-press it to add apps (the drawer opens in a pick mode) or widgets, and long-press anything on it to drag it somewhere else; let go without moving to get its menu, or, for a widget, handles on its edges that resize it to the grid. **Icon size** in the same menu sets how big icons are (70%–160% in steps of 5, with Small / Medium / Large presets and a live preview; Medium, 100%, is the original size). It applies to the home screen and the app drawer together, scales icon, label and row height, and changes the column count so nothing overlaps or clips. Swipe down (or tap the search pill) for the drawer with every app and a search (Enter opens the first match); long-press an app there for its menu (add to home, app info, uninstall; system apps have no uninstall), and swipe up to close it. The **Windows** button in the panel at the top opens Recents. The layout is saved on the device, and the app updates itself from the latest release here.
|
||||||
|
|
||||||
| home | drawer | app menu | resize handles |
|
| home | drawer | app menu | resize handles |
|
||||||
|---|---|---|---|
|
|---|---|---|---|
|
||||||
|  |  |  |  |
|
|  |  |  |  |
|
||||||
|
|
||||||
|
Icon size, before (100%) and at 130% / 70%, the drawer at 130%, and the error shown for a corrupt saved value:
|
||||||
|
|
||||||
|
| before | 130% | 70% | drawer 130% | corrupt value |
|
||||||
|
|---|---|---|---|---|
|
||||||
|
|  |  |  |  |  |
|
||||||
|
|
||||||
(Screenshots are of the browser demo at phone size.)
|
(Screenshots are of the browser demo at phone size.)
|
||||||
|
|
||||||
## Install
|
## Install
|
||||||
@@ -40,7 +46,7 @@ MoonBit owns the logic and the UI; Java is only what Android itself requires.
|
|||||||
|
|
||||||
| package | what | tested by |
|
| package | what | tested by |
|
||||||
|---|---|---|
|
|---|---|---|
|
||||||
| `grid/` | the home grid: packing (dense, with pinned cells), cell/box math, pin, resize steps, widget columns | `moon test` |
|
| `grid/` | the home grid: packing (dense, with pinned cells), cell/box math, pin, resize steps, widget columns, and the icon size setting (range, parsing, row height, column counts) | `moon test` |
|
||||||
| `gesture/` | pointer state machine: tap, long press (500 ms, 10 px slop), drag, release, swipe | `moon test` |
|
| `gesture/` | pointer state machine: tap, long press (500 ms, 10 px slop), drag, release, swipe | `moon test` |
|
||||||
| `updater/` | release/`version.json` parsing, `build-N` tags, the install/skip decision, 6 h throttle | `moon test` |
|
| `updater/` | release/`version.json` parsing, `build-N` tags, the install/skip decision, 6 h throttle | `moon test` |
|
||||||
| `jsonx/` | small `Json` accessors | `moon test` |
|
| `jsonx/` | small `Json` accessors | `moon test` |
|
||||||
|
|||||||
+32
-1
@@ -61,6 +61,8 @@ pub(all) enum Sheet {
|
|||||||
DrawerApp(Int32)
|
DrawerApp(Int32)
|
||||||
WidgetPicker
|
WidgetPicker
|
||||||
RecentsSetup
|
RecentsSetup
|
||||||
|
/// The icon size slider and presets.
|
||||||
|
IconSize
|
||||||
}
|
}
|
||||||
|
|
||||||
///|
|
///|
|
||||||
@@ -118,6 +120,19 @@ pub(all) struct Model {
|
|||||||
mut grid_left : Double
|
mut grid_left : Double
|
||||||
mut grid_top : Double
|
mut grid_top : Double
|
||||||
mut col_w : 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 query : String
|
||||||
mut wquery : String
|
mut wquery : String
|
||||||
mut drawer : Bool
|
mut drawer : Bool
|
||||||
@@ -176,6 +191,12 @@ pub fn Model::new() -> Model {
|
|||||||
grid_left: 0.0,
|
grid_left: 0.0,
|
||||||
grid_top: 0.0,
|
grid_top: 0.0,
|
||||||
col_w: 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: "",
|
query: "",
|
||||||
wquery: "",
|
wquery: "",
|
||||||
drawer: false,
|
drawer: false,
|
||||||
@@ -222,7 +243,7 @@ pub(all) enum Msg {
|
|||||||
// ---- from the platform
|
// ---- from the platform
|
||||||
/// Boot: the saved layout (this app's JSON, and the old WebView build's
|
/// 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.
|
/// `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(
|
Started(
|
||||||
now~ : Int64,
|
now~ : Int64,
|
||||||
last_check~ : Int64,
|
last_check~ : Int64,
|
||||||
@@ -294,6 +315,12 @@ pub(all) enum Msg {
|
|||||||
MoveEarlier(Int32)
|
MoveEarlier(Int32)
|
||||||
InfoOf(Int32)
|
InfoOf(Int32)
|
||||||
Settings
|
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
|
Wallpaper
|
||||||
Recents
|
Recents
|
||||||
RecentsUnavailable
|
RecentsUnavailable
|
||||||
@@ -331,6 +358,10 @@ pub(all) enum Effect {
|
|||||||
/// Ask the shell for a widget's limits and answer `LimitsKnown`.
|
/// Ask the shell for a widget's limits and answer `LimitsKnown`.
|
||||||
QueryLimits(Int32)
|
QueryLimits(Int32)
|
||||||
SaveHome(String)
|
SaveHome(String)
|
||||||
|
/// Store the icon size (percent).
|
||||||
|
SaveIconSize(Int32)
|
||||||
|
/// Write a line to the platform's error log.
|
||||||
|
LogError(String)
|
||||||
SaveLastCheck(Int64)
|
SaveLastCheck(Int64)
|
||||||
/// Send the message after this many ms.
|
/// Send the message after this many ms.
|
||||||
Delay(Int32, Msg)
|
Delay(Int32, Msg)
|
||||||
|
|||||||
+14
-1
@@ -84,6 +84,8 @@ pub(all) enum Effect {
|
|||||||
LoadWidgets
|
LoadWidgets
|
||||||
QueryLimits(Int32)
|
QueryLimits(Int32)
|
||||||
SaveHome(String)
|
SaveHome(String)
|
||||||
|
SaveIconSize(Int32)
|
||||||
|
LogError(String)
|
||||||
SaveLastCheck(Int64)
|
SaveLastCheck(Int64)
|
||||||
Delay(Int32, Msg)
|
Delay(Int32, Msg)
|
||||||
HoldTimer(Int32, Int32)
|
HoldTimer(Int32, Int32)
|
||||||
@@ -123,6 +125,12 @@ pub(all) struct Model {
|
|||||||
mut grid_left : Double
|
mut grid_left : Double
|
||||||
mut grid_top : Double
|
mut grid_top : Double
|
||||||
mut col_w : 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 query : String
|
||||||
mut wquery : String
|
mut wquery : String
|
||||||
mut drawer : Bool
|
mut drawer : Bool
|
||||||
@@ -153,6 +161,7 @@ pub(all) struct Model {
|
|||||||
mut gesture : @gesture.State
|
mut gesture : @gesture.State
|
||||||
}
|
}
|
||||||
pub fn Model::app_row(Self, String) -> Int32
|
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::drawer_open(Self) -> Bool
|
||||||
pub fn Model::first_match(Self) -> Int32
|
pub fn Model::first_match(Self) -> Int32
|
||||||
pub fn Model::first_widget_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)
|
#derive(Eq, @debug.Debug)
|
||||||
pub(all) enum Msg {
|
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)
|
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)
|
Measured(vw~ : Int32, vh~ : Int32, grid_left~ : Double, grid_top~ : Double, grid_w~ : Double, bottom_pad~ : Double, scroll_y~ : Double)
|
||||||
AppsLoaded(String?)
|
AppsLoaded(String?)
|
||||||
@@ -209,6 +218,9 @@ pub(all) enum Msg {
|
|||||||
MoveEarlier(Int32)
|
MoveEarlier(Int32)
|
||||||
InfoOf(Int32)
|
InfoOf(Int32)
|
||||||
Settings
|
Settings
|
||||||
|
IconSizeMenu
|
||||||
|
SetIconSize(String)
|
||||||
|
IconPreset(Int32)
|
||||||
Wallpaper
|
Wallpaper
|
||||||
Recents
|
Recents
|
||||||
RecentsUnavailable
|
RecentsUnavailable
|
||||||
@@ -249,6 +261,7 @@ pub(all) enum Sheet {
|
|||||||
DrawerApp(Int32)
|
DrawerApp(Int32)
|
||||||
WidgetPicker
|
WidgetPicker
|
||||||
RecentsSetup
|
RecentsSetup
|
||||||
|
IconSize
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(all) struct WidgetInfo {
|
pub(all) struct WidgetInfo {
|
||||||
|
|||||||
+172
-4
@@ -33,7 +33,7 @@ struct Sim {
|
|||||||
fn Sim::new() -> Sim {
|
fn Sim::new() -> Sim {
|
||||||
let m = Model::new()
|
let m = Model::new()
|
||||||
let s = { m, tree: [], table: [], log: [], last_x: 0.0, last_y: 0.0, }
|
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(
|
s.send(
|
||||||
Measured(
|
Measured(
|
||||||
vw=390,
|
vw=390,
|
||||||
@@ -757,7 +757,7 @@ test "the layout is saved on every change and restored" {
|
|||||||
}
|
}
|
||||||
assert_eq(saved, save_json(s.m.home))
|
assert_eq(saved, save_json(s.m.home))
|
||||||
let s2 = Sim::new()
|
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"])
|
assert_eq(s2.home_names(), ["Chrome", "Gmail"])
|
||||||
// restoring what is already saved doesn't save it again
|
// 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
|
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("{}", Ref(1)).length(), 0)
|
||||||
assert_eq(legacy_import("garbage", Ref(1)).length(), 0)
|
assert_eq(legacy_import("garbage", Ref(1)).length(), 0)
|
||||||
let s = Sim::new()
|
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_eq(s.m.home.length(), 2)
|
||||||
assert_true(s.log.contains(SaveHome(save_json(s.m.home)))) // saved in the new format
|
assert_true(s.log.contains(SaveHome(save_json(s.m.home)))) // saved in the new format
|
||||||
// a saved layout wins over the old one
|
// 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(
|
Restore(
|
||||||
saved=Some(save_json([slot_app("c.gmail/.Main")])),
|
saved=Some(save_json([slot_app("c.gmail/.Main")])),
|
||||||
legacy=Some(legacy),
|
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 class="magnifier" aria-hidden="true"></span>
|
||||||
#| <span>Search apps</span>
|
#| <span>Search apps</span>
|
||||||
#| </button>
|
#| </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">
|
#| <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>
|
#| <img class="icon" alt="" draggable="false" data-icon="i3"></img>
|
||||||
#| <span class="name">Chrome</span>
|
#| <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])
|
let none_html = @vdom.to_html(s.tree[0])
|
||||||
assert_true(!none_html.contains("resize-handle"))
|
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
|
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 {
|
pub fn Model::packed(self : Model) -> @grid.Packed {
|
||||||
@grid.pack(self.home, self.cols, self.nrows, hidden=fn(i) { self.hidden(i) })
|
@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)? {
|
) -> (Double, Double, Double, Double)? {
|
||||||
match packed.cells[i] {
|
match packed.cells[i] {
|
||||||
Some(c) => {
|
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))
|
Some((x + self.grid_left, y + self.grid_top, w, h))
|
||||||
}
|
}
|
||||||
None => None
|
None => None
|
||||||
@@ -303,11 +347,12 @@ fn Model::drag_lifted(
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
let half_w = self.col_w / 2.0
|
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(
|
let (fc, fr) = @grid.cell_at(
|
||||||
x - self.grid_left - half_w,
|
x - self.grid_left - half_w,
|
||||||
y - self.grid_top - half_h,
|
y - self.grid_top - half_h,
|
||||||
self.col_w,
|
self.col_w,
|
||||||
|
ch=self.cell_h(),
|
||||||
)
|
)
|
||||||
let mut to = self.slot_at(packed, x, y)
|
let mut to = self.slot_at(packed, x, y)
|
||||||
if to < 0 {
|
if to < 0 {
|
||||||
@@ -315,7 +360,7 @@ fn Model::drag_lifted(
|
|||||||
fc.to_double() * (self.col_w + @grid.col_gap.to_double()) +
|
fc.to_double() * (self.col_w + @grid.col_gap.to_double()) +
|
||||||
half_w
|
half_w
|
||||||
let cy = self.grid_top +
|
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
|
half_h
|
||||||
to = self.slot_at(packed, cx, cy)
|
to = self.slot_at(packed, cx, cy)
|
||||||
}
|
}
|
||||||
@@ -328,7 +373,7 @@ fn Model::drag_lifted(
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
let grid_bottom = self.grid_top +
|
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 {
|
if y > grid_bottom {
|
||||||
return // below the grid
|
return // below the grid
|
||||||
}
|
}
|
||||||
@@ -336,6 +381,7 @@ fn Model::drag_lifted(
|
|||||||
x - self.grid_left - carry.dx,
|
x - self.grid_left - carry.dx,
|
||||||
y - self.grid_top - carry.dy,
|
y - self.grid_top - carry.dy,
|
||||||
self.col_w,
|
self.col_w,
|
||||||
|
ch=self.cell_h(),
|
||||||
)
|
)
|
||||||
let cell = row * 64 + @cmp.minimum(col, 63)
|
let cell = row * 64 + @cmp.minimum(col, 63)
|
||||||
if cell != carry.cell {
|
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 }
|
guard self.packed().cells[i] is Some(cell) else { return }
|
||||||
s.x = cell.col
|
s.x = cell.col
|
||||||
s.y = cell.row
|
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 left = self.grid_left + bx
|
||||||
let top = self.grid_top + by
|
let top = self.grid_top + by
|
||||||
self.resize = Some({
|
self.resize = Some({
|
||||||
@@ -464,7 +510,7 @@ fn Model::drag_resize(
|
|||||||
y - r.top,
|
y - r.top,
|
||||||
1,
|
1,
|
||||||
20,
|
20,
|
||||||
@grid.cell_px.to_double(),
|
self.cell_h().to_double(),
|
||||||
rg,
|
rg,
|
||||||
lim.min_h,
|
lim.min_h,
|
||||||
lim.max_h,
|
lim.max_h,
|
||||||
@@ -477,7 +523,7 @@ fn Model::drag_resize(
|
|||||||
r.bottom - y,
|
r.bottom - y,
|
||||||
1,
|
1,
|
||||||
hi,
|
hi,
|
||||||
@grid.cell_px.to_double(),
|
self.cell_h().to_double(),
|
||||||
rg,
|
rg,
|
||||||
lim.min_h,
|
lim.min_h,
|
||||||
lim.max_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 {
|
fn step(m : Model, msg : Msg, fx : Array[Effect]) -> Unit {
|
||||||
match msg {
|
match msg {
|
||||||
Restore(saved~, legacy~) => {
|
Restore(saved~, legacy~, icon_size~) => {
|
||||||
let next = Ref(m.next_key)
|
let next = Ref(m.next_key)
|
||||||
let mut slots = None
|
let mut slots = None
|
||||||
if saved is Some(text) {
|
if saved is Some(text) {
|
||||||
@@ -550,6 +596,15 @@ fn step(m : Model, msg : Msg, fx : Array[Effect]) -> Unit {
|
|||||||
m.home = s
|
m.home = s
|
||||||
}
|
}
|
||||||
m.next_key = next.val
|
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)
|
fx.push(LoadApps)
|
||||||
}
|
}
|
||||||
Started(now~, last_check~, declined~, installed~) => {
|
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~) => {
|
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_left = grid_left
|
||||||
m.grid_top = grid_top
|
m.grid_top = grid_top
|
||||||
m.col_w = @grid.column_width(grid_w, m.cols)
|
m.grid_w = grid_w
|
||||||
m.nrows = @grid.rows_fit(
|
m.avail_h = vh.to_double() - bottom_pad - (grid_top + scroll_y)
|
||||||
vh.to_double() - bottom_pad - (grid_top + scroll_y),
|
m.relayout()
|
||||||
)
|
|
||||||
}
|
}
|
||||||
AppsLoaded(text) => {
|
AppsLoaded(text) => {
|
||||||
m.loading = false
|
m.loading = false
|
||||||
@@ -629,7 +683,7 @@ fn step(m : Model, msg : Msg, fx : Array[Effect]) -> Unit {
|
|||||||
@grid.Slot::widget(
|
@grid.Slot::widget(
|
||||||
w.label,
|
w.label,
|
||||||
id,
|
id,
|
||||||
rows=@grid.widget_rows(w.h),
|
rows=@grid.widget_rows(w.h, ch=m.cell_h()),
|
||||||
key=m.new_key(),
|
key=m.new_key(),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
@@ -824,6 +878,18 @@ fn step(m : Model, msg : Msg, fx : Array[Effect]) -> Unit {
|
|||||||
fx.push(OpenSettings)
|
fx.push(OpenSettings)
|
||||||
m.sheet = NoSheet
|
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 => {
|
Wallpaper => {
|
||||||
fx.push(PickWallpaper)
|
fx.push(PickWallpaper)
|
||||||
m.sheet = NoSheet
|
m.sheet = NoSheet
|
||||||
|
|||||||
+112
-2
@@ -170,7 +170,7 @@ fn Model::view_home(self : Model) -> Node[Msg] {
|
|||||||
el(
|
el(
|
||||||
"ul",
|
"ul",
|
||||||
classes=["slots", cls_if("dragging", self.lifted >= 0)],
|
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,
|
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 {
|
if self.loading {
|
||||||
children.push(
|
children.push(
|
||||||
el("p", classes=["empty"], children=[text("Loading apps…")]),
|
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)])
|
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]] {
|
fn Model::view_sheet(self : Model) -> Array[Node[Msg]] {
|
||||||
let items : 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_title("Home screen"))
|
||||||
items.push(sheet_btn("Add apps", PickApps))
|
items.push(sheet_btn("Add apps", PickApps))
|
||||||
items.push(sheet_btn("Add widget", PickWidget))
|
items.push(sheet_btn("Add widget", PickWidget))
|
||||||
|
items.push(sheet_btn("Icon size", IconSizeMenu))
|
||||||
items.push(sheet_btn("Wallpaper", Wallpaper))
|
items.push(sheet_btn("Wallpaper", Wallpaper))
|
||||||
items.push(sheet_btn("Settings", Settings))
|
items.push(sheet_btn("Settings", Settings))
|
||||||
items.push(sheet_btn("Check for updates", CheckUpdates))
|
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 => {
|
RecentsSetup => {
|
||||||
items.push(sheet_title("Enable window list"))
|
items.push(sheet_title("Enable window list"))
|
||||||
items.push(
|
items.push(
|
||||||
|
|||||||
Binary file not shown.
|
After Width: | Height: | Size: 134 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 79 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 69 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 102 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 76 KiB |
+28
-15
@@ -63,8 +63,8 @@ pub fn Slot::widget(
|
|||||||
|
|
||||||
///|
|
///|
|
||||||
/// Rows of app tiles nearest to a widget height in px, at least one.
|
/// Rows of app tiles nearest to a widget height in px, at least one.
|
||||||
pub fn widget_rows(px : Int32) -> Int32 {
|
pub fn widget_rows(px : Int32, ch~ : Int32 = cell_px) -> Int32 {
|
||||||
let k = (px + row_gap + (cell_px + row_gap) / 2) / (cell_px + row_gap)
|
let k = (px + row_gap + (ch + row_gap) / 2) / (ch + row_gap)
|
||||||
if k < 1 {
|
if k < 1 {
|
||||||
1
|
1
|
||||||
} else {
|
} else {
|
||||||
@@ -192,38 +192,51 @@ pub fn pack(
|
|||||||
}
|
}
|
||||||
|
|
||||||
///|
|
///|
|
||||||
/// A cell's box in px, given the column width: (x, y, w, h).
|
/// A cell's box in px, given the column width and the row height `ch`: (x, y, w, h).
|
||||||
pub fn box(cell : Cell, col_w : Double) -> (Double, Double, Double, Double) {
|
pub fn box(
|
||||||
|
cell : Cell,
|
||||||
|
col_w : Double,
|
||||||
|
ch~ : Int32 = cell_px,
|
||||||
|
) -> (Double, Double, Double, Double) {
|
||||||
let cg = col_gap.to_double()
|
let cg = col_gap.to_double()
|
||||||
let rg = row_gap.to_double()
|
let rg = row_gap.to_double()
|
||||||
(
|
(
|
||||||
cell.col.to_double() * (col_w + cg),
|
cell.col.to_double() * (col_w + cg),
|
||||||
cell.row.to_double() * (cell_px.to_double() + rg),
|
cell.row.to_double() * (ch.to_double() + rg),
|
||||||
cell.w.to_double() * col_w + (cell.w - 1).to_double() * cg,
|
cell.w.to_double() * col_w + (cell.w - 1).to_double() * cg,
|
||||||
cell.h.to_double() * cell_px.to_double() + (cell.h - 1).to_double() * rg,
|
cell.h.to_double() * ch.to_double() + (cell.h - 1).to_double() * rg,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
///|
|
///|
|
||||||
/// The cell nearest to a point (px in the grid, from its top left): (col, row).
|
/// The cell nearest to a point (px in the grid, from its top left): (col, row).
|
||||||
pub fn cell_at(x : Double, y : Double, col_w : Double) -> (Int32, Int32) {
|
pub fn cell_at(
|
||||||
|
x : Double,
|
||||||
|
y : Double,
|
||||||
|
col_w : Double,
|
||||||
|
ch~ : Int32 = cell_px,
|
||||||
|
) -> (Int32, Int32) {
|
||||||
let c = (x / (col_w + col_gap.to_double()) + 0.5).floor().to_int()
|
let c = (x / (col_w + col_gap.to_double()) + 0.5).floor().to_int()
|
||||||
let r = (y / (cell_px + row_gap).to_double() + 0.5).floor().to_int()
|
let r = (y / (ch + row_gap).to_double() + 0.5).floor().to_int()
|
||||||
(@cmp.maximum(0, c), @cmp.maximum(0, r))
|
(@cmp.maximum(0, c), @cmp.maximum(0, r))
|
||||||
}
|
}
|
||||||
|
|
||||||
///|
|
///|
|
||||||
/// The cell whose box contains a point, or `None` outside every cell (in the gaps).
|
/// The cell whose box contains a point, or `None` outside every cell (in the gaps).
|
||||||
pub fn cell_under(x : Double, y : Double, col_w : Double) -> (Int32, Int32)? {
|
pub fn cell_under(
|
||||||
|
x : Double,
|
||||||
|
y : Double,
|
||||||
|
col_w : Double,
|
||||||
|
ch~ : Int32 = cell_px,
|
||||||
|
) -> (Int32, Int32)? {
|
||||||
if x < 0.0 || y < 0.0 {
|
if x < 0.0 || y < 0.0 {
|
||||||
return None
|
return None
|
||||||
}
|
}
|
||||||
let pw = col_w + col_gap.to_double()
|
let pw = col_w + col_gap.to_double()
|
||||||
let ph = (cell_px + row_gap).to_double()
|
let ph = (ch + row_gap).to_double()
|
||||||
let c = (x / pw).floor().to_int()
|
let c = (x / pw).floor().to_int()
|
||||||
let r = (y / ph).floor().to_int()
|
let r = (y / ph).floor().to_int()
|
||||||
if x - c.to_double() * pw > col_w ||
|
if x - c.to_double() * pw > col_w || y - r.to_double() * ph > ch.to_double() {
|
||||||
y - r.to_double() * ph > cell_px.to_double() {
|
|
||||||
None
|
None
|
||||||
} else {
|
} else {
|
||||||
Some((c, r))
|
Some((c, r))
|
||||||
@@ -345,9 +358,9 @@ pub fn column_width(grid_width : Double, cols : Int32) -> Double {
|
|||||||
}
|
}
|
||||||
|
|
||||||
///|
|
///|
|
||||||
/// How many rows of the grid fit in `height` px.
|
/// How many rows of height `ch` fit in `height` px.
|
||||||
pub fn rows_fit(height : Double) -> Int32 {
|
pub fn rows_fit(height : Double, ch~ : Int32 = cell_px) -> Int32 {
|
||||||
let r = ((height + row_gap.to_double()) / (cell_px + row_gap).to_double())
|
let r = ((height + row_gap.to_double()) / (ch + row_gap).to_double())
|
||||||
.floor()
|
.floor()
|
||||||
.to_int()
|
.to_int()
|
||||||
@cmp.maximum(1, r)
|
@cmp.maximum(1, r)
|
||||||
|
|||||||
@@ -120,7 +120,9 @@ test "moving in the order" {
|
|||||||
|
|
||||||
///|
|
///|
|
||||||
test "widget heights in px to rows" {
|
test "widget heights in px to rows" {
|
||||||
assert_eq([40, 64, 100, 136, 208, 420].map(widget_rows), [1, 1, 2, 2, 3, 6])
|
assert_eq([40, 64, 100, 136, 208, 420].map(fn(p) { widget_rows(p) }), [
|
||||||
|
1, 1, 2, 2, 3, 6,
|
||||||
|
])
|
||||||
}
|
}
|
||||||
|
|
||||||
///|
|
///|
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
import {
|
import {
|
||||||
"moonbitlang/core/cmp",
|
"moonbitlang/core/cmp",
|
||||||
|
"moonbitlang/core/string",
|
||||||
}
|
}
|
||||||
+41
-5
@@ -6,13 +6,15 @@ import {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Values
|
// Values
|
||||||
pub fn box(Cell, Double) -> (Double, Double, Double, Double)
|
pub fn box(Cell, Double, ch? : Int32) -> (Double, Double, Double, Double)
|
||||||
|
|
||||||
pub fn cell_at(Double, Double, Double) -> (Int32, Int32)
|
pub fn cell_at(Double, Double, Double, ch? : Int32) -> (Int32, Int32)
|
||||||
|
|
||||||
|
pub fn cell_height(Int32) -> Int32
|
||||||
|
|
||||||
pub let cell_px : Int32
|
pub let cell_px : Int32
|
||||||
|
|
||||||
pub fn cell_under(Double, Double, Double) -> (Int32, Int32)?
|
pub fn cell_under(Double, Double, Double, ch? : Int32) -> (Int32, Int32)?
|
||||||
|
|
||||||
pub fn clear_cells(Array[Slot], Int32, Int32) -> Unit
|
pub fn clear_cells(Array[Slot], Int32, Int32) -> Unit
|
||||||
|
|
||||||
@@ -22,23 +24,57 @@ pub fn column_width(Double, Int32) -> Double
|
|||||||
|
|
||||||
pub fn columns_for(Int32) -> Int32
|
pub fn columns_for(Int32) -> Int32
|
||||||
|
|
||||||
|
pub fn css_factor(Int32) -> String
|
||||||
|
|
||||||
|
pub fn drawer_columns(Int32, Int32) -> Int32
|
||||||
|
|
||||||
|
pub let drawer_icon_px : Int32
|
||||||
|
|
||||||
pub fn fit(Double, Int32, Int32, Double, Double, Int32, Int32) -> Int32
|
pub fn fit(Double, Int32, Int32, Double, Double, Int32, Int32) -> Int32
|
||||||
|
|
||||||
|
pub fn home_columns(Int32, Double, Int32) -> Int32
|
||||||
|
|
||||||
|
pub let home_icon_px : Int32
|
||||||
|
|
||||||
|
pub let min_cols : Int32
|
||||||
|
|
||||||
pub fn move_slot(Array[Slot], Int32, Int32) -> Unit
|
pub fn move_slot(Array[Slot], Int32, Int32) -> Unit
|
||||||
|
|
||||||
pub fn pack(Array[Slot], Int32, Int32, hidden? : (Int32) -> Bool) -> Packed
|
pub fn pack(Array[Slot], Int32, Int32, hidden? : (Int32) -> Bool) -> Packed
|
||||||
|
|
||||||
|
pub fn parse_scale(String) -> Result[Int32, String]
|
||||||
|
|
||||||
pub fn pin(Array[Slot], Int32, Int32, Int32, Int32, Int32) -> Unit
|
pub fn pin(Array[Slot], Int32, Int32, Int32, Int32, Int32) -> Unit
|
||||||
|
|
||||||
pub let row_gap : Int32
|
pub let row_gap : Int32
|
||||||
|
|
||||||
pub fn rows_fit(Double) -> Int32
|
pub fn rows_fit(Double, ch? : Int32) -> Int32
|
||||||
|
|
||||||
|
pub let scale_default : Int32
|
||||||
|
|
||||||
|
pub let scale_large : Int32
|
||||||
|
|
||||||
|
pub let scale_max : Int32
|
||||||
|
|
||||||
|
pub let scale_medium : Int32
|
||||||
|
|
||||||
|
pub let scale_min : Int32
|
||||||
|
|
||||||
|
pub let scale_small : Int32
|
||||||
|
|
||||||
|
pub let scale_step : Int32
|
||||||
|
|
||||||
|
pub fn scale_valid(Int32) -> Bool
|
||||||
|
|
||||||
|
pub fn scaled_columns(Int32, Int32, Double, Int32, Int32) -> Int32
|
||||||
|
|
||||||
|
pub fn scaled_px(Int32, Int32) -> Int32
|
||||||
|
|
||||||
pub fn span(Int32, Double, Double) -> Double
|
pub fn span(Int32, Double, Double) -> Double
|
||||||
|
|
||||||
pub fn widget_cols(Int32, Double, Int32) -> Int32
|
pub fn widget_cols(Int32, Double, Int32) -> Int32
|
||||||
|
|
||||||
pub fn widget_rows(Int32) -> Int32
|
pub fn widget_rows(Int32, ch? : Int32) -> Int32
|
||||||
|
|
||||||
// Errors
|
// Errors
|
||||||
|
|
||||||
|
|||||||
+142
@@ -0,0 +1,142 @@
|
|||||||
|
///|
|
||||||
|
/// The icon size setting as plain functions: the allowed range, parsing a stored or
|
||||||
|
/// slider value, and how icon size, row height and column count follow from it.
|
||||||
|
/// The size is a whole percent of today's size (`scale_default` = 100: no change).
|
||||||
|
|
||||||
|
///|
|
||||||
|
pub let scale_min : Int32 = 70
|
||||||
|
|
||||||
|
///|
|
||||||
|
pub let scale_max : Int32 = 160
|
||||||
|
|
||||||
|
///|
|
||||||
|
pub let scale_default : Int32 = 100
|
||||||
|
|
||||||
|
///|
|
||||||
|
/// Slider step in percent.
|
||||||
|
pub let scale_step : Int32 = 5
|
||||||
|
|
||||||
|
///|
|
||||||
|
/// The presets: Small, Medium (today's size), Large.
|
||||||
|
pub let scale_small : Int32 = 80
|
||||||
|
|
||||||
|
///|
|
||||||
|
pub let scale_medium : Int32 = 100
|
||||||
|
|
||||||
|
///|
|
||||||
|
pub let scale_large : Int32 = 130
|
||||||
|
|
||||||
|
///|
|
||||||
|
/// The home icon at 100%, in px (`.slots .icon`).
|
||||||
|
pub let home_icon_px : Int32 = 40
|
||||||
|
|
||||||
|
///|
|
||||||
|
/// The drawer icon at 100%, in px (`.icon`).
|
||||||
|
pub let drawer_icon_px : Int32 = 52
|
||||||
|
|
||||||
|
///|
|
||||||
|
/// Fewest columns either grid is reduced to, however large the icons.
|
||||||
|
pub let min_cols : Int32 = 3
|
||||||
|
|
||||||
|
///|
|
||||||
|
/// A size is a valid setting: in range and on the step.
|
||||||
|
pub fn scale_valid(pct : Int32) -> Bool {
|
||||||
|
pct >= scale_min && pct <= scale_max && pct % scale_step == 0
|
||||||
|
}
|
||||||
|
|
||||||
|
///|
|
||||||
|
/// Parse a stored or slider value (decimal whole percent, nothing else). The error says
|
||||||
|
/// what was wrong and what is allowed; callers show and log it.
|
||||||
|
pub fn parse_scale(text : String) -> Result[Int32, String] {
|
||||||
|
let t = text.trim().to_owned()
|
||||||
|
let n = @string.parse_int(t) catch {
|
||||||
|
_ => return Err("icon size \"\{text}\" is not a whole number")
|
||||||
|
}
|
||||||
|
if scale_valid(n) {
|
||||||
|
Ok(n)
|
||||||
|
} else {
|
||||||
|
Err(
|
||||||
|
"icon size \{n} is outside \{scale_min}..\{scale_max} in steps of \{scale_step}",
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
///|
|
||||||
|
/// `base` px at `pct` percent, rounded to a whole px, at least 1.
|
||||||
|
pub fn scaled_px(base : Int32, pct : Int32) -> Int32 {
|
||||||
|
@cmp.maximum(1, (base * pct + 50) / 100)
|
||||||
|
}
|
||||||
|
|
||||||
|
///|
|
||||||
|
/// Height of a home row at `pct`.
|
||||||
|
pub fn cell_height(pct : Int32) -> Int32 {
|
||||||
|
scaled_px(cell_px, pct)
|
||||||
|
}
|
||||||
|
|
||||||
|
///|
|
||||||
|
/// The percent as a CSS number (`1`, `1.25`, `0.8`), for the `--s` custom property.
|
||||||
|
pub fn css_factor(pct : Int32) -> String {
|
||||||
|
let whole = pct / 100
|
||||||
|
let frac = pct % 100
|
||||||
|
if frac == 0 {
|
||||||
|
whole.to_string()
|
||||||
|
} else if frac < 10 {
|
||||||
|
"\{whole}.0\{frac}"
|
||||||
|
} else if frac % 10 == 0 {
|
||||||
|
"\{whole}.\{frac / 10}"
|
||||||
|
} else {
|
||||||
|
"\{whole}.\{frac}"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
///|
|
||||||
|
/// Columns of a grid `avail` px wide whose icons are `icon` px: `base` columns at 100%,
|
||||||
|
/// `base * 100 / pct` (rounded) at `pct`, no fewer than `min_cols` and then never so
|
||||||
|
/// many that a column (`gap` px apart) is narrower than its icon.
|
||||||
|
pub fn scaled_columns(
|
||||||
|
base : Int32,
|
||||||
|
pct : Int32,
|
||||||
|
avail : Double,
|
||||||
|
gap : Int32,
|
||||||
|
icon : Int32,
|
||||||
|
) -> Int32 {
|
||||||
|
let mut c = @cmp.maximum(min_cols, (base * 100 + pct / 2) / pct)
|
||||||
|
while c > 1 && column_width_in(avail, c, gap) < icon.to_double() {
|
||||||
|
c -= 1
|
||||||
|
}
|
||||||
|
c
|
||||||
|
}
|
||||||
|
|
||||||
|
///|
|
||||||
|
fn column_width_in(avail : Double, cols : Int32, gap : Int32) -> Double {
|
||||||
|
(avail - (cols - 1).to_double() * gap.to_double()) / cols.to_double()
|
||||||
|
}
|
||||||
|
|
||||||
|
///|
|
||||||
|
/// Home grid columns for a viewport width, the width of the grid and the size.
|
||||||
|
pub fn home_columns(vw : Int32, grid_w : Double, pct : Int32) -> Int32 {
|
||||||
|
scaled_columns(
|
||||||
|
columns_for(vw),
|
||||||
|
pct,
|
||||||
|
grid_w,
|
||||||
|
col_gap,
|
||||||
|
scaled_px(home_icon_px, pct),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
///|
|
||||||
|
/// Drawer columns (4 below 480px, else 5, at 100%); its list is the viewport less 16px
|
||||||
|
/// padding each side, with 8px between columns.
|
||||||
|
pub fn drawer_columns(vw : Int32, pct : Int32) -> Int32 {
|
||||||
|
scaled_columns(
|
||||||
|
if vw >= 480 {
|
||||||
|
5
|
||||||
|
} else {
|
||||||
|
4
|
||||||
|
},
|
||||||
|
pct,
|
||||||
|
(vw - 32).to_double(),
|
||||||
|
8,
|
||||||
|
scaled_px(drawer_icon_px, pct),
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -0,0 +1,136 @@
|
|||||||
|
///|
|
||||||
|
test "the default size is today's size" {
|
||||||
|
assert_eq(scale_default, 100)
|
||||||
|
assert_eq(scale_medium, scale_default)
|
||||||
|
assert_eq(cell_height(scale_default), cell_px)
|
||||||
|
assert_eq(scaled_px(home_icon_px, scale_default), 40)
|
||||||
|
assert_eq(scaled_px(drawer_icon_px, scale_default), 52)
|
||||||
|
// the column counts the app had before the setting existed
|
||||||
|
assert_eq(home_columns(390, 358.0, 100), columns_for(390))
|
||||||
|
assert_eq(home_columns(600, 528.0, 100), columns_for(600))
|
||||||
|
assert_eq(drawer_columns(390, 100), 4)
|
||||||
|
assert_eq(drawer_columns(600, 100), 5)
|
||||||
|
}
|
||||||
|
|
||||||
|
///|
|
||||||
|
test "presets and range are valid settings" {
|
||||||
|
for p in [scale_small, scale_medium, scale_large, scale_min, scale_max] {
|
||||||
|
assert_true(scale_valid(p))
|
||||||
|
}
|
||||||
|
assert_true(scale_min < scale_default && scale_default < scale_max)
|
||||||
|
}
|
||||||
|
|
||||||
|
///|
|
||||||
|
test "parse_scale accepts steps in range" {
|
||||||
|
assert_eq(parse_scale("100"), Ok(100))
|
||||||
|
assert_eq(parse_scale(" 85 "), Ok(85))
|
||||||
|
assert_eq(parse_scale("70"), Ok(70))
|
||||||
|
assert_eq(parse_scale("160"), Ok(160))
|
||||||
|
}
|
||||||
|
|
||||||
|
///|
|
||||||
|
test "parse_scale rejects corrupt values with a reason" {
|
||||||
|
assert_eq(parse_scale("abc"), Err("icon size \"abc\" is not a whole number"))
|
||||||
|
assert_eq(parse_scale(""), Err("icon size \"\" is not a whole number"))
|
||||||
|
assert_eq(parse_scale("1.5"), Err("icon size \"1.5\" is not a whole number"))
|
||||||
|
assert_eq(
|
||||||
|
parse_scale("65"),
|
||||||
|
Err("icon size 65 is outside 70..160 in steps of 5"),
|
||||||
|
)
|
||||||
|
assert_eq(
|
||||||
|
parse_scale("500"),
|
||||||
|
Err("icon size 500 is outside 70..160 in steps of 5"),
|
||||||
|
)
|
||||||
|
assert_eq(
|
||||||
|
parse_scale("-10"),
|
||||||
|
Err("icon size -10 is outside 70..160 in steps of 5"),
|
||||||
|
)
|
||||||
|
// in range but off the step
|
||||||
|
assert_eq(
|
||||||
|
parse_scale("102"),
|
||||||
|
Err("icon size 102 is outside 70..160 in steps of 5"),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
///|
|
||||||
|
test "sizes scale together" {
|
||||||
|
assert_eq(scaled_px(home_icon_px, 150), 60)
|
||||||
|
assert_eq(scaled_px(home_icon_px, 70), 28)
|
||||||
|
assert_eq(cell_height(150), 96)
|
||||||
|
assert_eq(cell_height(70), 45)
|
||||||
|
assert_eq(cell_height(scale_min) < cell_px, true)
|
||||||
|
assert_eq(scaled_px(1, 70), 1) // never below a pixel
|
||||||
|
}
|
||||||
|
|
||||||
|
///|
|
||||||
|
test "css_factor" {
|
||||||
|
assert_eq(css_factor(100), "1")
|
||||||
|
assert_eq(css_factor(130), "1.3")
|
||||||
|
assert_eq(css_factor(80), "0.8")
|
||||||
|
assert_eq(css_factor(105), "1.05")
|
||||||
|
assert_eq(css_factor(160), "1.6")
|
||||||
|
assert_eq(css_factor(70), "0.7")
|
||||||
|
}
|
||||||
|
|
||||||
|
///|
|
||||||
|
test "larger icons mean fewer columns, smaller mean more" {
|
||||||
|
assert_eq(home_columns(390, 358.0, 70), 7)
|
||||||
|
assert_eq(home_columns(390, 358.0, 130), 4)
|
||||||
|
assert_eq(home_columns(390, 358.0, 160), 3)
|
||||||
|
assert_eq(drawer_columns(390, 70), 6)
|
||||||
|
assert_eq(drawer_columns(390, 160), 3)
|
||||||
|
}
|
||||||
|
|
||||||
|
///|
|
||||||
|
test "columns never go below min_cols while icons fit" {
|
||||||
|
for pct in 70..<=160 {
|
||||||
|
if pct % scale_step == 0 {
|
||||||
|
assert_true(home_columns(390, 358.0, pct) >= min_cols)
|
||||||
|
assert_true(drawer_columns(390, pct) >= min_cols)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
///|
|
||||||
|
test "icons never overlap or clip: a column is at least as wide as its icon" {
|
||||||
|
// every size, on phones of several widths (grid is the viewport less 32px, max 528)
|
||||||
|
for vw in [320, 360, 390, 412, 480, 600, 800] {
|
||||||
|
let grid_w = ((if vw > 560 { 560 } else { vw }) - 32).to_double()
|
||||||
|
for pct in 70..<=160 {
|
||||||
|
if pct % scale_step != 0 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
let c = home_columns(vw, grid_w, pct)
|
||||||
|
assert_true(
|
||||||
|
column_width(grid_w, c) >= scaled_px(home_icon_px, pct).to_double(),
|
||||||
|
)
|
||||||
|
let d = drawer_columns(vw, pct)
|
||||||
|
let dw = (vw - 32).to_double()
|
||||||
|
assert_true(
|
||||||
|
(dw - (d - 1).to_double() * 8.0) / d.to_double() >=
|
||||||
|
scaled_px(drawer_icon_px, pct).to_double(),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
///|
|
||||||
|
test "a very narrow grid sheds columns to keep the icons whole" {
|
||||||
|
// 160px of grid at 160%: icons are 64px, so only two columns fit with the 8px gap
|
||||||
|
assert_eq(scaled_columns(5, 160, 160.0, 8, 64), 2)
|
||||||
|
assert_eq(scaled_columns(5, 100, 400.0, 8, 40), 5)
|
||||||
|
}
|
||||||
|
|
||||||
|
///|
|
||||||
|
test "row height parameter threads through the cell maths" {
|
||||||
|
let c : Cell = { col: 1, row: 2, w: 2, h: 2, }
|
||||||
|
let (x, y, w, h) = box(c, 60.0, ch=96)
|
||||||
|
assert_eq((x, y, w, h), (68.0, 208.0, 128.0, 200.0))
|
||||||
|
assert_eq(box(c, 60.0), box(c, 60.0, ch=cell_px))
|
||||||
|
assert_eq(rows_fit(500.0, ch=96), 4)
|
||||||
|
assert_eq(rows_fit(500.0), 7)
|
||||||
|
assert_eq(widget_rows(200, ch=96), 2)
|
||||||
|
assert_eq(cell_at(80.0, 220.0, 70.0, ch=96), (1, 2))
|
||||||
|
assert_eq(cell_under(80.0, 220.0, 70.0, ch=96), Some((1, 2)))
|
||||||
|
assert_eq(cell_under(80.0, 100.0, 70.0, ch=96), None) // in the row gap
|
||||||
|
}
|
||||||
@@ -235,6 +235,101 @@ const serve = () => new Promise((resolve) => {
|
|||||||
assert.ok(!(await p.$(".widget-slot")));
|
assert.ok(!(await p.$(".widget-slot")));
|
||||||
await p.evaluate(() => { window.launcher.reload(); }); await settle();
|
await p.evaluate(() => { window.launcher.reload(); }); await settle();
|
||||||
assert.equal(await p.$$eval(".slots > li", (ls) => ls.length), 4);
|
assert.equal(await p.$$eval(".slots > li", (ls) => ls.length), 4);
|
||||||
|
// ---- icon size: a slider in the home menu resizes every icon grid live, is saved, and survives a reload
|
||||||
|
const grid = () => p.$eval(".slots", (g) => {
|
||||||
|
const gs = g.getBoundingClientRect(), tiles = [...g.querySelectorAll(".tile")].map((t) => {
|
||||||
|
const r = t.getBoundingClientRect(), i = t.querySelector(".icon").getBoundingClientRect();
|
||||||
|
return { r, i, name: t.querySelector(".name").getBoundingClientRect(), font: parseFloat(getComputedStyle(t.querySelector(".name")).fontSize) };
|
||||||
|
});
|
||||||
|
return {
|
||||||
|
cols: getComputedStyle(g).gridTemplateColumns.split(" ").length,
|
||||||
|
row: parseFloat(getComputedStyle(g).gridTemplateRows.split(" ")[0]),
|
||||||
|
icon: tiles[0].i.width, font: tiles[0].font, gridLeft: gs.left, gridRight: gs.right,
|
||||||
|
tiles: tiles.map((t) => ({ l: t.r.left, r: t.r.right, t: t.r.top, b: t.r.bottom, il: t.i.left, ir: t.i.right, it: t.i.top, ib: t.i.bottom, nb: t.name.bottom })),
|
||||||
|
};
|
||||||
|
});
|
||||||
|
const noOverlapOrClip = (g, what) => {
|
||||||
|
for (const [n, a] of g.tiles.entries()) {
|
||||||
|
assert.ok(a.il >= a.l - 0.5 && a.ir <= a.r + 0.5, `${what}: icon ${n} inside its tile (x)`);
|
||||||
|
assert.ok(a.it >= a.t - 0.5 && a.nb <= a.b + 1, `${what}: icon and label ${n} inside its tile (y)`);
|
||||||
|
assert.ok(a.l >= g.gridLeft - 0.5 && a.r <= g.gridRight + 0.5, `${what}: tile ${n} inside the grid`);
|
||||||
|
for (const c of g.tiles.slice(n + 1)) {
|
||||||
|
assert.ok(a.r <= c.l + 0.5 || c.r <= a.l + 0.5 || a.b <= c.t + 0.5 || c.b <= a.t + 0.5, `${what}: tiles ${n} overlap`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
const base = await grid();
|
||||||
|
noOverlapOrClip(base, "100%");
|
||||||
|
assert.equal(base.icon, 40, "the default icon is today's 40px");
|
||||||
|
assert.equal(base.row, 64);
|
||||||
|
assert.equal(base.cols, 5);
|
||||||
|
await shot(p, "06-icon-size-before");
|
||||||
|
await longpress(".home", 0.95);
|
||||||
|
await p.click(".sheet-item >> text=Icon size"); await settle();
|
||||||
|
assert.equal(await p.$eval(".icon-size-slider", (e) => e.value), "100");
|
||||||
|
assert.equal((await p.textContent(".icon-size-value")).trim(), "100%");
|
||||||
|
const setSlider = async (v) => { await p.$eval(".icon-size-slider", (e, v) => { e.value = v; e.dispatchEvent(new Event("input", { bubbles: true })); }, v); await settle(); };
|
||||||
|
await setSlider("130");
|
||||||
|
const big = await grid();
|
||||||
|
noOverlapOrClip(big, "130%");
|
||||||
|
assert.equal(big.icon, 52, "icon 40 -> 52");
|
||||||
|
assert.equal(big.row, 83);
|
||||||
|
assert.equal(big.cols, 4, "fewer columns at a larger size");
|
||||||
|
assert.ok(big.font > base.font, "label text grows with the icon");
|
||||||
|
const pv = await p.$eval(".icon-preview .icon", (i) => i.getBoundingClientRect().width);
|
||||||
|
assert.equal(pv, 52, "the preview shows the size");
|
||||||
|
assert.equal((await p.textContent(".icon-size-value")).trim(), "130%");
|
||||||
|
await shot(p, "07-icon-size-large");
|
||||||
|
await p.click(".icon-presets >> text=Small"); await settle();
|
||||||
|
assert.equal(await p.$eval(".icon-size-slider", (e) => e.value), "80");
|
||||||
|
const small = await grid();
|
||||||
|
noOverlapOrClip(small, "80%");
|
||||||
|
assert.ok(small.icon < base.icon && small.cols > base.cols && small.row < base.row);
|
||||||
|
await setSlider("160");
|
||||||
|
noOverlapOrClip(await grid(), "160%");
|
||||||
|
await setSlider("70");
|
||||||
|
noOverlapOrClip(await grid(), "70%");
|
||||||
|
await shot(p, "08-icon-size-small");
|
||||||
|
await setSlider("130");
|
||||||
|
assert.equal(await p.evaluate(() => localStorage.getItem("launcher.iconSize")), "130");
|
||||||
|
await p.click(".sheet >> text=Done"); await settle();
|
||||||
|
// the drawer follows: bigger icons, fewer columns
|
||||||
|
await p.click(".search-pill"); await settle();
|
||||||
|
const dr = await p.$eval(".drawer .apps", (u) => ({
|
||||||
|
cols: getComputedStyle(u).gridTemplateColumns.split(" ").length,
|
||||||
|
icon: u.querySelector(".icon").getBoundingClientRect().width,
|
||||||
|
}));
|
||||||
|
assert.equal(dr.cols, 3, "drawer: 4 columns -> 3");
|
||||||
|
assert.ok(Math.abs(dr.icon - 67.6) < 0.1, `drawer icon 52px -> 67.6px: ${dr.icon}`);
|
||||||
|
await shot(p, "09-icon-size-drawer-large");
|
||||||
|
await p.click(".drawer-head >> text=Close"); await settle();
|
||||||
|
// saved: it survives a reload, and 100% is saved as 100
|
||||||
|
await p.reload(); await p.waitForSelector(".slots .tile");
|
||||||
|
const again = await grid();
|
||||||
|
assert.equal(again.icon, 52);
|
||||||
|
assert.equal(again.cols, 4);
|
||||||
|
await longpress(".home", 0.95);
|
||||||
|
await p.click(".sheet-item >> text=Icon size"); await settle();
|
||||||
|
await p.click(".icon-presets >> text=Medium"); await settle();
|
||||||
|
await p.click(".sheet >> text=Done"); await settle();
|
||||||
|
const back = await grid();
|
||||||
|
assert.equal(back.icon, 40); assert.equal(back.row, 64); assert.equal(back.cols, 5);
|
||||||
|
// a corrupt saved value is reported (alert and console), not silently replaced
|
||||||
|
const errors = [];
|
||||||
|
p.on("console", (m) => { if (m.type() === "error") errors.push(m.text()); });
|
||||||
|
await p.evaluate(() => localStorage.setItem("launcher.iconSize", "huge"));
|
||||||
|
await p.reload(); await p.waitForSelector(".slots .tile");
|
||||||
|
assert.ok(errors.some((e) => e.includes("saved icon size \"huge\" is not a whole number")), `logged: ${errors}`);
|
||||||
|
assert.ok((await p.textContent("#app")).includes("Icon size problem"), "a notice shows");
|
||||||
|
assert.equal(await p.evaluate(() => localStorage.getItem("launcher.iconSize")), "huge", "the bad value is left alone");
|
||||||
|
await longpress(".home", 0.95);
|
||||||
|
await p.click(".sheet-item >> text=Icon size"); await settle();
|
||||||
|
assert.ok(await p.$(".sheet .alert.destructive"), "the sheet shows the error");
|
||||||
|
await shot(p, "10-icon-size-corrupt");
|
||||||
|
await p.click(".icon-presets >> text=Medium"); await settle();
|
||||||
|
assert.equal(await p.evaluate(() => localStorage.getItem("launcher.iconSize")), "100", "choosing a size replaces it");
|
||||||
|
assert.ok(!(await p.$(".sheet .alert")), "and clears the error");
|
||||||
|
await p.click(".sheet >> text=Done"); await settle();
|
||||||
console.log("launcher ok");
|
console.log("launcher ok");
|
||||||
|
|
||||||
await b.close();
|
await b.close();
|
||||||
|
|||||||
@@ -133,6 +133,10 @@ extern "js" fn now_ms() -> Double =
|
|||||||
extern "js" fn storage_get(k : String) -> String =
|
extern "js" fn storage_get(k : String) -> String =
|
||||||
#|(k) => { try { return localStorage.getItem(k) ?? "" } catch { return "" } }
|
#|(k) => { try { return localStorage.getItem(k) ?? "" } catch { return "" } }
|
||||||
|
|
||||||
|
///|
|
||||||
|
extern "js" fn log_error(line : String) -> Unit =
|
||||||
|
#|(line) => console.error(line)
|
||||||
|
|
||||||
///|
|
///|
|
||||||
extern "js" fn storage_has(k : String) -> Bool =
|
extern "js" fn storage_has(k : String) -> Bool =
|
||||||
#|(k) => { try { return localStorage.getItem(k) !== null } catch { return false } }
|
#|(k) => { try { return localStorage.getItem(k) !== null } catch { return false } }
|
||||||
|
|||||||
+8
-1
@@ -170,6 +170,8 @@ fn exec(e : @app.Effect) -> Unit {
|
|||||||
dispatch(LimitsKnown(id, Some(json)))
|
dispatch(LimitsKnown(id, Some(json)))
|
||||||
}
|
}
|
||||||
SaveHome(json) => storage_set("launcher.home", json)
|
SaveHome(json) => storage_set("launcher.home", json)
|
||||||
|
SaveIconSize(pct) => storage_set("launcher.iconSize", pct.to_string())
|
||||||
|
LogError(line) => log_error(line)
|
||||||
SaveLastCheck(t) => storage_set("launcher.update.lastCheck", t.to_string())
|
SaveLastCheck(t) => storage_set("launcher.update.lastCheck", t.to_string())
|
||||||
Delay(ms, msg) => set_timeout(ms, fn() { dispatch(msg) })
|
Delay(ms, msg) => set_timeout(ms, fn() { dispatch(msg) })
|
||||||
HoldTimer(ms, token) => set_timeout(ms, fn() { feed(Hold(token)) })
|
HoldTimer(ms, token) => set_timeout(ms, fn() { feed(Hold(token)) })
|
||||||
@@ -518,7 +520,12 @@ fn main {
|
|||||||
None
|
None
|
||||||
}
|
}
|
||||||
let legacy = if saved is None { Some(storage_legacy()) } else { None }
|
let legacy = if saved is None { Some(storage_legacy()) } else { None }
|
||||||
dispatch(Restore(saved~, legacy~))
|
let icon_size = if storage_has("launcher.iconSize") {
|
||||||
|
Some(storage_get("launcher.iconSize"))
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
dispatch(Restore(saved~, legacy~, icon_size~))
|
||||||
if is_android() {
|
if is_android() {
|
||||||
// the shell keeps the build whose install the user cancelled (-1: none)
|
// the shell keeps the build whose install the user cancelled (-1: none)
|
||||||
let declined = h_declined_version()
|
let declined = h_declined_version()
|
||||||
|
|||||||
+20
-5
@@ -135,14 +135,19 @@ body { margin: 0; min-height: 100vh; color: #fff; -webkit-tap-highlight-color: t
|
|||||||
.tile { position: relative; display: flex; flex-direction: column; align-items: center; gap: .4rem;
|
.tile { position: relative; display: flex; flex-direction: column; align-items: center; gap: .4rem;
|
||||||
padding: .35rem .15rem; border-radius: calc(var(--radius) + 4px); cursor: pointer; }
|
padding: .35rem .15rem; border-radius: calc(var(--radius) + 4px); cursor: pointer; }
|
||||||
.tile:active { background: rgb(255 255 255 / .12); }
|
.tile:active { background: rgb(255 255 255 / .12); }
|
||||||
.icon { width: 3.25rem; height: 3.25rem; object-fit: contain; pointer-events: none;
|
/* --s is the icon size setting as a factor (1 = the original size); the model sets it on
|
||||||
|
the home grid, the drawer list and the sheet's preview, and picks the row height and
|
||||||
|
column count to match (app/view.mbt, grid/scale.mbt). */
|
||||||
|
.icon { width: calc(3.25rem * var(--s, 1)); height: calc(3.25rem * var(--s, 1)); object-fit: contain; pointer-events: none;
|
||||||
filter: drop-shadow(0 2px 4px rgb(0 0 0 / .3)); }
|
filter: drop-shadow(0 2px 4px rgb(0 0 0 / .3)); }
|
||||||
.icon.missing { border-radius: 999px; background: rgb(255 255 255 / .18); object-position: -999px 0; }
|
.icon.missing { border-radius: 999px; background: rgb(255 255 255 / .18); object-position: -999px 0; }
|
||||||
.name { max-width: 100%; font-size: .75rem; line-height: 1.2; text-align: center;
|
.name { max-width: 100%; font-size: calc(.75rem * var(--s, 1)); line-height: 1.2; text-align: center;
|
||||||
text-shadow: var(--shadow-text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
text-shadow: var(--shadow-text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
||||||
.slots .tile { gap: .25rem; padding: .2rem .1rem; }
|
.slots .tile, .icon-preview .tile { gap: calc(.25rem * var(--s, 1)); padding: calc(.2rem * var(--s, 1)) .1rem; }
|
||||||
.slots .icon { width: 2.5rem; height: 2.5rem; }
|
.slots .icon, .icon-preview .icon { width: calc(2.5rem * var(--s, 1)); height: calc(2.5rem * var(--s, 1)); }
|
||||||
.slots .name { font-size: .68rem; }
|
.slots .name, .icon-preview .name { font-size: calc(.68rem * var(--s, 1)); }
|
||||||
|
.drawer .apps { gap: calc(1.25rem * var(--s, 1)) .5rem; }
|
||||||
|
.drawer .tile { gap: calc(.4rem * var(--s, 1)); }
|
||||||
|
|
||||||
/* A widget takes whole rows. On a phone the native widget view covers the slot;
|
/* A widget takes whole rows. On a phone the native widget view covers the slot;
|
||||||
the label only shows while the slot is not live (or in a desktop browser). */
|
the label only shows while the slot is not live (or in a desktop browser). */
|
||||||
@@ -263,6 +268,16 @@ button { cursor: pointer; }
|
|||||||
background: none; color: inherit; font: inherit; text-align: left; cursor: pointer; }
|
background: none; color: inherit; font: inherit; text-align: left; cursor: pointer; }
|
||||||
.sheet-item:hover, .sheet-item:active { background: var(--accent); }
|
.sheet-item:hover, .sheet-item:active { background: var(--accent); }
|
||||||
.sheet .empty { text-shadow: none; color: var(--muted-foreground); }
|
.sheet .empty { text-shadow: none; color: var(--muted-foreground); }
|
||||||
|
/* ---- icon size sheet */
|
||||||
|
.icon-preview { list-style: none; margin: 0 0 1rem; padding: .75rem .5rem; display: flex; justify-content: space-around;
|
||||||
|
align-items: flex-start; min-height: 6rem; overflow: hidden; border-radius: var(--radius);
|
||||||
|
background: rgb(10 10 14 / .84); color: #fff; }
|
||||||
|
.icon-preview .tile { flex: 1 1 0; min-width: 0; cursor: default; }
|
||||||
|
.icon-size-row { display: flex; align-items: center; gap: .75rem; margin: 0 .5rem 1rem; }
|
||||||
|
.icon-size-slider { flex: 1; min-width: 0; height: 2rem; accent-color: var(--primary); touch-action: pan-y; }
|
||||||
|
.icon-size-value { min-width: 3.25rem; text-align: center; background: var(--secondary); }
|
||||||
|
.icon-presets { display: grid; grid-template-columns: repeat(3, 1fr); gap: .5rem; margin: 0 .25rem 1rem; }
|
||||||
|
.icon-error { margin: 0 .25rem 1rem; }
|
||||||
.widget-list { list-style: none; margin: 0; padding: 0; display: grid; }
|
.widget-list { list-style: none; margin: 0; padding: 0; display: grid; }
|
||||||
.widget-list li { display: flex; align-items: center; gap: .75rem; padding: .5rem; border-radius: var(--radius);
|
.widget-list li { display: flex; align-items: center; gap: .75rem; padding: .5rem; border-radius: var(--radius);
|
||||||
cursor: pointer; }
|
cursor: pointer; }
|
||||||
|
|||||||
Reference in new issue
Block a user