1 parent
dccbfd7d86
commit
17f81c60c8
20 files changed
+636
-447
No files matched your search
+53
-29
@@ -11,7 +11,7 @@ pub fn matches_query(label : String, query : String) -> Bool {
|
||||
}
|
||||
|
||||
///|
|
||||
pub fn Model::app_row(self : Model, component : String) -> Int {
|
||||
pub fn Model::app_row(self : Model, component : String) -> Int32 {
|
||||
for i in 0..<self.apps.length() {
|
||||
if self.apps[i].component == component {
|
||||
return i
|
||||
@@ -22,7 +22,7 @@ pub fn Model::app_row(self : Model, component : String) -> Int {
|
||||
|
||||
///|
|
||||
/// The home slot holding the app at `row` in the app list, or -1.
|
||||
pub fn Model::home_of(self : Model, row : Int) -> Int {
|
||||
pub fn Model::home_of(self : Model, row : Int32) -> Int32 {
|
||||
let comp = self.apps[row].component
|
||||
for i in 0..<self.home.length() {
|
||||
if self.home[i].kind == App && self.home[i].str == comp {
|
||||
@@ -33,7 +33,7 @@ pub fn Model::home_of(self : Model, row : Int) -> Int {
|
||||
}
|
||||
|
||||
///|
|
||||
pub fn Model::slot_of_widget(self : Model, wid : Int) -> Int {
|
||||
pub fn Model::slot_of_widget(self : Model, wid : Int32) -> Int32 {
|
||||
for i in 0..<self.home.length() {
|
||||
if self.home[i].kind == Widget && self.home[i].wid == wid {
|
||||
return i
|
||||
@@ -44,7 +44,7 @@ pub fn Model::slot_of_widget(self : Model, wid : Int) -> Int {
|
||||
|
||||
///|
|
||||
/// The first app (row in the list) whose label matches the search.
|
||||
pub fn Model::first_match(self : Model) -> Int {
|
||||
pub fn Model::first_match(self : Model) -> Int32 {
|
||||
for i in 0..<self.apps.length() {
|
||||
if matches_query(self.apps[i].label, self.query) {
|
||||
return i
|
||||
@@ -54,13 +54,16 @@ pub fn Model::first_match(self : Model) -> Int {
|
||||
}
|
||||
|
||||
///|
|
||||
pub fn Model::widget_matches(self : Model, i : Int) -> Bool {
|
||||
pub fn Model::widget_matches(self : Model, i : Int32) -> Bool {
|
||||
matches_query(self.widgets[i].label, self.wquery) ||
|
||||
matches_query(self.widgets[i].app, self.wquery) && trimmed(self.wquery) != ""
|
||||
(
|
||||
matches_query(self.widgets[i].app, self.wquery) &&
|
||||
trimmed(self.wquery) != ""
|
||||
)
|
||||
}
|
||||
|
||||
///|
|
||||
pub fn Model::first_widget_match(self : Model) -> Int {
|
||||
pub fn Model::first_widget_match(self : Model) -> Int32 {
|
||||
for i in 0..<self.widgets.length() {
|
||||
if self.widget_matches(i) {
|
||||
return i
|
||||
@@ -71,7 +74,7 @@ pub fn Model::first_widget_match(self : Model) -> Int {
|
||||
|
||||
///|
|
||||
/// Home slots that are not drawn: apps that are not installed.
|
||||
pub fn Model::hidden(self : Model, i : Int) -> Bool {
|
||||
pub fn Model::hidden(self : Model, i : Int32) -> Bool {
|
||||
self.home[i].kind == App && self.app_row(self.home[i].str) < 0
|
||||
}
|
||||
|
||||
@@ -93,14 +96,14 @@ fn Model::push_slot(self : Model, s : @grid.Slot) -> Unit {
|
||||
}
|
||||
|
||||
///|
|
||||
fn Model::new_key(self : Model) -> Int {
|
||||
fn Model::new_key(self : Model) -> Int32 {
|
||||
let k = self.next_key
|
||||
self.next_key += 1
|
||||
k
|
||||
}
|
||||
|
||||
///|
|
||||
fn Model::remove_slot(self : Model, at : Int, fx : Array[Effect]) -> Unit {
|
||||
fn Model::remove_slot(self : Model, at : Int32, fx : Array[Effect]) -> Unit {
|
||||
if at < 0 || at >= self.home.length() {
|
||||
return
|
||||
}
|
||||
@@ -121,13 +124,15 @@ fn Model::remove_slot(self : Model, at : Int, fx : Array[Effect]) -> Unit {
|
||||
}
|
||||
|
||||
///|
|
||||
fn Model::add_app(self : Model, row : Int, fx : Array[Effect]) -> Unit {
|
||||
fn Model::add_app(self : Model, row : Int32, fx : Array[Effect]) -> Unit {
|
||||
if self.home_of(row) >= 0 {
|
||||
self.say("Already on the home screen", fx)
|
||||
} else if self.home.length() >= home_cap {
|
||||
self.say("The home screen is full", fx)
|
||||
} else {
|
||||
self.push_slot(@grid.Slot::app(self.apps[row].component, key=self.new_key()))
|
||||
self.push_slot(
|
||||
@grid.Slot::app(self.apps[row].component, key=self.new_key()),
|
||||
)
|
||||
self.say("Added to home", fx)
|
||||
}
|
||||
}
|
||||
@@ -191,7 +196,7 @@ fn Model::close_drawer(self : Model, fx : Array[Effect]) -> Unit {
|
||||
fn Model::slot_box(
|
||||
self : Model,
|
||||
packed : @grid.Packed,
|
||||
i : Int,
|
||||
i : Int32,
|
||||
) -> (Double, Double, Double, Double)? {
|
||||
match packed.cells[i] {
|
||||
Some(c) => {
|
||||
@@ -209,7 +214,12 @@ fn inside(b : (Double, Double, Double, Double), x : Double, y : Double) -> Bool
|
||||
|
||||
///|
|
||||
/// The slot (not the lifted one) under a point, or -1.
|
||||
fn Model::slot_at(self : Model, packed : @grid.Packed, x : Double, y : Double) -> Int {
|
||||
fn Model::slot_at(
|
||||
self : Model,
|
||||
packed : @grid.Packed,
|
||||
x : Double,
|
||||
y : Double,
|
||||
) -> Int32 {
|
||||
for i in 0..<self.home.length() {
|
||||
if i == self.lifted {
|
||||
continue
|
||||
@@ -244,15 +254,13 @@ fn Model::drag_lifted(
|
||||
Some(b) => (b.0, b.1)
|
||||
None => (x0, y0)
|
||||
}
|
||||
let c = { dx: x0 - bx, dy: y0 - by, cell: -1 }
|
||||
let c = { dx: x0 - bx, dy: y0 - by, cell: -1, }
|
||||
self.carry = Some(c)
|
||||
c
|
||||
}
|
||||
}
|
||||
let widget = lifted.kind == Widget
|
||||
if !widget &&
|
||||
self.slot_box(packed, self.lifted) is Some(b) &&
|
||||
inside(b, x, y) {
|
||||
if !widget && self.slot_box(packed, self.lifted) is Some(b) && inside(b, x, y) {
|
||||
return
|
||||
}
|
||||
let half_w = self.col_w / 2.0
|
||||
@@ -264,7 +272,9 @@ fn Model::drag_lifted(
|
||||
)
|
||||
let mut to = self.slot_at(packed, x, y)
|
||||
if to < 0 {
|
||||
let cx = self.grid_left + fc.to_double() * (self.col_w + @grid.col_gap.to_double()) + half_w
|
||||
let cx = self.grid_left +
|
||||
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() +
|
||||
half_h
|
||||
@@ -331,7 +341,14 @@ fn Model::begin_resize(self : Model, edge : Edge, fx : Array[Effect]) -> Unit {
|
||||
Some(b) => (b.0, b.1)
|
||||
None => (self.grid_left, self.grid_top)
|
||||
}
|
||||
self.resize = Some({ edge, slot: i, left, top, cols: s.cols(self.cols), rows: s.height() })
|
||||
self.resize = Some({
|
||||
edge,
|
||||
slot: i,
|
||||
left,
|
||||
top,
|
||||
cols: s.cols(self.cols),
|
||||
rows: s.height(),
|
||||
})
|
||||
fx.push(QueryLimits(s.wid))
|
||||
}
|
||||
|
||||
@@ -405,7 +422,7 @@ pub fn update(m : Model, msg : Msg) -> Array[Effect] {
|
||||
}
|
||||
|
||||
///|
|
||||
fn Model::choose_widget(self : Model, i : Int, fx : Array[Effect]) -> Unit {
|
||||
fn Model::choose_widget(self : Model, i : Int32, fx : Array[Effect]) -> Unit {
|
||||
if i >= 0 && i < self.widgets.length() {
|
||||
if self.home.length() < home_cap {
|
||||
self.chosen = i
|
||||
@@ -508,7 +525,9 @@ fn step(m : Model, msg : Msg, fx : Array[Effect]) -> Unit {
|
||||
fx.push(HideKeyboard)
|
||||
}
|
||||
WidgetAdded(id) =>
|
||||
if m.chosen >= 0 && m.chosen < m.widgets.length() && m.home.length() < home_cap {
|
||||
if m.chosen >= 0 &&
|
||||
m.chosen < m.widgets.length() &&
|
||||
m.home.length() < home_cap {
|
||||
let w = m.widgets[m.chosen]
|
||||
m.push_slot(
|
||||
@grid.Slot::widget(
|
||||
@@ -566,7 +585,7 @@ fn step(m : Model, msg : Msg, fx : Array[Effect]) -> Unit {
|
||||
ReleaseFetched(text) => {
|
||||
let release = text.bind(@updater.parse_release)
|
||||
match release {
|
||||
Some({ version_url: Some(v), apk_url: Some(a), tag }) => {
|
||||
Some({ version_url: Some(v), apk_url: Some(a), tag, }) => {
|
||||
m.apk_url = Some(a)
|
||||
m.release_tag = tag
|
||||
fx.push(FetchVersion(v))
|
||||
@@ -588,7 +607,12 @@ fn step(m : Model, msg : Msg, fx : Array[Effect]) -> Unit {
|
||||
match (latest, m.apk_url) {
|
||||
(Some(latest), Some(url)) =>
|
||||
match
|
||||
@updater.decide(latest, m.installed, m.declined, manual=m.manual_check) {
|
||||
@updater.decide(
|
||||
latest,
|
||||
m.installed,
|
||||
m.declined,
|
||||
manual=m.manual_check,
|
||||
) {
|
||||
UpToDate(n) =>
|
||||
if m.manual_check {
|
||||
m.say("ultra Home is up to date (build \{n})", fx)
|
||||
@@ -599,10 +623,7 @@ fn step(m : Model, msg : Msg, fx : Array[Effect]) -> Unit {
|
||||
fx.push(InstallApk(url, n))
|
||||
}
|
||||
}
|
||||
_ =>
|
||||
if m.manual_check {
|
||||
m.say("Couldn't check for updates", fx)
|
||||
}
|
||||
_ => if m.manual_check { m.say("Couldn't check for updates", fx) }
|
||||
}
|
||||
}
|
||||
NoticeDone(gen) => if gen == m.notice_gen { m.notice = "" }
|
||||
@@ -757,7 +778,10 @@ pub fn input(
|
||||
inp : @gesture.Input,
|
||||
) -> Array[Effect] {
|
||||
let fx : Array[Effect] = []
|
||||
fn nearest(chain : Array[Int], pick : (@vdom.Handlers[Msg]) -> Msg?) -> Msg? {
|
||||
fn nearest(
|
||||
chain : Array[Int32],
|
||||
pick : (@vdom.Handlers[Msg]) -> Msg?,
|
||||
) -> Msg? {
|
||||
for id in chain {
|
||||
if id >= 0 && id < table.length() {
|
||||
if pick(table[id]) is Some(msg) {
|
||||
|
||||
Reference in new issue
Block a user