-
-
Save vlaaad/ec3793f55b654a8b1e4dc81b3cddc74b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns e30 | |
(:require [cljfx.api :as fx] | |
[cljfx.prop :as prop] | |
[cljfx.lifecycle :as lifecycle] | |
[cljfx.mutator :as mutator]) | |
(:import [java.util UUID Collection] | |
[javafx.scene.control TabPane Tab])) | |
(def *state | |
(atom [])) | |
(def ext-with-tabs | |
(fx/make-ext-with-props | |
{:tabs (prop/make (mutator/setter (fn [^TabPane pane ^Collection tabs] | |
(doto (.getTabs pane) | |
(.clear) | |
(.setAll tabs)))) | |
lifecycle/dynamics)})) | |
(fx/mount-renderer | |
*state | |
(fx/create-renderer | |
:opts {:fx.opt/map-event-handler | |
(fn [e] | |
(case (:event/type e) | |
::add-tab (swap! *state conj (str (UUID/randomUUID))) | |
::set-tabs (reset! *state (mapv #(.getId ^Tab %) (:fx/event e)))))} | |
:middleware (fx/wrap-map-desc | |
(fn [tab-ids] | |
{:fx/type :stage | |
:width 960 | |
:height 540 | |
:showing true | |
:scene {:fx/type :scene | |
:root {:fx/type :v-box | |
:children [{:fx/type :button | |
:text "Add tab" | |
:on-action {:event/type ::add-tab}} | |
{:fx/type :label | |
:text (str (mapv #(subs % 0 3) tab-ids))} | |
{:fx/type ext-with-tabs | |
:props {:tabs (for [id tab-ids] | |
{:fx/type :tab | |
:fx/key id | |
:id id | |
:text (subs id 0 3)})} | |
:desc {:fx/type :tab-pane | |
:style {:-fx-open-tab-animation "NONE" | |
:-fx-close-tab-animation "NONE"} | |
:tab-closing-policy :all-tabs | |
:tab-drag-policy :reorder | |
:on-tabs-changed {:event/type ::set-tabs}}}]}}})))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment