Skip to content

Commit

Permalink
Add option for scale interface
Browse files Browse the repository at this point in the history
  • Loading branch information
Psayker committed Apr 25, 2024
1 parent e6b8ff3 commit 639135b
Show file tree
Hide file tree
Showing 11 changed files with 238 additions and 7 deletions.
57 changes: 57 additions & 0 deletions libdino/src/entity/encryption.vala
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,61 @@ namespace Dino.Entities {
}
}

public enum InterfaceScale {
NONE,
SMALL,
MEDIUM,
LARGE,
EXTRA_LARGE;

public bool is_some() {
return this != NONE;
}

public static InterfaceScale parse(string str) {
switch (str) {
case "DINO_ENTITIES_INTERFACE_SCALE_SMALL":
return SMALL;
case "DINO_ENTITIES_INTERFACE_SCALE_MEDIUM":
return MEDIUM;
case "DINO_ENTITIES_INTERFACE_SCALE_LARGE":
return LARGE;
case "DINO_ENTITIES_INTERFACE_SCALE_EXTRA_LARGE":
return EXTRA_LARGE;
default:
return NONE;
}
}

public static double to_double(InterfaceScale val) {
switch (val) {
case InterfaceScale.SMALL:
return 0.6;
case InterfaceScale.MEDIUM:
return 0.8;
case InterfaceScale.LARGE:
return 1;
case InterfaceScale.EXTRA_LARGE:
return 1.5;
default:
return 0.8;
}
}

public static double to_css_pt(InterfaceScale val) {
switch (val) {
case InterfaceScale.SMALL:
return 8;
case InterfaceScale.MEDIUM:
return 10;
case InterfaceScale.LARGE:
return 12;
case InterfaceScale.EXTRA_LARGE:
return 16;
default:
return 10;
}
}
}

}
23 changes: 23 additions & 0 deletions libdino/src/entity/settings.vala
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,14 @@ public class Settings : Object {
convert_utf8_smileys_ = col_to_bool_or_default("convert_utf8_smileys", true);
check_spelling = col_to_bool_or_default("check_spelling", true);
default_encryption = col_to_encryption_or_default("default_encryption", Encryption.UNKNOWN);
interface_scale = col_to_interface_scale_or_default("interface_scale", InterfaceScale.MEDIUM);
send_button = col_to_bool_or_default("send_button", false);
enter_newline = col_to_bool_or_default("enter_newline", false);
dark_theme = col_to_bool_or_default("dark_theme", false);
}

public signal void update_interface_scale();

