fix inconsistently sized buttons and add platform classes

This commit is contained in:
Damien Elmes 2020-01-23 18:05:55 +10:00
parent 3acf926fb0
commit 4a25853c57
3 changed files with 32 additions and 9 deletions

View File

@ -5,6 +5,7 @@
import platform import platform
from typing import Dict from typing import Dict
from anki.utils import isMac
from aqt import QApplication, gui_hooks, isWin from aqt import QApplication, gui_hooks, isWin
from aqt.colors import colors from aqt.colors import colors
from aqt.qt import QColor, QIcon, QPalette, QPixmap, QStyleFactory, Qt from aqt.qt import QColor, QIcon, QPalette, QPixmap, QStyleFactory, Qt
@ -32,8 +33,17 @@ class ThemeManager:
return self._icon_cache.setdefault(path, icon) return self._icon_cache.setdefault(path, icon)
def body_class(self) -> str: def body_class(self) -> str:
"Returns '' in normal mode, 'nightMode' in night mode." "Returns space-separated class list for platform/theme."
return self.night_mode and "nightMode" or "" classes = []
if isWin:
classes.append("isWin")
elif isMac:
classes.append("isMac")
else:
classes.append("isLin")
if self.night_mode:
classes.append("nightMode")
return " ".join(classes)
def body_classes_for_card_ord(self, card_ord: int) -> str: def body_classes_for_card_ord(self, card_ord: int) -> str:
"Returns body classes used when showing a card." "Returns body classes used when showing a card."

View File

@ -266,14 +266,14 @@ class AnkiWebView(QWebEngineView): # type: ignore
if isWin: if isWin:
# T: include a font for your language on Windows, eg: "Segoe UI", "MS Mincho" # T: include a font for your language on Windows, eg: "Segoe UI", "MS Mincho"
family = _('"Segoe UI"') family = _('"Segoe UI"')
widgetspec = "button { font-size: 12px; font-family:%s; }" % family widgetspec = "button { font-family:%s; }" % family
widgetspec += "\n:focus { outline: 1px solid %s; }" % color_hl widgetspec += "\n:focus { outline: 1px solid %s; }" % color_hl
fontspec = "font-size:12px;font-family:%s;" % family fontspec = "font-size:12px;font-family:%s;" % family
elif isMac: elif isMac:
family = "Helvetica" family = "Helvetica"
fontspec = 'font-size:15px;font-family:"%s";' % family fontspec = 'font-size:15px;font-family:"%s";' % family
widgetspec = """ widgetspec = """
button { font-size: 13px; -webkit-appearance: none; background: #fff; border: 1px solid #ccc; button { -webkit-appearance: none; background: #fff; border: 1px solid #ccc;
border-radius:5px; font-family: Helvetica }""" border-radius:5px; font-family: Helvetica }"""
else: else:
family = self.font().family() family = self.font().family()
@ -282,7 +282,7 @@ border-radius:5px; font-family: Helvetica }"""
fontspec = 'font-size:14px;font-family:"%s";' % family fontspec = 'font-size:14px;font-family:"%s";' % family
widgetspec = """ widgetspec = """
/* Buttons */ /* Buttons */
button{ font-size:14px; -webkit-appearance:none; outline:0; button{ -webkit-appearance:none; outline:0;
background-color: %(color_btn)s; border:1px solid rgba(0,0,0,.2); background-color: %(color_btn)s; border:1px solid rgba(0,0,0,.2);
border-radius:2px; height:24px; font-family:"%(family)s"; } border-radius:2px; height:24px; font-family:"%(family)s"; }
button:focus{ border-color: %(color_hl)s } button:focus{ border-color: %(color_hl)s }

View File

@ -13,11 +13,7 @@
border: 1px solid vars.$night-faint-border; border: 1px solid vars.$night-faint-border;
border-radius: 3px; border-radius: 3px;
height: 24px;
padding: 5px; padding: 5px;
padding-left: 10px;
padding-right: 10px;
padding-bottom: 18px;
} }
button:hover { button:hover {
@ -25,3 +21,20 @@
} }
} }
.isWin {
button {
font-size: 12px;
}
}
.isMac {
button {
font-size: 13px;
}
}
.isLin {
button {
font-size: 14px;
}
}