starlit  Diff

Differences From Artifact [7085b387cd]:

To Artifact [81aedb85b1]:


    29     29   			end
    30     30   			local created = state == nil
    31     31   
    32     32   			if not state then
    33     33   				state = {
    34     34   					page = page or 'index';
    35     35   					form = self.id;
           36  +					self = self;
           37  +					close = function() self:close(user) end;
    36     38   				}
    37     39   				starlit.activeUI[user.name] = state
    38     40   				self:cb('setupState', user, ...)
    39     41   			elseif page ~= nil and state.page ~= page then
    40     42   				state.page = page
    41     43   				local psetup = self.pages[state.page].setupState
    42     44   				if psetup then psetup(state,user, ...) end
................................................................................
   148    150   			widget('container[%s,%s]%scontainer_end[]', state.x, state.y, src)
   149    151   			-- TODO alignments
   150    152   			state.x=state.x + state.spacing + st.w
   151    153   			state.h = math.max(state.h, st.h)
   152    154   		end
   153    155   		state.h = state.h + state.padding
   154    156   		state.w = state.x + state.padding/2
          157  +	elseif def.kind == 'pane' then
          158  +		widget('scroll_container[%s,%s;%s,%s;%s;vertical]',
          159  +			state.x, state.y, state.w, state.h,
          160  +			def.id)
          161  +		local y = 0
          162  +		for _, w in ipairs(def) do
          163  +			local src, st = starlit.ui.build(w, state)
          164  +			widget('container[%s,%s]%scontainer_end[]', 0, y, src)
          165  +			y=y + state.spacing + st.h
          166  +			state.w = math.max(state.w, st.w)
          167  +		end
          168  +		widget('scroll_container_end[]')
          169  +		if y > state.h then
          170  +			widget('scrollbar[%s,%s;%s,%s;vertical;%s;]',
          171  +				state.x, state.y, .5, state.h,
          172  +				def.id)
          173  +		end
          174  +		state.w = state.w + state.padding
          175  +		state.h = state.h + state.padding/2
   155    176   	elseif def.kind == 'list' then
   156    177   		local slotTypes = {
   157    178   			plain = {hue = 200, sat = -.1, lum = 0};
   158    179   			element = {hue = 20, sat = -.3, lum = 0};
   159    180   			chip = {hue = 0, sat = -1, lum = 0};
   160    181   			psi = {hue = 300, sat = 0, lum = 0};
   161    182   			power = {hue = 50, sat = 0, lum = .2};
................................................................................
   181    202   			def.w,   def.h,
   182    203   			def.idx))
   183    204   		local sm = 1
   184    205   		state.w = def.w * sm + (spac * (def.w - 1))
   185    206   		state.h = def.h * sm + (spac * (def.h - 1))
   186    207   	elseif def.kind == 'contact' then
   187    208   		if def.color then table.insert(lines, btnColorDef(def.id)) end
   188         -		widget('image_button%s[%s,%s;%s,%s;%s;%s;%s]',
          209  +		local img = def.img
          210  +		local desc
          211  +		if def.item then
          212  +			img  = ItemStack(def.item):get_name()
          213  +			desc = ItemStack(def.item):get_description()
          214  +		end
          215  +		widget('%simage_button%s[%s,%s;%s,%s;%s;%s;%s]',
          216  +			def.item and 'item_' or '',
   189    217   			def.close and '_exit' or '',
   190    218   			state.x, state.y, def.w, def.h,
   191         -			E(def.img), E(def.id), E(def.label or ''))
          219  +			E(img), E(def.id), E(def.label or ''))
          220  +		if desc and not def.desc then
          221  +			widget('tooltip[%s;%s]', E(def.id), E(desc))
          222  +		end
   192    223   	elseif def.kind == 'button' then
   193    224   		if def.color then table.insert(lines, btnColorDef(def.id)) end
   194    225   		local label = E(def.label or '')
   195    226   		if state.fg then label = lib.color(state.fg):fmt(label) end
   196    227   		widget('button%s[%s,%s;%s,%s;%s;%s]',
   197    228   			def.close and '_exit' or '',
   198    229   			state.x, state.y, def.w, def.h,
................................................................................
   210    241   		-- TODO paragraph formatter
   211    242   		widget('hypertext[%s,%s;%s,%s;%s;%s]',
   212    243   			state.x, state.y, def.w, def.h, E(def.id), E(def.text))
   213    244   	elseif def.kind == 'hbar' or def.kind == 'vbar' then -- TODO fancy image bars
   214    245   		local cl = lib.color(state.color)
   215    246   		local fg = state.fg or cl:readable(.8,1)
   216    247   		local wfac, hfac = 1,1
   217         -		local clamp = math.min(math.max(def.fac, 0), 1)
          248  +		local clamp = math.min(math.max(def.fac or 0, 0), 1)
   218    249   		if def.kind == 'hbar'
   219    250   			then wfac = wfac * clamp
   220    251   			else hfac = hfac * clamp
   221    252   		end
   222    253   		local x,y, w,h = state.x, state.y, def.w, def.h
   223    254   		widget('box[%s,%s;%s,%s;%s]',
   224    255   			x,y, w,h, cl:brighten(0.2):hex())
................................................................................
   228    259   			widget('hypertext[%s,%s;%s,%s;;%s]',
   229    260   				state.x, state.y, def.w, def.h,
   230    261   				string.format('<global halign=center valign=middle color=%s>%s', fg:hex(), E(def.text)))
   231    262   		end
   232    263   	end
   233    264   
   234    265   	if def.desc then
   235         -		widget('tooltip[%s,%s;%s,%s;%s]',
   236         -			state.x, state.y, def.w, def.h, E(def.desc))
          266  +		local coord
          267  +		if def.id then
          268  +			coord = E(def.id)
          269  +		else
          270  +			coord = string.format("%s,%s;%s,%s", state.x, state.y, def.w, def.h)
          271  +		end
          272  +		widget('tooltip[%s;%s;#000000;#ffffff]', coord, E(def.desc))
   237    273   	end
   238    274   
   239    275   	local originX = (parent and parent.x or 0)
   240    276   	local originY = (parent and parent.y or 0)
   241    277   	local l = table.concat(lines)
   242    278   	-- if state.fixed and (state.w < state.x or state.h < state.y) then
   243    279   	-- 	l = string.format('scroll_container[%s,%s;%s,%s;scroll_%s;%s]%sscroll_container_end[]',