Skip to content

Commit

Permalink
U ifixes (#16)
Browse files Browse the repository at this point in the history
* UI fixes

* Statusline
  • Loading branch information
zwim committed Jul 23, 2021
1 parent d817923 commit b9166c7
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 42 deletions.
3 changes: 3 additions & 0 deletions ChangeLog
@@ -1,3 +1,6 @@
Version: 1.1.1
Minor UX fixes

Version: 1.1.0
Added conversion
Average function
Expand Down
4 changes: 2 additions & 2 deletions VERSION
@@ -1,2 +1,2 @@
Version: 1.1.0
Date: 20210719
Version: 1.1.1
Date: 20210723
Binary file modified calculator.koplugin-1.1.0.zip
Binary file not shown.
Binary file added calculator.koplugin-1.1.1.zip
Binary file not shown.
1 change: 0 additions & 1 deletion calculatorconvertdialog.lua
Expand Up @@ -11,7 +11,6 @@ local UIManager = require("ui/uimanager")
local _ = require("gettext")
local Screen = require("device").screen
local ffiUtil = require("ffi/util")
local logger = require("logger")

local length_table = {
{"Å",10e-10},
Expand Down
8 changes: 4 additions & 4 deletions calculatorunitsdialog.lua
Expand Up @@ -165,9 +165,9 @@ function CalculatorUnitsDialog:init()
},
HorizontalSpan:new{width=self.title_bar:getSize().w * 0.1},
VerticalGroup:new{
align = "center",
align = "left",
TextWidget:new{
text = _("from"),
text = _(" from:"),
face = self.text_face,
},
CenterContainer:new{
Expand All @@ -179,9 +179,9 @@ function CalculatorUnitsDialog:init()
},
},
VerticalGroup:new{
align = "center",
align = "left",
TextWidget:new{
text = _("to"),
text = _(" to:"),
face = self.text_face,
},

Expand Down
89 changes: 54 additions & 35 deletions main.lua
Expand Up @@ -123,53 +123,24 @@ end
function Calculator:getStatusLine()
local angle_mode = Parser:eval(Parser:parse("getAngleMode()"))
angle_mode = self:getString(angle_mode, self.angle_modes)
angle_mode = angle_mode .. (" "):rep(9-#angle_mode)
angle_mode = angle_mode .. (" "):rep(7-#angle_mode)
local format = self:getString(self.number_format, self.number_formats)
format = format .. (" "):rep(12-#format)
return string.format(_("∡ %s Format: %s ≈%d"),
return string.format(_("∡ %s\tFormat: %s\t≈%d"),
angle_mode, format, self.significant_places)
end

function Calculator:onCalculatorStart()
self.angle_mode = G_reader_settings:readSetting("calculator_angle_mode") or self.angle_mode
self.number_format = G_reader_settings:readSetting("calculator_number_format") or self.number_format
self.significant_places = G_reader_settings:readSetting("calculator_significant_places") or self.significant_places

self:addKeyboard()

if self.angle_mode ~= Parser:eval(Parser:parse("getAngleMode()")) then
if self.angle_mode == "radiant" then
Parser:eval(Parser:parse("setrad()"))
elseif self.angle_mode == "degree" then
Parser:eval(Parser:parse("setdeg()"))
else
Parser:eval(Parser:parse("setgon()"))
end
end

self.status_line = self.status_line or self:getStatusLine()

function Calculator:generateInputDialog(status_line)
local hint = _([[Enter your calculations and press '⮠'
'♺' Convert, '⎚' Clear, '⇧' Load,
'⇩' Store, '☰' Settings, '✕' Close
or type 'help()⮠']])
local current_version = self:getCurrentVersion()
local latest_version = self:getLatestVersion(LATEST_VERSION, 20, 60)

if latest_version and current_version and latest_version > current_version then
hint = hint .. "\n\n" .. _("A calculator update is available:") .. "\n"
if current_version then
hint = hint .. "Current-" .. current_version
end
if latest_version then
hint = hint .. "Latest-" .. latest_version
end
end
self.input_dialog = InputDialog:new{
return InputDialog:new{
title = _("Calculator"),
input_hint = hint,
description = self.status_line,
description_face= Font:getFace("scfont"),
description = status_line,
description_face = Font:getFace("scfont"),
input = self.history,
input_face = Font:getFace("scfont"),
para_direction_rtl = false, -- force LTR
Expand Down Expand Up @@ -278,6 +249,54 @@ or type 'help()⮠']])
end
end,
}
end

function Calculator:expandTabs(str, num)
return str:gsub("\t",(" "):rep(num))
end

function Calculator:onCalculatorStart()
self.angle_mode = G_reader_settings:readSetting("calculator_angle_mode") or self.angle_mode
self.number_format = G_reader_settings:readSetting("calculator_number_format") or self.number_format
self.significant_places = G_reader_settings:readSetting("calculator_significant_places") or self.significant_places

self:addKeyboard()

if self.angle_mode ~= Parser:eval(Parser:parse("getAngleMode()")) then
if self.angle_mode == "radiant" then
Parser:eval(Parser:parse("setrad()"))
elseif self.angle_mode == "degree" then
Parser:eval(Parser:parse("setdeg()"))
else
Parser:eval(Parser:parse("setgon()"))
end
end

self.status_line = self.status_line or self:getStatusLine()

local current_version = self:getCurrentVersion()
local latest_version = self:getLatestVersion(LATEST_VERSION, 20, 60)

local hint
if latest_version and current_version and latest_version > current_version then
hint = hint .. "\n\n" .. _("A calculator update is available:") .. "\n"
if current_version then
hint = hint .. "Current-" .. current_version
end
if latest_version then
hint = hint .. "Latest-" .. latest_version
end
end

-- fill status line with spaces
local expand = -1 -- expand tabs with x spaces
repeat
expand = expand + 1
self.input_dialog = self:generateInputDialog(self:expandTabs(self.status_line, expand))
until (self.input_dialog.description_widget[1].lines_per_page > 1 or expand > 20)

self.input_dialog = self:generateInputDialog(self:expandTabs(self.status_line, expand - 1))

UIManager:show(self.input_dialog)
self.input_dialog:onShowKeyboard(true)
end
Expand Down

0 comments on commit b9166c7

Please sign in to comment.