private bool col_to_bool_or_default(string key, bool def) {
string? val = db.settings.select({db.settings.value}).with(db.settings.key, "=", key)[db.settings.value];
return val != null ? bool.parse(val) : def;
Expand All @@ -29,6 +32,12 @@ public class Settings : Object {
return val != null ? Encryption.parse(val) : def;
}

private InterfaceScale col_to_interface_scale_or_default(string key, InterfaceScale def) {
var sval = db.settings.value;
string? val = db.settings.select({sval}).with(db.settings.key, "=", key)[sval];
return val != null ? InterfaceScale.parse(val) : def;
}

private bool send_typing_;
public bool send_typing {
get { return send_typing_; }
Expand Down Expand Up @@ -103,6 +112,20 @@ public class Settings : Object {
}
}

private InterfaceScale interface_scale_;
public InterfaceScale interface_scale {
get { return interface_scale_; }
set {
string valstr = value.to_string();
db.settings.upsert()
.value(db.settings.key, "interface_scale", true)
.value(db.settings.value, valstr)
.perform();
interface_scale_ = value;
update_interface_scale();
}
}


public signal void send_button_update(bool visible);
private bool send_button_;
Expand Down
5 changes: 3 additions & 2 deletions main/data/conversation_item_widget.ui
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<property name="row-spacing">2</property>
<child>
<object class="DinoUiAvatarPicture" id="avatar_picture">
<property name="height-request">35</property>
<property name="height-request">35</property> <!-- Size of aatars in conversation -->
<property name="width-request">35</property>
<property name="valign">start</property>
<property name="margin-top">2</property>
Expand All @@ -23,6 +23,7 @@
<property name="xalign">0</property>
<property name="valign">baseline</property>
<attributes>
<attribute name="scale" value="1"/> <!-- Size of nickname if conersation -->
<attribute name="weight" value="PANGO_WEIGHT_BOLD"/>
</attributes>
<layout>
Expand All @@ -36,7 +37,7 @@
<property name="xalign">0</property>
<property name="valign">baseline</property>
<attributes>
<attribute name="scale" value="0.8"/>
<attribute name="scale" value="0.8"/> <!-- size of message time -->
</attributes>
<style>
<class name="dim-label"/>
Expand Down
10 changes: 5 additions & 5 deletions main/data/conversation_row.ui
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<property name="margin-end">14</property>
<child>
<object class="DinoUiAvatarPicture" id="picture">
<property name="height-request">35</property>
<property name="height-request">35</property> <!-- Conversation list avatar size -->
<property name="width-request">35</property>
<property name="valign">center</property>
</object>
Expand All @@ -42,7 +42,7 @@
<property name="hexpand">False</property>
<property name="xalign">1</property>
<attributes>
<attribute name="scale" value="0.7"/>
<attribute name="scale" value="0.7"/> <!-- Conversation list last message time -->
</attributes>
</object>
</child>
Expand All @@ -63,7 +63,7 @@
</style>
<attributes>
<!--<attribute name="weight" value="bold"/>-->
<attribute name="scale" value="0.8"/>
<attribute name="scale" value="0.8"/> <!-- Converstion list last message sender name -->
</attributes>
</object>
</child>
Expand All @@ -76,7 +76,7 @@
<property name="valign">end</property>
<property name="xalign">0</property>
<attributes>
<attribute name="scale" value="0.8"/>
<attribute name="scale" value="0.8"/> <!-- Conversation list last message text -->
</attributes>
</object>
</child>
Expand All @@ -91,7 +91,7 @@
<property name="visible">False</property>
<property name="xalign">0.5</property>
<attributes>
<attribute name="scale" value="0.6"/>
<attribute name="scale" value="0.6"/> <!-- Conversation list unread message -->
<attribute name="weight" value="PANGO_WEIGHT_BOLD"/>
</attributes>
</object>
Expand Down
3 changes: 3 additions & 0 deletions main/data/quote.ui
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@
<property name="ellipsize">end</property>
<property name="halign">start</property>
<property name="xalign">0</property>
<attributes>
<attribute name="scale" value="2"/> <!-- Quote size -->
</attributes>
<layout>
<property name="column">0</property>
<property name="row">1</property>
Expand Down
53 changes: 53 additions & 0 deletions main/data/settings_dialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,59 @@
</child>
</object>
</child>
<child>
<object class="AdwPreferencesGroup">
<child>
<object class="AdwActionRow">
<property name="title" translatable="yes">Interface scale</property>
<child>
<object class="GtkBox" id="interface_scale">
<child>
<object class="GtkCheckButton" id="scale_small">
<property name="label" translatable="yes">Small</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">False</property>
<property name="active">False</property>
<property name="group">scale_small</property>
</object>
</child>
<child>
<object class="GtkCheckButton" id="scale_medium">
<property name="label" translatable="yes">Medium</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">False</property>
<property name="active">False</property>
<property name="group">scale_small</property>
</object>
</child>
<child>
<object class="GtkCheckButton" id="scale_large">
<property name="label" translatable="yes">Large</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">False</property>
<property name="active">False</property>
<property name="group">scale_small</property>
</object>
</child>
<child>
<object class="GtkCheckButton" id="scale_xlarge">
<property name="label" translatable="yes">Extra Large</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">False</property>
<property name="active">False</property>
<property name="group">scale_small</property>
</object>
</child>
</object>
</child>
</object>
</child>
</object>
</child>
</object>
</child>
</template>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,12 @@ public class ConversationItemSkeleton : Plugins.ConversationItemWidgetInterface,
set_widget(widget, Plugins.WidgetType.GTK4, 2);
}

