import kotlinx.coroutines.IO
import kotlinx.coroutines.launch
-class FeedList : Document() {
+class FeedList(window: MainWindow) : Document() {
+ val window = window
+
val items = list<Item>("items")
val feedName = string("feedname")
val author = string("author")
fun selectItem(item: Item) {
feedName.setString(item.feedName)
- author.setString(item.author)
+ if(!item.author.isNullOrEmpty()) {
+ author.setString(item.author)
+ window.window.ui.setState(MainWindow.ITEM_HAS_AUTHOR)
+ } else {
+ window.window.ui.unsetState(MainWindow.ITEM_HAS_AUTHOR)
+ }
link.set(item.link, item.link)
category.setString(item.category ?: "")
+ if(!item.category.isNullOrEmpty()) {
+ category.setString(item.category)
+ window.window.ui.setState(MainWindow.ITEM_HAS_CATEGORY)
+ } else {
+ window.window.ui.unsetState(MainWindow.ITEM_HAS_CATEGORY)
+ }
var mimeType: String? = null
var content: String? = null
import java.time.format.DateTimeFormatter
class MainWindow() {
+ companion object {
+ const val ITEM_HAS_AUTHOR = 1000
+ const val ITEM_HAS_CATEGORY = 1001
+ }
+
val window : Toplevel
val sourceList = FeedSourceList()
- val feedList = FeedList()
+ val feedList = FeedList(this)
val dateFormatter = DateTimeFormatter.ofPattern(App.settings.dateFormat).withZone(ZoneId.systemDefault())
val dateTodayFormatter = DateTimeFormatter.ofPattern(App.settings.dateFormatToday).withZone(ZoneId.systemDefault())
llabel(varname = "feedname", hexpand = true)
}
row {
- rlabel("Author:", hfill = true)
- llabel(varname = "author")
+ val w1 = rlabel("Author:", hfill = true)
+ val w2 = llabel(varname = "author")
+ w1.setVisibilityStates(ITEM_HAS_AUTHOR)
+ w2.setVisibilityStates(ITEM_HAS_AUTHOR)
}
row {
rlabel("Link:", hfill = true)
linkbutton(varname = "link", styleClass = "ui-nopadding");
}
row {
- rlabel("Category: ", hfill = true)
- llabel(varname = "category")
+ val w1 = rlabel("Category: ", hfill = true)
+ val w2 = llabel(varname = "category")
+ w1.setVisibilityStates(ITEM_HAS_CATEGORY)
+ w2.setVisibilityStates(ITEM_HAS_CATEGORY)
}
row {
throw new RuntimeException(e);
}
}
+
+ public void setVisibilityStates(int... states) {
+ ToolkitFuncs ui = ToolkitFuncs.getInstance();
+ try (Arena arena = Arena.ofConfined()) {
+ MemorySegment statesArray = arena.allocate(ValueLayout.JAVA_INT, states.length);
+ MemorySegment.copy(states, 0, statesArray, ValueLayout.JAVA_INT, 0, states.length);
+ ui.set_widget_visibility_states.invoke(obj.getCtx(), widget, statesArray, states.length);
+ } catch (Throwable e) {
+ throw new RuntimeException(e);
+ }
+ }
}