]> uap-core.de Git - rssreader.git/commitdiff
hide item viewer controls when no item is selected
authorOlaf Wintermann <olaf.wintermann@gmail.com>
Fri, 29 Aug 2025 17:59:26 +0000 (19:59 +0200)
committerOlaf Wintermann <olaf.wintermann@gmail.com>
Fri, 29 Aug 2025 17:59:26 +0000 (19:59 +0200)
rss-application/src/main/kotlin/de/unixwork/rssreader/FeedList.kt
rss-application/src/main/kotlin/de/unixwork/rssreader/MainWindow.kt
ui-java/src/main/java/de/unixwork/ui/Container.java
ui-java/src/main/java/de/unixwork/ui/ContainerFuncs.java
ui-kotlin/src/main/kotlin/de/unixwork/ui/kotlin/Toplevel.kt

index 211ab59a29f06274e2f2c3bc6743fd81501db8ca..31cc8d7fb318f24cfd1df0e841deb799ea0c92f2 100644 (file)
@@ -10,6 +10,7 @@ class FeedList : Document() {
     val linkstr = string("link")
     val link = UiLinkData(linkstr)
     val webview = webview("webview")
+    val tabview = integer("tabview")
 
     var currentFeed: FeedCollection? = null
 
@@ -52,5 +53,7 @@ class FeedList : Document() {
         }
 
         webview.loadContent(null, content, mimeType, "utf-8")
+
+        tabview.setIntValue(1)
     }
 }
\ No newline at end of file
index ec308647e1804f20278de32ba0e49ed78682f9ab..4cc0abcae98cf34b1764797c3111a9115a04dd23 100644 (file)
@@ -2,6 +2,7 @@ package de.unixwork.rssreader
 
 import de.unixwork.ui.ColumnType
 import de.unixwork.ui.SubListItem
+import de.unixwork.ui.TabViewType
 import de.unixwork.ui.TableModel
 import de.unixwork.ui.UiList
 import de.unixwork.ui.UiString
@@ -83,22 +84,32 @@ class MainWindow {
                     }
                 }
 
