Added more styles

This commit is contained in:
Cooldude2606
2019-09-24 18:43:32 +01:00
parent 2cd9c80804
commit 3609d07504
8 changed files with 297 additions and 0 deletions

View File

@@ -7,6 +7,7 @@ local Gui = require 'expcore.gui' --- @dep expcore.gui
Gui.require_concept 'flow' --- @dep gui.concept.flow
--[[-- A flow which can be used to align text and other elements
@see flow
@element alignment
@usage-- Concept Structure
-- Root

View File

@@ -7,6 +7,7 @@ local Gui = require 'expcore.gui' --- @dep expcore.gui
Gui.require_concept 'frame' --- @dep gui.concept.frame
--[[-- A container frame that can be used to add a boader around your content
@see frame
@element container
@usage-- Concept Structure
-- Root

View File

@@ -0,0 +1,89 @@
--[[-- Core Module - ExpStyle
@module ExpStyle
]]
local Gui = require 'expcore.gui' --- @dep expcore.gui
Gui.require_concept 'label' --- @dep gui.concept.frame
local right_align =
Gui.new_concept('alignment')
--[[-- A label pair which has a static label and a data label which can be changed
@see label
@element data_label
@usage-- Concept Structure
-- Root
--> [data_label] - the static label
--> [properties.data_name] - the data label which can be updated
Gui.new_concept('data_label')
:set_data_label_name('game_ticks')
:set_data_caption('0')
:set_data_format(function(concept,element,data,...)
-- This is used with update_data_element and update_from_parent
local caption = tostirng('data')
local tooltip = 'This game has beeing running for: '..caption..' ticks'
return caption, tooltip
end)
]]
local data_label =
Gui.new_concept('label')
:save_as('data_label')
:new_property('data_label_name')
:new_property('data_caption')
:new_property('data_tooltip')
:new_property('data_format',nil,function(concept,element,data,...)
return tostring(data)
end)
-- Draw
:define_draw(function(properties,parent,element)
-- Make the label right aligned
local data_name = properties.data_label_name or properties.name..'_data'
local right_align_element = right_align:draw(parent,data_name)
-- Add a new label
local data_label_element =
right_align_element.add{
name = 'data_label'
}
-- Get the data caption
local caption = Gui.resolve_property(properties.data_caption,element)
if caption then
data_label_element.caption = caption
end
-- Get the data tooltip
local tooltip = Gui.resolve_property(properties.data_tooltip,element)
if tooltip then
data_label_element.tooltip = tooltip
end
return data_label_element
end)
function data_label:update_data_element(element,data,...)
local caption, tooltip = self.properties.data_format(self,element,data,...)
if caption then
element.caption = caption
end
if tooltip then
element.tooltip = tooltip
end
end
function data_label:update_from_parent(parent,data,...)
local properties = self.properties
local data_name = properties.data_label_name or properties.name..'_data'
local element = parent[data_name] and parent[data_name].data_label or error('Data label is not a child of this element element',2)
local caption, tooltip = properties.data_format(self,element,data,...)
if caption then
element.caption = caption
end
if tooltip then
element.tooltip = tooltip
end
end

View File

@@ -0,0 +1,52 @@
--[[-- Core Module - ExpStyle
@module ExpStyle
]]
local Gui = require 'expcore.gui' --- @dep expcore.gui
Gui.require_concept 'frame' --- @dep gui.concept.table
local right_align =
Gui.new_concept('alignment')
--[[-- A frame that acts as a footer to a section of content
@see frame
@element footer
@tparam string tooltip the tooltip to show on the title
@usage-- Concept Structure
-- Root
--> [footer] - the footer frame
-->> footer_caption - the lable with the title in it
-->> footer_content - the area to contain butons
Gui.new_concept('footer')
:set_title('Example Footer')
]]
Gui.new_concept('frame')
:save_as('footer')
:new_property('tooltip')
-- Draw
:define_draw(function(properties,parent,element)
-- Update the table style
Gui.set_padding(element,2,2,4,4)
element.style = 'subfooter_frame'
element.caption = nil
local style = element.style
style.horizontally_stretchable = true
style.use_header_filler = false
-- Add the caption to the frame
element.add{
type = 'label',
name = 'footer_caption',
caption = properties.title,
tooltip = properties.tooltip
}
-- Add the right align area
local align = right_align:draw(element,'footer_content')
return align
end)

View File

@@ -13,12 +13,16 @@ Gui.new_concept('scroll')
:set_horizontal_scroll('never')
--[[-- A table that is inside a vertical scroll area
@see table
@element scroll_table
@tparam number hight the max hight of the scroll area
@usage-- Concept Structure
-- Root
--> [scroll_table] - the scroll area
-->> table - the table area
Gui.new_concept('scroll_table')
:set_height(200)
:set_column_count(2)
]]
Gui.new_concept('table')

View File

@@ -46,6 +46,12 @@ end
@usage-- Concept Structure
-- Root
--> [time_label] - the label with the time
local time_label =
Gui.new_concept('time_label')
:set_use_hours(true)
:set_time(game.tick)
time_label:update_time(element,game.tick)
]]
local time_label =

View File

@@ -0,0 +1,49 @@
--[[-- Core Module - ExpStyle
@module ExpStyle
]]
local Gui = require 'expcore.gui' --- @dep expcore.gui
Gui.require_concept 'button' --- @dep gui.concept.table
--[[-- A button that will toggle its caption each time it is pressed
@see button
@element toggle_button
@tparam string alt_caption the caption to show on the button in its true state
@tparam string alt_tooltip the tooltip to show on the button in its true state
@usage-- Concept Structure
-- Root
--> [toggle_button] - the header button
Gui.new_concept('toggle_button')
:set_caption('<')
:set_tooltip('Press to close.')
:set_alt_caption('>')
:set_alt_tooltip('Press to open.')
:on_click(function(event)
local state = event.state and 'close' or 'open'
event.player.print('Toggle button is now: '..state)
end)
]]
Gui.new_concept('button')
:save_as('toggle_button')
:new_property('alt_caption')
:new_property('alt_tooltip')
-- Events
:on_click(function(event)
local concept = event.concept
local properties = concept.properties
local element = event.element
if element.caption == properties.caption then
element.caption = properties.alt_caption
element.tooltip = properties.alt_tooltip or properties.tooltip
event.state = true
else
element.caption = properties.caption
element.tooltip = properties.tooltip or properties.alt_tooltip
event.state = false
end
end)

View File

@@ -0,0 +1,95 @@
--[[-- Core Module - ExpStyle
@module ExpStyle
]]
local Gui = require 'expcore.gui' --- @dep expcore.gui
Gui.require_concept 'label' --- @dep gui.concept.frame
local right_align =
Gui.new_concept('alignment')
--[[-- A label triplet which has a static label, a data label which can be changed, and a unit label
@see label
@see data_label
@element unit_label
@usage-- Concept Structure
-- Root
--> [unit_label] - the static label
--> [properties.data_name] - the data label which can be updated
--> [properties.data_name..'_unit'] - the data label unit which can be updated
Gui.new_concept('unit_label')
:set_data_label_name('game_ticks')
:set_data_caption('0')
:set_data_unit('ticks')
:set_data_format(function(concept,element,data,...)
-- This is used with update_data_element and update_from_parent
local caption = tostirng(data)
local unit = data > 1 and 'ticks' or 'tick'
local tooltip = 'This game has beeing running for: '..caption..' ticks'
return caption, unit, tooltip
end)
]]
local unit_label =
Gui.new_concept('data_label')
:save_as('unit_label')
:new_property('data_label_name')
:new_property('data_caption')
:new_property('data_tooltip')
:new_property('data_unit')
:new_property('data_format',nil,function(concept,element,data,...)
local base_unit = concept.properties.data_unit
local caption = tostring(data)
local unit = data == 1 and base_unit or base_unit..'s'
return caption, unit
end)
-- Draw
:define_draw(function(properties,parent,element)
-- Get the unit data
local unit = Gui.resolve_property(properties.data_unit,element)
-- Add the unit label
parent.add{
name = element.name..'_unit',
caption = unit or '',
tooltip = element.tooltip
}
return element
end)
function unit_label:update_data_element(element,data,...)
local caption, unit, tooltip = self.properties.data_format(self,element,data,...)
local unit_element = element.parent.parent[element.name..'_unit']
if caption then
element.caption = caption
end
if tooltip then
element.tooltip = tooltip
unit_element.tooltip = tooltip
end
if unit then
unit_element.caption = unit
end
end
function unit_label:update_from_parent(parent,data,...)
local properties = self.properties
local data_name = properties.data_label_name or properties.name..'_data'
local element = parent[data_name] and parent[data_name].data_label or error('Data label is not a child of this element element',2)
local unit_element = parent[data_name..'_unit']
local caption, unit, tooltip = properties.data_format(self,element,data,...)
if caption then
element.caption = caption
end
if tooltip then
element.tooltip = tooltip
unit_element.tooltip = tooltip
end
if unit then
unit_element.caption = unit
end
end