Lots of style improvements

This commit is contained in:
2022-12-18 23:13:52 -08:00
parent 5e2e9e2752
commit 9aa5741e1a
5 changed files with 53 additions and 33 deletions

View File

@@ -3,7 +3,7 @@ using Adw 1;
Adw.ApplicationWindow mainWindow { Adw.ApplicationWindow mainWindow {
title: "Wince"; title: "Wince";
default-width: 400; default-width: 600;
default-height: 500; default-height: 500;
Gtk.Box { Gtk.Box {
@@ -15,7 +15,9 @@ Adw.ApplicationWindow mainWindow {
orientation: horizontal; orientation: horizontal;
margin-top: 10; margin-top: 10;
margin-start: 14; margin-start: 14;
margin-bottom: 14;
margin-end: 14; margin-end: 14;
halign: center;
styles ["linked"] styles ["linked"]
@@ -30,14 +32,19 @@ Adw.ApplicationWindow mainWindow {
} }
} }
Gtk.ScrolledWindow { Gtk.ScrolledWindow scrollWindow {
vexpand: true; vexpand: true;
visible: false;
Gtk.ListBox searchResults { Gtk.ListBox searchResults {}
margin-top: 14; }
margin-start: 14;
margin-end: 14; Gtk.Label poweredByText {
} halign: center;
valign: center;
vexpand: true;
use-markup: true;
label: "<span foreground=\"gray\" style=\"italic\">Wince is powered by Yelp</span>";
} }
} }
} }

View File

@@ -2,26 +2,28 @@ using Gtk 4.0;
using Adw 1; using Adw 1;
template Wince-BusinessRow : Gtk.ListBoxRow { template Wince-BusinessRow : Gtk.ListBoxRow {
styles ["card"]
margin-bottom: 14;
Gtk.Box { Gtk.Box {
orientation: vertical; orientation: vertical;
margin-start: 8; margin-start: 24;
margin-top: 8; margin-top: 12;
margin-bottom: 12;
Gtk.Label businessName { Gtk.Label businessName {
styles ["heading"] styles ["heading"]
xalign: 0; xalign: 0;
} }
Gtk.Label businessRating { Gtk.Box {
xalign: 0; orientation: horizontal;
}
Gtk.Label businessHours {
xalign: 0;
}
Gtk.LinkButton businessWebsite {
halign: start; halign: start;
spacing: 12;
Gtk.Label businessOpen {
}
Gtk.Label businessRating {
}
Gtk.Label businessDistance {
}
} }
} }
} }

View File

@@ -1,26 +1,30 @@
module Wince module Wince
@[Gtk::UiTemplate(resource: "/wince/ui/compiled/templates.ui", children: %w(businessName businessRating businessHours businessWebsite))] @[Gtk::UiTemplate(resource: "/wince/ui/compiled/templates.ui", children: %w(businessName businessRating businessOpen businessDistance))]
class BusinessRow < Gtk::ListBoxRow class BusinessRow < Gtk::ListBoxRow
include Gtk::WidgetTemplate include Gtk::WidgetTemplate
@name : Gtk::Label @name : Gtk::Label
@rating : Gtk::Label @rating : Gtk::Label
@hours : Gtk::Label @open : Gtk::Label
@website : Gtk::LinkButton @distance : Gtk::Label
def initialize(name : String, rating : String, hours : String, website : String) def initialize(name : String, rating : Float32, open : Bool, distance : Float32)
super() super()
@name = Gtk::Label.cast(template_child("businessName")) @name = Gtk::Label.cast(template_child("businessName"))
@rating = Gtk::Label.cast(template_child("businessRating")) @rating = Gtk::Label.cast(template_child("businessRating"))
@hours = Gtk::Label.cast(template_child("businessHours")) @open = Gtk::Label.cast(template_child("businessOpen"))
@website = Gtk::LinkButton.cast(template_child("businessWebsite")) @distance = Gtk::Label.cast(template_child("businessDistance"))
@name.text = name @name.text = name
@rating.text = rating @rating.text = rating.round(2).to_s
@hours.text = hours if open
@website.uri = website @open.markup = "<span foreground=\"green\">open</span>"
@website.label = "view on yelp" else
@open.markup = "<span foreground=\"red\">closed</span>"
end
distance_miles = distance / 1609.344
@distance.text = distance_miles.round(2).to_s + "mi"
end end
end end
end end

View File

@@ -28,11 +28,11 @@ module Wince
businesses.map do |business| businesses.map do |business|
name = business["name"].as_s? || "" name = business["name"].as_s? || ""
rating = business["rating"].as_f.to_s rating = business["rating"].as_f32
hours = business["is_closed"].as_bool.to_s open = business["is_closed"].as_bool
website = business["url"].as_s? || "" distance = business["distance"].as_f32
BusinessRow.new(name, rating, hours, website) BusinessRow.new(name, rating, open, distance)
end end
end end
@@ -44,10 +44,15 @@ module Wince
search = SEARCH_ENTRY.buffer.text search = SEARCH_ENTRY.buffer.text
location = LOCATION_ENTRY.buffer.text location = LOCATION_ENTRY.buffer.text
if !search || !location if search.blank? || location.blank?
SCROLL_VIEW.visible = false
POWERD_BY_TEXT.visible = true
return return
end end
SCROLL_VIEW.visible = true
POWERD_BY_TEXT.visible = false
response = Yelp.search_businesses(search, location) response = Yelp.search_businesses(search, location)
if response.status_code != 200 if response.status_code != 200

View File

@@ -10,6 +10,8 @@ module Wince
LOCATION_ENTRY = Gtk::Entry.cast(B_UI["locationEntry"]) LOCATION_ENTRY = Gtk::Entry.cast(B_UI["locationEntry"])
SEARCH_BUTTON = Gtk::Button.cast(B_UI["searchButton"]) SEARCH_BUTTON = Gtk::Button.cast(B_UI["searchButton"])
BUSINESS_LIST = Gtk::ListBox.cast(B_UI["searchResults"]) BUSINESS_LIST = Gtk::ListBox.cast(B_UI["searchResults"])
POWERD_BY_TEXT = Gtk::Label.cast(B_UI["poweredByText"])
SCROLL_VIEW = Gtk::ScrolledWindow.cast(B_UI["scrollWindow"])
APP = Adw::Application.new("dev.wince", Gio::ApplicationFlags::None) APP = Adw::Application.new("dev.wince", Gio::ApplicationFlags::None)
end end