-                grid(fill = true, columnspacing = 8, rowspacing = 8, margin = 8, defvfill = true) {
-                    row {
-                        rlabel("Feed:", hfill = true)
-                        llabel(varname = "feedname", hexpand = true)
-                    }
-                    row {
-                        rlabel("Author:", hfill = true)
-                        llabel(varname = "author")
-                    }
-                    row {
-                        rlabel("Link:", hfill = true)
-                        linkbutton(varname = "link", styleClass = "ui-nopadding");
+                tabview(fill = true, varname = "tabview", type = TabViewType.INVISIBLE) {
+                    tab {
+                        // Completely empty tab, we don't want any visible UI elements
+                        // when no feed item is selected.
+                        // As an alternative to using a tabview, we could use a
+                        // visibility state for the grid container
                     }
+                    tab {
+                        grid(fill = true, columnspacing = 8, rowspacing = 8, margin = 8, defvfill = true) {
+                            row {
+                                rlabel("Feed:", hfill = true)
+                                llabel(varname = "feedname", hexpand = true)
+                            }
+                            row {
+                                rlabel("Author:", hfill = true)
+                                llabel(varname = "author")
+                            }
+                            row {
+                                rlabel("Link:", hfill = true)
+                                linkbutton(varname = "link", styleClass = "ui-nopadding");
+                            }
 
-                    row {
-                        webview(varname = "webview", hfill = true, vfill = true, hexpand = true, vexpand = true, colspan = 2)
+                            row {
+                                webview(varname = "webview", hfill = true, vfill = true, hexpand = true, vexpand = true, colspan = 2)
+                            }
+                        }
                     }
                 }
             }
index 54684458a68913853bc3e2bc9cde9c59c2e3af64..247ffef1a80bb384e3831e8c79a4673f30aee59b 100644 (file)
@@ -1,5 +1,8 @@
 package de.unixwork.ui;
 
+import java.lang.foreign.Arena;
+import java.lang.foreign.MemorySegment;
+
 public class Container implements AutoCloseable {
     private UiObject object;
     private UiWidget widget;
@@ -57,6 +60,20 @@ public class Container implements AutoCloseable {
         }
     }
 
+    public static Container tab(UiObject obj, String label) {
+        ContainerFuncs ui = ContainerFuncs.getInstance();
+        try (Arena arena = Arena.ofConfined()) {
+            MemorySegment cstr = MemorySegment.NULL;
+            if(label != null) {
+                cstr = arena.allocateFrom(label);
+            }
+            ui.tab_create.invoke(obj.ptr, cstr);
+        } catch (Throwable e) {
+            throw new RuntimeException(e);
+        }
+        return new Container(obj, null);
+    }
+
     public static FrameBuilder frame(UiObject obj) {
         ContainerFuncs ui = ContainerFuncs.getInstance();
         return new FrameBuilder(obj, ui.frame_create);
index d16cc6f8ed28f196e41845b6b5db606fea3f31a7..d2b9e4f8d0976b3d522039b71abc527c559fa73c 100644 (file)
@@ -23,12 +23,14 @@ public class ContainerFuncs {
     public MethodHandle container_finish;
 
     public MethodHandle newline;
+    public MethodHandle tab_create;
 
     private ContainerFuncs(Linker linker, SymbolLookup lib) {
         FunctionDescriptor sigm_mm = FunctionDescriptor.of(ValueLayout.ADDRESS, ValueLayout.ADDRESS, ValueLayout.ADDRESS);
         FunctionDescriptor sigm_m = FunctionDescriptor.of(ValueLayout.ADDRESS, ValueLayout.ADDRESS);
         FunctionDescriptor sigv_m = FunctionDescriptor.ofVoid(ValueLayout.ADDRESS);
         FunctionDescriptor sigi_m = FunctionDescriptor.of(ValueLayout.JAVA_INT, ValueLayout.ADDRESS);
+        FunctionDescriptor sigv_mm = FunctionDescriptor.ofVoid(ValueLayout.ADDRESS, ValueLayout.ADDRESS);
 
         MemorySegment ui_vbox_create_addr = lib.find("ui_vbox_create").orElseThrow();
         MemorySegment ui_hbox_create_addr = lib.find("ui_hbox_create").orElseThrow();
@@ -47,6 +49,7 @@ public class ContainerFuncs {
         MemorySegment ui_container_finish = lib.find("ui_container_finish").orElseThrow();
 
         MemorySegment ui_newline_addr = lib.find("ui_newline").orElseThrow();
+        MemorySegment ui_tab_create_addr = lib.find("ui_tab_create").orElseThrow();
 
         vbox_create = linker.downcallHandle(ui_vbox_create_addr, sigm_mm);
         hbox_create = linker.downcallHandle(ui_hbox_create_addr, sigm_mm);
@@ -65,6 +68,7 @@ public class ContainerFuncs {
         container_finish = linker.downcallHandle(ui_container_finish, sigi_m);
 
         newline = linker.downcallHandle(ui_newline_addr, sigv_m);
+        tab_create = linker.downcallHandle(ui_tab_create_addr, sigv_mm);
     }
 
     static ContainerFuncs getInstance() {
index ad155da8598c1e99bef8df476b67ee7fcde68da7..c17fe8c4863c476e18354aa9f5ef854b7d8e9c83 100644 (file)
@@ -240,6 +240,14 @@ class Toplevel(obj: UiObject) {
         Container.newline(this@Toplevel.ui)
     }
 
+    fun tab(
+        label: String? = null,
+        ui: ContainerUI? = null
+    ) {
+        val tab = Container.tab(this@Toplevel.ui, label)
+        ui?.callback()
+        tab.close()
+    }
 
     private fun createFrame(
         container: FrameBuilder,