Dino.Entities.Settings settings = Dino.Application.get_default().settings;
settings.update_interface_scale.connect(() => {
update_name_label();
update_time();
});

if (item.requires_header) {
// TODO: For MUC messags, use real jid from message if known
avatar_picture.model = new ViewModel.CompatAvatarPictureModel(stream_interactor).add_participant(conversation, item.jid);
Expand Down Expand Up @@ -174,7 +180,12 @@ public class ConversationItemSkeleton : Plugins.ConversationItemWidgetInterface,
}

private void update_time() {
Dino.Entities.Settings settings = Dino.Application.get_default().settings;
Pango.AttrList attr_list = new Pango.AttrList();
attr_list.insert(Pango.attr_scale_new(InterfaceScale.to_double(settings.interface_scale)));

time_label.label = get_relative_time(item.time.to_local()).to_string();
time_label.set_attributes(attr_list);

time_update_timeout = Timeout.add_seconds((int) get_next_time_change(item.time), () => {
if (this.main_grid.parent == null) return false;
Expand All @@ -184,7 +195,11 @@ public class ConversationItemSkeleton : Plugins.ConversationItemWidgetInterface,
}

private void update_name_label() {
Dino.Entities.Settings settings = Dino.Application.get_default().settings;
Pango.AttrList attr_list = new Pango.AttrList();
attr_list.insert(Pango.attr_scale_new(InterfaceScale.to_double(settings.interface_scale)));
name_label.label = Util.get_participant_display_name(stream_interactor, conversation, item.jid, true);
name_label.set_attributes(attr_list);
}

private void update_received_mark() {
Expand Down
11 changes: 11 additions & 0 deletions main/src/ui/conversation_content_view/message_widget.vala
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,10 @@ public class MessageItemEditMode : Box {
[GtkChild] public unowned Frame frame;

construct {
Dino.Entities.Settings settings = Dino.Application.get_default().settings;

Util.force_css(frame, "* { border-radius: 3px; padding: 0px 7px; }");
Util.force_css(frame, " .dino-chatinput { font-size: %spt; }".printf(InterfaceScale.to_css_pt(settings.interface_scale).to_string()));

EmojiChooser chooser = new EmojiChooser();
chooser.emoji_picked.connect((emoji) => {
Expand All @@ -295,6 +298,14 @@ public class MessageItemEditMode : Box {
send_button.clicked.connect(() => send());
chat_text_view.cancel_input.connect(() => cancelled());
chat_text_view.send_text.connect(() => send());

// Dino.Entities.Settings settings = Dino.Application.get_default().settings;
// settings.update_interface_scale.connect(() => {
// Pango.AttrList attr_list = new Pango.AttrList();
// attr_list.insert(Pango.attr_scale_new(InterfaceScale.to_double(settings.interface_scale)));
// chat_text_view.text_view.override_font(Pango.font_description_from_string('DejaVu Sans Mono 12'));
// });

}

private void on_text_view_changed() {
Expand Down
9 changes: 9 additions & 0 deletions main/src/ui/conversation_content_view/quote_widget.vala
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,15 @@ namespace Dino.Ui.Quote {
Label message = (Label) builder.get_object("message");
Button abort_button = (Button) builder.get_object("abort-button");

Dino.Entities.Settings settings = Dino.Application.get_default().settings;
settings.update_interface_scale.connect(() => {
Pango.AttrList attr_list = new Pango.AttrList();
attr_list.insert(Pango.attr_scale_new(InterfaceScale.to_double(settings.interface_scale)));
message.set_attributes(attr_list);
time.set_attributes(attr_list);
author.set_attributes(attr_list);
});

avatar.model = new ViewModel.CompatAvatarPictureModel(model.stream_interactor).add_participant(model.conversation, model.author_jid);
model.bind_property("display-name", author, "label", BindingFlags.SYNC_CREATE);
model.bind_property("display-time", time, "label", BindingFlags.SYNC_CREATE);
Expand Down
Loading

0 comments on commit 639135b

Please sign in to comment.