Skip to content

Commit 4efbc0f

Browse files
committed
Add pie chart layouts.
1 parent e00599c commit 4efbc0f

File tree

3 files changed

+46
-8
lines changed

3 files changed

+46
-8
lines changed

share/gpick/layouts.lua

+42-5
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,11 @@ local makeLocked = function(container)
1212
end
1313
local addText = function(container, lines, style)
1414
local text = color:new()
15+
local heights = {0.15, 0.12, 0.10, 0.09, 0.08, 0.07, 0.06, 0.05, 0.04, 0.03}
16+
local y = 0
1517
for i = 0, lines - 1 do
16-
container:add(layout:newText("content_text", 0.02, i * 0.06 + 0.01, 0.96, 0.06, style, _("The quick brown fox jumps over the lazy dog")))
18+
container:add(layout:newText("content_text", 0.02, y, 0.96, heights[1 + i], style, _("The quick brown fox jumps over the lazy dog")))
19+
y = y + heights[1 + i] + 0.01
1720
end
1821
return container
1922
end
@@ -27,8 +30,8 @@ local addButtons = function(container, buttons, percentage, buttonStyle, textSty
2730
local texts = {_("Homepage"), _("About us"), _("Links to us"), _("Privacy"), _("Terms"), _("Contact us"), _("RSS")}
2831
for i = 0, buttons - 1 do
2932
local button = layout:newFill("button", padding, i * size + padding, 1 - padding * 2, size - padding, buttonStyle[i % styleCount + 1])
30-
button:add(makeHelper(layout:newText("button_text", 0.25, 0.65, 0.5, 0.3, textStyle[i % styleTextCount + 1], buttonStyle[i % styleCount + 1]:label())))
31-
button:add(layout:newText("button_text", 0.25, 0.25, 0.5, 0.5, textStyle[i % styleTextCount + 1], texts[i % #texts + 1]))
33+
button:add(makeHelper(layout:newText("button_text", 0.25, 0.7, 0.5, 0.25, textStyle[i % styleTextCount + 1], buttonStyle[i % styleCount + 1]:label())))
34+
button:add(layout:newText("button_text", 0.1, 0.25, 0.8, 0.5, textStyle[i % styleTextCount + 1], texts[i % #texts + 1]))
3235
root:add(button)
3336
end
3437
return container
@@ -99,7 +102,7 @@ gpick:addLayout('std_layout_menu_1', _("Menu"), function(system)
99102
system:setBox(root)
100103
root:add(addButtons(layout:newFill("menu", 0, 0, 1, 1, styles['menu']), 7, 1, { styles['button'], styles['button'], styles['button_hover'] }, { styles['button_text'], styles['button_text'], styles['button_text_hover'] }, 0.1))
101104
end)
102-
gpick:addLayout('std_layout_grid_1', _("Grid (4x3)"), function(system)
105+
gpick:addLayout('std_layout_grid_1', _("Grid") .. " (4x3)", function(system)
103106
local root = layout:newBox("root", 0, 0, 400, 300)
104107
system:setBox(root)
105108
for j = 0, 2 do
@@ -115,7 +118,7 @@ gpick:addLayout('std_layout_grid_1', _("Grid (4x3)"), function(system)
115118
end
116119
end
117120
end)
118-
gpick:addLayout('std_layout_grid_2', _("Grid (5x4)"), function(system)
121+
gpick:addLayout('std_layout_grid_2', _("Grid") .. " (5x4)", function(system)
119122
local root = layout:newBox("root", 0, 0, 500, 400)
120123
system:setBox(root)
121124
for j = 0, 3 do
@@ -131,4 +134,38 @@ gpick:addLayout('std_layout_grid_2', _("Grid (5x4)"), function(system)
131134
end
132135
end
133136
end)
137+
gpick:addLayout('std_layout_pie_1', _("Pie chart") .. ' 1', function(system)
138+
local root = layout:newBox("root", 0, 0, 400, 400)
139+
system:setBox(root)
140+
local style = layout:newStyle("background_b:" .. _("Background"), color:new(0.7, 0.7, 0.7), 1.0)
141+
system:addStyle(style)
142+
background = layout:newFill("background", 0, 0, 1, 1, style)
143+
root:add(background)
144+
local percents = {0.4, 0.2, 0.13, 0.07, 0.06, 0.05, 0.04, 0.03, 0.02}
145+
local start = -0.25
146+
for i, percent in ipairs(percents) do
147+
local itemIndex = i
148+
style = layout:newStyle("part" .. itemIndex .. "_b:" .. _("Part") .. " " .. itemIndex, color:new(0.8 - (0.1 * i), 0.8, 0.5 - (0.05 * i)), 1.0)
149+
system:addStyle(style)
150+
background:add(layout:newPie("part" .. itemIndex, 0.05, 0.05, 0.9, 0.9, start, start + percent, style))
151+
start = start + percent
152+
end
153+
end)
154+
gpick:addLayout('std_layout_pie_2', _("Pie chart") .. ' 2', function(system)
155+
local root = layout:newBox("root", 0, 0, 400, 400)
156+
system:setBox(root)
157+
local style = layout:newStyle("background_b:" .. _("Background"), color:new(0.7, 0.7, 0.7), 1.0)
158+
system:addStyle(style)
159+
background = layout:newFill("background", 0, 0, 1, 1, style)
160+
root:add(background)
161+
local percents = {0.4, 0.25, 0.15, 0.10, 0.10}
162+
local start = -0.25
163+
for i, percent in ipairs(percents) do
164+
local itemIndex = i
165+
style = layout:newStyle("part" .. itemIndex .. "_b:" .. _("Part") .. " " .. itemIndex, color:new(0.8 - (0.1 * i), 0.8, 0.5 - (0.05 * i)), 1.0)
166+
system:addStyle(style)
167+
background:add(layout:newPie("part" .. itemIndex, 0.05, 0.05, 0.9, 0.9, start, start + percent, style))
168+
start = start + percent
169+
end
170+
end)
134171
return {}

source/gtk/LayoutPreview.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ int gtk_layout_preview_set_system(GtkLayoutPreview *widget, common::Ref<layout::
150150
if (ns->system && ns->system->box()) {
151151
gtk_widget_set_size_request(GTK_WIDGET(widget), static_cast<int>(ns->system->box()->rect().getWidth()), static_cast<int>(ns->system->box()->rect().getHeight()));
152152
}
153+
gtk_widget_queue_draw(GTK_WIDGET(widget));
153154
return 0;
154155
}
155156
int gtk_layout_preview_set_color_at(GtkLayoutPreview *widget, Color *color, gdouble x, gdouble y) {

source/layout/Box.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -252,13 +252,13 @@ void Circle::draw(Context &context, const math::Rectangle<float> &parentRect) {
252252
cairo_set_antialias(cr, CAIRO_ANTIALIAS_NONE);
253253
cairo_fill_preserve(cr);
254254
cairo_set_antialias(cr, CAIRO_ANTIALIAS_DEFAULT);
255-
cairo_set_line_width(cr, 1);
256-
cairo_stroke(cr);
257255
if (context.system().selectedBox() == this) {
258-
cairo_rectangle(cr, drawRect.getX() + 1, drawRect.getY() + 1, drawRect.getWidth() - 2, drawRect.getHeight() - 2);
259256
cairo_set_source_rgb(cr, 1, 1, 1);
260257
cairo_set_line_width(cr, 2);
261258
cairo_stroke(cr);
259+
} else {
260+
cairo_set_line_width(cr, 1);
261+
cairo_stroke(cr);
262262
}
263263
drawChildren(context, parentRect);
264264
}

0 commit comments

Comments
 (0)