generated from defold/template-native-extension
-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
489 additions
and
432 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
local style = require("example.style") | ||
|
||
local M = {} | ||
|
||
local BASE_SIZE = 12 | ||
|
||
local fonts = {} | ||
|
||
function M.load() | ||
fonts = {} | ||
|
||
local size = BASE_SIZE * style.get_scale() | ||
local fontsize = size | ||
local fontsizebase = size | ||
local regular_data = assert(sys.load_resource("/example/bundle/fonts/Montserrat-Regular.ttf")) | ||
fonts["Regular"] = imgui.font_add_ttf_data(regular_data, #regular_data, fontsize, fontsizebase, imgui.GLYPH_RANGES_CYRILLIC) | ||
local bold_data = assert(sys.load_resource("/example/bundle/fonts/Montserrat-Bold.ttf")) | ||
fonts["Bold"] = imgui.font_add_ttf_data(bold_data, #bold_data, fontsize, fontsizebase) | ||
local italic_data = assert(sys.load_resource("/example/bundle/fonts/Montserrat-Italic.ttf")) | ||
fonts["Italic"] = imgui.font_add_ttf_data(italic_data, #italic_data, fontsize, fontsizebase) | ||
local bolditalic_data = assert(sys.load_resource("/example/bundle/fonts/Montserrat-BoldItalic.ttf")) | ||
fonts["BoldItalic"] = imgui.font_add_ttf_data(bolditalic_data, #bolditalic_data, fontsize, fontsizebase) | ||
end | ||
|
||
function M.get(name) | ||
return fonts[name] | ||
end | ||
|
||
return M |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
local M = {} | ||
|
||
local images = {} | ||
|
||
function M.load() | ||
-- Resource based Image | ||
local img1_data = assert(sys.load_resource("/example/bundle/images/image1.png")) | ||
images["image1"] = imgui.image_load_data("image1", img1_data, #img1_data) | ||
|
||
-- File based Image can be used on desktop platforms | ||
-- self.image1 = imgui.image_load("example/images/image1.png") | ||
|
||
local img2_data = assert(sys.load_resource("/example/bundle/images/image2.png")) | ||
images["image2"] = imgui.image_load_data("image2", img2_data, #img2_data) | ||
end | ||
|
||
function M.get(name) | ||
return images[name] | ||
end | ||
|
||
return M |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
local M = {} | ||
|
||
local SCALE = 2 | ||
|
||
function M.set() | ||
--[[local style = {} | ||
style.ChildBorderSize = 1 | ||
style.PopupRounding = 0 | ||
style.PopupBorderSize = 1 | ||
style.FramePadding = vmath.vector3(4, 3, 0) | ||
style.FrameRounding = 0 | ||
style.FrameBorderSize = 0 | ||
style.ItemSpacing = vmath.vector3(8, 4, 0) | ||
style.ItemInnerSpacing = vmath.vector3(4, 4, 0) | ||
style.CellPadding = vmath.vector3(4, 2, 0) | ||
style.TouchExtraPadding = vmath.vector3(0, 0, 0) | ||
style.IndentSpacing = 21 | ||
style.Alpha = 1 | ||
style.ScrollbarSize = 14 | ||
style.ScrollbarRounding = 9 | ||
style.GrabMinSize = 10 | ||
style.GrabRounding = 0 | ||
style.LogSliderDeadzone = 4 | ||
style.TabRounding = 4 | ||
style.TabBorderSize = 0 | ||
style.TabMinWidthForCloseButton = 0 | ||
style.ColorButtonPosition = 1 | ||
style.ButtonTextAlign = vmath.vector3(0.5, 0.5, 0) | ||
style.SelectableTextAlign = vmath.vector3(0, 0, 0) | ||
style.DisplayWindowPadding = vmath.vector3(19, 19, 0) | ||
style.DisplaySafeAreaPadding = vmath.vector3(3, 3, 0) | ||
style.MouseCursorScale = 1 | ||
style.CircleSegmentMaxError = 1.6 | ||
style.ColumnsMinSpacing = 6 | ||
style.AntiAliasedLines = true | ||
style.AntiAliasedLinesUseTex = true | ||
style.AntiAliasedFill = true | ||
style.CurveTessellationTol = 1.25 | ||
style.WindowPadding = vmath.vector3(8, 8, 0) | ||
style.WindowRounding = 0 | ||
style.WindowBorderSize = 1 | ||
style.WindowMinSize = vmath.vector3(32, 32, 0) | ||
style.WindowTitleAlign = vmath.vector3(0, 0.5, 0) | ||
style.WindowMenuButtonPosition = 0 | ||
style.ChildRounding = 0 | ||
imgui.set_style(style)--]] | ||
|
||
imgui.set_style_color(imgui.ImGuiCol_Text, 0.90, 0.90, 0.90, 0.90) | ||
imgui.set_style_color(imgui.ImGuiCol_TextDisabled, 0.60, 0.60, 0.60, 1.00) | ||
imgui.set_style_color(imgui.ImGuiCol_WindowBg, 0.09, 0.09, 0.15, 1.00) | ||
imgui.set_style_color(imgui.ImGuiCol_PopupBg, 0.05, 0.05, 0.10, 0.85) | ||
imgui.set_style_color(imgui.ImGuiCol_Border, 0.70, 0.70, 0.70, 0.65) | ||
imgui.set_style_color(imgui.ImGuiCol_BorderShadow, 0.00, 0.00, 0.00, 0.00) | ||
imgui.set_style_color(imgui.ImGuiCol_FrameBg, 0.00, 0.00, 0.01, 1.00) | ||
imgui.set_style_color(imgui.ImGuiCol_FrameBgHovered, 0.90, 0.80, 0.80, 0.40) | ||
imgui.set_style_color(imgui.ImGuiCol_FrameBgActive, 0.90, 0.65, 0.65, 0.45) | ||
imgui.set_style_color(imgui.ImGuiCol_TitleBg, 0.00, 0.00, 0.00, 0.83) | ||
imgui.set_style_color(imgui.ImGuiCol_TitleBgCollapsed, 0.40, 0.40, 0.80, 0.20) | ||
imgui.set_style_color(imgui.ImGuiCol_TitleBgActive, 0.00, 0.00, 0.00, 0.87) | ||
imgui.set_style_color(imgui.ImGuiCol_MenuBarBg, 0.01, 0.01, 0.02, 0.80) | ||
imgui.set_style_color(imgui.ImGuiCol_ScrollbarBg, 0.20, 0.25, 0.30, 0.60) | ||
imgui.set_style_color(imgui.ImGuiCol_ScrollbarGrab, 0.55, 0.53, 0.55, 0.51) | ||
imgui.set_style_color(imgui.ImGuiCol_ScrollbarGrabHovered, 0.56, 0.56, 0.56, 1.00) | ||
imgui.set_style_color(imgui.ImGuiCol_ScrollbarGrabActive, 0.56, 0.56, 0.56, 0.91) | ||
imgui.set_style_color(imgui.ImGuiCol_CheckMark, 0.90, 0.90, 0.90, 0.83) | ||
imgui.set_style_color(imgui.ImGuiCol_SliderGrab, 0.70, 0.70, 0.70, 0.62) | ||
imgui.set_style_color(imgui.ImGuiCol_SliderGrabActive, 0.30, 0.30, 0.30, 0.84) | ||
imgui.set_style_color(imgui.ImGuiCol_Button, 0.48, 0.72, 0.89, 0.49) | ||
imgui.set_style_color(imgui.ImGuiCol_ButtonHovered, 0.50, 0.69, 0.99, 0.68) | ||
imgui.set_style_color(imgui.ImGuiCol_ButtonActive, 0.80, 0.50, 0.50, 1.00) | ||
imgui.set_style_color(imgui.ImGuiCol_Header, 0.30, 0.69, 1.00, 0.53) | ||
imgui.set_style_color(imgui.ImGuiCol_HeaderHovered, 0.44, 0.61, 0.86, 1.00) | ||
imgui.set_style_color(imgui.ImGuiCol_HeaderActive, 0.38, 0.62, 0.83, 1.00) | ||
imgui.set_style_color(imgui.ImGuiCol_ResizeGrip, 1.00, 1.00, 1.00, 0.85) | ||
imgui.set_style_color(imgui.ImGuiCol_ResizeGripHovered, 1.00, 1.00, 1.00, 0.60) | ||
imgui.set_style_color(imgui.ImGuiCol_ResizeGripActive, 1.00, 1.00, 1.00, 0.90) | ||
imgui.set_style_color(imgui.ImGuiCol_PlotLines, 1.00, 1.00, 1.00, 1.00) | ||
imgui.set_style_color(imgui.ImGuiCol_PlotLinesHovered, 0.90, 0.70, 0.00, 1.00) | ||
imgui.set_style_color(imgui.ImGuiCol_PlotHistogram, 0.90, 0.70, 0.00, 1.00) | ||
imgui.set_style_color(imgui.ImGuiCol_PlotHistogramHovered, 1.00, 0.60, 0.00, 1.00) | ||
imgui.set_style_color(imgui.ImGuiCol_TextSelectedBg, 0.00, 0.00, 1.00, 0.35) | ||
|
||
imgui.scale_all_sizes(SCALE) | ||
end | ||
|
||
function M.get() | ||
return imgui.get_style() | ||
end | ||
|
||
function M.get_scale() | ||
return SCALE | ||
end | ||
|
||
return M |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
local style = require("example.style") | ||
|
||
return function(self) | ||
imgui.text("This is some useful text.") | ||
local changed, checked = imgui.checkbox("Demo window", self.show_demo_window) | ||
if changed then | ||
self.show_demo_window = checked | ||
end | ||
|
||
imgui.separator() | ||
|
||
if imgui.radio_button("Option 1", self.radio == 1) then | ||
self.radio = 1 | ||
end | ||
if imgui.radio_button("Option 2", self.radio == 2) then | ||
self.radio = 2 | ||
end | ||
if imgui.radio_button("Option 3", self.radio == 3) then | ||
self.radio = 3 | ||
end | ||
|
||
imgui.separator() | ||
|
||
if imgui.button("Button") then | ||
self.counter = self.counter + 1 | ||
end | ||
imgui.same_line() | ||
imgui.text(("counter = %d"):format(self.counter)) | ||
|
||
imgui.separator() | ||
|
||
local pos = go.get_position("object") | ||
local changed, x, y, z = imgui.input_float3("pos", pos.x, pos.y, pos.z) | ||
if changed then | ||
pos.x = x | ||
pos.y = y | ||
pos.z = z | ||
go.set_position(pos, "object") | ||
end | ||
|
||
local changed, x, y, z = imgui.input_int4("posi", pos.x, pos.y, pos.z, 0) | ||
if changed then | ||
pos.x = x | ||
pos.y = y | ||
pos.z = z | ||
go.set_position(pos, "object") | ||
end | ||
|
||
local changed, int = imgui.input_int("test int", self.int or 0) | ||
if changed then | ||
self.int = int | ||
end | ||
|
||
if imgui.button("open window with close button") then | ||
self.show_close_window = true | ||
end | ||
|
||
if imgui.begin_table("table_example", 3) then | ||
imgui.table_setup_scroll_freeze(1, 1) | ||
imgui.table_setup_column("FIRST NAME") | ||
imgui.table_setup_column("LAST NAME") | ||
imgui.table_setup_column("AGE") | ||
imgui.table_headers_row() | ||
|
||
imgui.table_next_row() | ||
imgui.table_next_column() | ||
imgui.text("Bilbo") | ||
imgui.table_next_column() | ||
imgui.text("Baggins") | ||
imgui.table_next_column() | ||
imgui.text("129") | ||
|
||
imgui.table_next_row() | ||
imgui.table_next_column() | ||
imgui.text("Frodo") | ||
imgui.table_next_column() | ||
imgui.text("Baggins") | ||
imgui.table_next_column() | ||
imgui.text("51") | ||
|
||
imgui.end_table() | ||
end | ||
|
||
imgui.separator() | ||
|
||
-- Manual wrapping | ||
imgui.text("Manual wrapping:") | ||
|
||
local button_count = 20 | ||
local button_size = 60 | ||
local window_pos_x, window_pos_y = imgui.get_window_pos() | ||
local region_x, region_y = imgui.get_window_content_region_max() | ||
local window_visible_x = window_pos_x + region_x | ||
local spacing_x = style.get().ItemSpacing.x | ||
|
||
for n = 1, button_count do | ||
imgui.push_id(tostring(n)) | ||
imgui.button("Box", button_size, button_size) | ||
local last_button_x, last_button_y = imgui.get_item_rect_max() | ||
local next_button_x = last_button_x + spacing_x + button_size | ||
if (n < button_count and next_button_x < window_visible_x) then | ||
imgui.same_line() | ||
end | ||
imgui.pop_id() | ||
end | ||
end |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
local JEDI = { "Luke", "Obi-Wan", "Yoda" } | ||
local SITH = { "Maul", "Vader", "Palpatine" } | ||
|
||
return function(self) | ||
local selected = imgui.tree_node("root") | ||
if selected then | ||
imgui.bullet() | ||
self.foo_selected = imgui.selectable("foo", self.foo_selected) | ||
imgui.bullet() | ||
self.bar_selected = imgui.selectable("bar", self.bar_selected) | ||
imgui.tree_pop() | ||
end | ||
|
||
|
||
-- this is the old way of creating combo boxes | ||
-- it still exists in the ImGUI API since it's a quick way ti create a combo box | ||
local changed, jedi = imgui.combo("Jedi##array", self.selected_jedi or 1, JEDI) | ||
if changed then | ||
self.selected_jedi = jedi | ||
end | ||
|
||
-- new way of creating combo boxes with a begin and end function | ||
if imgui.begin_combo("Jedi##selectable", "Select a Jedi") then | ||
for i=1,#JEDI do | ||
if imgui.selectable(JEDI[i], i == (self.selected_jedi or 1)) then | ||
self.selected_jedi = i | ||
end | ||
end | ||
imgui.end_combo() | ||
end | ||
|
||
imgui.separator() | ||
|
||
if imgui.button("Push me to focus on test double") then | ||
imgui.set_keyboard_focus_here(0) | ||
end | ||
local testdbl = self.testdbl or 0 | ||
local changed, value = imgui.input_double("test double", testdbl, 0.0001, 0.01, 5) | ||
if changed then | ||
self.testdbl = value | ||
end | ||
|
||
local progress = self.progress or 0 | ||
local changed, p = imgui.input_float("progress float", progress, 0.01, 1.0, 3) | ||
if changed then | ||
self.progress = p | ||
progress = p | ||
end | ||
|
||
imgui.separator() | ||
imgui.draw_progress(progress, -1, 0.0) | ||
imgui.separator() | ||
|
||
local changed, p = imgui.slider_float("slider float", self.slider_float or 0, 0.0, 100.0) | ||
if changed then | ||
self.slider_float = p | ||
end | ||
|
||
imgui.push_id("first") | ||
if imgui.button("Same name") then | ||
pprint("first same button") | ||
end | ||
imgui.pop_id() | ||
|
||
imgui.push_id("second") | ||
if imgui.button("Same name") then | ||
pprint("second same button") | ||
end | ||
imgui.pop_id() | ||
end |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
local values_line = {} | ||
local values_hist = {} | ||
|
||
local show_live_data = false | ||
|
||
local function make_data() | ||
values_line = {} | ||
values_hist = {} | ||
for i=1, 60 do | ||
local data = math.random(1, 30) | ||
values_hist[data] = (values_hist[data] or 0) + 1 | ||
table.insert(values_line, data) | ||
end | ||
end | ||
|
||
make_data() | ||
|
||
return function(self) | ||
local changed, checked = imgui.checkbox("Live Data", show_live_data) | ||
if changed then | ||
show_live_data = checked | ||
end | ||
|
||
if show_live_data == true then | ||
make_data() | ||
end | ||
imgui.separator() | ||
|
||
imgui.text_colored(" Data Plot ", 1, 0, 0, 1 ) | ||
imgui.plot_lines( "Data", 0, 150, 40, values_line ) | ||
|
||
imgui.separator() | ||
|
||
imgui.text_colored(" Data Histogram ", 0, 1, 0, 1 ) | ||
imgui.plot_histogram( "Histogram", 0, 150, 40, values_hist ) | ||
|
||
imgui.separator() | ||
end |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
local fonts = require("example.fonts") | ||
local images = require("example.images") | ||
|
||
return function(self) | ||
|
||
imgui.font_push(fonts.get("Regular")) | ||
imgui.text_colored("Example Text Regular - Привіт Світ", 1, 1, 1, 1 ) | ||
imgui.font_pop() | ||
imgui.separator() | ||
imgui.font_push(fonts.get("Bold")) | ||
imgui.text_colored("Example Text Bold", 1, 1, 1, 1 ) | ||
imgui.font_pop() | ||
imgui.separator() | ||
imgui.font_push(fonts.get("Italic")) | ||
imgui.text_colored("Example Text Italic", 1, 1, 1, 1 ) | ||
imgui.font_pop() | ||
imgui.separator() | ||
imgui.font_push(fonts.get("BoldItalic")) | ||
imgui.text_colored("Example Text Bold Italic", 1, 1, 1, 1 ) | ||
imgui.font_pop() | ||
imgui.separator() | ||
|
||
imgui.font_push(fonts.get("Regular")) | ||
imgui.text_colored("image stretched", 1, 1, 1, 1 ) | ||
imgui.image_add(images.get("image1"), 150,20) | ||
|
||
imgui.text_colored("image original aspect", 1, 1, 1, 1 ) | ||
imgui.image_add(images.get("image2"), 150,150) | ||
imgui.font_pop() | ||
end |
Oops, something went wrong.