expose h_align/v_align through full stack

display_hint becomes {kind, h_align, v_align} object in API, SQLite
gets alignment columns, SPA widget form gets alignment selects, layout
preview reflects actual alignment instead of hardcoded center
This commit is contained in:
2026-06-19 10:28:09 +02:00
parent ca2ef61097
commit b448fa15fe
8 changed files with 200 additions and 43 deletions

View File

@@ -1,9 +1,9 @@
use crate::error::SqliteConfigError;
use domain::{DisplayHint, DisplayHintKind, KeyMapping, WidgetConfig};
use domain::{DisplayHint, DisplayHintKind, HAlign, KeyMapping, VAlign, WidgetConfig};
use sqlx::Row;
use sqlx::sqlite::SqliteRow;
pub fn display_hint_to_str(hint: &DisplayHint) -> &'static str {
pub fn display_hint_kind_to_str(hint: &DisplayHint) -> &'static str {
match hint.kind {
DisplayHintKind::IconValue => "icon_value",
DisplayHintKind::TextBlock => "text_block",
@@ -11,17 +11,55 @@ pub fn display_hint_to_str(hint: &DisplayHint) -> &'static str {
}
}
fn display_hint_from_str(s: &str) -> Result<DisplayHint, SqliteConfigError> {
pub fn h_align_to_str(a: HAlign) -> &'static str {
match a {
HAlign::Left => "left",
HAlign::Center => "center",
HAlign::Right => "right",
}
}
pub fn v_align_to_str(a: VAlign) -> &'static str {
match a {
VAlign::Top => "top",
VAlign::Middle => "middle",
VAlign::Bottom => "bottom",
}
}
fn hint_kind_from_str(s: &str) -> Result<DisplayHintKind, SqliteConfigError> {
match s {
"icon_value" => Ok(DisplayHint::new(DisplayHintKind::IconValue)),
"text_block" => Ok(DisplayHint::new(DisplayHintKind::TextBlock)),
"key_value" => Ok(DisplayHint::new(DisplayHintKind::KeyValue)),
"icon_value" => Ok(DisplayHintKind::IconValue),
"text_block" => Ok(DisplayHintKind::TextBlock),
"key_value" => Ok(DisplayHintKind::KeyValue),
_ => Err(SqliteConfigError::Serialization(format!(
"unknown display hint: {s}"
))),
}
}
fn h_align_from_str(s: &str) -> Result<HAlign, SqliteConfigError> {
match s {
"left" => Ok(HAlign::Left),
"center" => Ok(HAlign::Center),
"right" => Ok(HAlign::Right),
_ => Err(SqliteConfigError::Serialization(format!(
"unknown h_align: {s}"
))),
}
}
fn v_align_from_str(s: &str) -> Result<VAlign, SqliteConfigError> {
match s {
"top" => Ok(VAlign::Top),
"middle" => Ok(VAlign::Middle),
"bottom" => Ok(VAlign::Bottom),
_ => Err(SqliteConfigError::Serialization(format!(
"unknown v_align: {s}"
))),
}
}
pub fn mappings_to_json(mappings: &[KeyMapping]) -> Result<String, SqliteConfigError> {
let entries: Vec<serde_json::Value> = mappings
.iter()
@@ -60,6 +98,8 @@ pub fn widget_from_row(row: &SqliteRow) -> Result<WidgetConfig, SqliteConfigErro
let id: i64 = row.get("id");
let name: String = row.get("name");
let hint_str: String = row.get("display_hint");
let h_align_str: String = row.get("h_align");
let v_align_str: String = row.get("v_align");
let ds_id: i64 = row.get("data_source_id");
let mappings_json: String = row.get("mappings");
let max_size: i64 = row.get("max_data_size");
@@ -67,7 +107,11 @@ pub fn widget_from_row(row: &SqliteRow) -> Result<WidgetConfig, SqliteConfigErro
Ok(WidgetConfig {
id: id as u16,
name,
display_hint: display_hint_from_str(&hint_str)?,
display_hint: DisplayHint {
kind: hint_kind_from_str(&hint_str)?,
h_align: h_align_from_str(&h_align_str)?,
v_align: v_align_from_str(&v_align_str)?,
},
data_source_id: ds_id as u16,
mappings: mappings_from_json(&mappings_json)?,
max_data_size: max_size as u16,