mirror of
https://github.com/hulthe/inkopslista.git
synced 2026-08-03 23:11:28 +02:00
Rename crate folders
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
[target.x86_64-pc-windows-msvc]
|
||||
# Increase default stack size to avoid running out of stack
|
||||
# space in debug builds. The size matches Linux's default.
|
||||
rustflags = [
|
||||
"-C", "link-arg=/STACK:8000000"
|
||||
]
|
||||
|
||||
[target.aarch64-pc-windows-msvc]
|
||||
# Increase default stack size to avoid running out of stack
|
||||
# space in debug builds. The size matches Linux's default.
|
||||
rustflags = [
|
||||
"-C", "link-arg=/STACK:8000000"
|
||||
]
|
||||
@@ -0,0 +1,21 @@
|
||||
[package]
|
||||
name = "inkopslista"
|
||||
version = "0.0.0"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
reqwest = { version = "0.12.26", features = ["json", "rustls-tls"], default-features = false }
|
||||
inkopslista-lib = { path = "../lib" }
|
||||
tokio = { version = "1.48.0", features = ["full"] }
|
||||
serde = { version = "1.0.228", features = ["derive"] }
|
||||
xdg = "3.0.0"
|
||||
serde_json = "1.0.148"
|
||||
anyhow = "1.0.100"
|
||||
|
||||
[dependencies.slint]
|
||||
version = "1.14.1"
|
||||
default-features = false
|
||||
features = ["live-preview", "backend-winit-wayland", "renderer-femtovg", "compat-1-2"]
|
||||
|
||||
[build-dependencies]
|
||||
slint-build = "1.14.1"
|
||||
@@ -0,0 +1,4 @@
|
||||
fn main() {
|
||||
let config = slint_build::CompilerConfiguration::new().with_style("cosmic-dark".into());
|
||||
slint_build::compile_with_config("ui/app.slint", config).expect("Slint build failed");
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
buliddir
|
||||
repo
|
||||
inköpslista
|
||||
@@ -0,0 +1,14 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -ex
|
||||
|
||||
cd "$(dirname 0)"
|
||||
CARGO_TARGET_DIR="${CARGO_TARGET_DIR:-../../target}"
|
||||
|
||||
# TODO: cross compilation with cross --target=aarch64-unknown-linux-gnu
|
||||
cargo b -r
|
||||
|
||||
cp "$CARGO_TARGET_DIR/release/inkopslista" inköpslista
|
||||
|
||||
# TODO: cross compilation with --arch=aarch64
|
||||
flatpak-builder -v --force-clean --user --install-deps-from=flathub --repo=repo --install builddir sh.nubo.Inkopslista.yml
|
||||
@@ -0,0 +1,9 @@
|
||||
[Desktop Entry]
|
||||
Name=Inköpslista
|
||||
Exec=inköpslista %U
|
||||
Terminal=false
|
||||
Type=Application
|
||||
Icon=sh.nubo.Inkopslista
|
||||
StartupWMClass=Inköpslista
|
||||
# Comment=
|
||||
# Categories=Network;
|
||||
@@ -0,0 +1,53 @@
|
||||
id: sh.nubo.Inkopslista
|
||||
runtime: org.freedesktop.Platform
|
||||
runtime-version: '25.08'
|
||||
sdk: org.freedesktop.Sdk
|
||||
|
||||
command: 'inköpslista'
|
||||
|
||||
modules:
|
||||
- name: inköpslista
|
||||
buildsystem: simple
|
||||
sources:
|
||||
# - type: script
|
||||
# dest-filename: gui
|
||||
# commands:
|
||||
# - echo "hello there"
|
||||
- type: file
|
||||
path: ./sh.nubo.Inkopslista.desktop
|
||||
- type: file
|
||||
path: ./inköpslista
|
||||
- type: file
|
||||
path: ../images/icon.svg
|
||||
- type: file
|
||||
path: ../images/icon_x512.png
|
||||
- type: file
|
||||
path: ../images/icon_x192.png
|
||||
- type: file
|
||||
path: ../images/icon_x144.png
|
||||
- type: file
|
||||
path: ../images/icon_x128.png
|
||||
- type: file
|
||||
path: ../images/icon_x72.png
|
||||
build-commands:
|
||||
- install -Dm755 inköpslista $FLATPAK_DEST/bin/inköpslista
|
||||
- install -Dm644 sh.nubo.Inkopslista.desktop $FLATPAK_DEST/share/applications/sh.nubo.Inkopslista.desktop
|
||||
|
||||
- install -Dm644 icon.svg $FLATPAK_DEST/share/icons/hicolor/scalable/apps/sh.nubo.Inkopslista.svg
|
||||
- install -Dm644 icon_x512.png $FLATPAK_DEST/share/icons/hicolor/512x512/apps/sh.nubo.Inkopslista.png
|
||||
- install -Dm644 icon_x192.png $FLATPAK_DEST/share/icons/hicolor/192x192/apps/sh.nubo.Inkopslista.png
|
||||
- install -Dm644 icon_x144.png $FLATPAK_DEST/share/icons/hicolor/144x144/apps/sh.nubo.Inkopslista.png
|
||||
- install -Dm644 icon_x128.png $FLATPAK_DEST/share/icons/hicolor/128x128/apps/sh.nubo.Inkopslista.png
|
||||
- install -Dm644 icon_x72.png $FLATPAK_DEST/share/icons/hicolor/72x72/apps/sh.nubo.Inkopslista.png
|
||||
|
||||
finish-args:
|
||||
# Wayland access
|
||||
- --socket=wayland
|
||||
# GPU acceleration if needed
|
||||
- --device=dri
|
||||
# Needs to talk to the network:
|
||||
- --share=network
|
||||
# Needs to save files locally
|
||||
- --filesystem=xdg-documents
|
||||
|
||||
|
||||
@@ -0,0 +1,78 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<svg
|
||||
width="160"
|
||||
height="160"
|
||||
viewBox="0 0 42.333333 42.333333"
|
||||
version="1.1"
|
||||
id="svg8"
|
||||
sodipodi:docname="icon.svg"
|
||||
inkscape:version="1.4.2 (ebf0e940d0, 2025-05-08)"
|
||||
inkscape:export-filename="icon_x512.png"
|
||||
inkscape:export-xdpi="307.20001"
|
||||
inkscape:export-ydpi="307.20001"
|
||||
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
|
||||
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
xmlns:svg="http://www.w3.org/2000/svg"
|
||||
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
|
||||
xmlns:cc="http://creativecommons.org/ns#"
|
||||
xmlns:dc="http://purl.org/dc/elements/1.1/">
|
||||
<sodipodi:namedview
|
||||
id="namedview1"
|
||||
pagecolor="#505050"
|
||||
bordercolor="#eeeeee"
|
||||
borderopacity="1"
|
||||
inkscape:showpageshadow="0"
|
||||
inkscape:pageopacity="0"
|
||||
inkscape:pagecheckerboard="0"
|
||||
inkscape:deskcolor="#505050"
|
||||
inkscape:zoom="2.0122589"
|
||||
inkscape:cx="-12.920802"
|
||||
inkscape:cy="57.895133"
|
||||
inkscape:window-width="1530"
|
||||
inkscape:window-height="980"
|
||||
inkscape:window-x="0"
|
||||
inkscape:window-y="0"
|
||||
inkscape:window-maximized="1"
|
||||
inkscape:current-layer="svg8" />
|
||||
<defs
|
||||
id="defs2" />
|
||||
<metadata
|
||||
id="metadata5">
|
||||
<rdf:RDF>
|
||||
<cc:Work
|
||||
rdf:about="">
|
||||
<dc:format>image/svg+xml</dc:format>
|
||||
<dc:type
|
||||
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
|
||||
</cc:Work>
|
||||
</rdf:RDF>
|
||||
</metadata>
|
||||
<rect
|
||||
style="fill:#302f3b;fill-opacity:1;stroke:none;stroke-width:13.5876;stroke-linecap:round"
|
||||
id="rect1"
|
||||
width="42.333332"
|
||||
height="42.333332"
|
||||
x="0"
|
||||
y="0"
|
||||
ry="14.986836" />
|
||||
<g
|
||||
id="layer1"
|
||||
style="display:inline;fill:#ffffff"
|
||||
transform="translate(5.2916666,4.9872409)">
|
||||
<path
|
||||
style="fill:#ffffff;stroke-width:0.177246"
|
||||
d="m 13.134179,31.651166 c -1.367874,-0.18043 -3.4872278,-0.85238 -4.780367,-1.51563 -1.871747,-0.96002 -4.179215,-3.22966 -5.0074297,-4.92534 -1.5914865,-3.25839 -1.6801158,-7.72336 -0.2278948,-11.48085 1.0247424,-2.65144 2.7098602,-4.5706201 5.4768881,-6.2376401 4.4640374,-2.6894 6.9208324,-4.59636 8.5218534,-6.61464 0.435944,-0.54955 0.851411,-0.9404 0.923263,-0.86855 0.34663,0.34663 0.709996,2.45556 0.596276,3.46071 l -0.118698,1.04918 0.543199,-0.3868 c 0.298763,-0.21273 0.754695,-0.66407 1.013185,-1.00297 0.258491,-0.3389 0.531184,-0.55268 0.605988,-0.47507 0.277608,0.28804 0.872923,2.3693 0.872923,3.05181 0,0.78189 -0.07309,0.70941 2.140938,2.12277 3.360595,2.14527 5.28622,5.2741001 5.845846,9.4985401 0.238089,1.79727 0.119928,4.12317 -0.289284,5.69424 -0.438918,1.68512 -1.295306,3.20011 -2.596637,4.59356 -2.715779,2.90803 -6.119638,4.1954 -10.928887,4.13338 -1.132683,-0.0146 -2.298705,-0.0581 -2.591161,-0.0967 z m 5.683631,-1.1265 c 5.074026,-0.89873 8.492767,-3.70496 9.49005,-7.7898 0.358508,-1.46844 0.317005,-5.28368 -0.07569,-6.95754 -0.594746,-2.53514 -2.005266,-4.78931 -3.64922,-5.8318801 -1.428352,-0.90583 -1.561881,-0.82384 -2.840659,1.7442101 -0.615739,1.23654 -1.777129,3.21756 -2.580868,4.40229 l -1.461342,2.15404 0.927607,0.3153 c 1.188141,0.40386 2.476979,1.20634 2.848748,1.77373 0.272049,0.4152 0.269021,0.4806 -0.04735,1.02231 -0.778356,1.33273 -2.272203,1.79512 -5.849412,1.81056 l -2.340153,0.0101 -2.489801,2.46697 c -2.6276133,2.60352 -2.8788341,3.03045 -2.0880964,3.54856 1.8126654,1.18771 7.0732674,1.8772 10.1561944,1.33115 z m 3.183004,-13.17071 c -0.205126,-0.14999 -0.329285,-0.4602 -0.329285,-0.8227 0,-0.96498 1.087198,-1.43355 1.715448,-0.73934 0.872429,0.96402 -0.338235,2.3283 -1.386163,1.56204 z m -3.186586,4.78402 c 1.133944,-0.30198 1.619925,-0.56299 1.85054,-0.9939 0.246861,-0.46126 -0.269147,-0.94676 -1.770094,-1.66543 -1.062457,-0.50872 -1.296906,-0.55176 -3.013183,-0.55311 -1.794444,-0.001 -1.910137,0.0225 -3.231141,0.66815 -1.860639,0.90936 -2.118197,1.48499 -0.948717,2.12031 1.182601,0.64245 5.357705,0.89133 7.112595,0.42398 z m -5.26747,-0.96936 c -1.113796,-0.13246 -1.303724,-0.23853 -1.149022,-0.64168 0.08921,-0.23246 0.582443,-0.27351 3.286452,-0.27351 1.749822,0 3.307658,0.0484 3.461858,0.10758 0.350902,0.13466 0.365077,0.53097 0.02367,0.66198 -0.432127,0.16582 -4.555272,0.2726 -5.622968,0.14563 z m -3.7845902,-3.81466 c 0.7343882,-0.537 0.2478022,-1.88618 -0.6802563,-1.88618 -0.5030742,0 -0.9992445,0.51278 -0.9992445,1.03268 0,0.90987 0.9453857,1.39029 1.6795008,0.8535 z"
|
||||
id="path865" />
|
||||
<path
|
||||
style="fill:#ffffff;fill-opacity:1;stroke:#000000;stroke-width:0;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
|
||||
d="m 7.5967544,-6.2400058 c 0,0 -0.041418,0.1031026 -0.02862,0.2093299 0.012798,0.1062273 0.084435,0.1741091 0.084435,0.1741091 l -0.083147,0.088222 c 0,0 -0.1053512,-0.138166 -0.073877,-0.2774823 0.031474,-0.1393166 0.1012092,-0.1941783 0.101209,-0.1941787 z"
|
||||
id="path1039" />
|
||||
</g>
|
||||
<g
|
||||
id="layer2"
|
||||
style="display:none" />
|
||||
<g
|
||||
id="layer3"
|
||||
style="display:none" />
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 5.0 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 6.3 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 7.1 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 9.8 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 28 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 3.5 KiB |
@@ -0,0 +1,52 @@
|
||||
use anyhow::{Context, Ok};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde_json;
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
|
||||
pub struct Config {
|
||||
pub address: String,
|
||||
}
|
||||
|
||||
impl Default for Config {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
address: "http://localhost:8000".to_string(),
|
||||
}
|
||||
}
|
||||
}
|
||||
const CONFIG_FILE_NAME: &'static str = "config.json";
|
||||
const XDG_PREFIX: &'static str = "inköpslista";
|
||||
|
||||
pub fn save_config(address: String) -> Result<(), anyhow::Error> {
|
||||
let xdg_dirs = xdg::BaseDirectories::with_prefix(XDG_PREFIX);
|
||||
let conf = Config { address: address };
|
||||
let conf = serde_json::to_string(&conf).context("unable to serialize config")?;
|
||||
|
||||
let path = xdg_dirs
|
||||
.place_config_file(CONFIG_FILE_NAME)
|
||||
.context("unable to create config directory")?;
|
||||
|
||||
tokio::spawn(async {
|
||||
let res = tokio::fs::write(path, conf)
|
||||
.await
|
||||
.context("unable to write config file");
|
||||
if let Err(err) = res {
|
||||
eprintln!("{err:?}");
|
||||
}
|
||||
});
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn get_config() -> Result<Config, anyhow::Error> {
|
||||
let xdg_dirs = xdg::BaseDirectories::with_prefix(XDG_PREFIX);
|
||||
let file = xdg_dirs
|
||||
.get_config_file(CONFIG_FILE_NAME)
|
||||
.context("no config file")?;
|
||||
let content = tokio::fs::read_to_string(file)
|
||||
.await
|
||||
.context("failed to read config file")?;
|
||||
|
||||
let conf: Config = serde_json::from_str(&content).context("Unable to deserealize contect")?;
|
||||
Ok(conf)
|
||||
}
|
||||
+176
@@ -0,0 +1,176 @@
|
||||
// Prevent console window in addition to Slint window in Windows release builds when, e.g., starting the app via file manager. Ignored on other platforms.
|
||||
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
|
||||
mod config;
|
||||
use std::{
|
||||
rc::Rc,
|
||||
sync::{Arc, Mutex},
|
||||
};
|
||||
|
||||
use inkopslista_lib::{Item, ItemData};
|
||||
use reqwest::Url;
|
||||
use slint::{Model, ModelRc, ToSharedString, VecModel};
|
||||
|
||||
use crate::config::{Config, get_config, save_config};
|
||||
|
||||
slint::include_modules!();
|
||||
|
||||
// TODO: use anyhow
|
||||
type MagicAnyError = anyhow::Error;
|
||||
|
||||
/// GET "/api/list" from the server
|
||||
async fn get_list(conf: &Mutex<Config>) -> Result<Vec<Item>, MagicAnyError> {
|
||||
// TODO: don't hardcode url
|
||||
let base = Url::parse(&conf.lock().unwrap().address)?;
|
||||
let url = base.join("/api/list")?;
|
||||
let list = reqwest::get(url).await?.json::<Vec<Item>>().await?;
|
||||
Ok(list)
|
||||
}
|
||||
|
||||
/// Add or update an item in the list
|
||||
async fn put_list(item: &str, data: &ItemData, conf: &Mutex<Config>) -> Result<(), MagicAnyError> {
|
||||
let client = reqwest::Client::new();
|
||||
let base = Url::parse(&conf.lock().unwrap().address)?.join("/api/list/")?;
|
||||
let url = base.join(item)?;
|
||||
let _response = client
|
||||
.put(url)
|
||||
.json(data)
|
||||
.send()
|
||||
.await?
|
||||
.error_for_status()?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn delete_item(item: &str, conf: &Mutex<Config>) -> Result<(), MagicAnyError> {
|
||||
let client = reqwest::Client::new();
|
||||
let base = Url::parse(&conf.lock().unwrap().address)?.join("/api/list/")?;
|
||||
let url = base.join(item)?;
|
||||
let _response = client.delete(url).send().await?.error_for_status()?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Convert shopping list to slint types
|
||||
fn update_slint_list(new_list: Vec<Item>, list: &VecModel<SItem>) {
|
||||
list.clear();
|
||||
new_list
|
||||
.iter()
|
||||
.map(|item| SItem {
|
||||
name: item.name.to_shared_string(),
|
||||
checked: item.data.checked,
|
||||
})
|
||||
.for_each(|item| list.push(item));
|
||||
}
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> Result<(), MagicAnyError> {
|
||||
let ui = App::new()?;
|
||||
let state = ui.global::<State>();
|
||||
let list = Rc::new(VecModel::default());
|
||||
state.set_list(ModelRc::new(list.clone()));
|
||||
let conf = get_config()
|
||||
.await
|
||||
.inspect_err(|err| eprintln!("{err:?}"))
|
||||
.unwrap_or_default();
|
||||
state.set_server_address(conf.address.to_shared_string());
|
||||
let conf = Arc::new(Mutex::new(conf));
|
||||
// HACK: load shopping list from server on start
|
||||
|
||||
let conf2 = conf.clone();
|
||||
match get_list(&conf2).await {
|
||||
Ok(new_list) => update_slint_list(new_list, &list),
|
||||
Err(e) => {
|
||||
eprintln!("{e:?}");
|
||||
}
|
||||
}
|
||||
let list2 = list.clone();
|
||||
let conf2 = conf.clone();
|
||||
state.on_add_to_list(move |item| {
|
||||
if list2.iter().any(|item2| item2.name == item) {
|
||||
return;
|
||||
// TODO: implement increment when number is added
|
||||
}
|
||||
list2.push(SItem {
|
||||
checked: false,
|
||||
name: item.clone(),
|
||||
});
|
||||
let conf2 = conf2.clone();
|
||||
tokio::spawn(async move {
|
||||
// TODO: add number to increment
|
||||
let res = put_list(&item, &ItemData { checked: false }, &conf2).await;
|
||||
if let Err(err) = res {
|
||||
eprintln!("{err:?}");
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
let conf2 = conf.clone();
|
||||
let list2 = list.clone();
|
||||
state.on_check_item(move |item| {
|
||||
let positem = list2
|
||||
.iter()
|
||||
.enumerate()
|
||||
.find(|(_, item2)| item2.name == item);
|
||||
let (pos, mut item) = match positem {
|
||||
Some(positem) => positem,
|
||||
None => return,
|
||||
};
|
||||
item.checked = !item.checked;
|
||||
list2.set_row_data(pos, item.clone());
|
||||
let conf2 = conf2.clone();
|
||||
|
||||
tokio::spawn(async move {
|
||||
let res = put_list(
|
||||
&item.name,
|
||||
&ItemData {
|
||||
checked: item.checked,
|
||||
},
|
||||
&conf2,
|
||||
)
|
||||
.await;
|
||||
if let Err(err) = res {
|
||||
eprintln!("{err:?}");
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
let conf2 = conf.clone();
|
||||
let list2 = list.clone();
|
||||
state.on_delete_checked(move || {
|
||||
let poss: Vec<_> = list2
|
||||
.iter()
|
||||
.enumerate()
|
||||
.filter(|(_, item)| item.checked)
|
||||
.map(|(pos, item)| (pos, item.name))
|
||||
.collect();
|
||||
for &(pos, _) in poss.iter().rev() {
|
||||
list2.remove(pos);
|
||||
}
|
||||
|
||||
let conf2 = conf2.clone();
|
||||
|
||||
tokio::spawn(async move {
|
||||
for (_, name) in poss {
|
||||
let res = delete_item(&name, &conf2).await;
|
||||
if let Err(err) = res {
|
||||
eprintln!("{err:?}");
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
state.on_set_server_address(move |address| {
|
||||
let _ = save_config(address.to_string());
|
||||
conf.lock().unwrap().address = address.to_string();
|
||||
|
||||
// create type for config file ✅
|
||||
// derives serde ✅
|
||||
// add library that gives us folder to save file in xdg typ ✅
|
||||
// write funciton that uses library to save file to folder place_config_file() ✅
|
||||
// call function on callback through tokio
|
||||
// write function to load file get_config_file(path) finns i xdg ✅
|
||||
// call function on start ✅
|
||||
// use config on get put delete server stuffs. (instead of the static string) ✅
|
||||
});
|
||||
|
||||
ui.run()?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
@@ -0,0 +1,151 @@
|
||||
import {
|
||||
TabWidget,
|
||||
AboutSlint,
|
||||
Button,
|
||||
VerticalBox,
|
||||
ListView,
|
||||
CheckBox,
|
||||
ScrollView,
|
||||
HorizontalBox,
|
||||
TextEdit,
|
||||
GridBox,
|
||||
} from "std-widgets.slint";
|
||||
import { SettingsView } from "settings.slint";
|
||||
import { State, SItem } from "state.slint";
|
||||
export { State, SItem }
|
||||
|
||||
|
||||
component GoodListItem inherits Rectangle {
|
||||
in-out property <SItem> item;
|
||||
background: #ffffff10;
|
||||
border-radius: 8pt;
|
||||
border-width: 10pt;
|
||||
HorizontalBox {
|
||||
check := CheckBox {
|
||||
checked: root.item.checked;
|
||||
toggled() => {
|
||||
State.check-item(item.name);
|
||||
debug("CheckBox checked: ", self.checked);
|
||||
}
|
||||
}
|
||||
|
||||
Text {
|
||||
opacity: (root.item.checked ? 0.5 : 1.0);
|
||||
font-size: 12pt;
|
||||
text: root.item.name;
|
||||
}
|
||||
}
|
||||
|
||||
input := TouchArea {
|
||||
clicked => {
|
||||
//root.item.checked = !root.item.checked;
|
||||
State.check-item(item.name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
component GoodsList {
|
||||
in property <[SItem]> items;
|
||||
|
||||
ListView {
|
||||
for item in items: VerticalLayout {
|
||||
GoodListItem {
|
||||
item: item;
|
||||
}
|
||||
|
||||
Rectangle {
|
||||
height: 4pt;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
component GoodButtons inherits ScrollView {
|
||||
in property <[string]> favorites: ["Mjölk", "Ost", "Ägg", "Bullens", "Oboy", "Mjöl", "Havregryn", "KrosTom"];
|
||||
in property <int> button-width: 100;
|
||||
in property <int> button-height: 60;
|
||||
in property <int> button-spacing: 10;
|
||||
|
||||
property <int> count-x: floor(root.width / 1pt / (button-width + button-spacing));
|
||||
property <int> count-y: ceil(favorites.length / count-x);
|
||||
|
||||
viewport-height: (count-y * (button-height + button-spacing)) * 1pt;
|
||||
|
||||
for item[idx] in favorites: Button {
|
||||
x: floor(mod(idx, count-x)) * (root.button-width + root.button-spacing) * 1pt;
|
||||
y: floor(idx / count-x) * (root.button-height + root.button-spacing) * 1pt;
|
||||
width: root.button-width * 1pt;
|
||||
height: root.button-height * 1pt;
|
||||
text: item;
|
||||
clicked => {
|
||||
State.add-to-list(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
component AddView inherits VerticalBox {
|
||||
in property <[SItem]> list;
|
||||
goods := GoodsList {
|
||||
items <=> list;
|
||||
}
|
||||
|
||||
HorizontalLayout {
|
||||
height: 50pt;
|
||||
input := TextEdit { }
|
||||
|
||||
Rectangle {
|
||||
width: 4pt; // spacing
|
||||
}
|
||||
|
||||
Button {
|
||||
width: self.height;
|
||||
text: "+";
|
||||
clicked => {
|
||||
State.add-to-list(input.text);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
GoodButtons { }
|
||||
}
|
||||
|
||||
component ShopView inherits VerticalBox {
|
||||
in property <[SItem]> list;
|
||||
|
||||
goods := GoodsList {
|
||||
items <=> list;
|
||||
}
|
||||
|
||||
Button {
|
||||
text: "I am done hehe";
|
||||
clicked => {
|
||||
State.delete-checked();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export component App inherits Window {
|
||||
|
||||
preferred-height: 700px;
|
||||
preferred-width: 480px;
|
||||
TabWidget {
|
||||
Tab {
|
||||
title: "Add";
|
||||
AddView {
|
||||
list <=> State.list;
|
||||
}
|
||||
}
|
||||
|
||||
Tab {
|
||||
title: "Shop";
|
||||
ShopView {
|
||||
list <=> State.list;
|
||||
}
|
||||
}
|
||||
|
||||
Tab {
|
||||
title: "Settings";
|
||||
SettingsView { }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
import { VerticalBox, LineEdit } from "std-widgets.slint";
|
||||
import { State } from "state.slint";
|
||||
|
||||
export component SettingsView inherits VerticalBox {
|
||||
alignment: start;
|
||||
Text {
|
||||
text: "server address:";
|
||||
font-size: 25px;
|
||||
}
|
||||
|
||||
LineEdit {
|
||||
edited(text) => {
|
||||
State.set-server-address(text);
|
||||
}
|
||||
text: State.server-address;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
export struct SItem {
|
||||
name: string,
|
||||
checked: bool,
|
||||
}
|
||||
|
||||
export global State {
|
||||
in-out property <[SItem]> list: [
|
||||
{ name: "Test 1", checked: true },
|
||||
{ name: "Test 2", checked: false },
|
||||
{ name: "Test 3", checked: false },
|
||||
];
|
||||
callback add-to-list(string);
|
||||
callback check-item(string);
|
||||
callback delete-checked();
|
||||
in-out property <string> server-address;
|
||||
callback set-server-address(string);
|
||||
set-server-address(address) => {
|
||||
server-address = address;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user